SPARQL Rule

Author

Olivier Corby <olivier.corby@inria.fr>
2018, April 9

Abstract

Corese defines an Inference Rule Language based on SPARQL construct-where query form. The where clause defines a condition and the construct clause defines the conclusion. Rules are applied in forward chaining until saturation.

Table of contents

 

Introduction

Corese defines an Inference Rule Language based on SPARQL construct-where query form. The where clause defines a condition and the construct clause defines the conclusion. Rules are applied in forward chaining until saturation. Corese implements OWL RL using such a rule base. The example below shows the inference rule that implements OWL transitivity.

construct {
  ?x ?p ?z
}
where {
  ?p a owl:TransitiveProperty .
  ?x ?p ?y .
  ?y ?p ?z 
}
The document uses the namespaces shown below.
prefix kg:  <http://ns.inria.fr/corese/kgram/>
prefix rul: <http://ns.inria.fr/corese/rule/>

 

Inference Rule Engine

A rule base consists of a list of rules. The rule engine evaluates a rule base as follows. It considers all the rules, in order in the rule base. For each rule, it executes the where clause and if there are solutions, it instantiates the triple patterns of the construct clause with every solution to form a set of triples. Then, it inserts these triples into the current dataset. In order to enhance tracability, triples infered by the rule engine are inserted in the kg:rule named graph in the dataset. The rule engine iterates the cycle above on the entire rule base, possibly several times, until no new triple is generated. Termination is ensured provided that two conditions are verified: no new graph nodes are inserted and no new properties are created. In this case, termination is ensured because the rule engine engine stops after saturation.

Negation is authorized in the where clause, e.g. minus and filter not exists. However, the rule engine does not perform any consistency checking. Hence, a rule can deduce something based on the absence of a pattern while another rule can infer the pattern that was considered absent, in which case there may be a contradiction. In addition, rules do not retract triples from the dataset.

The query below enables users to retrieve triples infered by the rule engine.

select * 
from kg:rule
where {  
    ?s ?p ?o
}

 

Syntax

Inference rules are construct where SPARQL queries. They can use every SPARQL statements, including property path, bind, values and service. Rules are defined in an RDF document with .rul extension, using RDF/XML syntax as shown below. Rules should be placed within CDATA sections in order to parse correctly < and & characters. Each rule must declare its prefix and namespaces.

<?xml version="1.0"?>
<rdf:RDF 
    xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns     = "http://ns.inria.fr/corese/rule/">

<rule>
<body>  
<![CDATA[
prefix owl: <http://www.w3.org/2002/07/owl#>
construct {
  ?x ?p ?z
}
where {
  ?p a owl:TransitiveProperty .
  ?x ?p ?y .
  ?y ?p ?z 
}
]]>
</body>
</rule>

<rule>
<body>  
<![CDATA[
prefix owl: <http://www.w3.org/2002/07/owl#>
construct {
  ?y ?p ?x
}
where {
  ?p a owl:SymmetricProperty .
  ?x ?p ?y .
}
]]>
</body>
</rule>

</rdf:RDF>