On Sun, Feb 20, 2011 at 2:10 AM, Mark Proctor <mproctor(a)codehaus.org> wrote:
On 19/02/2011 15:01, Simon Chen wrote:
> Let me make sure I get it correctly...
>
> The example you gave seems to be the one-hop case. For the two-hop
> case, we need something like this
>
> when
> edge(a, b), reach(b, c), not exists reach(a, c)
> then
> insertLogical( reach(a,c) )
>
> So, where do you put your logical around? It should include both
> edge(a,b) and reach(b,c), right?
>
> Another thought, can we have something like
> testExistsAndInsertLogical() to replace insertLogical()? But this may
> be buggy, as the conditions are all met, so the rule actually fired...
>
> I really need this working, so I'll probably take a crack at modifying
> drools, although haven't done it before...
I'm just thinking about what it is you want to do. Do you wan to
pre-compute a matrix for fast lookup if C is reachable from A? Where the
integrity of that matrix is maintained by logical insertions?
Or are you trying to do adhoc reachability with minimial maintained
state, no pre-calculated state, where performance is not such an issue?
Hi Mark,
Well, I came from the datalog world, where such issue doesn't exist.
Basically, I am trying to mimic datalog's reachability rules in
Drools. In datalog, we simply put:
reachable(a,b) :- link(a,b)
reachable(a,b) :- link(a,z), reachable(z,b)
Insertion is always easy to handle, but deletion isn't, unless we keep
some sort of dependency among different objects. It seems that
insertLogic() in Drools is an easy way out, except for the tricky
issue I mentioned in the original post.
To answer your question, I have all sort of different objects flying
around, and want to derive certain knowledge based on those objects.
The derived knowledge should be dependent on the existing objects,
which may change over time. This reachability is just an example of
such recursive dependency.
Thanks.
-Simon
Mark
> Thanks.
> -Simon
>
> On Saturday, February 19, 2011, Mark Proctor<mproctor(a)codehaus.org> wrote:
>> I think to impl this what is needed is a "logical" node. At the moment
>> the entire LHS forms the justification. But if we supported a logical
>> node, we could do this:
>> rule "reachDirect"
>> salience 10
>> when
>> logical( e : Edge(s1 : source, t1 : target) )
>> not( Reach(source == s1, target == t1) )
>> then
>> insertLogical( new Reach(e.getSource(),e.getTarget()) );
>> System.out.println( "Reach " + e.getSource() + ","
+
>> e.getTarget() );
>> end
>>
>>
>> That means that it would be inserted when there was no Reach, but it
>> would only be retracted when there was no matching Edge. The
>> justification is only for the part of the rule that is in the logical
>> grouping.
>>
>> To do this is actually quite a trivial change in drools, but it's not
>> something we do now. I think one reason why I held off was that i was
>> looking at Jess and Clips that have this and they state you can have
>> multiple logical elements. But i could't figure out how having 2 or 3
>> would differ, compare to having just one.
>>
>> Anway to support a singe logical element, you'd need to update the
>> parser to support 'logical' conditional element, in the same format as
>> 'not' and 'exists'. Then if you look at RuleTerminalNode
you'll see the
>> part of the code that is related to removing the justifications, on a
>> retract or modify - removeLogicalDependencies. Likewise if you look in
>> the DefaultKnowlegeHelper you'll see how the insertion works. That could
>> would instead be copied to the logical node. If a logical node exists
>> the RTN should have an if statement so the same code does not execute again.
>>
>> Any takers?
>>
>> Mark
>>
>>
>> On 19/02/2011 05:20, Simon Chen wrote:
>>> Hi all,
>>>
>>> I know this is kinda an old topic, but I just couldn't get it working.
>>>
>>> Here is a previous attempt using insertLogical() to handle transitive
>>> closure:
>>>
http://drools-java-rules-engine.46999.n3.nabble.com/transitive-closure-td...
>>> The problem with this one is that the newly "logically inserted"
object
>>> would violate its own "not exists" condition term, thus removing
itself,
>>> then goes the infinite circle of insert/remove...
>>>
>>> Here is a post that deals with transitive closure using "insert",
but it
>>> doesn't handle object removal correctly:
>>>
http://drools-java-rules-engine.46999.n3.nabble.com/one-question-about-Tr...
>>>
>>>
>>> To me, using insertLogical is attractive because it doesn't require me
to
>>> write specific rules to handle object removal. Is there a trick that I can
>>> use to actually implement transitive closure with insertLogical?
>>>
>>> Thanks a lot!
>>> -Simon
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users(a)lists.jboss.org
>>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users(a)lists.jboss.org
>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users