Question

I am currently messing around with Jena trying to create rules to add to my generic reasoner. I created the following simple rule:

[rule1: (?x ?rdf:type ?y),(?y rdfs:subClassOf ?z)-> (?x rdfs:type ?z)]

This works fine, and fires correctly, giving me everything I expect. After I did this I wanted to assign a timestamp to ?x, so that I'd know when the conclusion was come to, I wanted to used the Now builtin as follows.

[rule1: (?x ?rdf:type ?y),(?y rdfs:subClassOf ?z),now(?x)-> (?x rdfs:type ?z)]

This unfortunately does not work, it does nor throw an error, it just does not seem to bind any time value to ?x and also it seems to prevent the rule from being fired correctly as in the first case. The ontology I am using is below. Any ideas?

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:owl="http://www.w3.org/2002/07/owl#">
  <owl:Class rdf:about="livingthing"></owl:Class>
  <owl:Class rdf:about="Human">
    <rdfs:subClassOf rdf:resource="livingthing"/>
  </owl:Class>
  <rdf:Description rdf:about="john">
    <rdf:type rdf:resource="Human"/>
  </rdf:Description>
</rdf:RDF>
Was it helpful?

Solution

According to the javadoc, Now will “Bind the first arg to the current date time in the current locale and timezone.” I haven't tried using Now, but I'd expect that "the current date time in the current locale and timezone" is a some sort of RDF literal (perhaps a date or datetime)? Literals cannot be the subjects of triples in RDF. For the rule

[rule1: (?x ?rdf:type ?y),(?y rdfs:subClassOf ?z),now(?x) -> (?x rdfs:type ?z)]

to match in the graph, the variable ?x will be bound to the date literal, say, "2013-05-24" (but as I mentioned, I don't know exactly what Now will produce) but there cannot be any matches for (?x rdf:type ?y) because these would have the form "2013-05-24" rdf:type ?y and there cannot be triples of that form. This means that the rule cannot fire.

If you want to add a timestamp to something, you probably want an n-ary relation, so that you're actually representing (or representing, in addition to ?x rdf:type ?z) a relation inferredSubclassRule(?super,?sub,?time ), which can be represented in RDF by a blank node like:

[] a :inferredSubclassRule ;
   :hasSuperClass ?super ;
   :hasSubClass ?sub ;
   :hasTimestamp ?time .
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top