VirtJenaProvider Virtuoso Jena Provider 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 and 3.0.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.Note: You must use a matching set of Jena Provider and JDBC Driver. The Jena Provider for Jena 2.6 requires the Virtuoso JDBC 3 Driver. The Jena Provider for Jena 2.1x.x and 3.0.x requires the Virtuoso JDBC 4 Driver. The version of the Jena Provider (virt_jena.jar) can be verified thus: $ java -jar virt_jena3.jar OpenLink Virtuoso(TM) Provider for Jena(TM) Version 3.0.0 [Build 1.25] $ java -jar ./virt_jena2.jar OpenLink Virtuoso(TM) Provider for Jena(TM) Version 2.10.1 [Build 1.10] $ java -jar ./virt_jena.jar OpenLink Virtuoso(TM) Provider for Jena(TM) Version 2.6.2 [Build 1.10] Files contained in the zip files are generally older than specifically linked downloads (e.g., the Virtuoso JDBC Driver, virtjdbc3.jar), so don't replace if prompted during extraction. Instead, rename the file extracted from the zip, and compare their versions to be sure you keep only the most recent. $ java -cp ./virtjdbc3.jar virtuoso.jdbc3.Driver OpenLink Virtuoso(TM) Driver for JDBC(TM) Version 3.x [Build 3.62] $ java -cp ./virtjdbc3.fromzip.jar virtuoso.jdbc3.Driver OpenLink Virtuoso(TM) Driver for JDBC(TM) Version 3.x [Build 3.11] Compiling Jena Sample Programs 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 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 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 icu4j_3_4.jar iri.jar xercesImpl.jar axis.jar commons-logging-1.1.1.jar jena.jar arq.jar virtjdbc3.jar virt_jena.jar Jena 2.7 jena-arq-2.9.4.jar jena-iri-0.9.4.jar jena-core-2.7.4.jar jcl-over-slf4j-1.6.4.jar log4j-1.2.16.jarslf4j-api-1.6.4.jar slf4j-log4j12-1.6.4.jar xercesImpl-2.10.0.jar xml-apis-1.4.01.jar commons-lang3-3.4.jar virtjdbc4.jar virt_jena2.jar Jena 2.1x.x junit-4.5.jar jena-arq-2.10.1.jar jena-iri-0.9.6.jar jena-core-2.10.1.jar jena-core-2.10.1-tests.jar jcl-over-slf4j-1.6.4.jar log4j-1.2.16.jar slf4j-api-1.6.4.jar slf4j-log4j12-1.6.4.jar xercesImpl-2.11.0.jar xml-apis-1.4.01.jar virtjdbc4.jar virt_jena2.jar Jena 3.0.x junit-4.5.jar commons-lang3-3.3.2.jar jena-arq-3.0.0.jar jena-iri-3.0.0.jar jena-base-3.0.0.jar jena-core-3.0.0.jar jena-core-3.0.0-tests.jar jcl-over-slf4j-1.7.12.jar log4j-1.2.17.jar slf4j-api-1.7.12.jar slf4j-log4j12-1.7.12.jar xercesImpl-2.11.0.jar xml-apis-1.4.01.jar jena-shaded-guava-3.0.0.jar virtjdbc4.jar virt_jena3.jar 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 Example 1 returns the contents of the RDF Quad store of the targeted Virtuoso instance, with the following command: java VirtuosoSPARQLExample1 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 Example 3 performs simple addition and deletion operation on the content of the triple store, with the following command: java VirtuosoSPARQLExample3 Example 4 demonstrates the use of the graph.contains method for searching triples, with the following command: java VirtuosoSPARQLExample4 Example 5 demonstrates the use of the graph.find method for searching triples, with the following command: java VirtuosoSPARQLExample5 Example 6 demonstrates the use of the graph.getTransactionHandler method, with the following command: java VirtuosoSPARQLExample6 Example 7 demonstrates the use of the graph.getBulkUpdateHandler method, with the following command: java VirtuosoSPARQLExample7 Example 8 demonstrates how to insert triples into a graph, with the following command: java VirtuosoSPARQLExample8 Example 9 demonstrates the use of the CONSTRUCT, DESCRIBE, and ASK SPARQL query forms, with the following command: java VirtuosoSPARQLExample9 Example 12 demonstrates the execution of a SPARQL query against a virtuoso url and prints results, with the following command: java VirtuosoSPARQLExample12 Example 13 demonstrates the use of inference rules with the following command: java VirtuosoSPARQLExample13 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: Javadoc API Documentation for the Jena 2.6 Provider Javadoc API Documentation for the Jena 2.10+ 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