Re: [rules-users] Negation semantics in Drools

2009-04-17 Thread Paul Fodor
Hi Edson,

2009/4/17 Edson Tirelli 

>
>
>Paul,
>
>I am not an expert on logic programming, but in this case, your example
> is negating a goal (not a fact) in the backward chaining:
>
> win(X):- move(X,Y), not(win(Y)).
>
>Pure forward chaining systems don't have goals, since they are data
> driven.
>
>I don't think this would be a good or fair comparison because it is
> comparing a native concept in one side and an emulated concept in the other
> side. If you were negating an actual fact, the comparison would be more an
> apples-to-apples comparison.


>From the logic point of view, win/2 and move/2 are both literals (atoms, if
no explicit negation is used) and we define clauses (which can be
facts or rules). The logical semantics (well-founded model theory or stable
model semantics) makes no distinction between the negation of a literal
move/2 (defined through a set of facts) and the negation of a literal win/2
(which is defined through a recursive rule).

These are declarative semantics and have nothing to do with the operational
semantics (how to actually compute them).
There are forward chaining systems (such as: DLV, OntoBroker from Ontoprise,
IRIS) that compute them as well as some top-down systems (tabled XSB, Yap).

We are interested in measuring the performance for a set of features
that are considered important for the Semantic Web (computing logical
models, dynamic updates, joins or relations, recursion rules, persistent
data, etc.). For all these features we wanted to test the technology for
rule systems (production rule systems were one of the technologies we
studied). I agree that production rule systems are more fit for other
tasks (for instance, reactive rules), but we wanted to see if they can be
easily used for the Semantic Web tasks. For each feature that we tested, we
tried our best to represent it in the best way for every given system. We
are always open to sugestions of other banchmarks to test.

Regards,
 Paul


>
>Just my .02c
>
>
> Edson
>
> 2009/4/17 Paul Fodor 
>
>> Now, I am curious. What is the background on this exercise? There are
>>> some problems that are better suited for backward and others better suited
>>> for forward chaining. Most problems would be modeled in very different ways
>>> in each technology.
>>
>>
>> It is just a set of tests we made in a suite of benchmarks. We wanted
>> compare and benchmark both the different the technologies and various rule
>> systems.
>>
>>
>>>If we were just searching for the solution, it would just be the case
>>> of writing (in forward chaining) one or two rules that would provide the
>>> correct answer. But since this seems to be an academic exercise, I am
>>> curious to understand the goals of it so that we can properly model it.
>>
>>
>> The goal of this particular test (and our other stratified or
>> non-stratified tests) was to see how efficient are implementations of
>> default negation in rule systems. Programs using negation can be very
>> various, but we tried to come up with a bunch of standard classic problems
>> and implemented them in the best way possible in each rule system.
>>
>> You are right that each technology has its own strong and weak points
>> depending on the tasks intended to solve. Even the way of implementing each
>> particular task differs a lot on various rule systems.
>>
>> Regards,
>> Paul.
>>
>>
>>>Cheers,
>>
>>
>>>Edson
>>>
>>> 2009/4/17 Paul Fodor 
>>>
>>>> Hi Edson,
>>>>
>>>> The "insertLogical" doesn't work for non-stratified programs.
>>>> For instance, in the win-nowin example, if there is a move(1,2) and
>>>> a move(2,1), the order in which the two facts are inserted determines the
>>>> final model (please see hte tests below).
>>>>
>>>> In logic programming, this example has two stable models: {win(1)} and
>>>> {win(2)}, or a well-founded model {} (win(1) and win(2) are both 
>>>> undefined).
>>>>
>>>> Regards,
>>>> Paul.
>>>>  *
>>>>
>>>> package
>>>> *tests;
>>>>
>>>> *
>>>>
>>>> import
>>>> *tests.Test.Win;*
>>>>
>>>> import
>>>> *tests.Test.Move;
>>>>
>>>> *
>>>>
>>>> rule
>>>> *"direct"
>>>>
>>>> *when*
>>>>
>>>> m : Move(x : first, y : second)
>>>>

Re: [rules-users] Negation semantics in Drools

2009-04-17 Thread Paul Fodor
>
>Now, I am curious. What is the background on this exercise? There are
> some problems that are better suited for backward and others better suited
> for forward chaining. Most problems would be modeled in very different ways
> in each technology.


It is just a set of tests we made in a suite of benchmarks. We wanted
compare and benchmark both the different the technologies and various rule
systems.


>If we were just searching for the solution, it would just be the case of
> writing (in forward chaining) one or two rules that would provide the
> correct answer. But since this seems to be an academic exercise, I am
> curious to understand the goals of it so that we can properly model it.


The goal of this particular test (and our other stratified or non-stratified
tests) was to see how efficient are implementations of default negation in
rule systems. Programs using negation can be very various, but we tried to
come up with a bunch of standard classic problems and implemented them in
the best way possible in each rule system.

You are right that each technology has its own strong and weak points
depending on the tasks intended to solve. Even the way of implementing each
particular task differs a lot on various rule systems.

Regards,
Paul.


>Cheers,


