You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by "Sébastien Boulet [intactile DESIGN]" <bo...@intactile.com> on 2015/01/28 11:28:47 UTC
Forward RETE and redundant deduction
Hello,
I have two rules which could produce the same triple:
String rules = "[r1: (?a eg:p ?b) -> (?a, eg:q, ?b)]" +
"[r2: (?a eg:r ?b) -> (?a, eg:q, ?b)]";
i have configured a GenericRuleReasoner in FORWARD_RETE mode.
GenericRuleReasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
reasoner.setMode(GenericRuleReasoner.FORWARD_RETE);
InfModel model = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
When a triple satisfy the first rule and another triple satisfy the second rule:
Resource subject = model.createResource();
Property predicateP = model.getProperty("urn:x-hp:eg/p");
Literal literalA = model.createTypedLiteral("A");
Property predicateR = model.getProperty("urn:x-hp:eg/r");
model.add(subject, predicateP, literalA);
model.add(subject, predicateR, literalA);
only one triple is deduced:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:j.0="urn:x-hp:eg/" >
<rdf:Description rdf:nodeID="A0">
<j.0:r rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:r>
<j.0:p rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:p>
<j.0:q rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:q>
</rdf:Description>
</rdf:RDF>
When i remove the fist triple:
model.remove(subject, predicateP, literalA);
the sole deduced triple is removed even if the second rule is still satisfied:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:j.0="urn:x-hp:eg/" >
<rdf:Description rdf:nodeID="A0">
<j.0:r rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:r>
</rdf:Description>
</rdf:RDF>
is it the expected behavior ?
is there a workaround to deduce twice the same triple or at least to don’t remove the sole deduction ?
Thanks
Sébastien BOULET
LEAD DÉVELOPPEUR
intactile DESIGN
Création d’interfaces + subtiles
04 67 52 88 61
09 50 12 05 66
20 rue du carré du roi
34000 MONTPELLIER
France
www.intactile.com <http://intactile.com/>
Les informations contenues dans cet email et ses documents attachés sont confidentielles. Elles sont exclusivement adressées aux destinataires explicitement désignés ci-dessus et ne peuvent être divulguées sans consentement de son auteur. Si vous n'êtes pas le destinataire de cet email vous ne devez pas employer, révéler, distribuer, copier, imprimer ou transmettre le contenu de cet email et devez le détruire immédiatement.
Re: Forward RETE and redundant deduction
Posted by "Christophe FAGOT [intactile DESIGN]" <fa...@intactile.com>.
Hi Dave,
thanks for your detailed answer. Things are really clear for us now.
Chris.
> Le 1 févr. 2015 à 13:45, Dave Reynolds <da...@gmail.com> a écrit :
>
> On 29/01/15 10:06, Christophe FAGOT [intactile DESIGN] wrote:
>> Hi Dave,
>>
>> my answers and comments are in the following. It’s good to talk about RETE engines :-)
>>
>>> Le 28 janv. 2015 à 19:33, Dave Reynolds <da...@gmail.com> a écrit :
>>>
>>> On 28/01/15 14:06, Christophe FAGOT [intactile DESIGN] wrote:
>>>> Hi Andy,
>>>>
>>>> thanks for your answer, and I’m ok for the graph being a set of triples, it is the (very good) reason explaining why only one triple is produced. But the reasoner is not in forward model. It is a forward-RETE model, which means that the forward rules have to work incrementally, allowing to add and remove triples and maintaining the consistency of the model.
>>>>
>>>> So in the case described by Sébastien, the forward-RETE model should not remove the inferred triple since another rule has its body terms still validated. At least, this last rule should have been fired in order to indicate it that the triple which was not created previously (because it was still in the graph) is going to be removed, so this last rule should produce it again.
>>>
>>> The RETE engine stops once a triple has been deduced by one route. If you attempt to track each possible route by which a triple could be deduced and reference count them all then you will get a combinatoric explosion in numbers of possible deduction paths and performance plummets (which is why naive truth maintenance never worked out).
>>
>> You don’t need to track each possible route to maintain the truth. In a previous company Sébastien and I created a home-made RETE engine, and simple counters stored with triples are enough to maintain the truth of the graph. The counter is increased each time a triple is redundantly added, and decreased when the triple is asked to be removed. The triple is really removed from the graph when its counter is at 0. So, no combinatoric explosion.
>
> The first version of the Jena engine did such reference counting but it was later scrapped. Agreed that you don't have to store the deduction path but you still have to follow each deduction path in order to maintain the reference counts. For rule sets like OWL which involve lots of equality reasoning there can be lots such such duplicate paths. That's where the combinatorics bites. For the usages we were seeing with Jena then the benefit of avoiding redundantly re-deriving deductions outweighed the cost of have non-incremental deletes.
>
>>> The Jena engine works around this by not attempting to handle removals incrementally at all. A remove is supposed to mark the model as needing a new "prepare" stage and the entire deduction process is run from scratch again the next time you query the model.
>>
>> So, if I well understand what you say, the RETE Engine is monotonic and maintain the truth when adding some triples, but it’s not the case when triples are removed. Am I true?
>
> Yes.
>
>> If, when removing a triple, we want to maintain the truth in a graph managed by the RETE engine, we have to do as if the engine was a classical forward one and require a new « prepare » stage (meaning the removing of the whole previous inferences). Am I true on this point too ?
>
> Yes.
>
> Dave
Re: Forward RETE and redundant deduction
Posted by Dave Reynolds <da...@gmail.com>.
On 29/01/15 10:06, Christophe FAGOT [intactile DESIGN] wrote:
> Hi Dave,
>
> my answers and comments are in the following. It’s good to talk about RETE engines :-)
>
>> Le 28 janv. 2015 à 19:33, Dave Reynolds <da...@gmail.com> a écrit :
>>
>> On 28/01/15 14:06, Christophe FAGOT [intactile DESIGN] wrote:
>>> Hi Andy,
>>>
>>> thanks for your answer, and I’m ok for the graph being a set of triples, it is the (very good) reason explaining why only one triple is produced. But the reasoner is not in forward model. It is a forward-RETE model, which means that the forward rules have to work incrementally, allowing to add and remove triples and maintaining the consistency of the model.
>>>
>>> So in the case described by Sébastien, the forward-RETE model should not remove the inferred triple since another rule has its body terms still validated. At least, this last rule should have been fired in order to indicate it that the triple which was not created previously (because it was still in the graph) is going to be removed, so this last rule should produce it again.
>>
>> The RETE engine stops once a triple has been deduced by one route. If you attempt to track each possible route by which a triple could be deduced and reference count them all then you will get a combinatoric explosion in numbers of possible deduction paths and performance plummets (which is why naive truth maintenance never worked out).
>
> You don’t need to track each possible route to maintain the truth. In a previous company Sébastien and I created a home-made RETE engine, and simple counters stored with triples are enough to maintain the truth of the graph. The counter is increased each time a triple is redundantly added, and decreased when the triple is asked to be removed. The triple is really removed from the graph when its counter is at 0. So, no combinatoric explosion.
The first version of the Jena engine did such reference counting but it
was later scrapped. Agreed that you don't have to store the deduction
path but you still have to follow each deduction path in order to
maintain the reference counts. For rule sets like OWL which involve lots
of equality reasoning there can be lots such such duplicate paths.
That's where the combinatorics bites. For the usages we were seeing with
Jena then the benefit of avoiding redundantly re-deriving deductions
outweighed the cost of have non-incremental deletes.
>> The Jena engine works around this by not attempting to handle removals incrementally at all. A remove is supposed to mark the model as needing a new "prepare" stage and the entire deduction process is run from scratch again the next time you query the model.
>
> So, if I well understand what you say, the RETE Engine is monotonic and maintain the truth when adding some triples, but it’s not the case when triples are removed. Am I true?
Yes.
> If, when removing a triple, we want to maintain the truth in a graph managed by the RETE engine, we have to do as if the engine was a classical forward one and require a new « prepare » stage (meaning the removing of the whole previous inferences). Am I true on this point too ?
Yes.
Dave
Re: Forward RETE and redundant deduction
Posted by "Christophe FAGOT [intactile DESIGN]" <fa...@intactile.com>.
Hi Dave,
my answers and comments are in the following. It’s good to talk about RETE engines :-)
> Le 28 janv. 2015 à 19:33, Dave Reynolds <da...@gmail.com> a écrit :
>
> On 28/01/15 14:06, Christophe FAGOT [intactile DESIGN] wrote:
>> Hi Andy,
>>
>> thanks for your answer, and I’m ok for the graph being a set of triples, it is the (very good) reason explaining why only one triple is produced. But the reasoner is not in forward model. It is a forward-RETE model, which means that the forward rules have to work incrementally, allowing to add and remove triples and maintaining the consistency of the model.
>>
>> So in the case described by Sébastien, the forward-RETE model should not remove the inferred triple since another rule has its body terms still validated. At least, this last rule should have been fired in order to indicate it that the triple which was not created previously (because it was still in the graph) is going to be removed, so this last rule should produce it again.
>
> The RETE engine stops once a triple has been deduced by one route. If you attempt to track each possible route by which a triple could be deduced and reference count them all then you will get a combinatoric explosion in numbers of possible deduction paths and performance plummets (which is why naive truth maintenance never worked out).
You don’t need to track each possible route to maintain the truth. In a previous company Sébastien and I created a home-made RETE engine, and simple counters stored with triples are enough to maintain the truth of the graph. The counter is increased each time a triple is redundantly added, and decreased when the triple is asked to be removed. The triple is really removed from the graph when its counter is at 0. So, no combinatoric explosion.
>
> The Jena engine works around this by not attempting to handle removals incrementally at all. A remove is supposed to mark the model as needing a new "prepare" stage and the entire deduction process is run from scratch again the next time you query the model.
So, if I well understand what you say, the RETE Engine is monotonic and maintain the truth when adding some triples, but it’s not the case when triples are removed. Am I true?
If, when removing a triple, we want to maintain the truth in a graph managed by the RETE engine, we have to do as if the engine was a classical forward one and require a new « prepare » stage (meaning the removing of the whole previous inferences). Am I true on this point too ?
If what I write is true, I now fully understand what you wrote to me in the past about the removal into the RETE engine :-D
>
> That certainly used to work and I can't see why Sébastien's case would fail, though I don't see the code by which the results are getting accessed. I'm not in a position to test it from here.
It fails if, for whatever reason depending on the software you are developing, you can’t remove the whole infered triples each time you remove a single one.And it’s our case :-(
But whatever, having your explanations is good for us to understand if and where we can patch the current Jena RETE engine (and dependencies), or if we have to deal with it by our side.
Chris.
>
> Dave
>
>> Chris.
>>
>> Christophe FAGOT, PhD
>> RESPONSABLE R&D INFORMATIQUE
>>
>> intactile DESIGN
>> Création d’interfaces + subtiles
>> +33 (0)4 67 52 88 61
>> +33 (0)9 50 12 05 66
>> 20 rue du carré du roi
>> 34000 MONTPELLIER
>> France
>> www.intactile.com <http://intactile.com/>
>>
>> Hugh MacLeod : "It's not what the software does, it's what the user does"
>>
>> Les informations contenues dans cet email et ses documents attachés sont confidentielles. Elles sont exclusivement adressées aux destinataires explicitement désignés ci-dessus et ne peuvent être divulguées sans consentement de son auteur. Si vous n'êtes pas le destinataire de cet email vous ne devez pas employer, révéler, distribuer, copier, imprimer ou transmettre le contenu de cet email et devez le détruire immédiatement.
>>
>>> Le 28 janv. 2015 à 12:17, Andy Seaborne <an...@apache.org> a écrit :
>>>
>>> (Dave is not around at the moment so I'll try to answer some parts of your question ...)
>>>
>>> On 28/01/15 10:28, "Sébastien Boulet [intactile DESIGN]" wrote:
>>>> Hello,
>>>>
>>>> I have two rules which could produce the same triple:
>>>>
>>>> String rules = "[r1: (?a eg:p ?b) -> (?a, eg:q, ?b)]" +
>>>> "[r2: (?a eg:r ?b) -> (?a, eg:q, ?b)]";
>>>>
>>>> i have configured a GenericRuleReasoner in FORWARD_RETE mode.
>>>>
>>>> GenericRuleReasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
>>>> reasoner.setMode(GenericRuleReasoner.FORWARD_RETE);
>>>> InfModel model = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
>>>>
>>>> When a triple satisfy the first rule and another triple satisfy the second rule:
>>>>
>>>> Resource subject = model.createResource();
>>>> Property predicateP = model.getProperty("urn:x-hp:eg/p");
>>>> Literal literalA = model.createTypedLiteral("A");
>>>> Property predicateR = model.getProperty("urn:x-hp:eg/r");
>>>>
>>>> model.add(subject, predicateP, literalA);
>>>> model.add(subject, predicateR, literalA);
>>>>
>>>> only one triple is deduced:
>>>
>>> An RDF graph is a set of triples.
>>>
>>> A set only has one of each thing in it.
>>>
>>> If you
>>> add(triple)
>>> add(triple)
>>>
>>> you will see only one triple in the output. This is not to do with inference, it is to do with an RDF graph being a set.
>>>
>>>>
>>>> <rdf:RDF
>>>> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>>>> xmlns:j.0="urn:x-hp:eg/" >
>>>> <rdf:Description rdf:nodeID="A0">
>>>> <j.0:r rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:r>
>>>> <j.0:p rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:p>
>>>> <j.0:q rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:q>
>>>> </rdf:Description>
>>>> </rdf:RDF>
>>>>
>>>> When i remove the fist triple:
>>>>
>>>> model.remove(subject, predicateP, literalA);
>>>>
>>>> the sole deduced triple is removed even if the second rule is still satisfied:
>>>
>>> You ran the reasoner in forward model - it included all deductions at the start and then does not run again until you ask it to.
>>>
>>> To trigger it again:
>>>
>>> InfModel.rebind()
>>> "Cause the inference model to reconsult the underlying data to take into account changes."
>>>
>>> or run in backward mode.
>>>
>>> Andy
>>>
>>>>
>>>> <rdf:RDF
>>>> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>>>> xmlns:j.0="urn:x-hp:eg/" >
>>>> <rdf:Description rdf:nodeID="A0">
>>>> <j.0:r rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:r>
>>>> </rdf:Description>
>>>> </rdf:RDF>
>>>>
>>>> is it the expected behavior ?
>>>> is there a workaround to deduce twice the same triple or at least to don’t remove the sole deduction ?
>>>>
>>>> Thanks
>>>>
>>>>
>>>> Sébastien BOULET
>>>> LEAD DÉVELOPPEUR
>>>>
>>>> intactile DESIGN
>>>> Création d’interfaces + subtiles
>>>> 04 67 52 88 61
>>>> 09 50 12 05 66
>>>> 20 rue du carré du roi
>>>> 34000 MONTPELLIER
>>>> France
>>>> www.intactile.com <http://intactile.com/>
>>>>
>>>> Les informations contenues dans cet email et ses documents attachés sont confidentielles. Elles sont exclusivement adressées aux destinataires explicitement désignés ci-dessus et ne peuvent être divulguées sans consentement de son auteur. Si vous n'êtes pas le destinataire de cet email vous ne devez pas employer, révéler, distribuer, copier, imprimer ou transmettre le contenu de cet email et devez le détruire immédiatement.
>>
>>
>
Re: Forward RETE and redundant deduction
Posted by Dave Reynolds <da...@gmail.com>.
On 28/01/15 14:06, Christophe FAGOT [intactile DESIGN] wrote:
> Hi Andy,
>
> thanks for your answer, and I’m ok for the graph being a set of triples, it is the (very good) reason explaining why only one triple is produced. But the reasoner is not in forward model. It is a forward-RETE model, which means that the forward rules have to work incrementally, allowing to add and remove triples and maintaining the consistency of the model.
>
> So in the case described by Sébastien, the forward-RETE model should not remove the inferred triple since another rule has its body terms still validated. At least, this last rule should have been fired in order to indicate it that the triple which was not created previously (because it was still in the graph) is going to be removed, so this last rule should produce it again.
The RETE engine stops once a triple has been deduced by one route. If
you attempt to track each possible route by which a triple could be
deduced and reference count them all then you will get a combinatoric
explosion in numbers of possible deduction paths and performance
plummets (which is why naive truth maintenance never worked out).
The Jena engine works around this by not attempting to handle removals
incrementally at all. A remove is supposed to mark the model as needing
a new "prepare" stage and the entire deduction process is run from
scratch again the next time you query the model.
That certainly used to work and I can't see why Sébastien's case would
fail, though I don't see the code by which the results are getting
accessed. I'm not in a position to test it from here.
Dave
> Chris.
>
> Christophe FAGOT, PhD
> RESPONSABLE R&D INFORMATIQUE
>
> intactile DESIGN
> Création d’interfaces + subtiles
> +33 (0)4 67 52 88 61
> +33 (0)9 50 12 05 66
> 20 rue du carré du roi
> 34000 MONTPELLIER
> France
> www.intactile.com <http://intactile.com/>
>
> Hugh MacLeod : "It's not what the software does, it's what the user does"
>
> Les informations contenues dans cet email et ses documents attachés sont confidentielles. Elles sont exclusivement adressées aux destinataires explicitement désignés ci-dessus et ne peuvent être divulguées sans consentement de son auteur. Si vous n'êtes pas le destinataire de cet email vous ne devez pas employer, révéler, distribuer, copier, imprimer ou transmettre le contenu de cet email et devez le détruire immédiatement.
>
>> Le 28 janv. 2015 à 12:17, Andy Seaborne <an...@apache.org> a écrit :
>>
>> (Dave is not around at the moment so I'll try to answer some parts of your question ...)
>>
>> On 28/01/15 10:28, "Sébastien Boulet [intactile DESIGN]" wrote:
>>> Hello,
>>>
>>> I have two rules which could produce the same triple:
>>>
>>> String rules = "[r1: (?a eg:p ?b) -> (?a, eg:q, ?b)]" +
>>> "[r2: (?a eg:r ?b) -> (?a, eg:q, ?b)]";
>>>
>>> i have configured a GenericRuleReasoner in FORWARD_RETE mode.
>>>
>>> GenericRuleReasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
>>> reasoner.setMode(GenericRuleReasoner.FORWARD_RETE);
>>> InfModel model = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
>>>
>>> When a triple satisfy the first rule and another triple satisfy the second rule:
>>>
>>> Resource subject = model.createResource();
>>> Property predicateP = model.getProperty("urn:x-hp:eg/p");
>>> Literal literalA = model.createTypedLiteral("A");
>>> Property predicateR = model.getProperty("urn:x-hp:eg/r");
>>>
>>> model.add(subject, predicateP, literalA);
>>> model.add(subject, predicateR, literalA);
>>>
>>> only one triple is deduced:
>>
>> An RDF graph is a set of triples.
>>
>> A set only has one of each thing in it.
>>
>> If you
>> add(triple)
>> add(triple)
>>
>> you will see only one triple in the output. This is not to do with inference, it is to do with an RDF graph being a set.
>>
>>>
>>> <rdf:RDF
>>> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>>> xmlns:j.0="urn:x-hp:eg/" >
>>> <rdf:Description rdf:nodeID="A0">
>>> <j.0:r rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:r>
>>> <j.0:p rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:p>
>>> <j.0:q rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:q>
>>> </rdf:Description>
>>> </rdf:RDF>
>>>
>>> When i remove the fist triple:
>>>
>>> model.remove(subject, predicateP, literalA);
>>>
>>> the sole deduced triple is removed even if the second rule is still satisfied:
>>
>> You ran the reasoner in forward model - it included all deductions at the start and then does not run again until you ask it to.
>>
>> To trigger it again:
>>
>> InfModel.rebind()
>> "Cause the inference model to reconsult the underlying data to take into account changes."
>>
>> or run in backward mode.
>>
>> Andy
>>
>>>
>>> <rdf:RDF
>>> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>>> xmlns:j.0="urn:x-hp:eg/" >
>>> <rdf:Description rdf:nodeID="A0">
>>> <j.0:r rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:r>
>>> </rdf:Description>
>>> </rdf:RDF>
>>>
>>> is it the expected behavior ?
>>> is there a workaround to deduce twice the same triple or at least to don’t remove the sole deduction ?
>>>
>>> Thanks
>>>
>>>
>>> Sébastien BOULET
>>> LEAD DÉVELOPPEUR
>>>
>>> intactile DESIGN
>>> Création d’interfaces + subtiles
>>> 04 67 52 88 61
>>> 09 50 12 05 66
>>> 20 rue du carré du roi
>>> 34000 MONTPELLIER
>>> France
>>> www.intactile.com <http://intactile.com/>
>>>
>>> Les informations contenues dans cet email et ses documents attachés sont confidentielles. Elles sont exclusivement adressées aux destinataires explicitement désignés ci-dessus et ne peuvent être divulguées sans consentement de son auteur. Si vous n'êtes pas le destinataire de cet email vous ne devez pas employer, révéler, distribuer, copier, imprimer ou transmettre le contenu de cet email et devez le détruire immédiatement.
>
>
Re: Forward RETE and redundant deduction
Posted by "Christophe FAGOT [intactile DESIGN]" <fa...@intactile.com>.
Hi Andy,
thanks for your answer, and I’m ok for the graph being a set of triples, it is the (very good) reason explaining why only one triple is produced. But the reasoner is not in forward model. It is a forward-RETE model, which means that the forward rules have to work incrementally, allowing to add and remove triples and maintaining the consistency of the model.
So in the case described by Sébastien, the forward-RETE model should not remove the inferred triple since another rule has its body terms still validated. At least, this last rule should have been fired in order to indicate it that the triple which was not created previously (because it was still in the graph) is going to be removed, so this last rule should produce it again.
Chris.
Christophe FAGOT, PhD
RESPONSABLE R&D INFORMATIQUE
intactile DESIGN
Création d’interfaces + subtiles
+33 (0)4 67 52 88 61
+33 (0)9 50 12 05 66
20 rue du carré du roi
34000 MONTPELLIER
France
www.intactile.com <http://intactile.com/>
Hugh MacLeod : "It's not what the software does, it's what the user does"
Les informations contenues dans cet email et ses documents attachés sont confidentielles. Elles sont exclusivement adressées aux destinataires explicitement désignés ci-dessus et ne peuvent être divulguées sans consentement de son auteur. Si vous n'êtes pas le destinataire de cet email vous ne devez pas employer, révéler, distribuer, copier, imprimer ou transmettre le contenu de cet email et devez le détruire immédiatement.
> Le 28 janv. 2015 à 12:17, Andy Seaborne <an...@apache.org> a écrit :
>
> (Dave is not around at the moment so I'll try to answer some parts of your question ...)
>
> On 28/01/15 10:28, "Sébastien Boulet [intactile DESIGN]" wrote:
>> Hello,
>>
>> I have two rules which could produce the same triple:
>>
>> String rules = "[r1: (?a eg:p ?b) -> (?a, eg:q, ?b)]" +
>> "[r2: (?a eg:r ?b) -> (?a, eg:q, ?b)]";
>>
>> i have configured a GenericRuleReasoner in FORWARD_RETE mode.
>>
>> GenericRuleReasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
>> reasoner.setMode(GenericRuleReasoner.FORWARD_RETE);
>> InfModel model = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
>>
>> When a triple satisfy the first rule and another triple satisfy the second rule:
>>
>> Resource subject = model.createResource();
>> Property predicateP = model.getProperty("urn:x-hp:eg/p");
>> Literal literalA = model.createTypedLiteral("A");
>> Property predicateR = model.getProperty("urn:x-hp:eg/r");
>>
>> model.add(subject, predicateP, literalA);
>> model.add(subject, predicateR, literalA);
>>
>> only one triple is deduced:
>
> An RDF graph is a set of triples.
>
> A set only has one of each thing in it.
>
> If you
> add(triple)
> add(triple)
>
> you will see only one triple in the output. This is not to do with inference, it is to do with an RDF graph being a set.
>
>>
>> <rdf:RDF
>> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>> xmlns:j.0="urn:x-hp:eg/" >
>> <rdf:Description rdf:nodeID="A0">
>> <j.0:r rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:r>
>> <j.0:p rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:p>
>> <j.0:q rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:q>
>> </rdf:Description>
>> </rdf:RDF>
>>
>> When i remove the fist triple:
>>
>> model.remove(subject, predicateP, literalA);
>>
>> the sole deduced triple is removed even if the second rule is still satisfied:
>
> You ran the reasoner in forward model - it included all deductions at the start and then does not run again until you ask it to.
>
> To trigger it again:
>
> InfModel.rebind()
> "Cause the inference model to reconsult the underlying data to take into account changes."
>
> or run in backward mode.
>
> Andy
>
>>
>> <rdf:RDF
>> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>> xmlns:j.0="urn:x-hp:eg/" >
>> <rdf:Description rdf:nodeID="A0">
>> <j.0:r rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:r>
>> </rdf:Description>
>> </rdf:RDF>
>>
>> is it the expected behavior ?
>> is there a workaround to deduce twice the same triple or at least to don’t remove the sole deduction ?
>>
>> Thanks
>>
>>
>> Sébastien BOULET
>> LEAD DÉVELOPPEUR
>>
>> intactile DESIGN
>> Création d’interfaces + subtiles
>> 04 67 52 88 61
>> 09 50 12 05 66
>> 20 rue du carré du roi
>> 34000 MONTPELLIER
>> France
>> www.intactile.com <http://intactile.com/>
>>
>> Les informations contenues dans cet email et ses documents attachés sont confidentielles. Elles sont exclusivement adressées aux destinataires explicitement désignés ci-dessus et ne peuvent être divulguées sans consentement de son auteur. Si vous n'êtes pas le destinataire de cet email vous ne devez pas employer, révéler, distribuer, copier, imprimer ou transmettre le contenu de cet email et devez le détruire immédiatement.
Re: Forward RETE and redundant deduction
Posted by Andy Seaborne <an...@apache.org>.
(Dave is not around at the moment so I'll try to answer some parts of
your question ...)
On 28/01/15 10:28, "Sébastien Boulet [intactile DESIGN]" wrote:
> Hello,
>
> I have two rules which could produce the same triple:
>
> String rules = "[r1: (?a eg:p ?b) -> (?a, eg:q, ?b)]" +
> "[r2: (?a eg:r ?b) -> (?a, eg:q, ?b)]";
>
> i have configured a GenericRuleReasoner in FORWARD_RETE mode.
>
> GenericRuleReasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
> reasoner.setMode(GenericRuleReasoner.FORWARD_RETE);
> InfModel model = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
>
> When a triple satisfy the first rule and another triple satisfy the second rule:
>
> Resource subject = model.createResource();
> Property predicateP = model.getProperty("urn:x-hp:eg/p");
> Literal literalA = model.createTypedLiteral("A");
> Property predicateR = model.getProperty("urn:x-hp:eg/r");
>
> model.add(subject, predicateP, literalA);
> model.add(subject, predicateR, literalA);
>
> only one triple is deduced:
An RDF graph is a set of triples.
A set only has one of each thing in it.
If you
add(triple)
add(triple)
you will see only one triple in the output. This is not to do with
inference, it is to do with an RDF graph being a set.
>
> <rdf:RDF
> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
> xmlns:j.0="urn:x-hp:eg/" >
> <rdf:Description rdf:nodeID="A0">
> <j.0:r rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:r>
> <j.0:p rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:p>
> <j.0:q rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:q>
> </rdf:Description>
> </rdf:RDF>
>
> When i remove the fist triple:
>
> model.remove(subject, predicateP, literalA);
>
> the sole deduced triple is removed even if the second rule is still satisfied:
You ran the reasoner in forward model - it included all deductions at
the start and then does not run again until you ask it to.
To trigger it again:
InfModel.rebind()
"Cause the inference model to reconsult the underlying data to take into
account changes."
or run in backward mode.
Andy
>
> <rdf:RDF
> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
> xmlns:j.0="urn:x-hp:eg/" >
> <rdf:Description rdf:nodeID="A0">
> <j.0:r rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A</j.0:r>
> </rdf:Description>
> </rdf:RDF>
>
> is it the expected behavior ?
> is there a workaround to deduce twice the same triple or at least to don’t remove the sole deduction ?
>
> Thanks
>
>
> Sébastien BOULET
> LEAD DÉVELOPPEUR
>
> intactile DESIGN
> Création d’interfaces + subtiles
> 04 67 52 88 61
> 09 50 12 05 66
> 20 rue du carré du roi
> 34000 MONTPELLIER
> France
> www.intactile.com <http://intactile.com/>
>
> Les informations contenues dans cet email et ses documents attachés sont confidentielles. Elles sont exclusivement adressées aux destinataires explicitement désignés ci-dessus et ne peuvent être divulguées sans consentement de son auteur. Si vous n'êtes pas le destinataire de cet email vous ne devez pas employer, révéler, distribuer, copier, imprimer ou transmettre le contenu de cet email et devez le détruire immédiatement.
>
>