<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Hello,<br>
    <br>
    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.<br>
    <br>
    I need to write rules using the notion "window of consecutive
    sentences". <br>
    <br>
    Basically I am not very interested by those "SentenceWindow"
    objects, I just need them to define a kind of proximity between
    "ManualAnnotation" objects.<br>
    What I eventually need in the "when" of my rule is something like:<br>
    <br>
    <tt>when<br>
      &nbsp;&nbsp;&nbsp; ... maybe something creating the windows<br>
      &nbsp;&nbsp;&nbsp; a1 : ManualAnnotation ()<br>
      &nbsp;&nbsp;&nbsp; a2 : ManualAnnotation (this != a1)<br>
      &nbsp;&nbsp;&nbsp; SentenceWindow (this includes a1, this includes a2)<br>
      then<br>
      &nbsp;&nbsp;&nbsp; ... do something with a1 and a2 since they are "close" to each
      other<br>
      end</tt><br>
    <br>
    As I don't know the "internals" of Drools, I would like to have your
    opinion about what the best "idiom":<br>
    <ul>
      <li>create all SentenceWindow objects and insert them in the
        working memory, then write rules against all the facts (SentenceWindow
        and ManualAnnotation)<br>
      </li>
      <li>implement an accumulator that will create a list of&nbsp;
        SentenceWindow object </li>
    </ul>
    <br>
    The first option could look like:<br>
    <br>
    <code></code><code>rule "Create sentence windows"<br>
      &nbsp; &nbsp;when<br>
      &nbsp;&nbsp;&nbsp; &nbsp; # find 3 consecutive sentences<br>
      &nbsp; &nbsp;&nbsp; &nbsp;s1 : Sentence()<br>
      &nbsp; &nbsp;&nbsp; &nbsp;s2 : Sentence(this &gt; s1)<br>
      &nbsp; &nbsp;&nbsp; &nbsp;s3 : Sentence(this &gt; s2)<br>
      &nbsp; &nbsp;&nbsp; &nbsp;not Sentence(this != s2 &amp;&amp; &gt; s1 &amp;&amp; &lt;
      s3)<br>
      &nbsp; &nbsp;then<br>
      &nbsp; &nbsp;&nbsp; &nbsp;SentenceWindow swindow = new SentenceWindow();<br>
      &nbsp; &nbsp;&nbsp; &nbsp;swindow.setStart(s1.getStart());<br>
      &nbsp; &nbsp;&nbsp; &nbsp;swindow.setTheend(s3.getEnd());<br>
      &nbsp; &nbsp;&nbsp; &nbsp;insert(swindow);<br>
      end</code><br>
    <br>
    ... Then use the first rule "as is".<br>
    <br>
    The accumulator option could look like (I am not really sure the
    syntax is correct) :<br>
    <br>
    <tt>when<br>
      &nbsp;&nbsp;&nbsp; <b>$result : ArrayList() from accumulate ( $s: Sentence(),
        buildwindows($s))</b><br>
    </tt><tt>&nbsp;&nbsp;&nbsp; a1 : ManualAnnotation ()<br>
      &nbsp;&nbsp;&nbsp; a2 : ManualAnnotation (this != a1)<br>
      &nbsp;&nbsp;&nbsp;<b> SentenceWindows (this includes a1, this includes a2) </b></tt><b><tt>from
        $result</tt></b><br>
    <tt>
      then<br>
      &nbsp;&nbsp;&nbsp; ... </tt><tt>do something with a1 and a2 since they are
      "close" to each other</tt><br>
    <tt>
      end</tt><br>
    <br>
    Is it possible to decide if one way is best than the other?<br>
    <br>
    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)?<br>
    I mean something like:<br>
    <br>
    <tt>when<br>
      &nbsp;&nbsp;&nbsp; $result : ArrayList() from accumulate ( $s: Sentence(), <b>buildwindows(3,</b>
      $s))<br>
    </tt><br>
    <br>
    Thanks in advance for you insights,<br>
    <br>
    Best regards,<br>
    <br>
    Bruno.<br>
  </body>
</html>