# Rules¶

## Doing inference with a rule system¶

We want to infer the symmetric spouse relations to two persons that are the parents of a child. The task is hard with OWL, but can be done easily with rules.

With the N3 notation of RDF, it is possible to represent rules (implication):

http://www.w3.org/TeamSubmission/n3/

http://www.w3.org/2000/10/swap/doc/Rules

With rules, it is possible to infer new RDF triples into an ontology from the existing triples.

Create a rule to infer the spouse relations of the exercise Creating an OWL Ontology part a. with N3 notation rule system.

To test the reasoning before submitting your answer, you can give the N3 Logic Rule reasoner your Turtle formatted and reasoned (with OWL RL Reasoner) ontology from exercise Creating an OWL Ontology part a. as facts. You should select the option “Send form as HTTP POST (needed for large RDF data)” because the reasoned Turtle serialization may be too large to be transferred as a GET parameter.

Note: be careful with typos as the N3 Reasoner will throw internal server error and not any helpful information about syntactic mistakes.

A+ presents the exercise submission form here.

## Implementing inference with SPARQL rules¶

Implement the spouse relation inferences from the previous exercises as a SPARQL CONSTRUCT query. The result should be 3 couples (6 results) with the scenario in the family tree picture of Creating an OWL Ontology part a.

For manual testing, you can download and install the ontology editor Protégé.

To start Protégé, extract the archive file and run the run.bat (Windows), run.sh (Linux) or run.command (OS X).

In the computer class you probably have to add the following lines to the beginning of run.bat (change the path to where you extracted it):

z:
cd Desktop\Protege_VERSION_NUMBER


In Protégé, you can open an ontology from a file from the top menu File -> Open. You can then execute a SPARQL query into your ontology in Protégé from the SPARQL Query view, which you can enable from the menu (WindowTabsSPARQL Query).

If the SPARQL Query tab doesn’t work, update all plugins from File → “Check for plugins…”, and then restart Protégé.

A+ presents the exercise submission form here.

## Implementing OWL inference with a rule system¶

Inference regarding the essential properties of OWL semantics can be easily implemented with inference rules: Reasoning in OWL 2 RL and RDF Graphs using Rules.

Implement the rules regarding the used property structures in exercises Creating an OWL Ontology part c. and d. as N3 rules. More precisely, the following properties should be inferred correctly for each family member:

hasParent
hasGrandchild
hasGrandparent
hasSpouse


The idea is to use rules to describe common OWL properties, so that the rules would apply for any OWL ontology, not just your family ontology. To do this, don’t use properties (e.g. child and grandchild) from your own ontology, but instead use only OWL properties, e.g. owl:propertyChainAxiom. Regarding property chaining (with owl:propertyChainAxiom), it is enough that your rules work on chains of exactly two properties.

For example, a rule for the semantics of rdfs:domain could be written as:

{ ?p rdfs:domain ?c . ?x ?p ?y } => { ?x rdf:type ?c } .

How the common OWL properties should work as rules, can be seen in the “Table 5. The Semantics of Axioms about Properties” from the link given above. Use the ontology created in the exercise Creating an OWL Ontology to test your rules with the N3 reasoner. The tests require you get the same inferences as you got in Creating an OWL Ontology part c. and d. minus the classes.

The test data contains the following properties which can be used for rule inferencing:

<http://purl.org/vocab/bio/0.1/child> rdf:type owl:ObjectProperty ;
owl:equivalentProperty :hasChild .

:Man rdf:type owl:ObjectProperty ;
owl:propertyDisjointWith :Woman .

:Woman rdf:type owl:ObjectProperty .

:hasChild rdf:type owl:ObjectProperty ;
owl:inverseOf :hasParent ;
rdf:type owl:AsymmetricProperty .

:hasGrandchild rdf:type owl:ObjectProperty ;
owl:inverseOf :hasGrandparent ;
owl:propertyChainAxiom ( :hasChild :hasChild ) .

:hasGrandparent rdf:type owl:ObjectProperty .

:hasParent rdf:type owl:ObjectProperty .

:hasSpouse rdf:type owl:ObjectProperty ,
owl:InverseFunctionalProperty ,
owl:SymmetricProperty .


A+ presents the exercise submission form here.

Posting submission...