Custom Reasoning & Inference using British Royal Family Relationships -- Part 2
In a previous post, I demonstrated inbuilt Inference & Reasoning using British Royal Family relations. With regards to inbuilt Inference & Reasoning, I am referring to the fact that what I demonstrated in the aforementioned post was based on Virtuoso's implementation of semantics for specific relationship types defined using terms from RDF Schema and OWL ontologies.
This time around, I am moving beyond inbuilt relationship type semantics to custom inference rules that dynamically generate entity relationships via custom inference rules. This approach also enables development of inference rules that replace the defaults implemented by Virtuoso, if need be.
Problem
Given a few RDF Language sentences/statements that describe aspects of British Royal Family, how can I generate queries that provide solutions to the following questions:
- Ancestors and Descendants?
- Siblings?
- Aunties?
- Uncles?
- Cousins?
Data (RDF sentence/statement collection) at hand, using nanotation is as follows:
## Turtle Start ##
## Entity Relationships
<http://dbpedia.org/resource/Prince_William_of_Wales> a <#RoyalPerson>, <#MalePerson> ;schema:name "Prince William" ; rel:siblingOf <http://dbpedia.org/resource/Prince_Harry_of_Wales> .<http://dbpedia.org/resource/Elizabeth_Bowes-Lyon> a <#RoyalPerson>, <#FemalePerson> ;schema:name "Queen Mother" ;rel:parentOf <http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom> .<http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom> a <#RoyalPerson>, <#FemalePerson> ;schema:name "Queen Elizabeth II" ;rel:parentOf <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> ;rel:siblingOf <http://dbpedia.org/resource/Princess_Margaret,_Countess_of_Snowdon> .<http://dbpedia.org/resource/Charles,_Prince_of_Wales> a <#RoyalPerson>, <#MalePerson> ;schema:name "Prince Charles" ;rel:parentOf <http://dbpedia.org/resource/Prince_William_of_Wales> , <http://dbpedia.org/resource/Prince_Harry_of_Wales> .<http://dbpedia.org/resource/Princess_Margaret,_Countess_of_Snowdon> a <#RoyalPerson>, <#FemalePerson> ;schema:name "Princess Margaret" . <http://dbpedia.org/resource/Anne,_Princess_Royal> a <#RoyalPerson>, <#FemalePerson> ;schema:name "Princess Anne" ;rel:parentOf <http://dbpedia.org/resource/Peter_Phillips>, <http://dbpedia.org/resource/Zara_Phillips> .<http://dbpedia.org/resource/Zara_Phillips> a <#RoyalPerson>, <#FemalePerson> ;schema:name "Princess Zara Phillips" .<http://dbpedia.org/resource/Princess_Beatrice_of_York> a <#RoyalPerson>, <#FemalePerson> ;schema:name "Princess Beatrice" .<http://dbpedia.org/resource/Princess_Eugenie_of_York>a <#RoyalPerson>, <#FemalePerson> ;schema:name "Princess Eugenie" .<http://dbpedia.org/resource/Prince_Andrew,_Duke_of_York> a <#RoyalPerson>, <#MalePerson> ;schema:name "Prince Andrew" ;rel:parentOf <http://dbpedia.org/resource/Princess_Eugenie_of_York>, <http://dbpedia.org/resource/Princess_Beatrice_of_York> .<http://dbpedia.org/resource/Prince_Edward,_Earl_of_Wessex> a <#RoyalPerson>, <#MalePerson> ;schema:name "Prince Edward" .<http://dbpedia.org/resource/Prince_Harry_of_Wales> a <#RoyalPerson>, <#MalePerson> ;schema:name "Prince Harry" .<http://dbpedia.org/resource/Peter_Phillips> a <#RoyalPerson>, <#MalePerson> ;schema:name "Prince Peter Phillips" .
## Turtle End ##
Note: with regards to the embedded data above, this document morphs into a database that can be queried using SPARQL via OpenLink Virtuoso e.g., the instance that drives our URIBurner service).
Here's a visualization of the RDF Language based structured data, courtesy of our Structured Data Sniffer Browser Extension.
Solution
Create Custom Inference Rules that describe the semantics of the Entity Relationship Types missing from the data. Here is an example of a rule (macro) that describes rel:ancestorOf, using SPARQL as a Rule Language:
defmacro rel:ancestorOf { ?this rel:ancestorOf ?n }
{{ { ?this rel:parentOf+ ?n . }
UNION { ?this rel:siblingOf ?n . }
FILTER ( NOT EXISTS {?this
rel:siblingOf|^rel:siblingOf ?n} )
}}
Here are links to queries that show the effects custom Entity Relationship Types facilitated by Custom Inference Rules:
Conclusion
As is the case in the real-world, you can have a succinct collection of sentences/statements using a given language that serves as the basis for exposing deeper insights. I just happen to be achieving this goal using RDF Language and the Logic Processor built into Virtuoso -- our multi-model RDBMS.
One more thing, I just stumbled across a Google DeepMind video that illustrates what's covered in this post:
Links
- SPASQL (SQL extended using SPARQL) file -- Github repo containing custom inference rules definitions and sample queries
- Java variant using the Jena Framework -- ditto
- Java variant using the RDF4j Framework -- ditto
- OpenLink Structured Data Sniffer Browser Extension -- aids visualization of data in this post while also providing "on the fly" SPARQL Query Edting & Execution
- OpenLink Virtuoso -- powerful Multi-Model RDBMS and Data Virtualization platform that provides all the magic++