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

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.

Using 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 build
2) 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:

$ sh gradlew clean build
:clean UP-TO-DATE
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:startScripts
:distTar
:distZip
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 3.017 secs


$ sh gradlew run
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:run
Start loadind data to DB
End loadind data to DB


===========[Query1]==========
 PREFIX  rel:  <http://purl.org/vocab/relationship/>
 WITH <urn:spin:nanotation:demo:royal:family>
 SELECT *
 WHERE { ?s a <#RoyalPerson> . }
-----------------------------
------------------------------------------------------------------------------------------------------------------
| s                                                                    | graph                                   |
==================================================================================================================
| <http://dbpedia.org/resource/Prince_William_of_Wales>                | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Prince_Harry_of_Wales>                  | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Elizabeth_Bowes-Lyon>                   | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom>     | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Charles,_Prince_of_Wales>               | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Anne,_Princess_Royal>                   | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York>            | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex>          | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Princess_Margaret,_Countess_of_Snowdon> | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Peter_Phillips>                         | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Zara_Phillips>                          | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Princess_Beatrice_of_York>              | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Princess_Eugenie_of_York>               | <urn:spin:nanotation:demo:royal:family> |
------------------------------------------------------------------------------------------------------------------
============================

.
.
.

===========[Query13]==========
 PREFIX  rel:  <http://purl.org/vocab/relationship/>

 WITH <urn:spin:nanotation:demo:royal:family>
 SELECT DISTINCT *
 WHERE {
 { ?parent a <#RoyalPerson> ; rel:parentOf ?parentOf .}
 UNION
 { ?person a foaf:Person; <#hasAuntie> ?hasAuntie .}
 UNION
 { ?person a foaf:Person; <#hasUncle> ?hasUncle .}
 UNION
 { ?person a foaf:Person; <#hasCousin> ?hasCousin .}
 UNION
 { ?person a foaf:Person; <#hasUncle2> ?hasUncle2 .}
 UNION
 { ?person a foaf:Person; <#hasCousin2> ?hasCousin2 .}
 UNION
 { ?person a foaf:Person; rel:siblingOf ?hasSibling . }
 UNION
 { ?person a foaf:Person; rel:ancestorOf ?hasDescendant . }
 } 
-----------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| parent                                                           | parentOf                                                         | person                                                           | hasAuntie | hasUncle | hasCousin | hasUncle2 | hasCousin2 | hasSibling                                                           | hasDescendant | graph                                   |
=======================================================================================================================================================================================================================================================================================================================================================================================================
| <http://dbpedia.org/resource/Elizabeth_Bowes-Lyon>               | <http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom> |                                                                  |           |          |           |           |            |                                                                      |               | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom> | <http://dbpedia.org/resource/Charles,_Prince_of_Wales>           |                                                                  |           |          |           |           |            |                                                                      |               | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom> | <http://dbpedia.org/resource/Anne,_Princess_Royal>               |                                                                  |           |          |           |           |            |                                                                      |               | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom> | <http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York>        |                                                                  |           |          |           |           |            |                                                                      |               | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom> | <http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex>      |                                                                  |           |          |           |           |            |                                                                      |               | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Charles,_Prince_of_Wales>           | <http://dbpedia.org/resource/Prince_William_of_Wales>            |                                                                  |           |          |           |           |            |                                                                      |               | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Charles,_Prince_of_Wales>           | <http://dbpedia.org/resource/Prince_Harry_of_Wales>              |                                                                  |           |          |           |           |            |                                                                      |               | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Anne,_Princess_Royal>               | <http://dbpedia.org/resource/Peter_Phillips>                     |                                                                  |           |          |           |           |            |                                                                      |               | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Anne,_Princess_Royal>               | <http://dbpedia.org/resource/Zara_Phillips>                      |                                                                  |           |          |           |           |            |                                                                      |               | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York>        | <http://dbpedia.org/resource/Princess_Beatrice_of_York>          |                                                                  |           |          |           |           |            |                                                                      |               | <urn:spin:nanotation:demo:royal:family> |
| <http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York>        | <http://dbpedia.org/resource/Princess_Eugenie_of_York>           |                                                                  |           |          |           |           |            |                                                                      |               | <urn:spin:nanotation:demo:royal:family> |
|                                                                  |                                                                  | <http://dbpedia.org/resource/Prince_William_of_Wales>            |           |          |           |           |            | <http://dbpedia.org/resource/Prince_Harry_of_Wales>                  |               | <urn:spin:nanotation:demo:royal:family> |
|                                                                  |                                                                  | <http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom> |           |          |           |           |            | <http://dbpedia.org/resource/Princess_Margaret,_Countess_of_Snowdon> |               | <urn:spin:nanotation:demo:royal:family> |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
============================


BUILD SUCCESSFUL

Total time: 1.977 secs
$

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 build

2) 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:

$ sh gradlew clean build
Starting a Gradle Daemon (subsequent builds will be faster)
:clean UP-TO-DATE
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:startScripts
:distTar
:distZip
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 6.475 secs

$ sh gradlew run
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:run
Start loading data to DB
End loading data to DB
======== Query1 Exec:=========
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT *
WHERE { ?s a <#RoyalPerson> . }
-----------------------------
s                                                                  |
--------------------------------------------------------------------
http://dbpedia.org/resource/Prince_William_of_Wales                |
http://dbpedia.org/resource/Prince_Harry_of_Wales                  |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon                   |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom     |
http://dbpedia.org/resource/Charles,_Prince_of_Wales               |
http://dbpedia.org/resource/Anne,_Princess_Royal                   |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York            |
http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex          |
http://dbpedia.org/resource/Princess_Margaret,_Countess_of_Snowdon |
http://dbpedia.org/resource/Peter_Phillips                         |
http://dbpedia.org/resource/Zara_Phillips                          |
http://dbpedia.org/resource/Princess_Beatrice_of_York              |
http://dbpedia.org/resource/Princess_Eugenie_of_York               |
Rows =13
-----------------------------
Query2 Exec:
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT *
WHERE { ?s a ?t . }
-----------------------------
s                                                                  |t                                                   |
--------------------------------------------------------------------
:#hasRelative                                                      |http://www.w3.org/1999/02/22-rdf-syntax-ns#Property |
:#hasUncle                                                         |http://www.w3.org/1999/02/22-rdf-syntax-ns#Property |
:#hasAuntie                                                        |http://www.w3.org/1999/02/22-rdf-syntax-ns#Property |
:#hasCousin                                                        |http://www.w3.org/1999/02/22-rdf-syntax-ns#Property |
http://dbpedia.org/resource/Prince_William_of_Wales                |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Prince_William_of_Wales                |:#MalePerson                                        |
http://dbpedia.org/resource/Prince_William_of_Wales                |:#RoyalPerson                                       |
http://dbpedia.org/resource/Prince_Harry_of_Wales                  |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Prince_Harry_of_Wales                  |:#MalePerson                                        |
http://dbpedia.org/resource/Prince_Harry_of_Wales                  |:#RoyalPerson                                       |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon                   |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon                   |:#FemalePerson                                      |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon                   |:#RoyalPerson                                       |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom     |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom     |:#FemalePerson                                      |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom     |:#RoyalPerson                                       |
http://dbpedia.org/resource/Charles,_Prince_of_Wales               |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Charles,_Prince_of_Wales               |:#MalePerson                                        |
http://dbpedia.org/resource/Charles,_Prince_of_Wales               |:#RoyalPerson                                       |
http://dbpedia.org/resource/Anne,_Princess_Royal                   |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Anne,_Princess_Royal                   |:#FemalePerson                                      |
http://dbpedia.org/resource/Anne,_Princess_Royal                   |:#RoyalPerson                                       |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York            |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York            |:#MalePerson                                        |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York            |:#RoyalPerson                                       |
http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex          |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex          |:#MalePerson                                        |
http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex          |:#RoyalPerson                                       |
http://dbpedia.org/resource/Princess_Margaret,_Countess_of_Snowdon |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Princess_Margaret,_Countess_of_Snowdon |:#FemalePerson                                      |
http://dbpedia.org/resource/Princess_Margaret,_Countess_of_Snowdon |:#RoyalPerson                                       |
http://dbpedia.org/resource/Peter_Phillips                         |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Peter_Phillips                         |:#MalePerson                                        |
http://dbpedia.org/resource/Peter_Phillips                         |:#RoyalPerson                                       |
http://dbpedia.org/resource/Zara_Phillips                          |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Zara_Phillips                          |:#FemalePerson                                      |
http://dbpedia.org/resource/Zara_Phillips                          |:#RoyalPerson                                       |
http://dbpedia.org/resource/Princess_Beatrice_of_York              |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Princess_Beatrice_of_York              |:#FemalePerson                                      |
http://dbpedia.org/resource/Princess_Beatrice_of_York              |:#RoyalPerson                                       |
http://dbpedia.org/resource/Princess_Eugenie_of_York               |http://xmlns.com/foaf/0.1/Person                    |
http://dbpedia.org/resource/Princess_Eugenie_of_York               |:#FemalePerson                                      |
http://dbpedia.org/resource/Princess_Eugenie_of_York               |:#RoyalPerson                                       |
Rows =43
-----------------------------
Query3 Exec:
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT *
WHERE { ?s a <#RoyalPerson> ; rel:siblingOf ?sibling . 
}
-----------------------------
s                                                              |sibling                                                            |
--------------------------------------------------------------------
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://dbpedia.org/resource/Charles,_Prince_of_Wales               |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://dbpedia.org/resource/Anne,_Princess_Royal                   |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex          |
http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://dbpedia.org/resource/Anne,_Princess_Royal                   |
http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York            |
http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex          |
http://dbpedia.org/resource/Anne,_Princess_Royal               |http://dbpedia.org/resource/Charles,_Prince_of_Wales               |
http://dbpedia.org/resource/Anne,_Princess_Royal               |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York            |
http://dbpedia.org/resource/Anne,_Princess_Royal               |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex          |
http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex      |http://dbpedia.org/resource/Charles,_Prince_of_Wales               |
http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex      |http://dbpedia.org/resource/Anne,_Princess_Royal                   |
http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex      |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York            |
http://dbpedia.org/resource/Prince_Harry_of_Wales              |http://dbpedia.org/resource/Prince_William_of_Wales                |
http://dbpedia.org/resource/Prince_William_of_Wales            |http://dbpedia.org/resource/Prince_Harry_of_Wales                  |
http://dbpedia.org/resource/Zara_Phillips                      |http://dbpedia.org/resource/Peter_Phillips                         |
http://dbpedia.org/resource/Peter_Phillips                     |http://dbpedia.org/resource/Zara_Phillips                          |
http://dbpedia.org/resource/Princess_Eugenie_of_York           |http://dbpedia.org/resource/Princess_Beatrice_of_York              |
http://dbpedia.org/resource/Princess_Beatrice_of_York          |http://dbpedia.org/resource/Princess_Eugenie_of_York               |
http://dbpedia.org/resource/Prince_William_of_Wales            |http://dbpedia.org/resource/Prince_Harry_of_Wales                  |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Princess_Margaret,_Countess_of_Snowdon |
Rows =20
-----------------------------
Query4 Exec:
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT *
WHERE { ?s a <#RoyalPerson> ; rel:grandParent ?gp . 
}
-----------------------------
s                                                              |parent_urn_spin_nanotation_demo_royal_family_lib2_bnode_a_6    |gp                                                        |
--------------------------------------------------------------------
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Anne,_Princess_Royal          |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://dbpedia.org/resource/Prince_William_of_Wales       |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://dbpedia.org/resource/Prince_Harry_of_Wales         |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Anne,_Princess_Royal               |http://dbpedia.org/resource/Peter_Phillips                |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Anne,_Princess_Royal               |http://dbpedia.org/resource/Zara_Phillips                 |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://dbpedia.org/resource/Princess_Beatrice_of_York     |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://dbpedia.org/resource/Princess_Eugenie_of_York      |
Rows =10
-----------------------------
Query5 Exec:
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT ?person rel:ancestorOf as ?relation ?descendant
WHERE { ?person a <#RoyalPerson> ;
rel:ancestorOf ?descendant . 
}
-----------------------------
person                                                         |relation                                      |descendant                                                    |
--------------------------------------------------------------------
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex      |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Anne,_Princess_Royal               |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Charles,_Prince_of_Wales           |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Prince_Harry_of_Wales              |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Prince_William_of_Wales            |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Zara_Phillips                      |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Peter_Phillips                     |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Princess_Eugenie_of_York           |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Princess_Beatrice_of_York          |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex      |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Anne,_Princess_Royal               |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Charles,_Prince_of_Wales           |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Prince_Harry_of_Wales              |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Prince_William_of_Wales            |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Zara_Phillips                      |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Peter_Phillips                     |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Princess_Eugenie_of_York           |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Princess_Beatrice_of_York          |
http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Prince_Harry_of_Wales              |
http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Prince_William_of_Wales            |
http://dbpedia.org/resource/Anne,_Princess_Royal               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Zara_Phillips                      |
http://dbpedia.org/resource/Anne,_Princess_Royal               |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Peter_Phillips                     |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Princess_Eugenie_of_York           |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://purl.org/vocab/relationship/ancestorOf |http://dbpedia.org/resource/Princess_Beatrice_of_York          |
Rows =27
-----------------------------
Query6 Exec:
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT DISTINCT ?person rel:siblingOf as ?relation ?siblingOf
WHERE { ?person  a <#RoyalPerson> ;
rel:siblingOf  ?siblingOf
}
-----------------------------
person                                                         |relation                                     |siblingOf                                                          |
--------------------------------------------------------------------
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Charles,_Prince_of_Wales               |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Anne,_Princess_Royal                   |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex          |
http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Anne,_Princess_Royal                   |
http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York            |
http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex          |
http://dbpedia.org/resource/Anne,_Princess_Royal               |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Charles,_Prince_of_Wales               |
http://dbpedia.org/resource/Anne,_Princess_Royal               |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York            |
http://dbpedia.org/resource/Anne,_Princess_Royal               |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex          |
http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex      |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Charles,_Prince_of_Wales               |
http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex      |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Anne,_Princess_Royal                   |
http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex      |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York            |
http://dbpedia.org/resource/Prince_Harry_of_Wales              |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Prince_William_of_Wales                |
http://dbpedia.org/resource/Prince_William_of_Wales            |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Prince_Harry_of_Wales                  |
http://dbpedia.org/resource/Zara_Phillips                      |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Peter_Phillips                         |
http://dbpedia.org/resource/Peter_Phillips                     |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Zara_Phillips                          |
http://dbpedia.org/resource/Princess_Eugenie_of_York           |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Princess_Beatrice_of_York              |
http://dbpedia.org/resource/Princess_Beatrice_of_York          |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Princess_Eugenie_of_York               |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://purl.org/vocab/relationship/siblingOf |http://dbpedia.org/resource/Princess_Margaret,_Countess_of_Snowdon |
Rows =19
-----------------------------
Query7 Exec:
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT ?person <#hasAuntie> as ?relation  ?hasAuntie
WHERE { ?person a <#RoyalPerson> ;
<#hasAuntie> ?hasAuntie
}
-----------------------------
person                                                |relation    |hasAuntie                                        |
--------------------------------------------------------------------
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasAuntie |http://dbpedia.org/resource/Anne,_Princess_Royal |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasAuntie |http://dbpedia.org/resource/Anne,_Princess_Royal |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasAuntie |http://dbpedia.org/resource/Anne,_Princess_Royal |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasAuntie |http://dbpedia.org/resource/Anne,_Princess_Royal |


Rows =4
-----------------------------
Query8 Exec:
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT ?person <#hasUncle> as ?relation ?hasUncle
WHERE { ?person a <#RoyalPerson> ;
<#hasUncle> ?hasUncle
}
-----------------------------
person                                                |relation   |hasUncle                                                  |
--------------------------------------------------------------------
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasUncle |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasUncle |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Peter_Phillips            |:#hasUncle |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Zara_Phillips             |:#hasUncle |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasUncle |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasUncle |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Peter_Phillips            |:#hasUncle |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Zara_Phillips             |:#hasUncle |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasUncle |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasUncle |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Peter_Phillips            |:#hasUncle |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Zara_Phillips             |:#hasUncle |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasUncle |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasUncle |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasUncle |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasUncle |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Peter_Phillips            |:#hasUncle |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Zara_Phillips             |:#hasUncle |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Zara_Phillips             |:#hasUncle |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasUncle |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasUncle |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Peter_Phillips            |:#hasUncle |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasUncle |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasUncle |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasUncle |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Peter_Phillips            |:#hasUncle |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Zara_Phillips             |:#hasUncle |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasUncle |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
Rows =28
-----------------------------
Query9 Exec:
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT ?person <#hasUncle2> as ?relation ?hasUncle2
WHERE { ?person a <#RoyalPerson> ;
<#hasUncle2> ?hasUncle2
}
-----------------------------
person                                                |relation    |hasUncle2                                                 |
--------------------------------------------------------------------
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasUncle2 |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasUncle2 |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasUncle2 |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasUncle2 |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Peter_Phillips            |:#hasUncle2 |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Peter_Phillips            |:#hasUncle2 |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Peter_Phillips            |:#hasUncle2 |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Zara_Phillips             |:#hasUncle2 |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Zara_Phillips             |:#hasUncle2 |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Zara_Phillips             |:#hasUncle2 |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasUncle2 |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasUncle2 |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasUncle2 |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasUncle2 |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
Rows =14
-----------------------------
Query10 Exec:
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT ?person <#hasCousin> as ?relation ?hasCousin
WHERE { ?person a <#RoyalPerson> ;
<#hasCousin> ?hasCousin
}
-----------------------------
person                                                |relation    |hasCousin                                                 |
--------------------------------------------------------------------
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasCousin |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasCousin |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Peter_Phillips            |:#hasCousin |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Zara_Phillips             |:#hasCousin |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasCousin |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasCousin |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Peter_Phillips            |:#hasCousin |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Zara_Phillips             |:#hasCousin |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasCousin |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasCousin |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Peter_Phillips            |:#hasCousin |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Zara_Phillips             |:#hasCousin |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasCousin |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasCousin |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasCousin |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasCousin |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Peter_Phillips            |:#hasCousin |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Zara_Phillips             |:#hasCousin |http://dbpedia.org/resource/Charles,_Prince_of_Wales      |
http://dbpedia.org/resource/Zara_Phillips             |:#hasCousin |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasCousin |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasCousin |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Peter_Phillips            |:#hasCousin |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York   |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasCousin |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasCousin |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasCousin |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Peter_Phillips            |:#hasCousin |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Zara_Phillips             |:#hasCousin |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasCousin |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex |
Rows =28
-----------------------------
Query11 Exec:
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT ?person <#hasCousin2> as ?relation ?hasCousin2
WHERE { ?person a <#RoyalPerson> ;
<#hasCousin2> ?hasCousin2
}
-----------------------------
person                                                |relation     |hasCousin2                                            |
--------------------------------------------------------------------
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasCousin2 |http://dbpedia.org/resource/Zara_Phillips             |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasCousin2 |http://dbpedia.org/resource/Princess_Eugenie_of_York  |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasCousin2 |http://dbpedia.org/resource/Peter_Phillips            |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasCousin2 |http://dbpedia.org/resource/Princess_Beatrice_of_York |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasCousin2 |http://dbpedia.org/resource/Princess_Eugenie_of_York  |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasCousin2 |http://dbpedia.org/resource/Zara_Phillips             |
http://dbpedia.org/resource/Prince_Harry_of_Wales     |:#hasCousin2 |http://dbpedia.org/resource/Peter_Phillips            |
http://dbpedia.org/resource/Prince_William_of_Wales   |:#hasCousin2 |http://dbpedia.org/resource/Princess_Beatrice_of_York |
http://dbpedia.org/resource/Peter_Phillips            |:#hasCousin2 |http://dbpedia.org/resource/Princess_Beatrice_of_York |
http://dbpedia.org/resource/Peter_Phillips            |:#hasCousin2 |http://dbpedia.org/resource/Princess_Eugenie_of_York  |
http://dbpedia.org/resource/Zara_Phillips             |:#hasCousin2 |http://dbpedia.org/resource/Prince_Harry_of_Wales     |
http://dbpedia.org/resource/Zara_Phillips             |:#hasCousin2 |http://dbpedia.org/resource/Princess_Eugenie_of_York  |
http://dbpedia.org/resource/Zara_Phillips             |:#hasCousin2 |http://dbpedia.org/resource/Princess_Beatrice_of_York |
http://dbpedia.org/resource/Peter_Phillips            |:#hasCousin2 |http://dbpedia.org/resource/Prince_Harry_of_Wales     |
http://dbpedia.org/resource/Peter_Phillips            |:#hasCousin2 |http://dbpedia.org/resource/Prince_William_of_Wales   |
http://dbpedia.org/resource/Zara_Phillips             |:#hasCousin2 |http://dbpedia.org/resource/Prince_William_of_Wales   |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasCousin2 |http://dbpedia.org/resource/Prince_Harry_of_Wales     |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasCousin2 |http://dbpedia.org/resource/Zara_Phillips             |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasCousin2 |http://dbpedia.org/resource/Prince_Harry_of_Wales     |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasCousin2 |http://dbpedia.org/resource/Peter_Phillips            |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasCousin2 |http://dbpedia.org/resource/Prince_William_of_Wales   |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasCousin2 |http://dbpedia.org/resource/Zara_Phillips             |
http://dbpedia.org/resource/Princess_Beatrice_of_York |:#hasCousin2 |http://dbpedia.org/resource/Prince_William_of_Wales   |
http://dbpedia.org/resource/Princess_Eugenie_of_York  |:#hasCousin2 |http://dbpedia.org/resource/Peter_Phillips            |
Rows =24
-----------------------------
Query12 Exec:
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT ?s as ?ancestor
?descendant
WHERE { ?s a <#RoyalPerson> ;
rel:ancestorOf ?descendant
}
-----------------------------
ancestor                                                       |descendant                                                     |
--------------------------------------------------------------------------------------------------------------------------------
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex      |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Anne,_Princess_Royal               |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Charles,_Prince_of_Wales           |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Prince_Harry_of_Wales              |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Prince_William_of_Wales            |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Zara_Phillips                      |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Peter_Phillips                     |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Princess_Eugenie_of_York           |
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Princess_Beatrice_of_York          |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex      |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Anne,_Princess_Royal               |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Charles,_Prince_of_Wales           |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Prince_Harry_of_Wales              |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Prince_William_of_Wales            |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Zara_Phillips                      |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Peter_Phillips                     |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Princess_Eugenie_of_York           |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Princess_Beatrice_of_York          |
http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://dbpedia.org/resource/Prince_Harry_of_Wales              |
http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://dbpedia.org/resource/Prince_William_of_Wales            |
http://dbpedia.org/resource/Anne,_Princess_Royal               |http://dbpedia.org/resource/Zara_Phillips                      |
http://dbpedia.org/resource/Anne,_Princess_Royal               |http://dbpedia.org/resource/Peter_Phillips                     |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://dbpedia.org/resource/Princess_Eugenie_of_York           |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://dbpedia.org/resource/Princess_Beatrice_of_York          |
Rows =27
-----------------------------
Query13 Exec:
PREFIX  rel:  <http://purl.org/vocab/relationship/>
WITH <urn:spin:nanotation:demo:royal:family>
SELECT DISTINCT *
WHERE {
{ ?parent a <#RoyalPerson> ; rel:parentOf ?parentOf .}
UNION
{ ?person a foaf:Person; <#hasAuntie> ?hasAuntie .}
UNION
{ ?person a foaf:Person; <#hasUncle> ?hasUncle .}
UNION
{ ?person a foaf:Person; <#hasCousin> ?hasCousin .}
UNION
{ ?person a foaf:Person; <#hasUncle2> ?hasUncle2 .}
UNION
{ ?person a foaf:Person; <#hasCousin2> ?hasCousin2 .}
UNION
{ ?person a foaf:Person; rel:siblingOf ?hasSibling . }
UNION
{ ?person a foaf:Person; rel:ancestorOf ?hasDescendant . }
}
-----------------------------
parent                                                         |parentOf                                                       |person                                                         |hasAuntie |hasUncle |hasCousin |hasUncle2 |hasCousin2 |hasSibling                                                         |hasDescendant |
--------------------------------------------------------------------
http://dbpedia.org/resource/Elizabeth_Bowes-Lyon               |http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |null                                                           |null      |null     |null      |null      |null       |null                                                               |null          |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |null                                                           |null      |null     |null      |null      |null       |null                                                               |null          |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Charles,_Prince_of_Wales           |null                                                           |null      |null     |null      |null      |null       |null                                                               |null          |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex      |null                                                           |null      |null     |null      |null      |null       |null                                                               |null          |
http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |http://dbpedia.org/resource/Anne,_Princess_Royal               |null                                                           |null      |null     |null      |null      |null       |null                                                               |null          |
http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://dbpedia.org/resource/Prince_William_of_Wales            |null                                                           |null      |null     |null      |null      |null       |null                                                               |null          |
http://dbpedia.org/resource/Charles,_Prince_of_Wales           |http://dbpedia.org/resource/Prince_Harry_of_Wales              |null                                                           |null      |null     |null      |null      |null       |null                                                               |null          |
http://dbpedia.org/resource/Anne,_Princess_Royal               |http://dbpedia.org/resource/Peter_Phillips                     |null                                                           |null      |null     |null      |null      |null       |null                                                               |null          |
http://dbpedia.org/resource/Anne,_Princess_Royal               |http://dbpedia.org/resource/Zara_Phillips                      |null                                                           |null      |null     |null      |null      |null       |null                                                               |null          |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://dbpedia.org/resource/Princess_Beatrice_of_York          |null                                                           |null      |null     |null      |null      |null       |null                                                               |null          |
http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York        |http://dbpedia.org/resource/Princess_Eugenie_of_York           |null                                                           |null      |null     |null      |null      |null       |null                                                               |null          |
null                                                           |null                                                           |http://dbpedia.org/resource/Prince_William_of_Wales            |null      |null     |null      |null      |null       |http://dbpedia.org/resource/Prince_Harry_of_Wales                  |null          |
null                                                           |null                                                           |http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom |null      |null     |null      |null      |null       |http://dbpedia.org/resource/Princess_Margaret,_Countess_of_Snowdon |null          |
Rows =13
-----------------------------
BUILD SUCCESSFUL
Total time: 1.415 secs
$

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