<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 class="main-item">
<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> String line;<br> try {<br> if ((line = fileReader.readLine()) != null) {<br> return
line.toLowerCase();<br> } else {<br> System.out.println("This is an empty line.");<br> }<br> } catch (Exception ex) { <br> }<br> return line;<br>}<br><br>Now, I need to write the rules that will use this.
<br><br>rule "Generate New Line"<br><br> when <br> eval (getLine(fileReader) != null)<br> then <br> System.out.println("Generate new line");<br> //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 "File End"<br>
<br>
when <br>
eval (getLine(fileReader) == null)<br>
then <br>
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) 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