What could possibly be tricky about DL Safe SWRL rules? Well, the fact that I have to write out “DL Safe SWRL Rules” rather than merely “DL Safe Rules” or “SWRL Rules” should be some sort of indicator.
Recall that (arbitrary) SWRL rules act as a very expressive sort of class (or property, or class ‘n’ property, or…) axiom, the DL Safety restriction acts (most directly) on named individuals only. The restriction to named individuals is common to (most) databases and, in some ways, to Prolog and many rule languages as well.
(Sometimes, in query contexts, you’ll hear the term “active domain”. So, “domain”: the set of individuals we are talking about. “Active” I’m not so clear on, but I think the intuition is that it’s the part of the domain that you’ve directly touched and are working with by naming those individuals directly. Remember that in OWL it’s easy to describe things for which you have no name. Existential/someValuesOf restrictions are the obvious case. I can say that you have a parent without knowing, without knowing at all, who that parent is. I can say that you have a parent who is a doctor without knowing if that parent is your mom, your other mom, your dad, your step-dad, etc. That’s what makes arbitrary SWRL rules so powerful, yet difficult to work with: they have to consider all these possibilities (and more!). DL Safe SWRL rules merely need to consider the parents we’ve actually named.)
However, this is only one point of similarity. There are lots of ways that even DL Safe SWRL rules retain their SWRLiness…so one needs to be careful not to leap from, “Oh, DL Safe SWRL rules are more like Datalog rules because their variables range over the active domain alone!” to “So, I can slap a Datalog engine in front of my OWL reasoner and everything is hunky dory!”
No. This just isn’t true. There are cases where a full fledged OWL reasoner will give the same answers (for a particular class of answers) as a Datalog engine given the same input (e.g., a certain OWL KB and a bunch of DL Safe SWRL rules). But, as we saw, a SWRL KB with the rules interpreted as DL Safe will produce the same answers, for a certain class of answers as that SWRL KB with the rules treated generally. The relations between the formalisms (and their associated reasoner behavior) is not always obvious. Just off the top of my head, I’d say that as long as you don’t use any funky features such as negation as failure most more or less naive combinations of a rule engine with a DL reasoner to process DL Safe SWRL rules should be sound (i.e., won’t give you wrong answers) but not complete (i.e., will miss answers). (Don’t hold me to this!)
Take a simple example, ever so lightly adapted from the original DL Safe rule paper:
:Child (x) :- :GoodChild(x). :Child (x) :- :BadChild(x). :Oedipus rdf:type [a owl:Class; owl:unionOf (:BadChild, :GoodChild)].
(We’ll presume both rules are interpreted with the DL Safety restriction.)
(Ok, I’m not even pretending to make these directly usable anymore. It’s so much work! It really shouldn’t be the case that standardization makes building tutorials like this a slit-your-wrists matter. However, there is an SWRL encoding in RDF/XML of (a slightly modified version of) table 3 of the paper, which includes the Oedipus example.)
Question: Is Oedipus a child or not?
Let’s ask Pellet:
> ./pellet.sh -if http://owldl.com/ontologies/dl-safe.owl -r -c TREE -s OFF Input file: http://owldl.com/ontologies/dl-safe.owl Consistent: Yes Time: 2050 ms (Loading: 1456 Consistency: 82 Classification: 32 Realization: 480 ) Classification: owl:Thing - (dl-safe:Remus) dl-safe:BadChild - (dl-safe:Cain) dl-safe:Child - (dl-safe:Oedipus, dl-safe:Cain) dl-safe:GoodChild dl-safe:Grandchild dl-safe:Person - (dl-safe:Abel, dl-safe:Adam, dl-safe:Cain, dl-safe:Romulus)
% Below this line to the next percent sign goes in the top box. child(X) :- goodChild(X). child(X) :- badChild(X). rdfType(oedipus, unionOf([goodChild, badChild]). goodChild(bijan). % This goes into the query box child(X). % Hit "Run Query" and the result will include the following line mentioning bijan but no binding for oedipus X = bijan
Now, the rule engine person might chime in: “Ok, but you’re missing something…the rules that make sense out of the OWL part!” At this point, I heave a big ole sigh and say, “Not going to happen.” At least, not naively. You could go the KAON2 route in which case you translated the ontology part into potentially quite a few rules. Unless you are in one of the specific tractable fragments like HornSHIQ or DLP which have a fairly close correspondence between OWL Axioms and Rules, you aren’t going to get anything readable out of it. Implementing something like KAON2 is a comparable effort to implementing something like Pellet. You aren’t going to pop a simple axiomatization of the OWL vocabulary into a rules engine and get anything useful.
There is no magic pixie make-your-life-easy-by-rules dust. Sorry.
(This doesn’t mean standard rule engines aren’t useful, by any stretch of the imagination. A lot of the “best” ontologies fit into Horn-fragments of OWL or mostly into Horn-fragments of OWL which means that rule tech can be fairly straightforwardly applied. I’m not engaged in advocacy at the moment, but trying to raise the level of clarity. Decisions made for bad reasons are often bad!
Similarly, there are things you might be able to do to massage this particular example. But working from ad hoc examples is a pretty bad way to proceed (at least for completeness and correctness; for optimizations it’s a little more justifiable).)
Another perhaps tricky bit is contraposition. You can flip conditionals around if you have negation available. For example, consider the sentences:
If Bijan has finished the SWRL series, then he is working another series. If he is NOT working on another series, then Bijan has NOT finished the SWRL series.
In many rule systems, contraposition doesn’t really hold because you have no (classical) negation. But SWRL rules (including DL Safe ones) are standard first order conditionals.
A simple way to play with this is to make use of the correspondence between SWRL and OWL axioms. Basically, you can convert any OWL axiom to a SWRL rule, though DL Safety will restrict the meaning a bit.