&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 &quot;represent&quot; your file... that would be your File interface. It would have a method: readLine() that returns a Line object, as well as an &quot;eof&quot; 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) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" color="#000000">
rule &quot;R1: Read one more line&quot;<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(&quot;Generate new line&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; assert( $f.readLine() ); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; modify( $f ); // as readLine &quot;modifies&quot; the state of the File
<br>end</font><br><br>3) Create the rules to effectivelly &quot;analyze&quot; 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 &quot;Rx: analyze line&quot;<br>&nbsp;&nbsp; salience 10<br>when<br>&nbsp;&nbsp;&nbsp; Line( content matches &quot;xxx&quot; ) <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 &quot;close file&#39;<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="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><font style="background: rgb(255, 255, 255) none repeat scroll 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) none repeat scroll 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(&quot;This is an empty line.&quot;);<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 &quot;Generate New Line&quot;<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(&quot;Generate new line&quot;);<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) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" color="#000000">

rule &quot;File End&quot;<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(&quot;Reached end of file&quot;); // 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) none repeat scroll 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>