Using British Royal Family Data Snippets — to demonstrate SPARQL Query Language-based Reasoning & Inference
Brevity is a function of sophisticated use of language (systematic use of signs, syntax, and semantics for encoding information [data in some context]).
In this post I demonstrate how a few RDF Language sentences about the British Royal Family can enable a SPARQL-compliant RDBMS, equipped with deductive capabilities, to produce inferred query results by way of reasoning & inference against the semantics (nature) of the predicates used in those same few sentences.
Courtesy of RDF Language based nanotation, in this case using Turtle Notation, I am able to use this blog post as a structured data source for this exercise — that is, a demonstration of SPARQL Query Language-based reasoning and inference over snippets of data about the British Royal Family.
{
## Collection of RDF Language Statements (using
## Turtle Notation) that describe various
## Relationship Types (or Relations) that connect
## various members of the British Royal Family.
## These statements have been created using terms
## from the Relationship Vocabulary at
## http://purl.org/vocab/relationship/
## and Described in this URIBurner Document @prefix rel: <http://purl.org/vocab/relationship/> . <http://dbpedia.org/resource/Prince_William_of_Wales>
rel:siblingOf
<http://dbpedia.org/resource/Prince_Harry_of_Wales>
.
<http://dbpedia.org/resource/Elizabeth_Bowes-Lyon>
rel:ancestorOf
<http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom>
.
<http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom>
rel:ancestorOf
<http://dbpedia.org/resource/Charles,_Prince_of_Wales>
.
<http://dbpedia.org/resource/Charles,_Prince_of_Wales>
rel:ancestorOf
<http://dbpedia.org/resource/Prince_William_of_Wales> ,
<http://dbpedia.org/resource/Prince_Harry_of_Wales>
.
}
Here’s how the data above is interpreted and presented to me by OSDS — the OpenLink Structured Data Sniffer:
Loading the Raw Data
Now that I have my raw data (here in the form of a Turtle-based collection of sentences/statements), I can load it into my SPARQL 1.1-compliant Virtuoso RDBMS using a variety of methods; for instance, I could use the URI that Identifies this document (this blog post) in the FROM
clause of a SPARQL query:
DEFINE get:soft "replace"
SELECT DISTINCT *
FROM <{URI-Of-This-Document}>
WHERE {?s ?p ?o}
Setting Up Inference Rules
As suggested earlier, I am using terms from the relationship vocabulary to drive this exercise, of which terms I will make Virtuoso aware by performing a few additional steps.
First, I need to get the Relationship Vocabulary — a collection of RDF Language sentences that define a variety of relationship types — loaded into the Virtuoso instance behind our URIBurner service. There are two easy ways to do this:
- Use SPARQL with a Virtuoso Pragma (
get:soft “replace”
orget:soft “add”
) that invokes its Sponger Middleware Layer, and theFROM <http://purl.org/vocab/relationship/>
clause to retrieve the vocabulary data file, as in—
DEFINE get:soft "replace"
SELECT *
FROM <http://vocab.org/relationship/rel-vocab-20100607.rdf>
WHERE { ?s ?p ?o }
— followed by —
COPY <http://vocab.org/relationship/rel-vocab-20100607.rdf>
TO <http://purl.org/vocab/relationship/>
2. Or via a SPARQL 1.1 LOAD
command—
DEFINE get:soft "no-sponge"
LOAD <http://vocab.org/relationship/rel-vocab-20100607.rdf>
INTO <http://purl.org/vocab/relationship/>
In each case, the Sponger Middleware negotiates the content-format of the vocabulary (which may also be referred to as an ontology, a schema, or a data-dictionary) when retrieving this data from the originating server, en route to local RDF document storage.
You can use this SPARQL query to check whether the ontology has been successfully loaded —
SELECT *
FROM <http://purl.org/vocab/relationship/>
WHERE { ?s ?p ?o }
Inference Rule Creation
Inference rules are created in the SQL realm of Virtuoso, by associating a uniquely identified Rule with a Vocabulary or Ontology that describes the existence and nature (semantics) of various entity relationship types. Here’s an example of such an association using a SQL command (calling the rdfs_rule_set();
stored procedure) that you can execute using any of Virtuoso’s data access interfaces (command-line iSQL, ODBC, JDBC, HTML-based iSQL, etc.) —
rdfs_rule_set
( 'urn:relationships:ontology:inference:rules' ,
'http://purl.org/vocab/relationship/'
) ;
You can then verify the Rule’s Existence with this SQL query —
SELECT * FROM sys_rdf_schema ;
Querying for Inferred Data about the British Royal Family
Each of the following SPARQL query examples includes four elements:
- the Query Definition
- a Live Link to the Query Results (Solution)
- a Live Link to Edit the Query
- the implicit option to replace
<urn:royals:demo>
with<{url-of-this-post}>
in theFROM
clause of each example
Query 1 — Descendants of Elizabeth Bowes-Lyon (Queen Mother), without Reasoning & Inference
PREFIX rel: <http://purl.org/vocab/relationship/>
SELECT *
FROM <urn:royals:demo>
WHERE
{ <http://dbpedia.org/resource/Elizabeth_Bowes-Lyon>
rel:ancestorOf ?o
}
- Live Link to the Query Results. This solution is empty, because the Inference Rules were not invoked, and the data did not include any statements explicitly using the
rel:ancestorOf
property. - Live Link to the Query Editor
Query 2 — Descendants of Elizabeth Bowes-Lyon (Queen Mother) using Reasoning & Inference pragma
## Demonstrates effects of the Transitive nature
## of the rel:ancestorOf relation which is what
## enables the system to construct an inferred
## list of descendantsDEFINE input:inference
‘urn:relationships:ontology:inference:rules’PREFIX rel: <http://purl.org/vocab/relationship/>SELECT *
FROM <urn:royals:demo>
WHERE
{
<http://dbpedia.org/resource/Elizabeth_Bowes-Lyon>
rel:ancestorOf ?o
}
- Live Link to the Query Results
- Live Link to the Query Editor
Query 3 — Descendants of Elizabeth Bowes-Lyon (Queen Mother), using
SPARQL 1.1 Property Paths feature
In this case, the inference & reasoning effect is crafted into the query, rather than being declared. Note: the unary operator “+
” indicates a property path of one or more occurrences of the relation in question (rel:ancestorOf
) connects the relation subject (the Queen Mother) to one or more objects (descendants, in this case).
PREFIX rel: <http://purl.org/vocab/relationship/>SELECT *
FROM <urn:royals:demo>
WHERE
{
<http://dbpedia.org/resource/Elizabeth_Bowes-Lyon>
rel:ancestorOf+ ?o
}
- Live Link to the Query Results
- Live Link to the Query Editor
Query 4 — Prince Harry’s Sibling using Reasoning & Inference Pragma
You can comment out (using one or more leading “#
” characters) the Inference rule pragma (the DEFINE
lines) to disable the Reasoning & Inference effects (i.e., generation of inferred data).
## Demonstrates the effects of Symmetric relation
## semantics; i.e., the query solution is unchanged
## whether Prince Harry is the Subject or Object of
## the rel:siblingOf relationsDEFINE input:inference
'urn:relationships:ontology:inference:rules'PREFIX rel: <http://purl.org/vocab/relationship/>SELECT *
FROM <urn:royals:demo>
WHERE
{
<http://dbpedia.org/resource/Prince_Harry_of_Wales>
rel:siblingOf ?o
}
- Live Link to the Query Results
- Live Link to the Query Editor
Query 5 — Relationship Symmetry using SPARQL 1.1 Property Paths
Here, the unary operator “+
” indicates a property path comprised of one or more occurrences of the relation (rel:siblingOf
) connecting the relation subject (Harry) to one or more siblings; while unary operator “^
” indicates a property path of one or more occurrences of the relation (rel:siblingOf
) connecting the relation object (Harry) to one or more siblings; and the binary operator “|
” provides the OR condition between “+
” and “^
”.
PREFIX rel: <http://purl.org/vocab/relationship/>SELECT *
FROM <urn:royals:demo>
WHERE
{
<http://dbpedia.org/resource/Prince_Harry_of_Wales>
( rel:siblingOf+|^rel:siblingOf ) ?o
}
- Live Link to the Query Results
- Live Link to the Query Editor
Query 6 — Queen Elizabeth II Ancestry with Reasoning and Inference
## Demonstrates effects of the Transitive nature
## of the rel:descendantOf relation, which is what
## enables the system to construct an inferred list
## of ancestors. This also demonstrates the Inverse
## nature of the rel:descendentOf as it relates to
## rel:ancestorOf, since rel:descendentOf isn't
## used in any of the sentences used to describe
## the Royal Family.DEFINE input:inference
'urn:relationships:ontology:inference:rules'PREFIX rel: <http://purl.org/vocab/relationship/>SELECT *
FROM <urn:royals:demo>
WHERE
{
<http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom>
rel:descendantOf ?o
}
- Live Link to the Query Results
- Live Link to the Query Editor
Query 7 — Queen Elizabeth II Ancestry with Reasoning and Inference using SPARQL 1.1 Property Paths
PREFIX rel: <http://purl.org/vocab/relationship/>SELECT *
FROM <urn:royals:demo>
WHERE
{
<http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom>
rel:descendantOf+|^rel:ancestorOf ?o
}
- Live Link to the Query Results
- Live Link to the Query Editor
Query 8 — Descendants of Queen Elizabeth II, using Reasoning & Inference Pragma
## Demonstrates the effects of the Transitive nature
## of the rel:ancestorOf relation, which is what
## enables the system to construct an inferred list
## of descendantsDEFINE input:inference
'urn:relationships:ontology:inference:rules'PREFIX rel: <http://purl.org/vocab/relationship/>SELECT *
FROM <urn:royals:demo>
WHERE
{
<http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom>
rel:ancestorOf ?o
}
- Live Link to the Query Results
- Live Link to the Query Editor
Query 9 —Descendants of Queen Elizabeth II, using SPARQL 1.1 Property Paths to leverage the Transitive nature of rel:ancestorOf
PREFIX rel: <http://purl.org/vocab/relationship/>SELECT *
FROM <urn:royals:demo>
WHERE
{
<http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom>
rel:ancestorOf+|^rel:descendentOf ?o
}
- Live Link to the Query Results
- Live Link to the Query Editor
Conclusion
The concept of a Deductive Database isn’t new; what’s different today is the existence of the open standards (URIs, HTTP, RDF Language, OWL Ontology, and SPARQL) that enable the implementation and delivery of this functionality in a standard form, as exemplified by OpenLink Virtuoso, our SPARQL compliant RDBMS that also includes scalable reasoning and inference functionality.
The ability to create, share, and consume semantically-rich data snippets is a critical requirement for a new generation of smart agents that will increasingly shape our experiences with “Big Data”, “Semantically-enhanced World Wide Web” (a/k/a “Semantic Web”), and the burgeoning “Internet of Things.”
Related
- Part 2 — British Royal Family Relationship using Custom Reasoning & Inference Rules
- W3C Turtle Spec
- About Embedding Nanotation inside Medium Posts & Comments
- SPARQL 1.1 Property Paths
- SPARQL 1.1 Property Paths excerpt from SPARQL Tutorial by @Harald Sack
- Simple SPARQL-based Data Integration that leverages inference rules or SPARQL 1.1 Property Paths
- A Description of RDF using RDF (presented using HTML)
- Browse Terms from Relationship Vocabulary
- URIBurner Service Home Page
- Virtuoso Home Page