Projects/Nepomuk/VirtuosoInternal: Difference between revisions

From KDE TechBase
(Removed page from translation)
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Connecting directly to virtuoso =


via isql
== Connecting directly to virtuoso ==


= List of tables =
Virtuoso ships with an executable called <tt>isql-vt</tt>. Just running that executable should connect you to virtuoso.
is a relational database and what not


All the tables in Virtuoso start with the <code>DB.DBA.</code> prefix.
If you distribution does not provide the corresponding executable or if it doesn't work for you. Try this script -
<syntaxhighlight lang="bash">
#!/bin/bash
filename=`ps aux | grep virtuoso-t | grep -v grep | sed -e 's/.*\/tmp\///;s/ini.*/ini/'`
port=$(grep ServerPort /tmp/$filename | sed -e 's/.*=//')
exec isql-vt -S $port
</syntaxhighlight>
 
== Running queries directly ==
 
If for some reason you want to run queries directly on virtuoso, you'll need to connect to virtuoso via <tt>isql-vt</tt> and then type in the query. From 4.10, we use virtuoso's inbuilt prefix expansion, so you don't need to care about the prefixes.


* RDF_QUAD -- The main table which contains all the statements. It contains four rows "S", "P", "O" and "G" for the subject, predicate, object and graph.
=== Example ===
*


= Default Indexes =
<syntaxhighlight lang="sql">
SQL> sparql select ?r ?name where { ?r nco:fullname ?name . };
</syntaxhighlight>


= Common Commands =
== List of tables ==
== status ==
== sparql_to_sql_text ==


The sparql_to_sql_text() function can be used to convert a SPARQL query directly to the SQL it would be executed as.
Virtuoso internally uses a relational database to store the triples. It contains the following tables -
 
* DB.DBA.RDF_QUAD -- The main table which contains all the statements. It contains four rows "S", "P", "O" and "G" for the subject, predicate, object and graph.
* DB.DBA.RDF_IRI
* DB.DBA.RDF_DATATYPE - Contains all the literal data types which are stored.
* DB.DBA.RDF_PREFIX
* DB.DBA.RDF_OBJ
* DB.DBA.RDF_LANGUAGE
 
Read http://docs.openlinksw.com/virtuoso/rdfdatarepresentation.html to properly understand how virtuoso stores the data internally.
 
Virtuoso has 2 main types - IRI_ID, which is the data type of the graph, subject and predicate. IRI_ID are of the form "#i25". In order to convert an integer to an IRI_ID, use the '''iri_id_from_num( int )''' function, and the '''iri_id_num( iri_id )''' to convert an IRI_ID to an integer. In order to convert an IRI_ID to its string representation use the following functions '''id_to_iri( iri_id, int )''', and '''iri_to_id( string, int )'''. The second integer option should be 0, unless you want the iri/id to be created if it doesn't exist.
 
== Default Indexes ==
 
== Common Commands ==
 
Apart from directly running SQL and SPARQL queries, virtuoso also provides some additional commands, which are listed over here.
 
