<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Message</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2873" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=469424909-31052007><FONT face=Arial
color=#0000ff size=2>Hi Mithun,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=469424909-31052007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=469424909-31052007><FONT face=Arial
color=#0000ff size=2>Assert(), assertLogical(), modify() and retract() in DRL
are implicit functions to do the exact same as WorkingMemory's related members
(much like request and response in a JSP).</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=469424909-31052007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=469424909-31052007><FONT face=Arial
color=#0000ff size=2>What's more there is an implicit "drools" global too that
can be used to access an instance of DefaultKnowledgeHelper.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=469424909-31052007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=469424909-31052007><FONT face=Arial
color=#0000ff size=2>I don't know whether there are any other implicit
objects.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=469424909-31052007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=469424909-31052007><FONT face=Arial
color=#0000ff size=2>With kind regards,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=469424909-31052007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=469424909-31052007><FONT face=Arial
color=#0000ff size=2>Mike</FONT></SPAN></DIV><BR>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] <B>On Behalf Of </B>Mithun
Gooty<BR><B>Sent:</B> 31 May 2007 08:01<BR><B>To:</B> Rules Users
List<BR><B>Subject:</B> RE: [rules-users] How to use the value of a function
in both theLHSand RHS side of the rule ?<BR></FONT><BR></DIV>
<DIV></DIV>
<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> </DIV>
<DIV><SPAN class=876085206-31052007><FONT face=Arial color=#0000ff
size=2> 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 am aware of assertObject() method but not assert()
method. </FONT></SPAN></DIV>
<DIV><SPAN class=876085206-31052007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </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> Krishnan,<BR><BR> 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> 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> when
<BR> $f : File( eof == false
)<BR> then <BR>
System.out.println("Generate new
line");<BR> assert( $f.readLine()
); <BR> 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> salience 10<BR>when<BR>
Line( content matches "xxx" ) <BR>then<BR> // 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> $f: File(
eof == true )<BR>then<BR>
$f.closeFile();<BR>end<BR><BR> 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> That is how I would do it.<BR><BR> Hope it
helps.<BR> Edson<BR><BR>
<DIV><SPAN class=gmail_quote>2007/5/17, Krishnan <<A
href="mailto:krishiyer@gmail.com">krishiyer@gmail.com</A>>:</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> 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) 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) 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> Edson Tirelli<BR> Software
Engineer - JBoss Rules Core Developer<BR> Office: +55 11
3529-6000<BR> Mobile: +55 11 9287-5646 <BR> JBoss, a
division of Red Hat @ <A href="http://www.jboss.com">www.jboss.com</A>
</BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>