>    Edson
>
> 2009/4/17 Paul Fodor 
>
>> Hi Edson,
>>
>> The "insertLogical" doesn't work for non-stratified programs.
>> For instance, in the win-nowin example, if there is a move(1,2) and
>> a move(2,1), the order in which the two facts are inserted determines the
>> final model (please see hte tests below).
>>
>> In logic programming, this example has two stable models: {win(1)} and
>> {win(2)}, or a well-founded model {} (win(1) and win(2) are both undefined).
>>
>> Regards,
>> Paul.
>>  *
>>
>> package
>> *tests;
>>
>> *
>>
>> import
>> *tests.Test.Win;*
>>
>> import
>> *tests.Test.Move;
>>
>> *
>>
>> rule
>> *"direct"
>>
>> *when*
>>
>> m : Move(x : first, y : second)
>>
>> *not* Win(first == y)
>>
>> *then*
>>
>> *insertLogical*(*new* Win(m.getFirst()));*
>>
>> end
>> *
>>
>> move
>>
>> 1
>>
>> 2
>>
>> move
>>
>> 2
>>
>> 1
>>
>> Test:
>>
>> reading rulefile: win.drl ...
>>
>> reading datafile: win_upper3_drools.drools ...
>>
>> loading cputime: 0.016
>>
>> loading walltime: 0.016
>>
>> calculating ...
>>
>> computing cputime: 0.0
>>
>> computing walltime: 0.0040
>>
>> Derived facts in memory:move(1, 2).
>>
>> win(2).
>>
>> move(2, 1).
>>
>> 3
>>
>> move
>>
>> 2
>>
>> 1
>>
>> move
>>
>> 1
>>
>> 2
>>
>> Test:
>>
>> reading rulefile: win.drl ...
>>
>> reading datafile: win_upper4_drools.drools ...
>>
>> loading cputime: 0.016
>>
>> loading walltime: 0.016
>>
>> calculating ...
>>
>> computing cputime: 0.0
>>
>> computing walltime: 0.0040
>>
>> Derived facts in memory:move(2, 1).
>>
>> win(1).
>>
>> move(1, 2).
>>
>> 3
>>
>> 2009/4/17 Edson Tirelli 
>>   >
>> >
>> >I did not had time to analyze what jess is doing, but note that what
>> is important is the final answer. In your example, with Move(1,2) and
>> Move(2,3), the final answer must be Win(2), right? And that is what Drools
>> will answer, does not matter the order in which the data is entered into the
>> engine.
>> >
>> >BUT, *very important*: the following construct in backward chaining:
>> >
>> > win(X):- move(X,Y), not(win(Y)).
>> >
>> > Is better represented in forward chaining using *logicalInsert*
>> instead of a regular *insert*:
>> >
>> > rule "direct" % Drools
>> >
>> > when
>> > m : Move(x : first, y : second)
>> > not Win(first == y)
>> > then
>> > logicalInsert(new Win(m.getFirst()));
>> > end
>> >
>> > Since in your backward chaining rule, only one win() predicate
>> instantiation will remain true.
>> >
>> > So, even with differences in the reasoning algorithm, the answer is
>> correct.
>> >
>> > Please explain further if I am missing anything.
>> >
>> > Edson
>> >
&

Re: [rules-users] Negation semantics in Drools

2009-04-17 Thread Paul Fodor
I looked in the manual and I think this was your intended behaviour for
insertLogical (your approach to the best it can be done). I think it's fine.
Not many programs are non locally stratified, so this is definitely good
enough.
Paul.
On Fri, Apr 17, 2009 at 5:13 PM, Paul Fodor  wrote:

> Hi Edson,
>
> The "insertLogical" doesn't work for non-stratified programs.
> For instance, in the win-nowin example, if there is a move(1,2) and
> a move(2,1), the order in which the two facts are inserted determines the
> final model (please see hte tests below).
>
> In logic programming, this example has two stable models: {win(1)} and
> {win(2)}, or a well-founded model {} (win(1) and win(2) are both undefined).
>
> Regards,
> Paul.
>  *
>
> package
> *tests;
>
> *
>
> import
> *tests.Test.Win;*
>
> import
> *tests.Test.Move;
>
> *
>
> rule
> *"direct"
>
> *when*
>
> m : Move(x : first, y : second)
>
> *not* Win(first == y)
>
> *then*
>
> *insertLogical*(*new* Win(m.getFirst()));*
>
> end
> *
>
> move
>
> 1
>
> 2
>
> move
>
> 2
>
> 1
>
> Test:
>
> reading rulefile: win.drl ...
>
> reading datafile: win_upper3_drools.drools ...
>
> loading cputime: 0.016
>
> loading walltime: 0.016
>
> calculating ...
>
> computing cputime: 0.0
>
> computing walltime: 0.0040
>
> Derived facts in memory:move(1, 2).
>
> win(2).
>
> move(2, 1).
>
> 3
>
> move
>
> 2
>
> 1
>
> move
>
> 1
>
> 2
>
> Test:
>
> reading rulefile: win.drl ...
>
> reading datafile: win_upper4_drools.drools ...
>
> loading cputime: 0.016
>
> loading walltime: 0.016
>
> calculating ...
>
> computing cputime: 0.0
>
> computing walltime: 0.0040
>
> Derived facts in memory:move(2, 1).
>
> win(1).
>
> move(1, 2).
>
> 3
>
> 2009/4/17 Edson Tirelli 
>   >
> >
> >I did not had time to analyze what jess is doing, but note that what
> is important is the final answer. In your example, with Move(1,2) and
> Move(2,3), the final answer must be Win(2), right? And that is what Drools
> will answer, does not matter the order in which the data is entered into the
> engine.
> >
> >BUT, *very important*: the following construct in backward chaining:
> >
> > win(X):- move(X,Y), not(win(Y)).
> >
> > Is better represented in forward chaining using *logicalInsert*
> instead of a regular *insert*:
> >
> > rule "direct" % Drools
> >
> > when
> > m : Move(x : first, y : second)
> > not Win(first == y)
> > then
> > logicalInsert(new Win(m.getFirst()));
> > end
> >
> > Since in your backward chaining rule, only one win() predicate
> instantiation will remain true.
> >
> > So, even with differences in the reasoning algorithm, the answer is
> correct.
> >
> > Please explain further if I am missing anything.
> >
> > Edson
> >
> >
> > 2009/4/17 Paul Fodor 
> >>
> >> Hi Edson, Greg,
> >> I don't think the rule is written wrong. This is how the win-nowin
> program is written in logic programming: X wins if there is a move from X to
> some Y and Y doesn't win:
> >>
> >> win(X):- move(X,Y), not(win(Y)).
> >>
> >> rule "direct" % Drools
> >>
> >> when
> >> m : Move(x : first, y : second)
> >> not Win(first == y)
> >> then
> >>  insert(new Win(m.getFirst()));
> >> end
> >>
> >> I think that it's interesting that, in Jess (another production rule
> system), the stratified model is always computed right, no matter what was
> the order of the facts in the database. If you want to take a look, please
> see the equivalent program in Jess for win-nowin that I attached. Just run
> it with:
> >> jess test.clp
> >>
> >> win_upper1_jess.jess
> >>
> >> (move (cur 1) (next 2))
> >> (move (cur 1) (next 3))
> >> (move (cur 2) (next 4))
> >> (move (cur 2) (next 5))
> >> ...
> >>
> >> win_upper2_jess.jess
> >>
> >> (move (cur 2) (next 4))
> >> (move (cur 2) (next 5))
> >> (move (cur 1) (next 2))
> >> (move (cur 1) (next 3))
> >> ...
> >>
> >> test.clp:
> >>
> >> (deftemplate move (slot cur) (slot next))
> >> (deftemplate win (slot val))
> >>
> >> (defrule find_wi

Re: [rules-users] Negation semantics in Drools

2009-04-17 Thread Paul Fodor
Hi Edson,

The "insertLogical" doesn't work for non-stratified programs.
For instance, in the win-nowin example, if there is a move(1,2) and
a move(2,1), the order in which the two facts are inserted determines the
final model (please see hte tests below).

In logic programming, this example has two stable models: {win(1)} and
{win(2)}, or a well-founded model {} (win(1) and win(2) are both undefined).

Regards,
Paul.
*

package
* tests;

*

import
* tests.Test.Win;*

import
* tests.Test.Move;

*

rule
* "direct"

*when*

m : Move(x : first, y : second)

*not* Win(first == y)

*then*

*insertLogical*(*new* Win(m.getFirst()));*

end
*

move

1

2

move

2

1

Test:

reading rulefile: win.drl ...

reading datafile: win_upper3_drools.drools ...

loading cputime: 0.016

loading walltime: 0.016

calculating ...

computing cputime: 0.0

computing walltime: 0.0040

Derived facts in memory:move(1, 2).

win(2).

move(2, 1).

3

move

2

1

move

1

2

Test:

reading rulefile: win.drl ...

reading datafile: win_upper4_drools.drools ...

loading cputime: 0.016

loading walltime: 0.016

calculating ...

computing cputime: 0.0

computing walltime: 0.0040

Derived facts in memory:move(2, 1).

win(1).

move(1, 2).

3

2009/4/17 Edson Tirelli 
>
>
>I did not had time to analyze what jess is doing, but note that what is
important is the final answer. In your example, with Move(1,2) and
Move(2,3), the final answer must be Win(2), right? And that is what Drools
will answer, does not matter the order in which the data is entered into the
engine.
>
>BUT, *very important*: the following construct in backward chaining:
>
> win(X):- move(X,Y), not(win(Y)).
>
> Is better represented in forward chaining using *logicalInsert*
instead of a regular *insert*:
>
> rule "direct" % Drools
>
> when
> m : Move(x : first, y : second)
> not Win(first == y)
> then
> logicalInsert(new Win(m.getFirst()));
> end
>
> Since in your backward chaining rule, only one win() predicate
instantiation will remain true.
>
> So, even with differences in the reasoning algorithm, the answer is
correct.
>
> Please explain further if I am missing anything.
>
> Edson
>
>
> 2009/4/17 Paul Fodor 
>>
>> Hi Edson, Greg,
>> I don't think the rule is written wrong. This is how the win-nowin
program is written in logic programming: X wins if there is a move from X to
some Y and Y doesn't win:
>>
>> win(X):- move(X,Y), not(win(Y)).
>>
>> rule "direct" % Drools
>>
>> when
>> m : Move(x : first, y : second)
>> not Win(first == y)
>> then
>>  insert(new Win(m.getFirst()));
>> end
>>
>> I think that it's interesting that, in Jess (another production rule
system), the stratified model is always computed right, no matter what was
the order of the facts in the database. If you want to take a look, please
see the equivalent program in Jess for win-nowin that I attached. Just run
it with:
>> jess test.clp
>>
>> win_upper1_jess.jess
>>
>> (move (cur 1) (next 2))
>> (move (cur 1) (next 3))
>> (move (cur 2) (next 4))
>> (move (cur 2) (next 5))
>> ...
>>
>> win_upper2_jess.jess
>>
>> (move (cur 2) (next 4))
>> (move (cur 2) (next 5))
>> (move (cur 1) (next 2))
>> (move (cur 1) (next 3))
>> ...
>>
>> test.clp:
>>
>> (deftemplate move (slot cur) (slot next))
>> (deftemplate win (slot val))
>>
>> (defrule find_win
>>  (move (cur ?cur) (next ?next))
>>  (not (win (val ?next)))
>>  =>
>>  (assert (win (val ?cur)))
>> )
>>
>> (defquery query-win
>>   (win (val ?val))
>> )
>> (open "win_result.txt" output a)
>> (printout output  ./win_upper1_jess.jess crlf)
>> (reset)
>> (load-facts "./win_upper1_jess.jess")
>> (bind ?tmx (call java.lang.management.ManagementFactory getThreadMXBean))
>> (deffunction cputime () (return (* (?tmx getCurrentThreadCpuTime) 1E-9)))
>> (bind ?starttime_wall (time))
>> (bind ?starttime_cpu (cputime))
>> (run)
>> (bind ?query_result (run-query* query-win))
>> (bind ?count 0)
>> (while (?query_result next)
>> (++ ?count)
>> )
>> (printout output "solutions: " ?count crlf)
>> (bind ?endtime_cpu (cputime))
>> (bind ?endtime_wall (time))
>> (bind ?walltime (- ?endtime_wall ?starttime_wall))
>> (bind ?cputime (- ?endtime_cpu ?starttime_cpu))
>> (printout output "computing cputime: " ?cputime crlf)
>> (printout output "computing walltime: " ?wall

Re: [rules-users] Comparison info with other engines

2009-04-17 Thread Paul Fodor
2009/4/17 Lindy hagan 

> I'm wondering if anybody has comparison info with other engines. I just
> started to evaluate the products
> not sure which factors to consider. But I have these requirements:
>

It has to be a production rule system or any rule system (logic programming,
deductive databases, triples rule engines)? Check the benchmarks at:
http://rulebench.projects.semwebcentral.org
The benchmarks may have features which you might not need, and not all the
tested systems are free. Its main goal was to compare technologies, but it
might help you decide what system you want.
Regards,
Paul Fodor


> Must Be
> 1)Free or inexpensive product.
> 2)Rules change frequently, level of effort should be minimum.
> 3)Multiple join condition (A rule is determined ranging from 1 to 10 data
> fields.)
> 4)Should support approximately 75 rules.
>
> Better if we have.
> 1)Change Rules dynamically if possible.
> 2)Ease of use for Business users and developers.
> 3)Rule versioning.
>
> Will be happy if any one can send me rule comparison document or suggest me
> which tools can i use to evaluate.
>
> Thanks,
> Lindy
>
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Negation semantics in Drools

2009-04-17 Thread Paul Fodor
I see. Thank you,
Paul.

2009/4/17 Edson Tirelli 

>
>I did not had time to analyze what jess is doing, but note that what is
> important is the final answer. In your example, with Move(1,2) and
> Move(2,3), the final answer must be Win(2), right? And that is what Drools
> will answer, does not matter the order in which the data is entered into the
> engine.
>
>BUT, *very important*: the following construct in backward chaining:
>
> win(X):- move(X,Y), not(win(Y)).
>
> Is better represented in forward chaining using *logicalInsert* instead
> of a regular *insert*:
>
> rule "direct" % Drools
> when
> m : Move(x : first, y : second)
> not Win(first == y)
> then
> logicalInsert(new Win(m.getFirst()));
> end
>
> Since in your backward chaining rule, only one win() predicate
> instantiation will remain true.
>
> So, even with differences in the reasoning algorithm, the answer is
> correct.
>
> Please explain further if I am missing anything.
>
> Edson
>
>
> 2009/4/17 Paul Fodor 
>
>  Hi Edson, Greg,
>> I don't think the rule is written wrong. This is how the win-nowin program
>> is written in logic programming: X wins if there is a move from X to some Y
>> and Y doesn't win:
>> win(X):- move(X,Y), not(win(Y)).
>>
>> rule "direct" % Drools
>>
>> when
>> m : Move(x : first, y : second)
>> not Win(first == y)
>> then
>>  insert(new Win(m.getFirst()));
>> end
>>
>> I think that it's interesting that, in Jess (another production rule
>> system), the stratified model is always computed right, no matter what was
>> the order of the facts in the database. If you want to take a look, please
>> see the equivalent program in Jess for win-nowin that I attached. Just run
>> it with:
>> jess test.clp
>>
>> win_upper1_jess.jess
>>
>> (move (cur 1) (next 2))
>> (move (cur 1) (next 3))
>> (move (cur 2) (next 4))
>> (move (cur 2) (next 5))
>> ...
>>
>> win_upper2_jess.jess
>>
>> (move (cur 2) (next 4))
>> (move (cur 2) (next 5))
>> (move (cur 1) (next 2))
>> (move (cur 1) (next 3))
>> ...
>>
>> test.clp:
>>
>> (deftemplate move (slot cur) (slot next))
>> (deftemplate win (slot val))
>>
>> (defrule find_win
>>  (move (cur ?cur) (next ?next))
>>  (not (win (val ?next)))
>>  =>
>>  (assert (win (val ?cur)))
>> )
>>
>> (defquery query-win
>>   (win (val ?val))
>> )
>> (open "win_result.txt" output a)
>> (printout output  ./win_upper1_jess.jess crlf)
>> (reset)
>> (load-facts "./win_upper1_jess.jess")
>> (bind ?tmx (call java.lang.management.ManagementFactory getThreadMXBean))
>> (deffunction cputime () (return (* (?tmx getCurrentThreadCpuTime) 1E-9)))
>> (bind ?starttime_wall (time))
>> (bind ?starttime_cpu (cputime))
>> (run)
>> (bind ?query_result (run-query* query-win))
>> (bind ?count 0)
>> (while (?query_result next)
>> (++ ?count)
>> )
>> (printout output "solutions: " ?count crlf)
>> (bind ?endtime_cpu (cputime))
>> (bind ?endtime_wall (time))
>> (bind ?walltime (- ?endtime_wall ?starttime_wall))
>> (bind ?cputime (- ?endtime_cpu ?starttime_cpu))
>> (printout output "computing cputime: " ?cputime crlf)
>> (printout output "computing walltime: " ?walltime crlf)
>> (close output)
>>
>> Regards,
>> Paul Fodor.
>> 2009/4/16 Edson Tirelli 
>>
>>
>>>Ha, thanks a lot Greg. I need new glasses... he is actually comparing
>>> with the parameter "second", but when creating the win fact, using the
>>> parameter "first".
>>>
>>> not Win(first == m.second)
>>>   insert(new Win(m.first));
>>>
>>>Yes, in this case the engine is working exactly as it should.
>>>
>>>Anyway, I added the (fixed) test case to the codebase, just in case.
>>> :)
>>>
>>>Thanks,
>>>Edson
>>>
>>> 2009/4/16 Greg Barton 
>>>
>>> You don't have to worry.  The engine is acting as it should.
>>>>
>>>> The rule Paul had was this, a bit simplified for clarity:
>>>>
>>>> rule "direct"
>>>> when
>>>>m : Move()
>>>>not Win(first == m.second)
>>>> then
>>>>insert(new W

Re: [rules-users] Negation semantics in Drools

2009-04-17 Thread Paul Fodor
Hi Edson, Greg,
I don't think the rule is written wrong. This is how the win-nowin program
is written in logic programming: X wins if there is a move from X to some Y
and Y doesn't win:
win(X):- move(X,Y), not(win(Y)).

rule "direct" % Drools
when
m : Move(x : first, y : second)
not Win(first == y)
then
 insert(new Win(m.getFirst()));
end

I think that it's interesting that, in Jess (another production rule
system), the stratified model is always computed right, no matter what was
the order of the facts in the database. If you want to take a look, please
see the equivalent program in Jess for win-nowin that I attached. Just run
it with:
jess test.clp

win_upper1_jess.jess

(move (cur 1) (next 2))
(move (cur 1) (next 3))
(move (cur 2) (next 4))
(move (cur 2) (next 5))
...

win_upper2_jess.jess

(move (cur 2) (next 4))
(move (cur 2) (next 5))
(move (cur 1) (next 2))
(move (cur 1) (next 3))
...

test.clp:

(deftemplate move (slot cur) (slot next))
(deftemplate win (slot val))

(defrule find_win
 (move (cur ?cur) (next ?next))
 (not (win (val ?next)))
 =>
 (assert (win (val ?cur)))
)

(defquery query-win
  (win (val ?val))
)
(open "win_result.txt" output a)
(printout output  ./win_upper1_jess.jess crlf)
(reset)
(load-facts "./win_upper1_jess.jess")
(bind ?tmx (call java.lang.management.ManagementFactory getThreadMXBean))
(deffunction cputime () (return (* (?tmx getCurrentThreadCpuTime) 1E-9)))
(bind ?starttime_wall (time))
(bind ?starttime_cpu (cputime))
(run)
(bind ?query_result (run-query* query-win))
(bind ?count 0)
(while (?query_result next)
(++ ?count)
)
(printout output "solutions: " ?count crlf)
(bind ?endtime_cpu (cputime))
(bind ?endtime_wall (time))
(bind ?walltime (- ?endtime_wall ?starttime_wall))
(bind ?cputime (- ?endtime_cpu ?starttime_cpu))
(printout output "computing cputime: " ?cputime crlf)
(printout output "computing walltime: " ?walltime crlf)
(close output)

Regards,
Paul Fodor.
2009/4/16 Edson Tirelli 