=== status ===
The [http://docs.openlinksw.com/virtuoso/fn_status.html status()] function can be used to return the current running queries on virtuoso.
 
 
=== sparql_to_sql_text ===
 
The [http://docs.openlinksw.com/virtuoso/fn_sparql_to_sql_text.html sparql_to_sql_text()] function can be used to convert a SPARQL query directly to the SQL it would be executed as.


<syntaxhighlight lang="sql">
<syntaxhighlight lang="sql">
varchar sparql_to_sql_text
varchar sparql_to_sql_text
( in squery varchar );  
( in squery varchar );  
</syntaxhighlight>
Example -
<syntaxhighlight lang="sql">
SQL> select sparql_to_sql_text('prefix nco: <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#> select ?r ?name where { ?r nco:fullname ?name . }');
SPARQL_TO_SQL_TEXT
VARCHAR
_______________________________________________________________________________
SELECT __id2i ( "s_1_0-t0"."S" ) AS "r",
  __ro2sq ( "s_1_0-t0"."O" ) AS "name"
FROM DB.DBA.RDF_QUAD AS "s_1_0-t0"
WHERE "s_1_0-t0"."P" = __i2idn ( __bft( 'http://www.semanticdesktop.org/ontologies/2007/03/22/nco#fullname' , 1))
OPTION (QUIETCAST)
1 Rows. -- 1 msec.
</syntaxhighlight>
</syntaxhighlight>


Line 27: Line 76:
It's very useful in debugging why many sparql queries are taking so long.
It's very useful in debugging why many sparql queries are taking so long.


http://docs.openlinksw.com/virtuoso/fn_sparql_to_sql_text.html
[[Category:Documentation]]
[[Category:Development]]
[[Category:Tutorials]]

Latest revision as of 12:32, 9 February 2018

Connecting directly to virtuoso

Virtuoso ships with an executable called isql-vt. Just running that executable should connect you to virtuoso.

If you distribution does not provide the corresponding executable or if it doesn't work for you. Try this script -

#!/bin/bash
filename=`ps aux | grep virtuoso-t | grep -v grep | sed -e 's/.*\/tmp\///;s/ini.*/ini/'`
port=$(grep ServerPort /tmp/$filename | sed -e 's/.*=//')
exec isql-vt -S $port

Running queries directly

If for some reason you want to run queries directly on virtuoso, you'll need to connect to virtuoso via isql-vt and then type in the query. From 4.10, we use virtuoso's inbuilt prefix expansion, so you don't need to care about the prefixes.

Example

SQL> sparql select ?r ?name where { ?r nco:fullname ?name . };

List of tables

Virtuoso internally uses a relational database to store the triples. It contains the following tables -

  • DB.DBA.RDF_QUAD -- The main table which contains all the statements. It contains four rows "S", "P", "O" and "G" for the subject, predicate, object and graph.
  • DB.DBA.RDF_IRI
  • DB.DBA.RDF_DATATYPE - Contains all the literal data types which are stored.
  • DB.DBA.RDF_PREFIX
  • DB.DBA.RDF_OBJ
  • DB.DBA.RDF_LANGUAGE

Read http://docs.openlinksw.com/virtuoso/rdfdatarepresentation.html to properly understand how virtuoso stores the data internally.

Virtuoso has 2 main types - IRI_ID, which is the data type of the graph, subject and predicate. IRI_ID are of the form "#i25". In order to convert an integer to an IRI_ID, use the iri_id_from_num( int ) function, and the iri_id_num( iri_id ) to convert an IRI_ID to an integer. In order to convert an IRI_ID to its string representation use the following functions id_to_iri( iri_id, int ), and iri_to_id( string, int ). The second integer option should be 0, unless you want the iri/id to be created if it doesn't exist.

Default Indexes

Common Commands

Apart from directly running SQL and SPARQL queries, virtuoso also provides some additional commands, which are listed over here.

status

The status() function can be used to return the current running queries on virtuoso.


sparql_to_sql_text

The sparql_to_sql_text() function can be used to convert a SPARQL query directly to the SQL it would be executed as.

varchar sparql_to_sql_text
( in squery varchar );


Example -

SQL> select sparql_to_sql_text('prefix nco: <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#> select ?r ?name where { ?r nco:fullname ?name . }');
SPARQL_TO_SQL_TEXT
VARCHAR
_______________________________________________________________________________

SELECT __id2i ( "s_1_0-t0"."S" ) AS "r",
  __ro2sq ( "s_1_0-t0"."O" ) AS "name"
FROM DB.DBA.RDF_QUAD AS "s_1_0-t0"
WHERE "s_1_0-t0"."P" = __i2idn ( __bft( 'http://www.semanticdesktop.org/ontologies/2007/03/22/nco#fullname' , 1))
OPTION (QUIETCAST)

1 Rows. -- 1 msec.


It's very useful in debugging why many sparql queries are taking so long.