[rules-users] How to use the value of a function in both the LHS and RHS side of the rule ?

Krishnan krishiyer at gmail.com
Thu May 17 09:01:12 EDT 2007


Hi,

I want to parse a file and match the file for several regular expressions.
Based on what I match, I write more
rules so that based on all the rules, I can set my results.

Brute force method : Parse the entire file and add all the lines into the
working memory. Write rules that
check each line for some regular expression. This works great.

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.

So, I wrote a function inside the rule file like the below

function String getLine(BufferedReader fileReader) {
    String line;
    try {
        if ((line = fileReader.readLine()) != null) {
            return line.toLowerCase();
        } else {
            System.out.println("This is an empty line.");
        }
    } catch (Exception ex) {
    }
    return line;
}

Now, I need to write the rules that will use this.

rule "Generate New Line"

    when
        eval (getLine(fileReader) != null)
    then
        System.out.println("Generate new line");
        //assert(getLine(fileReader)); // need to somehow assert the line
specified in the eval condition

end

Also, I am confused, how to specify file end.

rule "File End"

    when
        eval (getLine(fileReader) == null)
    then
        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 ?

end

Any help is appreciated.

TIA,
Krishnan (newbie)

-
Sivaramakrishna Iyer Krishnan (Anand)

Never assume the obvious is true.
- William Safire
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070517/b5f6ba63/attachment.html 


More information about the rules-users mailing list