<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
You could just call a function?<br>
<span class="q"> $first : ArrayList( )<br>
$second : ArrayList( this != $first )
<br>
Integer( $index : intValue ) from
returnArrayOfMatchingIndexes($first, $second)<br>
<br>
This still uses from, but the function call returns a collection, which
from iterates over in turn.<br>
<br>
Mark<br>
</span><br>
Aaron Dixon wrote:
<blockquote
cite="mid:5b1018900708070708n4269419bu8d1081ccb0ad252c@mail.gmail.com"
type="cite"><br>
I spoke too soon. The from will match items in the two Lists that are
not at the same index.<br>
<br>
As for asserting ArrayList( ) facts -- in my actual application I have
facts that have Collections attributes for which I need this behavior.
I just made the problem simpler for this post.
<br>
<br>
<br>
<div><span class="gmail_quote">On 8/7/07, <b class="gmail_sendername">Aaron
Dixon</b> <<a moz-do-not-send="true" href="mailto:atdixon@gmail.com">atdixon@gmail.com</a>>
wrote:</span>
<blockquote class="gmail_quote"
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">The
"from" conditional element solves part of my problem:<br>
<br>
rule "Find matching entry in parallel arrays (alternate)"<span class="q"><br>
when<br>
$first : ArrayList( )<br>
$second : ArrayList( this != $first )
<br>
</span><span class="q"> $fi : Object() from $first<br>
$si : Object() from $second<br>
eval( $fi == $si )<br>
</span> then<br>
System.out.println ( " Found match at index ? : " + $fi + "!"
);
<br>
end
<br>
<br>
I do want reference equality (==) in my eval. But I understand that
object equality would look just like:<br>
<br>
eval( $fi .equals( $si ) )<br>
<br>
<br>
Thanks!<br>
<span class="sg"><br>
Aaron</span>
<div><span class="e" id="q_11440a5ae3f16734_5"><br>
<br>
<br>
<div><span class="gmail_quote">On 8/7/07, <b
class="gmail_sendername">Mike D</b> <<a moz-do-not-send="true"
href="mailto:mike.dalaker@kewill.com" target="_blank"
onclick="return top.js.OpenExtLink(window,event,this)">mike.dalaker@kewill.com</a>>
wrote:</span>
<blockquote class="gmail_quote"
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
Mark,<br>
<br>
Just to be sure I read this correctly:<br>
<br>
eval( $fi == $si )<br>
<br>
means it's checking objects, not values within the object?<br>
If a compare of values is needed, another eval would have to be written
to
<br>
compare temp value.<br>
<br>
Thanks,<br>
Mike<br>
<br>
<br>
Oh, and can we change the documenatation examples please?<br>
<br>
Somthing like...<br>
<br>
rule<br>
when<br>
Team( $team : name == "ManU" )<br>
$person : Person( favouriteTeam == $team )
<br>
then<br>
System.out.println( $person.getName() + " likes Manchester" );<br>
end<br>
<br>
rule<br>
when<br>
Team( $team : name == "Chelsea" )<br>
$person : Person( favouriteTeam != $team )
<br>
then<br>
System.out.println( $person.getName() + " does not like Chelsea
at<br>
all" );<br>
end<br>
<br>
<br>
<br>
Mark Proctor wrote:<br>
><br>
> We don't really recommend you assert ArrayLists etc as facts, as
they
<br>
> have no contextual meaning<br>
><br>
> $first : ArrayList( )<br>
> $second : ArrayList( this != $first )<br>
> $fi Object() from $first<br>
> $si Object from $second<br>
> eval( $fi == $si )<br>
><br>
> 'from' allows iteration of lists, so you could potentially do it
this<br>
> way, although it doesn't provide an index number for you.... You
could<br>
> possibly have a global that as part of a function in eval get
<br>
> incremented and that global is available in the consequence. But
you'll<br>
> have to be very careful with concurrency.... Might be easier to
have a<br>
> hashmap of indexes where the key is made up of $first and $second.
Btw
<br>
> == checks for same instances, not an equality check, is that what
you<br>
> wanted?<br>
><br>
> Mark<br>
><br>
> Aaron Dixon wrote:<br>
>> My problem boils down to finding matching entries in parallel
arrays.
<br>
>><br>
>> Here is a rule that succesfully does just that:<br>
>><br>
>> rule "Find matching entry in parallel arrays"<br>
>> when<br>
>> $first : ArrayList( )<br>
>> $second : ArrayList( this != $first )
<br>
>> $i : Integer( this < $first.size )<br>
>> eval( $first.get($i) == $second.get($i) )<br>
>> then<br>
>> System.out.println ( "Found match at index " + $i +
"!" );
<br>
>> end<br>
>><br>
>><br>
>> To execute this rule, I must insert (assert) the two ArrayList
facts<br>
>> as well as at least as many Integer facts as there are items
in the<br>
>> ArrayLists.
<br>
>><br>
>> What I don't like about this rule is that<br>
>><br>
>> (1) I have to assert the Integers<br>
>> (2) I can't support arbitrarily-sized lists in my rules
(without<br>
>> asserting that many Integer facts)<br>
>><br>
>> So -- Is there a better way?<br>
>><br>
>> What if a future version of Drools supported implicit Number
facts<br>
>> that allowed for these kinds of indexing rules?
<br>
>><br>
>> Aaron<br>
>><br>
>><br>
>><br>
>><br>
>>
------------------------------------------------------------------------<br>
>><br>
>> _______________________________________________
<br>
>> rules-users mailing list<br>
>> <a moz-do-not-send="true"
href="mailto:rules-users@lists.jboss.org" target="_blank"
onclick="return top.js.OpenExtLink(window,event,this)">rules-users@lists.jboss.org</a><br>
>> <a moz-do-not-send="true"
href="https://lists.jboss.org/mailman/listinfo/rules-users"
target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
https://lists.jboss.org/mailman/listinfo/rules-users
</a><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> rules-users mailing list<br>
> <a moz-do-not-send="true"
href="mailto:rules-users@lists.jboss.org" target="_blank"
onclick="return top.js.OpenExtLink(window,event,this)">
rules-users@lists.jboss.org</a><br>
> <a moz-do-not-send="true"
href="https://lists.jboss.org/mailman/listinfo/rules-users"
target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
><br>
><br>
<br>
--<br>
View this message in context: <a moz-do-not-send="true"
href="http://www.nabble.com/finding-matching-entries-in-parallel-arrays-tf4225120.html#a12034578"
target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://www.nabble.com/finding-matching-entries-in-parallel-arrays-tf4225120.html#a12034578
</a><br>
Sent from the drools - user mailing list archive at <a
moz-do-not-send="true" href="http://Nabble.com" target="_blank"
onclick="return top.js.OpenExtLink(window,event,this)">Nabble.com</a>.<br>
<br>
_______________________________________________
<br>
rules-users mailing list<br>
<a moz-do-not-send="true"
href="mailto:rules-users@lists.jboss.org" target="_blank"
onclick="return top.js.OpenExtLink(window,event,this)">rules-users@lists.jboss.org</a><br>
<a moz-do-not-send="true"
href="https://lists.jboss.org/mailman/listinfo/rules-users"
target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">https://lists.jboss.org/mailman/listinfo/rules-users
</a><br>
</blockquote>
</div>
<br>
</span></div>
</blockquote>
</div>
<br>
<pre wrap="">
<hr size="4" width="90%">
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<br>
</body>
</html>