Monday, January 05, 2009

OWL 2 RL in SPARQL using SPIN

The evolving OWL 2 standard comes with a profile called OWL RL. According to the OWL 2 RL W3C page "the OWL 2 RL profile is aimed at applications that require scalable reasoning without sacrificing too much expressive power. It is designed to accommodate both OWL 2 applications that can trade the full expressivity of the language for efficiency, and RDF(S) applications that need some added expressivity from OWL 2. This is achieved by defining a syntactic subset of OWL 2 which is amenable to implementation using rule-based technologies".

This means that there will soon be a well-defined specification that expresses the semantics of a good subset of OWL in a format that can be handled by rule engines. Many OWL implementations (such as OWLIM or Jena) have already used such a rule-based approach for ages and in many cases their performance is much better than with tableaux-based OWL implementations.

Based on its CONSTRUCT keyword, SPARQL can also be considered to be a rule language. SPIN is a new SPARQL-based vocabulary that we have recently introduced with TopBraid Composer 3.0 beta. SPIN can be used to encapsulate reusable SPARQL queries as templates. These templates can then be instantiated in any RDF or OWL ontology to add inference rules and constraint checks.

Mostly as an exercise and a proof-of-concept, I have converted the OWL RL rules into SPIN templates. The SPIN library at http://topbraid.org/spin/owlrl now contains the complete OWL 2 RL specification in executable form, formalized in SPARQL CONSTRUCT rules.

The following screen shows the example OWL RL rule cax-eq2 encoded as a SPIN template:



The example above implements the rule that if c1 has been declared to be owl:equivalentClass of c2 and x is an instance of c2, then x is also an instance of c1. In order to activate this type of inferencing in your model, you just need to instantiate this template as a spin:rule at owl:Thing. Or simply import the file http://topbraid.org/spin/owlrl-all, which activates all rules for all instances of owl:Thing.

This mechanism can not only be used to fine-tune the inferences for a specific model, but also to enhance the expressivity of other inference engines. TopBraid Composer allows users to combine inference engines, e.g. to run SPARQL rules on top of Jena inferencing. By activating a couple of rules from the OWL RL library, you can use some new OWL 2 keywords such as owl:key or owl:propertyChain in your model. And you can do all this yourself - just write your own SPIN rules to implement your own domain-specific modeling language and then share them with the others on the Semantic Web!

Note: the OWL RL SPIN library above is basically untested but I would appreciate bug reports or other suggestions on how to improve it. The conversion of most rules was straight-forward, but there were a handful of rules that were tricky to convert to SPARQL, especially those with "for-all" semantics. In one case (owl:key) I had to introduce a user-defined SPIN function to negate a list traversal. In some other cases I had to rely on built-in Jena functions such as list:member. For property chains, I only implemented chains with the length of two, e.g. the infamous "uncle" relationship. However, other lengths can easily be added if they ever become relevant in practice.

The following example uses the OWL RL property chain rule to infer the uncle relationship between two instances. The source code of the corresponding OWL file (in N3 is below, updated for the latest OWL 2 version from June 11, 2009).




@prefix spin: <http://spinrdf.org/spin#> .
@prefix xsd: <http://www.w3.org/2001/xmlschema#> .
@prefix owlrl: <http://topbraid.org/spin/owlrl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix : <http://topbraid.org/spin/owlrl-test#> .

<http://topbraid.org/spin/owlrl-test>
a owl:Ontology ;
owl:imports ;
owl:versionInfo "Created with TopBraid Composer"^^xsd:string .

# Instantiate SPIN template with property chain semantics
owl:Thing
spin:rule
[ a owlrl:prp-spo2-2
] .

:Person
a owl:Class ;
rdfs:subClassOf owl:Thing .

:Darwin
a :Person ;
:parent :Holger .

:Holger
a :Person ;
:brother :Thorsten .

:Thorsten
a :Person .

:brother
a owl:ObjectProperty .

:parent
a owl:ObjectProperty .

:uncle
a owl:ObjectProperty ;
owl:propertyChainAxiom (:parent :brother) .

# defines the new OWL 2 property if needed
owl:propertyChainAxiom
a rdf:Property ;
rdfs:label "property chain axiom"^^xsd:string ;
rdfs:range rdf:List .

0 Comments:

Post a Comment

<< Home