Virtuoso Jena Provider

What is Jena?

Jena is an open source Semantic Web framework for Java. It provides an API to extract data from and write to RDF graphs. The graphs are represented as an abstract "model". A model can be sourced with data from files, databases, URIs or a combination of these. A Model can also be queried through SPARQL and updated through SPARUL.

What is the Virtuoso Jena Provider?

The Virtuoso Jena RDF Data Provider is a fully operational Native Graph Model Storage Provider for the Jena Framework, which enables Semantic Web applications written using the Jena RDF Frameworks to directly query the Virtuoso RDF Quad Store. Providers are available for the latest Jena 2.6.x - 2.13.x, 3.0.x and 4.3.x versions.



Setup

Prerequisites

Download the latest Virtuoso Jena Provider for your Jena framework version, Virtuoso JDBC Driver, Jena Framework, and associated classes and sample programs.

Compiling Jena Sample Programs

  1. Edit the sample programs VirtuosoSPARQLExampleX.java, where X = {1,2,3,4,5,6,7,8,9,13,14}. Set the JDBC connection strings therein to point to a valid Virtuoso Server instance, using the form:

    "jdbc:virtuoso://<virtuoso-hostname-or-IP-address>[:<data port>]/charset=UTF-8/log_enable=2", "<username>", "<password>"

    For example,

    "jdbc:virtuoso://localhost:1111/charset=UTF-8/log_enable=2", "dba", "dba"

    • Use charset=UTF-8 to ensure compatibility with non-Western codepages or character sets such as Cyrillic
    • Use log_enable=2 to turn on row-level autocommit, important when processing large RDF data sets
  2. Ensure your active CLASSPATH includes full paths to all of the following files
    • Required Jena jar file for the version being used, as indicated in the Testing section next
    • virt_jenaX.jar - Virtuoso Jena Provider for the required version
    • virtjdbcX.jar - Virtuoso JDBC Driver for the required version
  3. Compile the Jena Sample applications using the following command:

    javac VirtuosoSPARQLExample*.java

Testing

Once the Provider classes and sample program have been successfully compiled, the Provider can be tested using the included sample programs.

Prerequisites

Ensure your active CLASSPATH includes the full path to the directory containing the compiled VirtuosoSPARQLExample?*.class files, as well as to each of the following files depending on Jena version in use --

Jena 2.6

Jena 2.7

Jena 2.1x.x

Jena 3.x

Jena 4.3.x

If you've extracted the zips into the same directory where you compiled the example files, a command like this should do the job --


export CLASSPATH=`pwd`:`pwd`/*.jar:$CLASSPATH

The Tests

  1. Example 1 returns the contents of the RDF Quad store of the targeted Virtuoso instance, with the following command:

    java VirtuosoSPARQLExample1

  2. Example 2 reads in the contents of the following FOAF URIs --

    http://kidehen.idehen.net/dataspace/person/kidehen#this http://www.w3.org/People/Berners-Lee/card#i http://demo.openlinksw.com/dataspace/person/demo#this

    -- and returns the RDF data stored, with the following command:

    java VirtuosoSPARQLExample2

  3. Example 3 performs simple addition and deletion operation on the content of the triple store, with the following command:

    java VirtuosoSPARQLExample3

  4. Example 4 demonstrates the use of the graph.contains method for searching triples, with the following command:

    java VirtuosoSPARQLExample4

  5. Example 5 demonstrates the use of the graph.find method for searching triples, with the following command:

    java VirtuosoSPARQLExample5

  6. Example 6 demonstrates the use of the graph.getTransactionHandler method, with the following command:

    java VirtuosoSPARQLExample6

  7. Example 7 demonstrates the use of the graph.getBulkUpdateHandler method, with the following command:

    java VirtuosoSPARQLExample7

  8. Example 8 demonstrates how to insert triples into a graph, with the following command:

    java VirtuosoSPARQLExample8

  9. Example 9 demonstrates the use of the CONSTRUCT, DESCRIBE, and ASK SPARQL query forms, with the following command:

    java VirtuosoSPARQLExample9

  10. Example 12 demonstrates the execution of a SPARQL query against a virtuoso url and prints results, with the following command:

    java VirtuosoSPARQLExample12

  11. Example 13 demonstrates the use of inference rules with the following command:

    java VirtuosoSPARQLExample13

  12. Example 14 demonstrates the use of the Jena in memory Inference and Ontology Model rules with the following command:

    java VirtuosoSPARQLExample14

Javadoc API Documentation

Javadocs covers the complete set of classes, interfaces, and methods implemented by the provider:

Notes

Bypass Jena/ARQ parser

To use Virtuoso-specific SPARQL extensions (such as bif:contains), queries must bypass the Jena/ARQ parser and go straight to the Virtuoso server. This is done by using the VirtuosoQueryExecutionFactory.create() method, instead of and without the Jena-specific QueryFactory.create() method, which always invokes the Jena/ARQ parser, which in turn rejects any Virtuoso-specific extensions. Thus one would execute a query as follows to bypass the Jena parser --


VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create (query, set);
vqe.execSelect();

-- rather than --


Query sparql = QueryFactory.create(query);
VirtuosoQueryExecution vqe = VirtuosoQueryExecutionFactory.create (sparql, set);
vqe.execSelect();

CategoryRDF CategoryOpenSource CategoryVirtuoso CategoryVOS CategoryJena CategoryDocumentation