well if you don't want the rule engine to do the matching, you can just
assert the parent object, and use an eval to check constraints on its
members, that is always an option.

On 4/7/06, Juergen <[EMAIL PROTECTED]> wrote:
>
> fact binding being an variable assignment, how could you do the
> following in drools:
>
> assume 1000 objects A(text), 10 objects B(id, a) (with attribute B.a
> refering to some A) asserted in working memory;
> want to find some A, B where e.g. B.id > 10, and B is related to some A
> in working memory, and A.text matches some regexp
>
> Not possible because binding is only assignment:
> rule "some rule"
>         when
>                 b : B(id > 10, bindA : a)
>                 bindA : A(text matches ".*foobar.*")
>         then
>                 ...
> end
>
> You could write the rule as:
> rule "other rule"
>         when
>                 bindA : A(text matches ".*foobar.*")
>                 b : B(id > 10, a == bindA)
>         then
>                 ...
> end
>
> But it seems a lot more inefficient, because it would have to check 1000
> A, whereas the first rule would only check 10 B and the 10 A they are
> refering to.
>
> Could it be done with eval+exists?
> But I think exists is not intended to be used like in that:
>
> rule "rule with eval"
>         when
>                 b : B(id > 10, bindA : a)
>                 exists bindA
>                 eval ( ... some java-code to: bindA.text matches
> ".*foobar.*" ...)
>         then
>                 ...
> end
>
> Thanks, Juergen.
>
> Michael Neale wrote:
> > you are right, each binding is literally a variable assignment, and the
> last
> > one counts, so its doesn't really make sense to have multiple
> assignments in
> > most cases.
> >
> > There is no reason why it is written that way in the LHS, the example
> you
> > suggest is possibly more appropriate - of course it means something
> > different. The aim of that test/example is really to show examples of
> the
> > different types of constraints, not so much in how to write a rule.
> >
> >
> > On 4/7/06, Juergen <[EMAIL PROTECTED]> wrote:
> >
> >>Referring to org.drools.integrationtests.helloworld example:
> >>
> >>                $m : Message(list contains "hello")
> >>                Message(text:message == "hola")
> >>                Message(number > 40)
> >>                Message(birthday > "10-Jul-1974")
> >>                Message(message matches ".*ho.*")
> >>
> >>I first assumed that all 5 column conditions must be fulfilled by the
> >>same Message object, and not just by any. (Adding a clone of the message
> >>would trigger the rule 32 times)
> >>
> >>A better less misleading LHS [a] seems to me:
> >>$m : Message(list contains "hello", message matches ".*ho.*", message ==
> >>"hola", number > 40, birthday > "10-Jul-1974")
> >>
> >>My question: Would it be possible to rewrite the LHS [a] to:
> >>
> >>                $m : Message(list contains "hello")
> >>                $m : Message(text:message == "hola")
> >>                $m : Message(number > 40)
> >>                $m : Message(birthday > "10-Jul-1974")
> >>                $m : Message(message matches ".*ho.*")
> >>
> >>$m should only be bound the first time, subsequent "bindings" would only
> >>check for object identity or equality?
> >>
> >>Currently, fact binding with : seems to behave like an assignment. The
> >>upper LHS yields no errors, but the last binding counts; and the rule is
> >>still triggered 32 times when asserting a clone of the message.
> >>
> >>Thanks, Juergen
>
>

Reply via email to