Thanks, I&#39;ll look at the eval article, wasn&#39;t sure how to avoid them but will endeavor to find a way.&nbsp;<div><br></div><div>I found my way around the original problem, not even sure what it was now.</div><div><br></div>
<div>I&#39;m not sure the memberOf and taglist would generally work for us. The problem is that there are several patterns in the test object that are like this. Here are a couple of examples from the full application. A patient (yup we&#39;ve switched contexts) has several problems, each is defined by a code. I want to determine if the patient is a diabetes patient, a &quot;diabetes patient&quot; is defined as a patient who as any one of a number of coded problems. Some patients may have 80 or more problem codes, there are about 20 codes that define what could be a diabetes patient. There are multiple lists like this, COPD has another list of codes for example.</div>
<div><br></div><div>Similar problems exist with medications, is this patient on a statin? Statins are a class of medication there are dozens of them any one of them will satisfy the query, and of course the patient may be on dozens of medications.</div>
<div><br></div><div>Not sure that clarified things. I&#39;ve generally got things working but needless to say there is always room to make things better (like getting rid of the evals)...<br><br><div class="gmail_quote">On Mon, Dec 1, 2008 at 10:48 AM, Dan Seaver <span dir="ltr">&lt;<a href="mailto:dan.seaver@ge.com">dan.seaver@ge.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
Charlie,<br>
I&#39;m not sure why your function doesn&#39;t compile as it looks fine to me. Do<br>
you have any other details about the message you&#39;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 &quot;eval&quot; statements whenever possible as<br>
they can severely hamper performance. Edson wrote up some helpful hints -<br>
see &quot;Eval is Evil&quot; 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&#39;s<br>
tagList items and then use &quot;memberOf&quot; to determine if it&#39;s one of the<br>
engineering TagCodes. (You may be able to use the &quot;from&quot; statement with the<br>
Person&#39;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>
&gt;<br>
&gt; I&#39;m fairly new to Drools so there may be an easier way to do this. I need<br>
&gt; to<br>
&gt; check to see if any one of a list of tags on an object are in another list<br>
&gt; of tags and am trying to do that with a function. the compiler tells me it<br>
&gt; can&#39;t compile my eval function:<br>
&gt;<br>
&gt; #list any import classes here.<br>
&gt; **<br>
&gt;<br>
&gt; *import* com.cp.services.rules.sources.Person;<br>
&gt; **<br>
&gt;<br>
&gt; *import* com.cp.services.rules.actions.PersonActions;<br>
&gt; **<br>
&gt;<br>
&gt; *import* com.cp.rules.TagCodes;<br>
&gt; **<br>
&gt;<br>
&gt; *import* java.util.List;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; #declare any global variables here<br>
&gt; **<br>
&gt;<br>
&gt; *global* com.cp.services.rules.actions.PersonActions personActions;<br>
&gt;<br>
&gt; **<br>
&gt;<br>
&gt; *function* *boolean* hasOneOf(List list1, String[] list2){<br>
&gt;<br>
&gt; *for* (Object obj : list1) {<br>
&gt;<br>
&gt; String string = (String)obj;<br>
&gt;<br>
&gt; *for* (*int* j = 0; j &lt; list2.length; j++) {<br>
&gt;<br>
&gt; *if* (string != *null* &amp;&amp; string.equals(list2[j])) {<br>
&gt;<br>
&gt; *return* *true*;<br>
&gt;<br>
&gt; }<br>
&gt;<br>
&gt; }<br>
&gt;<br>
&gt; }<br>
&gt;<br>
&gt; *return* *false*;<br>
&gt;<br>
&gt; }<br>
&gt;<br>
&gt; **<br>
&gt;<br>
&gt; *rule* &quot;Engineering&quot;<br>
&gt;<br>
&gt; *dialect* &quot;mvel&quot;<br>
&gt;<br>
&gt; *when*<br>
&gt; **<br>
&gt;<br>
&gt; #conditions<br>
&gt;<br>
&gt; Person( ageInYears &gt;= 18 ) *and*<br>
&gt;<br>
&gt; *eval* ( hasOneOf(Person(tagList), TagCodes(engrTags)) )<br>
&gt;<br>
&gt; *then*<br>
&gt;<br>
&gt; #actions<br>
&gt;<br>
&gt; personActions.addAction(&quot;EngineeringGroup&quot;);<br>
&gt;<br>
&gt; *<br>
&gt;<br>
&gt; end<br>
</div></div><div class="Ih2E3d">&gt; *<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<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></div>