<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    On 23/02/2012 03:38, Hezi Stern wrote:
    <blockquote
      cite="mid:018701ccf1dc$aabb4300$0031c900$@delegatecom.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <meta name="Generator" content="Microsoft Word 14 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif][if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal">Hi All,<o:p></o:p></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal">I am seeking some kind of filtering (if
          statement) inside the LHS.<o:p></o:p></p>
        <p class="MsoNormal">I have the following example rule (note: <span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">$attributeFilteredSentences and
            $cmdescriptor are defined in the extends rule which is not
            presented)</span>:<o:p></o:p></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal" style="text-autospace:none"><b><span
              style="font-size:10.0pt;font-family:&quot;Courier
              New&quot;;color:#960000">rule</span></b><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black"> </span><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:green">" choose message sentence example"</span><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black"> extends "
            attributeFilteredSentences&nbsp; collection"</span><span
            style="font-size:10.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span
              style="font-size:10.0pt;font-family:&quot;Courier
              New&quot;;color:#960000">when</span></b><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          </span><span style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;"><o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          </span><span style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;"><o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            SContextState(state == SContextState.ONE)</span><span
            style="font-size:10.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span
            style="font-size:10.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sentences:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            ArrayList()<o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span
              style="font-size:10.0pt;font-family:&quot;Courier
              New&quot;;color:#960000">from</span></b><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black"> </span><b><span
              style="font-size:10.0pt;font-family:&quot;Courier
              New&quot;;color:#960000">collect</span></b><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black"> (Sentences.Sentence(</span><span
            style="font-size:10.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;descriptor.meanings.meaning ==
            $cmdescriptor.meanings.meaning</span><span
            style="font-size:10.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;) </span><b><span
              style="font-size:10.0pt;font-family:&quot;Courier
              New&quot;;color:#960000">from</span></b><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;
            $attributeFilteredSentences)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</span><span
            style="font-size:10.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span
            style="font-size:10.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span
              style="font-size:10.0pt;font-family:&quot;Courier
              New&quot;;color:#960000">then</span></b><span
            style="font-size:10.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>
        <p class="MsoNormal"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logger.info(</span><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:green">"RULE: entered rule: "</span><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">+drools.getRule().getName());<o:p></o:p></span></p>
        <p class="MsoNormal"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black"><o:p>&nbsp;</o:p></span></p>
        <p class="MsoNormal" style="margin-left:.5in;text-indent:.5in"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">//some logic&#8230;<o:p></o:p></span></p>
        <p class="MsoNormal" style="margin-left:.5in;text-indent:.5in"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black"><o:p>&nbsp;</o:p></span></p>
        <p class="MsoNormal" style="text-autospace:none"><b><span
              style="font-size:10.0pt;font-family:&quot;Courier
              New&quot;;color:#960000">end<o:p></o:p></span></b></p>
        <p class="MsoNormal" style="text-autospace:none"><b><span
              style="font-size:10.0pt;font-family:&quot;Courier
              New&quot;;color:#960000"><o:p>&nbsp;</o:p></span></b></p>
        <p class="MsoNormal">as can be seen I am filtering sentences
          based on the meanings, and the meaning collection must be
          identical as in <span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black">$cmdescriptor (this is the case when
            SContextState.ONE)<o:p></o:p></span></p>
        <p class="MsoNormal"><span
            style="font-size:10.0pt;font-family:&quot;Courier
            New&quot;;color:black"><o:p>&nbsp;</o:p></span></p>
        <p class="MsoNormal">Now to my question: I have cases ((this is
          the case when SContextState.TWO) where I do not need exact
          validation but rather superset of (for this I have a
          supersetOf operator implemented)<o:p></o:p></p>
        <p class="MsoNormal">I would like to avoid duplicating&nbsp; this
          rule (as I have similar condition in many other rules) and
          being able to filter once with &#8220;==&#8221; and once with &#8220;supersetOf&#8221;
          depending on the SContextState.</p>
      </div>
    </blockquote>
    I have found that query's can be used to provide re-usable rule
    fragments. In the example below I could have inlined the intentory
    LHS in the updateInventory rule, but instead I separated it out into
    a query so that multiple rules can re-use it. There is a small
    performance overhead from using queries, compared to normal
    patterns, but in most cases this is compensated by more maintainable
    and readable code.<br>
    <br>
    <pre><div style="background-color: transparent;" class="line" id="LC42">query inventory(Character $char, List $inventory) </div><div style="background-color: transparent;" class="line" id="LC43">&nbsp;&nbsp;&nbsp;&nbsp;$char := Character()    </div><div style="background-color: transparent;" class="line" id="LC44">&nbsp;&nbsp;&nbsp;&nbsp;$inventory := List() from accumulate( Holding( $char, $thing; ),</div><div style="background-color: transparent;" class="line" id="LC45">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;collectList( $thing ) )   </div><div style="background-color: transparent;" class="line" id="LC46">end</div></pre>
    <pre><div class="line" id="LC27">rule updateInventory salience 5  when                            </div><div class="line" id="LC28">&nbsp;&nbsp;&nbsp;&nbsp;SessionCharacter( $char : character, $us : session )                          </div><div class="line" id="LC29">&nbsp;&nbsp;&nbsp;&nbsp;inventory( $char, $things; )                                                      </div><div class="line" id="LC30">then</div><div class="line" id="LC31">&nbsp;&nbsp;&nbsp;&nbsp;$us.channels["inventory"].send( $things ); </div><div class="line" id="LC32">end</div></pre>
    <br>
    Mark<br>
    <blockquote
      cite="mid:018701ccf1dc$aabb4300$0031c900$@delegatecom.com"
      type="cite">
      <div class="WordSection1">
        <p class="MsoNormal"><o:p></o:p></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal">Any ideas how to do this?<o:p></o:p></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal">Thanks,<o:p></o:p></p>
        <p class="MsoNormal">Hezi<o:p></o:p></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal" style="text-autospace:none"><o:p>&nbsp;</o:p></p>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
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>