>
>Ha, thanks a lot Greg. I need new glasses... he is actually comparing
> with the parameter "second", but when creating the win fact, using the
> parameter "first".
>
> not Win(first == m.second)
>   insert(new Win(m.first));
>
>Yes, in this case the engine is working exactly as it should.
>
>Anyway, I added the (fixed) test case to the codebase, just in case. :)
>
>Thanks,
>Edson
>
> 2009/4/16 Greg Barton 
>
> You don't have to worry.  The engine is acting as it should.
>>
>> The rule Paul had was this, a bit simplified for clarity:
>>
>> rule "direct"
>> when
>>m : Move()
>>not Win(first == m.second)
>> then
>>insert(new Win(m.first));
>> end
>>
>> If the insertion order is [Move(1,2), Move(2,3)] then the rule matches
>> first on Move(2,3) and Win(2) is inserted.  No other rule fires because now
>> Move(1,2) and Win(2) match up, removing the instantiation with Move(1,2)
>> from the agenda.
>>
>> If the insertion order is [Move(2,3), Move(1,2)] then the order is this:
>>
>> matched Move(1,2) insert Win(1)
>> matched Move(2,3) insert Win(2)
>>
>> The insertion of Win(1) in the first firing does NOT prevent the
>> instantiation with Move(2,3) from then firing.
>>
>> So it's all good. :)  Sample code and output attached.
>>
>> --- On Thu, 4/16/09, Greg Barton  wrote:
>>
>> > From: Greg Barton 
>> > Subject: Re: [rules-users] Negation semantics in Drools
>> > To: "Rules Users List" 
>> > Date: Thursday, April 16, 2009, 8:50 PM
>>  > It is on the latest snapshot release,
>> > 5.0.0.20090417.005612-483
>> >
>> > --- On Thu, 4/16/09, Edson Tirelli 
>> > wrote:
>> >
>> > > We need to investigate if that is still happening
>> > in
>> > > latest trunk.
>> >
>> >
>> >
>> > ___
>> > rules-users mailing list
>> > rules-users@lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>>
>>
>> ___
>> rules-users mailing list
>> rules-users@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
> --
>  Edson Tirelli
>  JBoss Drools Core Development
>  JBoss, a division of Red Hat @ www.jboss.com
>
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Negation semantics in Drools

2009-04-16 Thread Paul Fodor
On Thu, Apr 16, 2009 at 1:18 PM, Greg Barton  wrote:

>
> This is not a problem with negation.  I don't think you understand rule
> conflict resolution.
>
> Here's your rule:
>
> rule "direct"
> when
>  m : Move(x : first, y : second)
>  not Win(first == y)
> then
>  insert(new Win(m.getFirst()));
> end
>
> This rule, regardles of whether it uses negation, will be affected by fact
> insertion order.  This is because the first condition will match on any Move
> in working memory.  When all of the potential firings of this rule are put
> on the agenda, which will initially be one for each Move in working memory,
> one must be selected to fire.  The order of fact insertion (recency) is one
> of the ways Drools resolves this by default.


Thank you. I see.


> If you don't want that behavior you can change it by using a different
> conflict resolver instance.  See classes in the package org.drools.conflict:
>
>
> https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/javadocs/unstable/drools-core/org/drools/conflict/package-summary.html

Or define your own.


That is very dificult task. The win-nowin test was just an example of use of
the default negation. My requirement covers stratified or non-stratified
logic programs, and not one example in particular.
I don't really think that it is possible to implement a general "rule
conflict resolution" resolver for default negation. This is hard
in production rule systems.

Paul.


> You can install a new one by calling either of these methods on your
> RuleBaseConfiguration:
>
> setProperty("drools.conflictResolver", )
>
> or
>
> setConflictResolver()
>
> --- On Thu, 4/16/09, Paul Fodor  wrote:
>
> > From: Paul Fodor 
> > Subject: [rules-users] Negation semantics in Drools
> > To: "Rules Users List" 
> > Date: Thursday, April 16, 2009, 10:43 AM
>  > Dear Sir,
> >
> > I found a problem with negation in Drools when changing the
> > order of the
> > facts in the database also changes the final model.
> > Consider the classic win-nowin problem encoded in Drools as
> > follows:
> >
> > win.drl:
> >
> > package tests;
> > import tests.Test.Win;
> > import tests.Test.Move;
> > rule "direct"
> > when
> > m : Move(x : first, y : second)
> > not Win(first == y)
> > then
> >  insert(new Win(m.getFirst()));
> > end
> >
> > With two moves in the database: move(1,2) and move(2,3),
> > for one order of the facts in the input file we get one
> > result: win(2),
> > while for the other order (i.e., move(2,3) and move(1,2))
> > we get 2 results:
> > win(1) and win(2).
> >
> > For win_upper1_drools.drools:
> > > java tests.Test win_upper1_drools.drools win.drl
> > result
> > reading rulefile: win.drl ...
> > reading datafile: win_upper1_drools.drools ...
> > computing cputime: 0.0
> > computing walltime: 0.0030
> > Derived facts in memory:move(1, 2).
> > win(2).
> > move(2, 3).
> > 3
> >
> > For win_upper2_drools.drools:
> > > java tests.Test win_upper2_drools.drools win.drl
> > result
> > reading rulefile: win.drl ...
> > reading datafile: win_upper2_drools.drools ...
> > computing cputime: 0.0
> > computing walltime: 0.0040
> > Derived facts in memory:win(1).
> > win(2).
> > move(1, 2).
> > move(2, 3).
> > 4
> >
> > I attached all the sources used in these tests in the
> > email. This example is
> > locally stratified. I am using the latest released version
> > of Drools.
> >
> > Regards,
> >  Paul Fodor
> >
> > win.drl:
> >
> > package tests;
> > import tests.Test.Win;
> > import tests.Test.Move;
> > rule "direct"
> > when
> > m : Move(x : first, y : second)
> >  not Win(first == y)
> > then
> >  insert(new Win(m.getFirst()));
> > end
> >
> >
> > win_upper1_drools.drools:
> >
> > move
> > 1
> > 2
> > move
> > 2
> > 3
> >
> > win_upper2_drools.drools:
> >
> > move
> > 2
> > 3
> > move
> > 1
> > 2
> >
> > Test.java:
> >
> > package tests;
> > import java.io.*;
> > import java.io.InputStreamReader;
> > import org.drools.RuleBase;
> > import org.drools.RuleBaseFactory;
> > import org.drools.StatefulSession;
> > import org.drools.compiler.PackageBuilder;
> > import org.drools.FactHandle;
> >

[rules-users] Negation semantics in Drools

2009-04-16 Thread Paul Fodor
Dear Sir,

I found a problem with negation in Drools when changing the order of the
facts in the database also changes the final model.
Consider the classic win-nowin problem encoded in Drools as follows:

win.drl:

package tests;
import tests.Test.Win;
import tests.Test.Move;
rule "direct"
when
m : Move(x : first, y : second)
not Win(first == y)
then
 insert(new Win(m.getFirst()));
end

