Exploiting the Benefits of Reasoning & Inference using various RDF Frameworks and OpenLink Virtuoso 8.x

Using Jena and/or RDF4J/Sesame to exploit Custom Reasoning & Inference Functionality in Virtuoso 8.x

Hugh Williams
OpenLink Virtuoso Weblog
4 min readNov 21, 2017

--

Today’s enterprise and academic developers are very comfortable with Java and JDBC, which naturally leads them to Java-based frameworks such as Apache Jena™ (Jena™) and Eclipse RDF4J™ (RDF4J™, formerly OpenRDF Sesame™) when developing applications that leverage data represented as collections of RDF statements.

This post demonstrates use of the Reasoning & Inference capabilities of Virtuoso 8.x through both the Jena and RDF4J frameworks.

Virtuoso 8.x Reasoning & Inference

Among its many features, OpenLink Virtuoso™ is an RDF quad-store (sometimes treated as a triple-store), with powerful reasoning & inference functionality which can use built-in or custom inference rules, which may range from very simple to extremely complex.

Virtuoso offers high-performance data access and scalability that’s accessible to Java applications, services, and frameworks via JDBC connectivity.

Virtuoso also provides custom Java-based adapters (functioning as abstractions built atop its JDBC layer) for use with frameworks such as Jena and RDF4J. When working with these connectors, users may choose to exploit the built-in reasoning functionality provided by these frameworks, or to push the demands of that functionality from client-side (RDF4J, Jena, etc.) to the server-side (i.e., Virtuoso hosted).

Usage Examples

The examples that follow reuse data from prior posts about Virtuoso 8.0 reasoning and inference, i.e., a dataset that describes a sampling of relationship types across the British Royal Family. All inference in these examples is done by the Virtuoso server; no inference is done by the client-side frameworks.

Jena 3

Download the sample program zip file and extract to your directory of choice with the command unzip jena3_spin_example.zip.

$ unzip jena3_spin_example.zip
Archive: jena3_spin_example.zip
creating: jena3_spin_example/
extracting: jena3_spin_example/run.bat
creating: jena3_spin_example/src/
inflating: jena3_spin_example/gradlew
inflating: jena3_spin_example/readme.txt
creating: jena3_spin_example/gradle/
inflating: jena3_spin_example/settings.gradle
creating: jena3_spin_example/lib/
inflating: jena3_spin_example/spin_setup.sqlj
inflating: jena3_spin_example/build.gradle
inflating: jena3_spin_example/gradlew.bat
creating: jena3_spin_example/src/main/
creating: jena3_spin_example/src/main/java/
inflating: jena3_spin_example/src/main/java/Main.java
creating: jena3_spin_example/gradle/wrapper/
inflating: jena3_spin_example/gradle/wrapper/gradle-wrapper.properties
inflating: jena3_spin_example/gradle/wrapper/gradle-wrapper.jar
inflating: jena3_spin_example/lib/virtjdbc4_2.jar
inflating: jena3_spin_example/lib/virt_jena3.jar
$

The sample program uses the open source Gradle build automation tools to compile and run the sample program, as detailed in the included readme.txt file:

1) Use this command to compile the sample program:      gradlew clean build2) Use this command to run the sample program:      gradlew run
**NOTE 1**
The example connects to a Virtuoso instance on
localhost port 1111, with userid and password
both "dba". To connect to a different Virtuoso
server instance or use different credentials,
you will need to edit the file "build.gradle",
and change the args ['{hostname or IP address}',
'{port number}', '{username}', '{password}'] to
suit your target instance.
...
run {
args = ['localhost', '1111', 'dba', 'dba']
}
...

**NOTE 2**
Most of the demo's requirements are contained in
the zip file. gradle will automatically download
any missing dependencies when the demo is run for
the first time, so you’ll need an active internet
connection at that time.

The output of building and running the sample program is shown below:

Using RDF4J

Download the sample program zip file and extract to your directory of choice with the command unzip rdf4j_spin_sample.zip.

$ unzip rdf4j_spin_sample.zip
Archive: rdf4j_spin_sample.zip
creating: rdf4j_spin_sample/
creating: rdf4j_spin_sample/.gradle/
creating: rdf4j_spin_sample/.gradle/3.2.1/
creating: rdf4j_spin_sample/.gradle/3.2.1/taskArtifacts/
inflating: rdf4j_spin_sample/.gradle/3.2.1/taskArtifacts/fileHashes.bin
inflating: rdf4j_spin_sample/.gradle/3.2.1/taskArtifacts/fileSnapshots.bin
inflating: rdf4j_spin_sample/.gradle/3.2.1/taskArtifacts/taskArtifacts.bin
inflating: rdf4j_spin_sample/.gradle/3.2.1/taskArtifacts/taskArtifacts.lock
inflating: rdf4j_spin_sample/build.gradle
creating: rdf4j_spin_sample/gradle/
creating: rdf4j_spin_sample/gradle/wrapper/
inflating: rdf4j_spin_sample/gradle/wrapper/gradle-wrapper.jar
inflating: rdf4j_spin_sample/gradle/wrapper/gradle-wrapper.properties
inflating: rdf4j_spin_sample/gradlew
inflating: rdf4j_spin_sample/gradlew.bat
creating: rdf4j_spin_sample/lib/
inflating: rdf4j_spin_sample/lib/virt_rdf4j.jar
inflating: rdf4j_spin_sample/lib/virtjdbc4_2.jar
inflating: rdf4j_spin_sample/readme.txt
inflating: rdf4j_spin_sample/settings.gradle
inflating: rdf4j_spin_sample/spin_setup.sqlj
creating: rdf4j_spin_sample/src/
creating: rdf4j_spin_sample/src/main/
creating: rdf4j_spin_sample/src/main/java/
inflating: rdf4j_spin_sample/src/main/java/Main.java
$

The sample program uses the open source Gradle build automation tools to compile and run the sample program, as detailed in the included readme.txt file:

1) Use this command to compile the sample program:      gradlew clean build2) Use this command to run the sample program:      gradlew run
**NOTE 1**
The example connects to a Virtuoso instance on
localhost port 1111, with userid and password
both "dba". To connect to a different Virtuoso
server instance or use different credentials,
you will need to edit the file "build.gradle",
and change the args ['{hostname or IP address}',
'{port number}', '{username}', '{password}'] to
suit your target instance.
...
run {
args = ['localhost', '1111', 'dba', 'dba']
}
...

**NOTE 2**
Most of the demo's requirements are contained in
the zip file. gradle will automatically download
any missing dependencies when the demo is run for
the first time, so you’ll need an active internet
connection at that time.

The output of building and running the sample program is shown below:

Conclusion

As demonstrated in this post, a Java developer can take full advantage of frameworks such as Jena and RDF4J while using Virtuoso as the backend RDBMS or Quad Store. The fact that Virtuoso was written in ‘C’ is a powerful virtue that’s exploitable via Java application developers without any impedance regarding preferences and best practices.

Driver/Provider Downloads

Related

--

--