<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>

<META content="MSHTML 6.00.2900.3086" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=876085206-31052007><FONT face=Arial color=#0000ff size=2>Hi 
All,</FONT></SPAN></DIV>
<DIV><SPAN class=876085206-31052007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=876085206-31052007><FONT face=Arial color=#0000ff 
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Can anybody tell as to wat 
does the assert() method do in a DRL file, like the way it is used in the below 
example. I&nbsp;am aware of&nbsp;assertObject() method but not assert() method. 
</FONT></SPAN></DIV>
<DIV><SPAN class=876085206-31052007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=876085206-31052007><FONT face=Arial color=#0000ff size=2>Thank 
you,</FONT></SPAN></DIV>
<DIV><SPAN class=876085206-31052007><FONT face=Arial color=#0000ff 
size=2>Mithun</FONT></SPAN></DIV>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px">
  <DIV></DIV>
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT 
  face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> 
  rules-users-bounces@lists.jboss.org 
  [mailto:rules-users-bounces@lists.jboss.org] <B>On Behalf Of </B>Edson 
  Tirelli<BR><B>Sent:</B> Thursday, May 17, 2007 7:28 PM<BR><B>To:</B> Rules 
  Users List<BR><B>Subject:</B> Re: [rules-users] How to use the value of a 
  function in both the LHSand RHS side of the rule 
  ?<BR><BR></FONT></DIV>&nbsp;&nbsp; Krishnan,<BR><BR>&nbsp;&nbsp; I always 
  prefer to use specific tools for specific jobs. So, if I were implementing 
  that, I would not put the I/O code inside the DRL.<BR>&nbsp;&nbsp; If you want 
  your rules to drive the parsing, I would model it like that: <BR><BR>1) Create 
  a class to "represent" your file... that would be your File interface. It 
  would have a method: readLine() that returns a Line object, as well as an 
  "eof" property (true when EOF was reached). <BR><BR>2) Create a rule to drive 
  your parsing:<BR><BR><BR><FONT 
  style="BACKGROUND: rgb(255,255,255) 0% 50%; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial" 
  color=#000000>rule "R1: Read one more line"<BR>&nbsp;&nbsp;&nbsp; when 
  <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $f : File( eof == false 
  )<BR>&nbsp;&nbsp;&nbsp; then <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  System.out.println("Generate new 
  line");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; assert( $f.readLine() ); 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; modify( $f ); // as readLine 
  "modifies" the state of the File <BR>end</FONT><BR><BR>3) Create the rules to 
  effectivelly "analyze" your lines. If you want to read all lines first and 
  then analyze them, just make rule R1 to have a greater salience. Otherwise, if 
  you want each line analyzed as it is parsed, make your other rules have a 
  greater salience as showed bellow: <BR><BR>rule "Rx: analyze 
  line"<BR>&nbsp;&nbsp; salience 10<BR>when<BR>&nbsp;&nbsp;&nbsp; Line( content 
  matches "xxx" ) <BR>then<BR>&nbsp;&nbsp;&nbsp; // do 
  something<BR>end<BR><BR>4. Create the rule to close your file when EOF is 
  reached:<BR><BR>rule "close file'<BR>when<BR>&nbsp;&nbsp;&nbsp; $f: File( eof 
  == true )<BR>then<BR>&nbsp;&nbsp;&nbsp; 
  $f.closeFile();<BR>end<BR><BR>&nbsp;&nbsp; Keeping the procedural code in your 
  java classes instead of DRL functions makes all your rules more clear, makes 
  easy to unit test each part, and reduces the overall complexity. 
  <BR><BR>&nbsp;&nbsp; That is how I would do it.<BR><BR>&nbsp;&nbsp; Hope it 
  helps.<BR>&nbsp;&nbsp;&nbsp; Edson<BR><BR>
  <DIV><SPAN class=gmail_quote>2007/5/17, Krishnan &lt;<A 
  href="mailto:krishiyer@gmail.com">krishiyer@gmail.com</A>&gt;:</SPAN>
  <BLOCKQUOTE class=gmail_quote 
  style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
    <DIV><FONT 
    style="BACKGROUND: rgb(255,255,255) 0% 50%; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial" 
    color=#000000><BR>Hi, <BR><BR>I want to parse a file and match the file for 
    several regular expressions. Based on what I match, I write more <BR>rules 
    so that based on all the rules, I can set my results. <BR><BR>Brute force 
    method : Parse the entire file and add all the lines into the working 
    memory. Write rules that <BR>check each line for some regular expression. 
    This works great. <BR><BR>I want to optimize the above, as we are checking 
    each line, if we got we are looking for, then I want to get out. <BR></FONT>
    <DIV><FONT color=#ff6600><BR></FONT></DIV><FONT 
    style="BACKGROUND: rgb(255,255,255) 0% 50%; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial" 
    color=#000000>So, I wrote a function inside the rule file like the below 
    <BR><BR>function String getLine(BufferedReader fileReader) 
    {<BR>&nbsp;&nbsp;&nbsp; String line;<BR>&nbsp;&nbsp;&nbsp; try 
    {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((line = 
    fileReader.readLine()) != null) {<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp; return 
    line.toLowerCase();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else 
    {<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
    System.out.println("This is an empty 
    line.");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    }<BR>&nbsp;&nbsp;&nbsp; } catch (Exception ex) {&nbsp; &nbsp;&nbsp;&nbsp; 
    <BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; return line;<BR>}<BR><BR>Now, 
    I need to write the rules that will use this. <BR><BR>rule "Generate New 
    Line"<BR><BR>&nbsp;&nbsp;&nbsp; when <BR>&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp; eval (getLine(fileReader) != null)<BR>&nbsp;&nbsp;&nbsp; 
    then <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("Generate 
    new line");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    //assert(getLine(fileReader)); // need to somehow assert the line specified 
    in the eval condition <BR><BR>end<BR><BR>Also, I am confused, how to specify 
    file end. <BR><BR></FONT><FONT 
    style="BACKGROUND: rgb(255,255,255) 0% 50%; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial" 
    color=#000000>rule "File End"<BR><BR>&nbsp;&nbsp;&nbsp; when 
    <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eval (getLine(fileReader) == 
    null)<BR>&nbsp;&nbsp;&nbsp; then <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
    System.out.println("Reached end of file"); // I am assuming this is not 
    needed since if all rules are executed, then it will get out of fireRules() 
    anyways ?<BR><BR>end</FONT><BR><FONT 
    style="BACKGROUND: rgb(255,255,255) 0% 50%; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial" 
    color=#000000><BR>Any help is appreciated. <BR><BR>TIA, <BR>Krishnan 
    (newbie)<BR><BR></FONT></DIV>- <BR>Sivaramakrishna Iyer Krishnan (Anand) 
    <BR><BR>Never assume the obvious is true. <BR>- William Safire 
    <BR>_______________________________________________<BR>rules-users mailing 
    list<BR><A onclick="return top.js.OpenExtLink(window,event,this)" 
    href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR><A 
    onclick="return top.js.OpenExtLink(window,event,this)" 
    href="https://lists.jboss.org/mailman/listinfo/rules-users" 
    target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR><BR></BLOCKQUOTE></DIV><BR><BR 
  clear=all><BR>-- <BR>&nbsp;&nbsp;Edson Tirelli<BR>&nbsp;&nbsp;Software 
  Engineer - JBoss Rules Core Developer<BR>&nbsp;&nbsp;Office: +55 11 
  3529-6000<BR>&nbsp;&nbsp;Mobile: +55 11 9287-5646 <BR>&nbsp;&nbsp;JBoss, a 
  division of Red Hat @ <A href="http://www.jboss.com">www.jboss.com</A> 
</BLOCKQUOTE></BODY></HTML>