Adding a timer to Jena rules?

206 views Asked by At

I have designed a set of Jena rules, where some of these rules keep working for a very long time without returning results. I tried to reduce my OWL file to check whether the rules are entering an infinite loop or not. Fortunately, it does not appear that there is an infinite loop, and a small number of classes (e.g., 100) is processed very quickly. However, when I add more classes, even just one more class, it takes a much longer to process.

Is there any way to add a timer to each rule, e.g., to terminate a rule if it is taking longer than a certain amount of time without returning results? If it is possible, how can I do it? If not, is there some workaround that would achieve similar results?

My Jena rule

[rule1: (?a rdf:type owl:Class) (?b rdf:type owl:Class) (?d rdf:type owl:Class) 
        equal(?a,?b) notEqual(?b,?d) notEqual(?a,?d)  (?d rdfs:subClassOf ?a)
        (?d rdf:type ?c) 
        -> (?a rdf:type ?c) print(?a,'is a Type of',?c)]

Some of my ontology

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:foaf="http://xmlns.com/foaf/0.1/"
   xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/"
   xmlns:dbpediaR="http://dbpedia.org/resource/" xmlns:dbpediaO="http://dbpedia.org/ontology/"
   xmlns:dbpediaOP="http://dbpedia.org/ontology/PopulatedPlace/"
   xmlns:dbpediaOW="http://dbpedia.org/ontology/Work/"
   xmlns:dbpediaP2="http://dbpedia.org/property/2000"
   xmlns:dbpediaP21="http://dbpedia.org/property/2010" xmlns:dbpediaP="http://dbpedia.org/property/"
   xmlns:dbpedia="http://dbpedia.org/" xmlns:skos="http://www.w3.org/2004/02/skos/core#"
   xmlns:w3prov="http://www.w3.org/ns/prov#"
   xmlns:w3wgs84="http://www.w3.org/2003/01/geo/wgs84_pos#"
   xmlns:georss="http://www.georss.org/georss/">
   <owl:Class rdf:about="http://www.w3.org/2002/07/owl#Thing"/>
<owl:Class rdf:about="http://dbpedia.org/resource/Vrije">
      <dbpediaO:wikiPageDisambiguates rdf:resource="dbpediaR:Het_Vrije_Volk"/>
      <dbpediaO:wikiPageDisambiguates rdf:resource="dbpediaR:Vrije_Universiteit"/>
      <dbpediaO:wikiPageDisambiguates rdf:resource="dbpediaR:Vrije_Universiteit_Brussel"/>
      <dbpediaO:wikiPageDisambiguates rdf:resource="dbpediaR:Brugse_Vrije"/>
      <foaf:isPrimaryTopicOf rdf:resource="http://en.wikipedia.org/wiki/Vrije"/>
      <w3prov:wasDerivedFrom rdf:resource="http://en.wikipedia.org/wiki/Vrije%3Foldid%3D437015722"/>
   </owl:Class>
 </rdf:RDF>
1

There are 1 answers

1
RobV On BEST ANSWER

It would help if you explained the intent of the rule, as written it looks a bit odd. You start by selecting a 3 way cross products of all types so you are immediately making life hard for the rule engine i.e.

(?a rdf:type owl:Class) (?b rdf:type owl:Class) (?d rdf:type owl:Class)

So given 100 owl:Class instances in your data your rule has to consider 100*100*100 combinations i.e 1 million combinations. Which is why adding a small amount of extra data makes this so much worse.

As for what the equal() and unequal() assertions are trying to do I am entirely unsure.

Are you simply trying to assert rdf:type for indirect super-classes? In which case this can be done more simply like so:

[(?a rdf:subClassOf ?b) (?b rdf:type ?c) -> (?a rdf:type ?c)]

Note that it doesn't matter if the triples generated already exist since RDF is a set of triples so duplicate data is simply ignored.