Difference between revisions of "Projects/Nepomuk/VirtuosoInternal"

Jump to: navigation, search
(Example)
(Marked this version for translation)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Connecting directly to virtuoso =
+
<languages />
 +
<translate>
  
Virtuoso ships with an executable called <code>isql-vt</code>. Just running that executable should connect you to virtuoso.
+
== Connecting directly to virtuoso == <!--T:1-->
  
 +
<!--T:2-->
 +
Virtuoso ships with an executable called <tt>isql-vt</tt>. Just running that executable should connect you to virtuoso.
 +
 +
<!--T:3-->
 
If you distribution does not provide the corresponding executable or if it doesn't work for you. Try this script -
 
If you distribution does not provide the corresponding executable or if it doesn't work for you. Try this script -
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Line 11: Line 16:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
= Running queries directly =
+
== Running queries directly == <!--T:4-->
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. Make sure the query has the required prefixes and starts with the keyword <tt>sparql</tt> if it is a sparql query.
+
  
I've attached a list of common prefixes for convenience -
+
<!--T:5-->
<syntaxhighlight lang="text">
+
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.
prefix nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#>  
+
 
prefix nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#>  
+
=== Example === <!--T:6-->
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#>
+
</syntaxhighlight>
+
  
=== Example ===
+
<!--T:7-->
 
<syntaxhighlight lang="sql">
 
<syntaxhighlight lang="sql">
SQL> sparql prefix nco: <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#> select ?r ?name where { ?r nco:fullname ?name . };
+
SQL> sparql select ?r ?name where { ?r nco:fullname ?name . };
 
</syntaxhighlight>
 
</syntaxhighlight>
  
= List of tables =
+
== List of tables == <!--T:8-->
is a relational database and what not
+
  
All the tables in Virtuoso start with the <code>DB.DBA.</code> prefix.
+
<!--T:9-->
 +
Virtuoso internally uses a relational database to store the triples. It contains the following tables -
  
* 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.
+
<!--T:10-->
*
+
* 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
  
= Default Indexes =
+
<!--T:11-->
 +
Read http://docs.openlinksw.com/virtuoso/rdfdatarepresentation.html to properly understand how virtuoso stores the data internally.
  
= Common Commands =
+
<!--T:12-->
 +
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 == <!--T:13-->
 +
 
 +
== Common Commands == <!--T:14-->
 +
 
 +
<!--T:15-->
 
Apart from directly running SQL and SPARQL queries, virtuoso also provides some additional commands, which are listed over here.
 
Apart from directly running SQL and SPARQL queries, virtuoso also provides some additional commands, which are listed over here.
  
== status ==
+
=== status === <!--T:16-->
== sparql_to_sql_text ==
+
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 === <!--T:17-->
  
 +
<!--T:18-->
 
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.
 
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.
  
 +
<!--T:19-->
 
<syntaxhighlight lang="sql">
 
<syntaxhighlight lang="sql">
 
varchar sparql_to_sql_text
 
varchar sparql_to_sql_text
Line 59: Line 70:
  
  
 +
<!--T:20-->
 
Example -
 
Example -
 
<syntaxhighlight lang="sql">
 
<syntaxhighlight lang="sql">
Line 66: Line 78:
 
_______________________________________________________________________________
 
_______________________________________________________________________________
  
 +
<!--T:21-->
 
SELECT __id2i ( "s_1_0-t0"."S" ) AS "r",
 
SELECT __id2i ( "s_1_0-t0"."S" ) AS "r",
 
   __ro2sq ( "s_1_0-t0"."O" ) AS "name"
 
   __ro2sq ( "s_1_0-t0"."O" ) AS "name"
Line 72: Line 85:
 
OPTION (QUIETCAST)
 
OPTION (QUIETCAST)
  
 +
<!--T:22-->
 
1 Rows. -- 1 msec.
 
1 Rows. -- 1 msec.
 
</syntaxhighlight>
 
</syntaxhighlight>
  
  
 +
<!--T:23-->
 
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.
 +
 +
<!--T:24-->
 +
[[Category:Documentation]]
 +
[[Category:Development]]
 +
[[Category:Tutorials]]
 +
</translate>

Latest revision as of 17:34, 13 December 2012

Other languages:English 100%

Contents

[edit] 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

[edit] 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.

[edit] Example

SQL> sparql SELECT ?r ?name WHERE { ?r nco:fullname ?name . };

[edit] 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.

[edit] Default Indexes

[edit] Common Commands

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

[edit] status

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


[edit] 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.


This page was last modified on 13 December 2012, at 17:34. This page has been accessed 3,112 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal