I wouldn't use (X... xs) in this context.

Try the simple modification of isEqual( Annotation[] annos ) and
call it with isEqual( new Annotation[]{$a3,$a4,$a5})
and we'll see what we'll see.

-W


On 06/03/2013, Bojan Janisch <[email protected]> wrote:
> Like you wish wolfgang. The complete Rule is:
>
> rule "Generate Finding_ConceptId"
> no-loop
>     when
>               $a1:ODMAnswer(
>         q1:QuestionId,
>         q1.toLowerCase.contains("diagnose") ||
>         q1.toLowerCase.contains("indication"),
>         q1.toLowerCase.contains("sections"),
>         a1_begin:begin,
>         label1:ResponseAttribute)
>
>         $a2:ODMAnswer(
>               ResponseAttribute.contains(label1),
>         QuestionId.contains("sectionheader"),
>         comesBefore($a1,$a2));
>
>         $a3:ODMAnswer(
>         q3:QuestionId,
>         !q3.contains("finding.conceptId"),
>         !q3.contains("itemGroup"),
>         !q3.contains("section"),
>         a3_begin:begin,
>         a3_end:end,
>         label2:ResponseAttribute,
>         isInAnnotation($a1,$a3))
>
>         $a4:ODMAnswer(
>         q4:QuestionId.contains("finding.conceptId"),
>         a4_begin:begin,
>         comesAfter($a2,$a4),
>         isBetween($a2,$a3,$a4),
>         isInAnnotation($a1,$a4))
>
>         not $a5:ODMAnswer(
>         isInAnnotation($a1,$a5),
>         isBigger($a3,$a5),
>               !isEqual($a3,$a4,$a5))                  
>     then
>         String questionId = "finding.conceptId";
>       String attribute = label1 +" "+ label2;
>       int begin = a4_begin;
>       int ende = a3_end;
>       boolean addToIndexes = true;
>       
>       
>       insert(annotate(aJCas, questionId, attribute, begin, ende,
> addToIndexes));
> end
>
> The functions are in a seperate FactChecker class, because the
> "incode-comparison"
> was too much of a chaos. So I wrote functions which explains themselves what
> they do:
> ==================================================================
> public static boolean isInAnnotation(Annotation a, Annotation b){
>       if(isNull(a,b)){
>               return false;
>       }
>       if(b.getBegin() > a.getBegin() && b.getEnd() < a.getEnd()){
>               return true;
>       }
>       if(a.getBegin() > b.getBegin() && a.getEnd() < b.getEnd()){
>               return true;
>       }
>       return false;
> }
> ==================================================================
> public static boolean isInAnnotation(Annotation... a){
>       for (int i = 0; i < a.length; i++){
>               if(i+1 == a.length){
>                       return false;
>               }
>               if(isInAnnotation(a[i], a[i+1])){
>                       return true;
>               }
>       }
>       
>       return false;
> }
> ==================================================================
> public static boolean comesBefore(Annotation a, Annotation b){
>       if(isNull(a,b)){
>               return false;
>       }
>       if(b.getEnd() <= a.getBegin()){
>               return true;
>       }
>
>       return false;
> }
> ==================================================================
> public static boolean comesAfter(Annotation a, Annotation b){
>       if(isNull(a,b)){
>               return false;
>       }
>       if(a.getEnd() <= b.getBegin()){
>               return true;
>       }
>
>       return false;
> }
> ==================================================================
> public static boolean isEqual(Annotation a, Annotation b){
>       if(isNull(a,b)){
>               return false;
>       }
>       if(a.equals(b)){
>               return true;
>       }
>       
>       return false;
> }
> ==================================================================
> public static boolean isEqual(Annotation... a){
>       ArrayList<Annotation> outLoop = new
> ArrayList<Annotation>(Arrays.asList(a));
>       ArrayList<Annotation> inLoop = new 
> ArrayList<Annotation>(Arrays.asList(a));
>       
>       for (Annotation anno1 : outLoop) {
>               if(anno1 == null){
>                       
>               }
>               inLoop.remove(anno1);
>               for (Annotation anno2 : inLoop) {
>                       if(isEqual(anno1,anno2)){
>                               return true;
>                       }
>               }
>       }
>       
>       return false;
> }
> ==================================================================
> public static boolean isNull(Annotation... a){
>       for (Annotation annotation : a) {
>               if(annotation == null){
>                       return true;
>               }
>       }
>
>       return false;
> }
> ==================================================================
> public static boolean isBigger(Annotation a, Annotation b){
>       if(isNull(a,b)){
>               return false;
>       }
>       if(a.getBegin() == b.getBegin() && a.getEnd() < b.getEnd()){
>               return true;
>       }               
>       if(b.getBegin() < a.getBegin() && a.getEnd() == b.getEnd()){
>               return true;
>       }
>       if(b.getBegin() < a.getBegin() && a.getEnd() < b.getEnd()){
>               return true;
>       }
>       
>       return false;
> }
> ==================================================================
> public static boolean isBetween(Annotation a, Annotation b, Annotation c){
>       if(isNull(a,b,c)){
>               return false;
>       }
>       Annotation min = getMin(a,b);
>       Annotation max = getMax(a,b);
>       
>       if(isOverlapping(a,c) || isOverlapping(b,c)){
>               return true;
>       }
>       
>       if(c.getBegin() > min.getEnd() && c.getEnd() < max.getBegin()){
>               return true;
>       }
>
>       return false;   
> }
> ==================================================================
> public static Annotation getMax(Annotation a, Annotation b){
>       isNull(a,b);
>       if(a.getBegin() >= b.getBegin()){
>               return a;
>       }
>       
>       return b;
> }
> ==================================================================
> public static Annotation getMin(Annotation a, Annotation b){
>       isNull(a,b);
>       if(a.getEnd() <= b.getEnd()){
>               return a;
>       }
>       
>       return b;
> }
> ==================================================================
>
> I've posted all functions that are used by the rule. Actually it crushes
> if I use more than 2 statements in the isEqual() call in $a5.
> It works with !isEqual($a3,$a4) && !isEqual($a3,$a5) && !isEqual($a4,$a5)
> but not with !isEqual($a3,$a4,$a5).
>
> So do you got an idea where the problem comes from?
>
> JB
>
>
> ----- Ursprüngliche Mail -----
> Von: "Wolfgang Laun" <[email protected]>
> An: "Rules Users List" <[email protected]>
> Gesendet: Mittwoch, 6. März 2013 15:09:47
> Betreff: Re: [rules-users] Cannot invoke method because
> of    ArrayIndexOutOfBoundsException
>
> Nice try - but, please, don't. Kindly post the code that actually
> causes your problem.
>
> -W
>
>
> On 06/03/2013, Bojan Janisch <[email protected]> wrote:
>> Hello Guys,
>>
>> sorry to bother you with this problem, but I'm out of ideas.
>> I'm using Drools in textmining-context and in basic I have
>> a function that checks 2 named entites for equality to
>> ensure that the entities are all different and that the rules
>> do work only on different named entity objects:
>>
>> public static boolean isEqual(Annotation a, Annotation b){
>> if(a.equals(b)){
>>    return true;
>> }
>>      
>> return false;
>> }
>>
>> Sometimes there are conditions that need tests of more than
>> 2 named entites. For this I've written a super method that
>> calls the isEqual method in a loop:
>>
>> public static boolean isEqual(Annotation... a){
>> ArrayList<Annotation> outLoop = new
>> ArrayList<Annotation>(Arrays.asList(a));
>> ArrayList<Annotation> inLoop = new
>> ArrayList<Annotation>(Arrays.asList(a));
>>              
>> for (Annotation anno1 : outLoop) {
>>    inLoop.remove(anno1);
>>    for (Annotation anno2 : inLoop) {
>>       if(isEqual(anno1,anno2)){
>>       return true;
>>       }
>>    }
>> }
>>
>> return false;
>> }
>>
>>
>> My rules could (theoretically) now call the function
>> eval(isEqual($ne1,$ne2)) or
>> eval(isEqual($ne1,$ne2,$ne3) or even
>> eval(isEqual($ne1,$ne2,$ne3,$ne4,$ne5)) and so on.
>>
>> So there starts my problem:
>>
>> Each time I'm getting an ArrayIndexOutOfBounds Exception from the second
>> method that looks like this:
>>
>> java.lang.RuntimeException: cannot invoke method: isEqual
>>         ...
>>      at java.lang.Thread.dispatchUncaughtException(Thread.java:1888)
>> Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
>>      at
>> org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.executeAll(MethodAccessor.java:149)
>>      at
>> org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:48)
>>      at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:108)
>>      at
>> org.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38)
>>         ...
>>
>> Could someone explain me what's wrong with my code? Thanks for any help.
>>
>> Greetings
>> JB
>> _______________________________________________
>> rules-users mailing list
>> [email protected]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
> _______________________________________________
> rules-users mailing list
> [email protected]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> rules-users mailing list
> [email protected]
> https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to