With two moves in the database: move(1,2) and move(2,3),
for one order of the facts in the input file we get one result: win(2),
while for the other order (i.e., move(2,3) and move(1,2)) we get 2 results:
win(1) and win(2).

For win_upper1_drools.drools:
> java tests.Test win_upper1_drools.drools win.drl result
reading rulefile: win.drl ...
reading datafile: win_upper1_drools.drools ...
computing cputime: 0.0
computing walltime: 0.0030
Derived facts in memory:move(1, 2).
win(2).
move(2, 3).
3

For win_upper2_drools.drools:
> java tests.Test win_upper2_drools.drools win.drl result
reading rulefile: win.drl ...
reading datafile: win_upper2_drools.drools ...
computing cputime: 0.0
computing walltime: 0.0040
Derived facts in memory:win(1).
win(2).
move(1, 2).
move(2, 3).
4

I attached all the sources used in these tests in the email. This example is
locally stratified. I am using the latest released version of Drools.

Regards,
 Paul Fodor

win.drl:

package tests;
import tests.Test.Win;
import tests.Test.Move;
rule "direct"
when
m : Move(x : first, y : second)
 not Win(first == y)
then
 insert(new Win(m.getFirst()));
end


win_upper1_drools.drools:

move
1
2
move
2
3

win_upper2_drools.drools:

move
2
3
move
1
2

Test.java:

