[rules-users] To accumulate or not to accumulate

Bruno Freudensprung bruno.freudensprung at temis.com
Fri Aug 19 07:14:07 EDT 2011


Hello,

I am trying to implement rules handling "Sentence", "ManualAnnotation" 
objects (imagine someone highligthing words of the document). Basically 
"Sentence" objects have "start" and "end" positions (fields) into the 
text of a document, and they are Comparable according to their location 
into the document.

I need to write rules using the notion "window of consecutive sentences".

Basically I am not very interested by those "SentenceWindow" objects, I 
just need them to define a kind of proximity between "ManualAnnotation" 
objects.
What I eventually need in the "when" of my rule is something like:

when
     ... maybe something creating the windows
     a1 : ManualAnnotation ()
     a2 : ManualAnnotation (this != a1)
     SentenceWindow (this includes a1, this includes a2)
then
     ... do something with a1 and a2 since they are "close" to each other
end

As I don't know the "internals" of Drools, I would like to have your 
opinion about what the best "idiom":

    * create all SentenceWindow objects and insert them in the working
      memory, then write rules against all the facts (SentenceWindow and
      ManualAnnotation)
    * implement an accumulator that will create a list of 
      SentenceWindow object


The first option could look like:

|||rule "Create sentence windows"
    when
       # find 3 consecutive sentences
       s1 : Sentence()
       s2 : Sentence(this > s1)
       s3 : Sentence(this > s2)
       not Sentence(this != s2 && > s1 && < s3)
    then
       SentenceWindow swindow = new SentenceWindow();
       swindow.setStart(s1.getStart());
       swindow.setTheend(s3.getEnd());
       insert(swindow);
end|

... Then use the first rule "as is".

The accumulator option could look like (I am not really sure the syntax 
is correct) :

when
*$result : ArrayList() from accumulate ( $s: Sentence(), buildwindows($s))*
     a1 : ManualAnnotation ()
     a2 : ManualAnnotation (this != a1)
*SentenceWindows (this includes a1, this includes a2) **from $result*
then
     ... do something with a1 and a2 since they are "close" to each other
end

Is it possible to decide if one way is best than the other?

And one last question: it is possible to "parametrize" an accumulator 
(in order to provide the number of sentences that should be put in the 
windows)?
I mean something like:

when
     $result : ArrayList() from accumulate ( $s: Sentence(), 
*buildwindows(3,* $s))


Thanks in advance for you insights,

Best regards,

Bruno.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110819/86b996b3/attachment.html 


More information about the rules-users mailing list