[rules-users] OR with multiple binding in LHS
Francesco Campagnola
fcampagnola at gmail.com
Wed Mar 14 06:58:04 EDT 2007
It doesn't work...
I tried this rule using version 3.1M1
rule "orCondition"
when
myObj : (MyObject(field1 == "a", $field2 : field2, $field3 :
field3) or MyObject(field1 == "b", $field2 : field2, $field3 :
field3)) //correct column
AnotherPattern( attr2 == $field2, attr3 == $field3 )
then
System.out.println("fields = "+ field2 + field3);
end
and I got this exception, that is the same exception received using
3.0.5version:
Exception in thread "main" org.drools.rule.InvalidRulePackage: Duplicate
declaration for variable '$field2' in the rule 'orCondition'
Duplicate declaration for variable '$field3' in the rule 'orCondition'.
I tried also the first solution proposed, for the 3.0.5 version:
rule "orCondition"
when
myObj : (MyObject(field1 == "a", $field2 : field2, $field3 :
field3) or MyObject(field1 == "b")) //correct column
AnotherPattern( attr2 == $field2, attr3 == $field3 )
then
System.out.println("fields = "+ field2 + field3);
end
..but I got this exception:
Exception in thread "main" org.drools.rule.InvalidPatternException: Required
Declarations not bound: '$field2
at org.drools.reteoo.ReteooBuilder.checkUnboundDeclarations(Unknown
Source)
at org.drools.reteoo.ReteooBuilder.addRule(Unknown Source)
at org.drools.reteoo.ReteooBuilder.addRule(Unknown Source)
at org.drools.reteoo.ReteooRuleBase.addRule(Unknown Source)
at org.drools.common.AbstractRuleBase.addPackage(Unknown Source)
at org.drools.jsr94.rules.admin.RuleExecutionSetImpl.<init>(Unknown
Source)
at
org.drools.jsr94.rules.admin.LocalRuleExecutionSetProviderImpl.createRuleExecutionSet(Unknown
Source)
at
org.drools.jsr94.rules.admin.LocalRuleExecutionSetProviderImpl.createRuleExecutionSet(Unknown
Source)
at
org.drools.jsr94.rules.admin.RuleExecutionSetProviderImpl.createRuleExecutionSet(Unknown
Source)
2007/3/13, Edson Tirelli <tirelli at post.com>:
>
>
> Francesco,
>
> You need to be careful when doing that, if you are using 3.0.xversion.
> First thing is that both sides of your "or" must be perfectly
> "balanced", i.e., the same classes in the same order. I didn't tried
> that, but I think it works if you simply declare your binding once:
>
> rule "orCondition"
> when
> myObj : (MyObject(field1 == "a", $field2 : field2, $field3 :
> field3) or MyObject(field1 == "b")) //correct column
> AnotherPattern( attr2 == $field2, attr3 == $field3 )
> then
> System.out.println("fields = "+ field2 + field3);
> end
>
> This is a workaround for the 3.0.x versions.Try it and let me know
> plz.
>
> In 3.1M1 and later, all this is fixed and the correct is to declare
> the variable in all logical branches:
>
> rule "orCondition"
> when
> myObj : (MyObject(field1 == "a", $field2 : field2, $field3 :
> field3) or MyObject(field1 == "b", $field2 : field2, $field3 :
> field3)) //correct column
> AnotherPattern( attr2 == $field2, attr3 == $field3 )
> then
> System.out.println("fields = "+ field2 + field3);
> end
>
> []s
> Edson
>
>
> Francesco Campagnola wrote:
>
> > Hi,
> >
> > I'd like to write a rule that contains an OR condition in the LHS, to
> > match the presence in the working memory of an object with particular
> > values of a specific field. In the rest of LHS, i need to bind other
> > values of the specific object matched. Is there a particular sintax to
> > use for the binding?
> >
> > For example:
> >
> > rule "orCondition"
> > when
> > myObj : (MyObject(field1 == "a") or MyObject(field1 ==
> > "b")) //correct column
> >
> > field2: myObj.getField2 () // how to correctly get
> > field3: myObj.getField3() // those values?
> > then
> > System.out.println("fields = "+ field2 + field3);
> >
> > Thanks in advance, FC.
> >
> >------------------------------------------------------------------------
> >
> >_______________________________________________
> >rules-users mailing list
> >rules-users at lists.jboss.org
> >https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
>
> --
> Edson Tirelli
> Software Engineer - JBoss Rules Core Developer
> Office: +55 11 3124-6000
> Mobile: +55 11 9218-4151
> JBoss, a division of Red Hat @ www.jboss.com
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070314/7db1514a/attachment.html
More information about the rules-users
mailing list