RE: [rules-users] Constaint evaluation
by Greg Barton
The ideas is that objects in working memory are those that meant to be tracked: their changes are made visible to the rules via the insert/update/retract methods. A global is not in working memory, so it's changes cannot be tracked. You can change the contents of a global all day long and the rules would never be notified.
It's a similar concept to threads and synchronization. You can have unsynchronized access to member variables in a class when in a multithreaded environment, but the results are unpredictable. Likewise, you can use globals in conditions, and change the value of the global as you go, but the results are unpredictable.
--- On Wed, 6/10/09, Malenfant, Andre <andre.malenfant(a)cgi.com> wrote:
> From: Malenfant, Andre <andre.malenfant(a)cgi.com>
> Subject: RE: [rules-users] Constaint evaluation
> To: "Kris Verlaenen" <Kris.Verlaenen(a)cs.kuleuven.be>
> Cc: "Rules Users List" <rules-users(a)lists.jboss.org>
> Date: Wednesday, June 10, 2009, 2:20 PM
> Thanks Kris,
>
> I will try with code constraints.
>
> But on the globals subject, I read in the documentation
> that one should not use a global in a rule. I have trouble
> understanding why. I don't think drools clones the global
> object (might not be possible anyway). If my rule
> consequences change the state of a global (this usage is
> considered valid as per the documentation as well) then what
> is the harm of using it in a condition? I could understand
> with immutable objects like String but...
>
> I can change my code to insert that global in the working
> memory but I would like to understand why I should do so...
> And if I do and the state of that object is changed by a
> consequence of my rules, I have to call update? For the same
> reason? I guess I am trying to understand the underlying
> mechanism.
>
> Thanks
>
>
> -----Original Message-----
> From: Kris Verlaenen [mailto:Kris.Verlaenen@cs.kuleuven.be]
>
> Sent: Wednesday, June 10, 2009 11:38 AM
> To: Rules Users List; Malenfant, Andre
> Cc: Rules Users List
> Subject: Re: [rules-users] Constaint evaluation
>
> It depends on what type of constraint you are using.
>
> If you are using a rule constraint, that constraint will be
> evaluated
> just the same as normal rules. This means that the
> constraints are
> evaluated when data is inserted / updated / removed.
> Note that, if you
> want to make sure the engine is using up-to-date
> information, you must
> notify the engine (using update) when you change the data
> in the working
> memory. Also note that globals are considered
> immutable. You should
> never write rules that depend on the state of a global and
> where the
> global can be changed.
>
> If you are using code constraints, the constraint is
> evaluated at the
> point the code constraint is reached.
>
> Kris
>
> Quoting "Malenfant, Andre" <andre.malenfant(a)cgi.com>:
>
> > I have some trouble understanding how conditions and
> constraints are
> > evaluated:
> >
> > I have a rule flow split node with constraints on a
> global object.
> > The split node always takes the same path like if the
> constraints are
> > evaluated at the beginning of the execution of the
> process and not
> > when the process flow reaches that split node. What I
> would expect is
> > that the split node constraints takes into account the
> state of the
> > global object as modified by previous rules in the
> flow.
> >
> > Am I right to think that rules conditions and split
> nodes constraints
> > are evaluated only when inserting/updating objects in
> the working
> > memory? The documentation is not really useful (unless
> I haven't
> > found the appropriate one).
> >
> > Thanks
> >
> > André
> >
> > -----Original Message-----
> > From: rules-users-bounces(a)lists.jboss.org
> > [mailto:rules-users-bounces@lists.jboss.org]
> On Behalf Of Malenfant,
> > Andre
> > Sent: Wednesday, June 10, 2009 11:07 AM
> > To: Kris Verlaenen
> > Cc: Rules Users List
> > Subject: RE: [rules-users] Globals in ruleflow
> >
> > Thanks for trying this for me...
> >
> > As it turns out, while I was creating a test sample
> for you I
> > realized
> > that my ruleflow was not loading properly and I forgot
> to check for
> > errors on the builder. Now it works.
> >
> > Still, the behavior is strange. If my rule doesn't
> load and even
> > though
> > my DRL loaded, my globals were not available. Since
> the DRL declared
> > the
> > same globals it should not have given me that error.
> >
> > Thanks
> >
> > -----Original Message-----
> > From: Kris Verlaenen [mailto:Kris.Verlaenen@cs.kuleuven.be]
>
> > Sent: Tuesday, June 09, 2009 5:51 PM
> > To: Rules Users List; Malenfant, Andre
> > Cc: Rules Users List
> > Subject: Re: [rules-users] Globals in ruleflow
> >
> > Andre,
> >
> > There should be no problem in using the same global in
> both your
> > rules
> > and processes.
> >
> > I have tried a simple example as you described but
> have not been able
> > to
> > reproduce the problem. Could you send me a
> self-contained example
> > that
> > shows the issue?
> >
> > Kris
> >
> > Quoting "Malenfant, Andre" <andre.malenfant(a)cgi.com>:
> >
> > > I am experimenting with rule flows and I get the
> following error:
> > >
> > > Unexpected global [myglobal]
> > >
> > > When calling setGlobal on the session.
> > >
> > > This code works without the workflow (globals
> declared in the drl)
> > > but
> > > fails when I include the rule flow. I declared
> the same globals in
> > > the
> > > rule flow in the header section.
> > >
> > > _______________________________________________
> > > rules-users mailing list
> > > rules-users(a)lists.jboss.org
> > > https://lists.jboss.org/mailman/listinfo/rules-users
> > >
> >
> >
> >
> >
> > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
>
>
>
>
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 9 months
5.0 newbie question
by Earnest Dyke
Greetings all,
I just downloaded 5.0 yesterday and have been going through the doc and have a question: with Rules is the idea to have one active flow per session or can a session have more than one active flow?
Earnie!
16 years, 9 months
Re: [rules-users] Weighted rules / scoring
by Greg Barton
Don't forget that if you want other rules to react to the changed score you must call update() on the altered object:
rule "Myscoreincreaserule"
dialect "mvel"
when
a : Applicant( name == "chris")
then
a.setScore( a.score + 2 );
update( a );
end
--- On Mon, 6/8/09, Chris Strachan <chris.strac(a)googlemail.com> wrote:
> From: Chris Strachan <chris.strac(a)googlemail.com>
> Subject: Re: [rules-users] Weighted rules / scoring
> To: "Rules Users List" <rules-users(a)lists.jboss.org>
> Date: Monday, June 8, 2009, 1:06 PM
>
> Hi,
>
> Don't think I intended to create a new instance, just
> modify the one
> matched in the rule. The following seems to have got
> it working.
>
> rule "Myscoreincreaserule"
> dialect "mvel"
> when
> a : Applicant( name == "chris"
> )
> then
> a.setScore( a.score + 2 );
> end
>
> Thanks for pointing me in the right direction.
>
> Greg Barton wrote:
> > 1) Where is the variable "score" initialized? If it's
> not a global the rule wouldn't compile.
> >
> > 2) Is your intent to create a new Applicant instance,
> or modify the one matched in the rule? (Or maybe you
> want to gather the score from the matched instance and put
> it (+2) into a new instance?
> >
> > --- On Sun, 6/7/09, Chris Strachan <chris.strac(a)googlemail.com>
> wrote:
> >
> >
> >> From: Chris Strachan <chris.strac(a)googlemail.com>
> >> Subject: [rules-users] Weighted rules / scoring
> >> To: rules-users(a)lists.jboss.org
> >> Date: Sunday, June 7, 2009, 1:11 PM
> >> Hi,
> >>
> >>
> >>
> >> I want to be able to use drools / guvnor brms to
> store
> >> weighted rules
> >>
> >> (scoring), however I can't seem to find a way to
> do
> >> this.
> >>
> >>
> >>
> >> I attempted the following,
> >>
> >>
> >>
> >> rule "Myscoreincreaserule"
> >>
> >> dialect
> "mvel"
> >>
> >> when
> >>
> >>
> Applicant( name ==
> >> "chris" )
> >>
> >> then
> >>
> >>
> Applicant fact0 = new Applicant();
> >>
> >>
> fact0.setScore( score + 2 );
> >>
> >>
> insert(fact0 );
> >>
> >> end
> >>
> >>
> >>
> >> drools didn't seem to like the way I did this.
> >> Perhaps this isn't
> >>
> >> permitted, in effect I am trying to do - score =
> score +
> >> 2.
> >>
> >>
> >>
> >> Upon validation I get the following error.
> >>
> >>
> >>
> >>
> [Myscoreincreaserule] Unable to build
> >> expression for 'consequence': Failed
> >>
> >> to compile: 1 compilation error(s): - (1,3)
> unqualified
> >> type in strict mode
> >>
> >> for: age ' Applicant fact0 = new Applicant();
> >> fact0.setScore( score + 2 );
> >>
> >> insert(fact0 ); '
> >>
> >>
> >>
> >> Any ideas on how I should be approaching this?
> >>
> >>
> >>
> >> Thanks,
> >>
> >>
> >> -----Inline Attachment Follows-----
> >>
> >> _______________________________________________
> >> rules-users mailing list
> >> rules-users(a)lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >>
> >>
> >
> >
> >
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 9 months
Re: [rules-users] Weighted rules / scoring
by Greg Barton
1) Where is the variable "score" initialized? If it's not a global the rule wouldn't compile.
2) Is your intent to create a new Applicant instance, or modify the one matched in the rule? (Or maybe you want to gather the score from the matched instance and put it (+2) into a new instance?
--- On Sun, 6/7/09, Chris Strachan <chris.strac(a)googlemail.com> wrote:
> From: Chris Strachan <chris.strac(a)googlemail.com>
> Subject: [rules-users] Weighted rules / scoring
> To: rules-users(a)lists.jboss.org
> Date: Sunday, June 7, 2009, 1:11 PM
> Hi,
>
>
>
> I want to be able to use drools / guvnor brms to store
> weighted rules
>
> (scoring), however I can't seem to find a way to do
> this.
>
>
>
> I attempted the following,
>
>
>
> rule "Myscoreincreaserule"
>
> dialect "mvel"
>
> when
>
> Applicant( name ==
> "chris" )
>
> then
>
> Applicant fact0 = new Applicant();
>
> fact0.setScore( score + 2 );
>
> insert(fact0 );
>
> end
>
>
>
> drools didn't seem to like the way I did this.
> Perhaps this isn't
>
> permitted, in effect I am trying to do - score = score +
> 2.
>
>
>
> Upon validation I get the following error.
>
>
>
> [Myscoreincreaserule] Unable to build
> expression for 'consequence': Failed
>
> to compile: 1 compilation error(s): - (1,3) unqualified
> type in strict mode
>
> for: age ' Applicant fact0 = new Applicant();
> fact0.setScore( score + 2 );
>
> insert(fact0 ); '
>
>
>
> Any ideas on how I should be approaching this?
>
>
>
> Thanks,
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 9 months
Templates / Generated rules debugging
by Malenfant, Andre
Hi,
Can some of your share your technique for debugging/troubleshooting rules:
Here is the situation:
- I have a web application that uses rules at specific points.
- I use templates and decision tables so the actual rules are compiled by my application using a spread sheet compiler.
- Since this is a web application, I cannot debug the rules in Eclipse (unless I am missing something)
I must not be the only one asking this question but I cannot find answers in the archives.
Thanks,
André Malenfant
16 years, 9 months
Strange situation when defining arrays in Drools 5
by Luis Silva
Last friday, I had the next situation. In drools 4.0.7 I had the expression:
new double[]{-1, 1}
And it worked.
But in Drools 5.0 I had to erase the blank space (before "1" and after ","),
because I was getting a warning message, during knowledge base building :
"line 29:114 extraneous input '1' expecting RIGHT_CURLY"
and an exception, during rule execution :
"org.drools.runtime.rule.ConsequenceException:
java.lang.IndexOutOfBoundsException"
So the working expression for Drool 5.0 was: new double[]{-1,1}
--
Luis Enrique Silva Valdivieso
16 years, 9 months
Timestamp for processing Historical Data
by PriyaSha
Hi,
I had a chance to go through the fusion sample. I tried the same example
with another logfile as input
Input:
1000 critical Symantec
5000 critical Symantec
6000 critical Symantec
Here I set the timestamp as ( some date in the past + first column of the
input).
*
Following is the simple DRL which has the rule to count number of OMTicket
using sliding window.
package* org.drools.examples.broker;
*
import* org.drools.examples.broker.model.OMTicket;
*
dialect* "mvel"
*
declare* OMTicket
@role( event )
@timestamp (timestamp)
@expires (1h)
*
end*
*
rule* "Count over last 5 seconds"
*
salience* 10
*
no-loop* *true
when
*
Number( $count : intValue ) *from* *accumulate* (
OMTicket($severity:severity) over window:time(5s) *from* entry-point "OM
stream", count() )
*
then*
System.out.println("Number of Critical Tickets over last 5 seconds : " +
$count);
*end*
Here, I just read and insert facts as events with no scheduling.
But the ouput varies for each invocation and it is also not as expected.
Am I missing any configuration here?
16 years, 9 months
ResourceChangeNotifier and subscribeResourceChangeListener()
by Andrew Nguyen
I am using Guvnor and have configured a change-set.xml to look towards
http://..../LATEST. I would like to add a listener to
ResourceChangeNotifier that will respond to detected changes. I
implemented the ResourceChangeListener interface and have added it via
the subscribeResourceChangeListener() but my resourcesChanged()
function never seems to be called. I'm wondering if my assumption and
usage of everything is correct...
Thanks,
Andrew
16 years, 9 months
Rules storage in a database
by Bhamidi, Krishna
Hello,
we have stored rules in a database, and require to migrate the rules from say a development database to a test database, and further to a production database and use Guvnor for analysts to view current rules in the production database. Has anyone attempted this, and is there an appropriate deployment scenario for this? Has anyone attempted a similar deployment scenario?
We have found that the tables that get created are not always the same - we have had 4 tables created in one environment, and 8 in another; what drives the table creation? Any documentation we can refer to?
Would appreciate pointers.
Krishna
16 years, 9 months