Hi Dave, thanks for the answer. I was not aware that the backward reasoner started at triple patterns (retrieved from the SPARQL query), so I will definitely test whether that indeed causes the rule to be applied once instead of twice in the example described in my second post.
My setup uses Apache Jena Fuseki, so the PROPruleMode should be configured via a assembly TTL file. Do you know how to do that? I found the 'http://jena.hpl.hp.com/2003/RuleReasoner/ruleMode' property in the ReasonerVocabulary.java file [1], but it does not seem to load this property when I use the following assembly: @prefix rr: <http://jena.hpl.hp.com/2003/RuleReasoner> . . . . <#infGraph> rdf:type ja:InfModel ; ja:reasoner [ ja:rulesFrom <file:src/test/resources/et.rules> ; rr:ruleMode "backward" ; ] ; ja:content <#test-inf> . Any pointers are welcome! Regards, Barry [1] https://github.com/apache/jena/blob/cc038809fb622779933831011909714e22ef494c/jena-core/src/main/java/org/apache/jena/vocabulary/ReasonerVocabulary.java#L77 -----Original Message----- From: Dave Reynolds [mailto:[email protected]] Sent: woensdag 17 januari 2018 09:33 To: [email protected] Subject: Re: GenericRuleReasoner with limited scope On 16/01/18 09:55, Nouwt, B. (Barry) wrote: > Hi everyone, > > Currently I'm using the GenericRuleReasoner of Apache Jena in my project to > apply custom rules to my RDF data. This works as expected: as soon as I > execute the first SPARQL query in Apache Jena Fuseki, the GenericRuleReasoner > correctly determines all the derived triples and the query can be answered. > > Now I am looking for the following GenericRuleReasoner (or another reasoner) > behavior: > > 1. I would like the GenericRuleReasoner to take the SPARQL query into > account when reasoning. So, only reason about those facts that 'seem' > relevant for answering the SPARQL query. > 2. I would like the GenericRuleReasoner to remove the derived triples > after the SPARQL query has been answered. So, the next time it receives the > same SPARQL query, it will not be able to reuse the previous reasoning result. If I understand what you want then use the backward rather than forward engine. The GenericRuleReasoner contains two engines which can be used separately or in a cascade (hybrid mode). For configuring this see PROPruleMode in https://jena.apache.org/documentation/inference/#RULEconfiguration The backward reasoner is driven by goals at the level of triple patterns and isn't aware of the overall sparql query so the goals are not very selective but it will at least help with point #1. In terms of point #2 then the backward engine, by default, will not retain any answers. You can use the tabling declarations to cause it to selectively remember the answer to specific (sub)goals if you need to see: https://jena.apache.org/documentation/inference/#RULEbackward Note that in hybrid mode (the default) you can still use backward rules by writing them with the arrow reversed. The advantage of switching the reasoner mode is that you can use the same rule source syntax and run the rules in either forward or backward mode to test the difference. Dave This message may contain information that is not intended for you. If you are not the addressee or if this message was sent to you by mistake, you are requested to inform the sender and delete the message. TNO accepts no liability for the content of this e-mail, for the manner in which you use it and for damage of any kind resulting from the risks inherent to the electronic transmission of messages.
