Projects/Nepomuk/VirtuosoInternal: Difference between revisions

From KDE TechBase
(Added running queries manually)
(10 intermediate revisions by the same user not shown)
Line 16: Line 16:
I've attached a list of common prefixes for convenience -
I've attached a list of common prefixes for convenience -
<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
prefix nao:     <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> .
prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#>  
prefix nfo:     <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#> .
prefix nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#>  
prefix nie:     <http://www.semanticdesktop.org/ontologies/2007/01/19/nie#> .
prefix nie: <http://www.semanticdesktop.org/ontologies/2007/01/19/nie#>  
prefix ncal:   <http://www.semanticdesktop.org/ontologies/2007/04/02/ncal#> .
prefix ncal: <http://www.semanticdesktop.org/ontologies/2007/04/02/ncal#>  
prefix nco:     <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#> .
prefix nco: <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#>  
prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>  
prefix pimo:   <http://www.semanticdesktop.org/ontologies/2007/11/01/pimo#> .
prefix pimo: <http://www.semanticdesktop.org/ontologies/2007/11/01/pimo#>  
prefix nmo:     <http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#> .
prefix nmo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#>  
prefix nmm:     <http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#> .
prefix nmm: <http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#>  
prefix nrl:     <http://www.semanticdesktop.org/ontologies/2007/08/15/nrl#> .
prefix nrl: <http://www.semanticdesktop.org/ontologies/2007/08/15/nrl#>  
prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  
prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
prefix xsd: <http://www.w3.org/2001/XMLSchema#>  
</syntaxhighlight>
 
=== Example ===
<syntaxhighlight lang="sql">
SQL> sparql prefix nco: <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#> select ?r ?name where { ?r nco:fullname ?name . };
</syntaxhighlight>
</syntaxhighlight>


Line 36: Line 41:


* 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.
* 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.
*
* RDF_DATATYPE - Contains all the literal data types which are stored.
* RDF_PREFIX
* RDF_OBJ
* RDF_LANGUAGE
 
Read http://docs.openlinksw.com/virtuoso/rdfdatarepresentation.html to properly understand how virtuoso stores the data internally.


= Default Indexes =
= Default Indexes =
Line 44: Line 54:


== status ==
== 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 ==
== 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.
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>




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

Revision as of 10:15, 21 September 2012

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. Make sure the query has the required prefixes and starts with the keyword sparql if it is a sparql query.

I've attached a list of common prefixes for convenience -

prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> 
prefix nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#> 
prefix nie: <http://www.semanticdesktop.org/ontologies/2007/01/19/nie#> 
prefix ncal: <http://www.semanticdesktop.org/ontologies/2007/04/02/ncal#> 
prefix nco: <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#> 
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
prefix pimo: <http://www.semanticdesktop.org/ontologies/2007/11/01/pimo#> 
prefix nmo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#> 
prefix nmm: <http://www.semanticdesktop.org/ontologies/2009/02/19/nmm#> 
prefix nrl: <http://www.semanticdesktop.org/ontologies/2007/08/15/nrl#> 
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
prefix xsd: <http://www.w3.org/2001/XMLSchema#>

Example

SQL> sparql prefix nco: <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#> select ?r ?name where { ?r nco:fullname ?name . };

List of tables

is a relational database and what not

All the tables in Virtuoso start with the DB.DBA. prefix.

  • 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.
  • RDF_DATATYPE - Contains all the literal data types which are stored.
  • RDF_PREFIX
  • RDF_OBJ
  • RDF_LANGUAGE

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

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.