Corese News Corese

SPARQL Rules in Corese

Birahim Sall, Olivier Corby, INRIA, Novembre 2008.
See also: Corese

Corese proposes the notion of backward rules implemented as SPARQL construct queries. The construct part is interpreted as the head of the rule, the consequent that is proved. The where part is interpreted as the body, the condition that makes the head proved. When considered recursively, a set of construct SPARQL queries can be seen as a set of rules processed in backward chaining

Define a rule

construct {
  ?x rdf:type ex:Adult
}
where {
  ?x rdf:type ex:Human
  ?x ex:age ?age
  filter(?age >= 18)
}

Prove a query in backward chaining

IResults res = engine.SPARQLProve("select * where {?x rdf:type ex:Adult}");

Define a Rule Base

A rule base is defined within RDF/XML markup in a document whose suffix is ".brul".

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY rule   "http://ns.inria.fr/corese/2008/rule"> 
<!ENTITY rdf    "http://www.w3.org/1999/02/22-rdf-syntax-ns">
<!ENTITY rdfs   "http://www.w3.org/2000/01/rdf-schema">
<!ENTITY xsd    "http://www.w3.org/2001/XMLSchema#">
]>

<rdf:RDF 
    xmlns:rdf  ="&rdf;#" xmlns:rdfs ="&rdfs;#" xmlns:xsd  ="&xsd;" 
    xmlns:rule ="&rule;#" xmlns      ="&rule;#" >
        
<rule rdf:ID="rule1">
<rule:value>
prefix ex: <http://example.org>
construct {
  ?x rdf:type ex:Adult
}
where {
  ?x rdf:type ex:Human
  ?x ex:age ?age
  filter(?age >= 18)
}
</rule:value>
</rule>

</rdf:RDF>