package tests;
import java.io.*;
import java.io.InputStreamReader;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.compiler.PackageBuilder;
import org.drools.FactHandle;
import java.util.Iterator;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
public class Test {
public static void main (String args[]) {
 if (args.length < 3) {
 usage();
 }
 long starttime_cpu, endtime_cpu, starttime_sys, endtime_sys;
 double cputime, walltime;
 ThreadMXBean tb_cpu = ManagementFactory.getThreadMXBean();
 // create rulebase
 try {
 FileWriter output = new FileWriter(args[2]);
 BufferedWriter bufWrite = new BufferedWriter(output);
 bufWrite.write(args[0] + "\n");
 bufWrite.flush();
 System.out.println("reading rulefile: " + args[1] + " ...");
 Reader source = new
InputStreamReader(Test.class.getResourceAsStream(args[1]));
 final PackageBuilder builder = new PackageBuilder();
 builder.addPackageFromDrl(source);
 if (builder.hasErrors()) {
  System.out.println(builder.getErrors().toString());
  System.exit(0);
 }
 final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 ruleBase.addPackage(builder.getPackage());
 final StatefulSession session = ruleBase.newStatefulSession();
 // loading datafile
 System.out.println("reading datafile: " + args[0] + " ...");
 FileReader input = new FileReader(args[0]);
 starttime_sys = System.nanoTime();
 starttime_cpu = tb_cpu.getCurrentThreadCpuTime();
 BufferedReader bufRead = new BufferedReader(input);
 String first, second, line = bufRead.readLine();
 while (line != null) {
  if (line.compareTo("move") == 0) {
  first = bufRead.readLine();
  second = bufRead.readLine();
  session.insert(new Move(first, second));
  }
  else if (line.compareTo("par") == 0) {
  first = bufRead.readLine();
  second = bufRead.readLine();
  session.insert(new ClassPar(first, second));
  }
  else if (line.compareTo("sib") == 0) {
  first = bufRead.readLine();
  second = bufRead.readLine();
  session.insert(new ClassSib(first, second));
  }
  line = bufRead.readLine();
 }
 endtime_cpu = tb_cpu.getCurrentThreadCpuTime();
 endtime_sys = System.nanoTime();
 cputime = (endtime_cpu - starttime_cpu) * 1e-9;
 cputime = Math.round(cputime * 1000) * 1e-3;
 walltime = (endtime_sys - starttime_sys) * 1e-9;
 walltime = Math.round(walltime * 1000) * 1e-3;
 bufWrite.write("loading cputime: " + cputime + "\n");
 bufWrite.write("loading walltime: " + walltime + "\n");
 bufWrite.flush();
 System.out.println("loading cputime: " + cputime);
 System.out.println("loading walltime: " + walltime);
 /*
 System.out.print("Facts in memory:");
 long count = 0;
 for (Iterator it = session.iterateFactHandles(); it.hasNext(); ) {
  FactHandle factHandle = (FactHandle) it.next();
  count ++;
  //System.out.println(session.getObject(factHandle));
 }
 System.out.println(count);
 */
 // computing
 

Re: [rules-users] wordnet in drools

2008-07-08 Thread Paul Fodor
>> I am new to Drools and I wonder if anyone used WordNet from Drools.
>> Basically, I want to make some simple joins, such as, find words that
>> are in the same synset, all hypernyms of a word, hyponyms, meronyms of
>> verbs, adjectives, etc.

> I haven't heard of it being applied with Drools. Do let me know your
> findings if you produce anything interesting.

Hi Mark,
We couldn't find any implementation for WordNet from Drools, so we
wrote an implementation. Anyone, please feel free to use it (attached
below). If you want some additional functions, feel free to let me
know. It is an interface to WordNet for Drools using a SQL database
(MySQL). The computation times are pretty good compared with other
Java based rule engines, but an order of magnitude slower than C-based
Prolog systems. I wonder if this is not an indexing problem for Java
objects (we create about 300,000 instances of the same class to store
the WordNet ontology). We can also consult the database directly
(without putting the WordNet ontology in JVM), but that is slower than
having all objects in main memory (beside the same tests for the
Prolog systems had the whole ontology in the main memory, so we want
to do the same for Drools).
Regards,
Paul Fodor

WordNetInterface_rules.drl:

package drools

import drools.WordNetInterface.S;
import drools.WordNetInterface.G;
import drools.WordNetInterface.Hyp;
import drools.WordNetInterface.Mm;
import drools.WordNetInterface.Ent;
import drools.WordNetInterface.Sim;
import drools.WordNetInterface.Ant;
import drools.WordNetInterface.Reach;

rule "CoordinateTerms"
salience 10
when
s1 : S( si : synset_id, w1 : word)
s2 : S( synset_id == si, word != w1, w2 : word)
then
insert( new Reach(w1,w2) );
//System.out.println( "Reach " + w1 + "," + w2 );
end

rule "testAllGlosses"
salience 10
when
s : S( si : synset_id, w : word)
g : G( synset_id == si, gl : gloss)
then
insert( new Reach(w,gl) );
//System.out.println( "Reach " + w + "," + gl );
end

rule "testAllHypernyms"
salience 10
when
s1 : S( si1 : synset_id, w1 : word)
h : Hyp( synset_id1 == si1, si2 : synset_id2)
s2 : S( synset_id == si2, w2 : word)
then
insert( new Reach(w1,w2) );
//System.out.println( "Reach " + w1 + "," + w2 );
end

rule "testAllHyponyms"
salience 10
when
s1 : S( si1 : synset_id, w1 : word)
h : Hyp( synset_id2 == si1, si2 : synset_id1)
s2 : S( synset_id == si2, w2 : word)
then
insert( new Reach(w1,w2) );
//System.out.println( "Reach " + w1 + "," + w2 );
end

rule "testAllMeronyms"
salience 10
when
s1 : S( si1 : synset_id, w1 : word)
m : Mm( synset_id2 == si1, si2 : synset_id1)
s2 : S( synset_id == si2, w2 : word)
then
insert( new Reach(w1,w2) );
//System.out.println( "Reach " + w1 + "," + w2 );
end

rule "testAllHolonyms"
salience 10
when
s1 : S( si1 : synset_id, w1 : word)
m : Mm( synset_id1 == si1, si2 : synset_id2)
s2 : S( synset_id == si2, w2 : word)
then
insert( new Reach(w1,w2) );
//System.out.println( "Reach " + w1 + "," + w2 );
end

rule "testAllTroponyms"
salience 10
when
s1 : S( si1 : synset_id, w1 : word)
en : Ent( synset_id1 == si1, si2 : synset_id2)
s2 : S( synset_id == si2, w2 : word)
then
insert( new Reach(w1,w2) );
// System.out.println( "Reach " + w1 + "," + w2 );
end

rule "testAllSimilars"
salience 10
when
s1 : S( si1 : synset_id, w1 : word)
sim1 : Sim( synset_id1 == si1, si2 : synset_id2)
s2 : S( synset_id == si2, w2 : word)
then
insert( new Reach(w1,w2) );
//System.out.println( "Reach " + w1 + "," + w2 );
end

rule "testAllAntonyms"
salience 10
when
s1 : S( si1 : synset_id, w_n1 : w_num, w1 : word)
a : Ant( synset_id1 == si1, w_num1 == w_n1, si2 : synset_id2,
w_n2 : w_num2)
s2 : S( synset_id == si2, w_num == w_n2, w2 : word)
then
insert( new Reach(w1,w2) );
//System.out.println( "Reach " + w1 + "," + w2 );
end

WordNetInterface.java:

package drools;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.audit.WorkingMemoryFileLogger;
import org.drools.base.RuleNameEqualsAgendaFilter;
import org.drools.compiler.PackageBuilder;
import org.drools.compi

[rules-users] Re: transitive closure

2008-07-03 Thread Paul Fodor
How can I check if an instance was not already inserted?

For instance, my transitive closure works for non-cycled data, but it
re-derives the same relations for cycled data.

TransitiveClosure.drl:
package org.drools.examples

import org.drools.examples.TransitiveClosureExample.Edge;
import org.drools.examples.TransitiveClosureExample.Reach;

rule "reachDirect"
salience 10
when
e : Edge(s1 : source, t1 : target)
//not( exists( Reach(source == s1, target == t1) ) )
then
insertLogical( new Reach(e.getSource(),e.getTarget()) );
System.out.println( "Reach " + e.getSource() + "," + e.getTarget() );
end

rule "reachIndirect"
salience 10
when
e : Edge(s1 : source, t1 : target)
r : Reach(t2 : target, source == t1 )
//not( exists( Reach(source == s1, target == t2) ) )
then
insertLogical( new Reach(e.getSource(),r.getTarget()) );
System.out.println( "Reach " + e.getSource() + "," + r.getTarget() );
end

TransitiveClosureExample.java:
package org.drools.examples;
import java.io.InputStreamReader;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.audit.WorkingMemoryFileLogger;
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;

public class TransitiveClosureExample {
public static void main(final String[] args) throws Exception {
PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
final PackageBuilder builder = new PackageBuilder( conf );
builder.addPackageFromDrl( new InputStreamReader(
TransitiveClosureExample.class.getResourceAsStream(
"TransitiveClosure.drl" ) ) );
final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( builder.getPackage() );
final StatefulSession session = ruleBase.newStatefulSession();
final WorkingMemoryFileLogger logger = new
WorkingMemoryFileLogger( session );
logger.setFileName( "log/transitiveClosure" );

final Edge edgeAB = new Edge( "a","b" );
final Edge edgeBC = new Edge( "b","c" );
final Edge edgeCD = new Edge( "c","d" );
final Edge edgeDA = new Edge( "d","a" );

session.insert( edgeAB );
session.insert( edgeBC );
session.insert( edgeCD );
session.insert( edgeDA );

session.fireAllRules();
logger.writeToDisk();
session.dispose();
}

public static class Edge {
private String source;
private String target;
public Edge() {}
public Edge(String source, String target) {
super();
this.source = source;
this.target = target;
}
public String getSource() {
return source;
}
public String getTarget() {
return target;
}
}

public static class Reach {
private String source;
private String target;
public Reach() {}
public Reach(String source, String target) {
super();
this.source = source;
this.target = target;
}
public void setSource(String source) {
this.source = source;
}
public String getSource() {
return source;
}
public void setTarget(String target) {
    this.target = target;
}
public String getTarget() {
return target;
}
}
}

Please tell me if you have any idea.
Thanks,
Paul Fodor
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Re: transitive closure

2008-07-03 Thread Paul Fodor
Even if the package says "org.drools.examples", these files are not in
the Drools examples. I am just using that package to write these files
into while testing in Eclipse.

On Thu, Jul 3, 2008 at 4:31 PM, Paul Fodor <[EMAIL PROTECTED]> wrote:
> On Thu, Jul 3, 2008 at 3:56 PM, Paul Fodor <[EMAIL PROTECTED]> wrote:
>> Dear Sir,
>>
>> I am new to Drools and I want to ask how can I implement the classical
>> transitive closure in Drools. For instance we have a bunch of facts
>> edge/2 and the transitive closure:
>>
>> reach(X,Y):- edge(X,Y).
>> reach(X,Y):- edge(X,Z),reach(Z,Y).
>
> My current version looks like the following, but it never terminates.
> It re-derives reach(c,c) forever.
>
> TransitiveClosure.drl :
> package org.drools.examples
>
> import org.drools.examples.TransitiveClosureExample.Edge;
> import org.drools.examples.TransitiveClosureExample.Reach;
>
> rule "reachDirect"
>salience 10
>when
>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
>
> rule "reachIndirect"
>salience 10
>when
>e : Edge(s1 : source, t1 : target)
>r : Reach(t2 : target, source == t1 )
>not( Reach(source == s1, target == t2) )
>then
>insertLogical( new Reach(e.getSource(),r.getTarget()) );
>System.out.println( "Reach " + e.getSource() + "," + r.getTarget() );
> end
>
> TransitiveClosureExample.java :
>
> package org.drools.examples;
> import java.io.InputStreamReader;
> import org.drools.RuleBase;
> import org.drools.RuleBaseFactory;
> import org.drools.StatefulSession;
> import org.drools.audit.WorkingMemoryFileLogger;
> import org.drools.compiler.PackageBuilder;
> import org.drools.compiler.PackageBuilderConfiguration;
>
> public class TransitiveClosureExample {
>public static void main(final String[] args) throws Exception {
>PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
>final PackageBuilder builder = new PackageBuilder( conf );
>builder.addPackageFromDrl( new InputStreamReader(
> TransitiveClosureExample.class.getResourceAsStream(
> "TransitiveClosure.drl" ) ) );
>final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
>ruleBase.addPackage( builder.getPackage() );
>final StatefulSession session = ruleBase.newStatefulSession();
>final WorkingMemoryFileLogger logger = new
> WorkingMemoryFileLogger( session );
>logger.setFileName( "log/transitiveClosure" );
>
>final Edge edgeAB = new Edge( "a","b" );
>final Edge edgeBC = new Edge( "b","c" );
>final Edge edgeCD = new Edge( "c","d" );
>
>session.insert( edgeAB );
>session.insert( edgeBC );
>session.insert( edgeCD );
>
>session.fireAllRules();
>logger.writeToDisk();
>session.dispose();
>}
>
>public static class Edge {
>private String source;
>private String target;
>public Edge() {}
>public Edge(String source, String target) {
>super();
>this.source = source;
>this.target = target;
>}
>public String getSource() {
>return source;
>}
>public String getTarget() {
>return source;
>}
>}
>
>public static class Reach {
>private String source;
>private String target;
>public Reach() {}
>public Reach(String source, String target) {
>        super();
>this.source = source;
>this.target = target;
>}
>public void setSource(String source) {
>this.source = source;
>}
>public String getSource() {
>return source;
>}
>public void setTarget(String target) {
>this.target = target;
>}
>public String getTarget() {
>return target;
>}
>}
> }
>
> Any sugestion?
>
> Regards,
>  Paul Fodor
>
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Re: transitive closure

2008-07-03 Thread Paul Fodor
On Thu, Jul 3, 2008 at 3:56 PM, Paul Fodor <[EMAIL PROTECTED]> wrote:
> Dear Sir,
>
> I am new to Drools and I want to ask how can I implement the classical
> transitive closure in Drools. For instance we have a bunch of facts
> edge/2 and the transitive closure:
>
> reach(X,Y):- edge(X,Y).
> reach(X,Y):- edge(X,Z),reach(Z,Y).

My current version looks like the following, but it never terminates.
It re-derives reach(c,c) forever.

TransitiveClosure.drl :
package org.drools.examples

import org.drools.examples.TransitiveClosureExample.Edge;
import org.drools.examples.TransitiveClosureExample.Reach;

rule "reachDirect"
salience 10
when
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

rule "reachIndirect"
salience 10
when
e : Edge(s1 : source, t1 : target)
r : Reach(t2 : target, source == t1 )
not( Reach(source == s1, target == t2) )
then
insertLogical( new Reach(e.getSource(),r.getTarget()) );
System.out.println( "Reach " + e.getSource() + "," + r.getTarget() );
end

TransitiveClosureExample.java :

package org.drools.examples;
import java.io.InputStreamReader;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.audit.WorkingMemoryFileLogger;
import org.drools.compiler.PackageBuilder;
import org.drools.compiler.PackageBuilderConfiguration;

public class TransitiveClosureExample {
public static void main(final String[] args) throws Exception {
PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
final PackageBuilder builder = new PackageBuilder( conf );
builder.addPackageFromDrl( new InputStreamReader(
TransitiveClosureExample.class.getResourceAsStream(
"TransitiveClosure.drl" ) ) );
final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( builder.getPackage() );
final StatefulSession session = ruleBase.newStatefulSession();
final WorkingMemoryFileLogger logger = new
WorkingMemoryFileLogger( session );
logger.setFileName( "log/transitiveClosure" );

final Edge edgeAB = new Edge( "a","b" );
final Edge edgeBC = new Edge( "b","c" );
final Edge edgeCD = new Edge( "c","d" );

session.insert( edgeAB );
session.insert( edgeBC );
session.insert( edgeCD );

session.fireAllRules();
logger.writeToDisk();
session.dispose();
}

public static class Edge {
private String source;
private String target;
public Edge() {}
public Edge(String source, String target) {
super();
this.source = source;
this.target = target;
}
public String getSource() {
return source;
}
public String getTarget() {
return source;
}
}

public static class Reach {
private String source;
private String target;
public Reach() {}
public Reach(String source, String target) {
super();
this.source = source;
this.target = target;
}
public void setSource(String source) {
this.source = source;
}
public String getSource() {
return source;
}
public void setTarget(String target) {
this.target = target;
}
public String getTarget() {
return target;
}
}
}

Any sugestion?

Regards,
 Paul Fodor
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] transitive closure

2008-07-03 Thread Paul Fodor
Dear Sir,

I am new to Drools and I want to ask how can I implement the classical
transitive closure in Drools. For instance we have a bunch of facts
edge/2 and the transitive closure:

reach(X,Y):- edge(X,Y).
reach(X,Y):- edge(X,Z),reach(Z,Y).

Should I create classes Edge and Reach with attributes source and target?

rule "reachDirect"
when
exists( Edge(X,Y) )
then
insertLogical( new Reach(X,Y) );
end

rule "reachIndirect"
when
exists( Edge(X,Z) )
exists( Reach(Z,Y) )
then
insertLogical( new Reach(X,Y) );
end

Regards,
 Paul Fodor
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] wordnet in drools

2008-07-02 Thread Paul Fodor
Dear Sir,

I am new to Drools and I wonder if anyone used WordNet from Drools.
Basically, I want to make some simple joins, such as, find words that
are in the same synset, all hypernyms of a word, hyponyms, meronyms of
verbs, adjectives, etc.

 Regards,
  Paul Fodor
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] nqueens or puzzle16 problems

2008-07-02 Thread Paul Fodor
Dear Sir,

I am new to Drools and I wonder if any of the classic declarative
problems, such as, nqueens, puzzle16 were implemented in Drools by
anyone. I realize that might be hard because of the bottom-up
evaluation.

Regards,
 Paul Fodor
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users