<br> If I understood the problem, one way would be (assuming $tags is a global list):<br><br>when<br> Person( ageInYears >= 18, $tagList : tagList ) <br> exists( String( this memberof $tags ) from $tagList )<br>
then<br> ...<br>end<br><br> If $tags is a fact, just bind it before the "exists".<br><br>
<div class="gmail_quote"> []s<br> Edson<br><br><br>2008/12/1 Dan Seaver <span dir="ltr"><<a href="mailto:dan.seaver@ge.com">dan.seaver@ge.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Charlie,<br>
I'm not sure why your function doesn't compile as it looks fine to me. Do<br>
you have any other details about the message you're getting from the<br>
compiler?<br>
<br>
In any case, you may want to consider solving the problem a different way.<br>
In general, you should try to avoid "eval" statements whenever possible as<br>
they can severely hamper performance. Edson wrote up some helpful hints -<br>
see "Eval is Evil" at -<br>
<a href="http://blog.athico.com/2007/03/writing-better-rules.html" target="_blank">http://blog.athico.com/2007/03/writing-better-rules.html</a><br>
<br>
As an alternative, try populating working memory with each of the Person's<br>
tagList items and then use "memberOf" to determine if it's one of the<br>
engineering TagCodes. (You may be able to use the "from" statement with the<br>
Person's tagList instead of populating working memory) This allows Drools to<br>
do all of the work for you and may very well be faster than using loops.<br>
<br>
Let me know if you need further clarification.<br>
<div><div></div><div class="Wj3C7c"><br>
<br>
Charlie Holland wrote:<br>
><br>
> I'm fairly new to Drools so there may be an easier way to do this. I need<br>
> to<br>
> check to see if any one of a list of tags on an object are in another list<br>
> of tags and am trying to do that with a function. the compiler tells me it<br>
> can't compile my eval function:<br>
><br>
> #list any import classes here.<br>
> **<br>
><br>
> *import* com.cp.services.rules.sources.Person;<br>
> **<br>
><br>
> *import* com.cp.services.rules.actions.PersonActions;<br>
> **<br>
><br>
> *import* com.cp.rules.TagCodes;<br>
> **<br>
><br>
> *import* java.util.List;<br>
><br>
><br>
><br>
> #declare any global variables here<br>
> **<br>
><br>
> *global* com.cp.services.rules.actions.PersonActions personActions;<br>
><br>
> **<br>
><br>
> *function* *boolean* hasOneOf(List list1, String[] list2){<br>
><br>
> *for* (Object obj : list1) {<br>
><br>
> String string = (String)obj;<br>
><br>
> *for* (*int* j = 0; j < list2.length; j++) {<br>
><br>
> *if* (string != *null* && string.equals(list2[j])) {<br>
><br>
> *return* *true*;<br>
><br>
> }<br>
><br>
> }<br>
><br>
> }<br>
><br>
> *return* *false*;<br>
><br>
> }<br>
><br>
> **<br>
><br>
> *rule* "Engineering"<br>
><br>
> *dialect* "mvel"<br>
><br>
> *when*<br>
> **<br>
><br>
> #conditions<br>
><br>
> Person( ageInYears >= 18 ) *and*<br>
><br>
> *eval* ( hasOneOf(Person(tagList), TagCodes(engrTags)) )<br>
><br>
> *then*<br>
><br>
> #actions<br>
><br>
> personActions.addAction("EngineeringGroup");<br>
><br>
> *<br>
><br>
> end<br>
</div></div><div class="Ih2E3d">> *<br>
><br>
> _______________________________________________<br>
> rules-users mailing list<br>
> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
><br>
><br>
<br>
</div><font color="#888888">--<br>
View this message in context: <a href="http://www.nabble.com/function-problem-tp20633662p20774756.html" target="_blank">http://www.nabble.com/function-problem-tp20633662p20774756.html</a><br>
Sent from the drools - user mailing list archive at Nabble.com.<br>
</font><div><div></div><div class="Wj3C7c"><br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>