Drools Syntax
by Lindy hagan
Hi,
Could anyone tell me what will be the syntax to check for a list in the drl
file.
For ex:
If the user object contains userid (userId) and list of privileges
(privilegeList) values can be User Privilege or Admin Privilege.
I want to create 3 rules :
privilegeList.contains("User Privilege ") && privilegeList.contains("Admin
Privilege") first rule
privilegeList.contains("User Privilege ") second rule,
privilegeList.contains("Admin Privilege") third rule,
can this be done in Drools?
Thanks,
Lindy
16 years, 8 months
Scaling to large numbers of rules
by Adam Sussman
I am hoping that I am doing something wrong here and that one of you can
point me in the right direction.
Can anyone provide some advice on scaling up the number of rules in a
single KnowledgeBase? While I have seen all sorts of reports on having
lots of facts, I have not seen anything about having lots of rules.
I need to get to about 200K rules in a single KnowledgeBase, and also
to run several of these side by side in the same system.
The problem:
As the number of rules increases, the time to compile and load them
into memory skyrockets. Now while I realize that the Rete algorithm
complexity is about the number of rules, the times I am seeing are
pretty scary. Also, at about 30k rules, things just fall apart.
On a 64 bit Linux OS with 2 2.4Ghz processors using a 64bit JVM from
OpenJDK (1.6.1) with 1 Gig of memory allocated to the JVM, loading
from .drl files:
1000 rules:
KnowledgeBuilder.add: 7 seconds
KnowledgeBase.addKnowledgePackages: .8 seconds
10000 rules:
KnowledgeBuilder.add: 79 seconds
KnowledgeBase.addKnowledgePackages: 23 seconds
15000 rules:
KnowledgeBuilder.add: 138 seconds
KnowledgeBase.addKnowledgePackages: 55 seconds
20000 rules:
KnowledgeBuilder.add: 488 seconds
KnowledgeBase.addKnowledgePackages: 100 seconds
30000 rules:
KnowledgeBuilder.add: out of memory
KnowledgeBase.addKnowledgePackages: never runs
At this rate, 200k rules will take 13-14 hours to compile
and 2-3 hours to load into RAM, assuming I can even get
to that many rules. This just is not usable.
Time to fire all rules is negligible (fortunately!).
The rules I am testing on are very simple 1-3 variable equality whens
with a simple System.out.println then clause.
The benchmark code I am running is as follows:
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( drlFile, RuleRunner.class ), ResourceType.DRL );
Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
kbase.addKnowledgePackages( pkgs );
Sample rule:
rule "00000005 - random rule"
when
Transaction(someId == 35156 && someOtherId == '79F81FB8134A129F' && someCollection contains 'EC3F2A1DCA88')
then
System.out.println("match rule 00000005 - random rule");
end
Any help would be appreciated.
Regards,
Adam Sussman
CONFIDENTIALITY NOTICE:
This message contains information which may be confidential or privileged. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this transmission in error, please notify me immediately by telephone.
16 years, 8 months
Re: [rules-users] not able to debug drools flow
by Jakob Marovt
Hi,
I`m experiencing the same problems as Vishal. I am using Eclipse 3.5
and newest Drools. I am only able to debug project as Java
application, but when I want to debug it as Drools application all I
get is this problem. I also tried disabling firewall and changing its
settings but as it seems it does not help.
So if anyone has figured out a solution to this problem, I would
really appreciate an answer.
Thanks,
Jakob
probably related to your personal firewall:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6303969
http://www.techienuggets.com/Comments?tx=3786
I don't think this is a Drools specific issue.
Mark
Vishal Anand wrote:
>
**>* Hi,*
>
**>* *
>
**>* I am using Drools 5.0 and have create a simple application using *
>* drools flow, it runs perfectly but when trying to debug it as n drools *
>* application I get the following error:*
>
**>* *
>
**>* FATAL ERROR in native method: JDWP No transports initialized, *
>* jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)*
>
**>* ERROR: transport error 202: connect failed: Connection refused*
>
**>* ERROR: JDWP Transport dt_socket failed to initialize,
TRANSPORT_INIT(510)*
>
**>* JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports *
>* initialized [../../../src/share/back/debugInit.c:690]*
>
**>* *
>
**>* *
>
**>* While stack trace shows the following:*
>
**>* *
>
**>* *
>
**>* java.lang.IncompatibleClassChangeError: Expected static method *
>*org.drools.eclipse.launching.DroolsVMDebugger.renderCommandLine([Ljava/lang/String;)Ljava/lang/String;
*
>
**>* at org.drools.eclipse.launching.DroolsVMDebugger.run(Unknown Source)*
>
**>* at *
>*org.eclipse.jdt.launching.JavaLaunchDelegate.launch(JavaLaunchDelegate.java:101)
*
>
**>* at *
>*org.drools.eclipse.launching.DroolsLaunchConfigurationDelegate.launch(Unknown
*
>* Source)*
>
**>* at *
>*org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:853)
*
>
**>* at *
>*org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:703)
*
>
**>* at *
>*org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:866)
*
>
**>* at *
>*org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1069)
*
>
**>* at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)*
>
**>* *
>
**>* *
>
**>* I am using eclipse 3.4*
>
**>* *
>
**>* What could be the issue ?*
>
**>* *
>
**>* Thanks*
>
**>* Vishal*
>
**>*------------------------------------------------------------------------
*
>
**>* _______________________________________________*
>* rules-users mailing list*
>* rules-users at lists.jboss.org<http://lists.jboss.org/mailman/listinfo/rules-users>
*
**>* https://lists.jboss.org/mailman/listinfo/rules-users*
**>* *
16 years, 8 months
Accumulator - Syntax question
by joseph berdat
Hello,
The rule below check which quote have a price above the average.
In this form the rule is working, but from the log files it seems that
this rule is doing a cross join.
rule "above average value"
dialect "mvel"
when
Double( $average : doubleValue) from
accumulate( Quote( $price : value ), average( $price ) )
$quote : Quote(value > $average)
then
System.out.println("Quote above average [" + $quote.id + "]
value [" + $quote.value + "] average [" + $average + "]")
end
I could not get the correct syntax. I would like to write something
like:
when
Quote(value > doubleValue) from accumulate( Quote( $price : value ),
average( $price ) )
Thanks,
regards.
16 years, 8 months
Trouble getting Dynamic Salience working - add in rules-templates
by Bill Tarr
Thank you for the response Greg. For starters, I did NOT know about specificity... very helpful to know, and I feel certain I will be using it in the future. I don't feel any of the documentation I've read on Drools really got this subject across for me, I not sure the the Drools developer book really covers it at all.
Back to my actual implementation. We are using rules-templates, which have a "unique behavior" I've been calling a feature, but some might consider a bug... or have found a way to work around. Templates do not render rule lines which contains NULL parameters. This hasn't bit my too badly to this point, but MAY pose an interesting issue for specificity (now that I know about it!)
My real world example is a good bit more complicated. My LH includes:
PARAMETERS
--------------------------
Product - NOT NULL
Start Date
End State
Price Group - NOT NULL
State Group
Some of the info is coming from a single instance of an object I'm calling "transporter" I use to gather info from other rules. It will have a list of state groups and price groups. So psuedocode for my template LH will look something like:
template.pricegroups.contains( "@{PRICE_GROUP}" )
template.stategroups.contains( "@{STATE_GROUP}" )
policy (
startDate > @{START_DATE}
endDate < @{END_DATE}
product = "@{PRODUCT}"
)
The problem I run into here, is that in any given rule, only a subset of these will appear. So one rule may produce:
// this rules parameters have a NULL STATE_GROUP
template.pricegroups.contains( "pg1" )
policy (
startDate > 2009-01-01
endDate < 2010-01-10}
product = "prod1"
)
and another might produce
// this rule has a STATE_GROUP, but no START_DATE and END_DATE
template.pricegroups.contains( "pg1" )
template.stategroups.contains( "NY" )
policy (
product = "prod2"
)
In this example, I actually want the SECOND rule to win the conflict. It is "more specific" for our business rule, a policy for NY should match, but the the first rule should not. In reality, the first rule has more facts, so which one will actually fire first by rules of specificity?
My activation-group and salience hack was one workaround for this condition. I set the second rule with a higher salience, and add them both to the same activation-group.
I will try different combinations of rule-templates and specificity when I am in the office tomorrow (midnight here in San Diego.) If you have any further feedback on this, I do appreciate your taking the time to show a Drools newbie some very useful stuff.
Thanks!
Bill
Message: 2
Date: Tue, 1 Sep 2009 19:29:40 -0700 (PDT)
From: Greg Barton <greg_barton(a)yahoo.com>
Subject: Re: [rules-users] Trouble getting Dynamic Salience working
To: Rules Users List <rules-users(a)lists.jboss.org>
Message-ID: <52492.42683.qm(a)web81501.mail.mud.yahoo.com>
Content-Type: text/plain; charset="iso-8859-1"
I hope you're not going through all of that trouble just to get the functionality from that concrete example. You get that for free with Drools' default conflict resolution, which includes "specificity." Specificity means that rules with the more specific conditions, and all else equal, are fired first. So between these two rules, only the CheeseSausagePepperoniPepper one fires:
rule "CheeseOnly"
when
p : Pizza( )
t1: Topping( pizza == p, name == "cheese" )
then
System.out.println( "Eating cheese pizza" );
retract( t1 );
retract( p );
end
rule "CheeseSausagePepperoniPepper"
when
p : Pizza( )
t1: Topping( pizza == p, name == "cheese" )
t2: Topping( pizza == p, name == "sausage" )
t3: Topping( pizza == p, name == "pepperoni" )
t4: Topping( pizza == p, name == "pepper" )
then
System.out.println( "Eating cheese sausage pepperoni pepper pizza" );
retract( t4 );
retract( t3 );
retract( t2 );
retract( t1 );
retract( p );
end
See the attached project.
--- On Tue, 9/1/09, Bill Tarr <javatestcase(a)yahoo.com> wrote:
> From: Bill Tarr <javatestcase(a)yahoo.com>
> Subject: [rules-users] Trouble getting Dynamic Salience working
> To: rules-users(a)lists.jboss.org
> Date: Tuesday, September 1, 2009, 7:28 PM
> We have a winner!? Many thanks
> Michal, hope I can return the favor one day.
>
> salience ( return getSalience4() )
>
> for the record, my function looks something like (after
> tempate evaluation):
>
> <pre>
> function int getSalience4(){
> ??? int salience = 0;
> ??? if("VALUE"=="VALUE") salience += 1000;
>
> ??? return salience;
> }
> </pre>
>
> I think the combination activation-group and dynamic
> salience for rule-template projects are pretty useful.
>
> Just for anyone interested,?the tempate code looks
> something like this:
>
> <pre>
> rule "Some Rule_(a){row.rowNumber}"
>
> ??? activation-group "@{PARAM1}-@{PARAM2}"
> ??? salience ( return getSalience(a){row.rowNumber}() )
> </pre>
>
> where PARAM1 and PARAM2 make up a kind of key. I only want
> to execute one rule that matches that key, no matter how
> many options there are.
>
> Rules that have additional parameters get higher salience
> than rules with less parameters, so here is my function.
>
> <pre>
> function int getSalience(a){row.rowNumber}(){
> ??? int salience = 0;
> ??? if("@{PARAM3}"=="@{PARAM3}") salience += 1000;
> ??? if("@{PARAM4}"=="@{PARAM4}") salience += 1000;
> ??? return salience;
> }
> </pre>
>
> A concrete example could be pizza.? So there are?3 types
> of pizza, all are grouped in the same activation-group.
>
> cheese, pepperoni
> cheese, pepperoni, sausage
> cheese, pepperoni, meatball, pepper
>
> Any cheese and pepperoni pizza should could match all these
> rules, but more toppings is always better for me.
>
> So cheese, pepperoni, onion, pepper getts a salience of
> 2000, and is the only rule evaluated.
>
>
>
> On Tue Sep 1 18:39:13 EDT 2009, Michal Bali michalbali at
> gmail.com? wrote:
>
> does this work?
> salience ( return getSalience() )
>
> or this:
>
> salience ( getSalience();)
>
>
> On Tue, Sep 1, 2009 at 6:50 PM, Bill Tarr <javatestcase
> at yahoo.com> wrote:
>
> > Possibily just a simple MVEL error, but I've been
> struggling for a while
> > and thought I'd see if anyone could help.
> >
> > I just want to run a logic test to determine salience
> for some rules I am
> > generating with rules-templates.??Even after making
> the logical test "true"
> > I can't get any of variation to compile.
> >
> > (true ? "1000" : "0")
> > **produces**
> > Unable to build expression for 'salience' : not a
> statement, or badly
> > formed structure
> >
> > ( true ? 1000 : 0)
> > **produces**
> > Unable to build expression for 'salience' : invalid
> number literal: 1000
> >
> > salience ( getSalience() )
> > ...
> > function int getSalience(){return 0;}
> > **produces**
> > Unable to build expression for 'salience' :
> org.mvel2.util.MethodStub
> > cannot be cast to java.lang.Class'(
> getSalienceNONCDW() )'
> >
> > Seems like I am missing something simple, but I've
> tried many variations on
> > the above, and have been unable to find any working
> examples of using a
> > logical test in salience, so if anyone has any
> direction it would be greatly
> > appreciated.
> >
> > Thanks!
> >
> > Bill
>
>
> ? ? ?
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 8 months
Guvnor fails to vaildate rule, though same rule compiles and run successfully when compiled command line with ANT.
by Codedrop
Recently upgraded from Drools 4.0.7 to 5.1.0 and have imported our rules into
Guvnor. Unable to determine why the same rules will not correctly validate
in Guvnor which prevents building a package for deployment.
Sample Rule:
salience 50
agenda-group "idia"
when
Root(identityRequest != null)
then
logger.debug("Main - Main Data Evaluation");
System.out.println("Main - Main Data
Evaluation");
drools.getWorkingMemory().setFocus("mainAnalysis");
Throws the following validation error when you select ‘Validate’:
[Main - Data Evaluation] Unable to create Field Extractor for
'identityRequest' of '[ClassObjectType
class=com.netid.idia.model.natal.rootIdentityRequest.Root]' in rule 'Main -
Data Evaluation'
Unsure why identityRequest is failing. There is a valid getter in the java
file and guvnor displays identityRequest in the list of attributes for
‘Root’. Oddly, if I change the when clause to be
Root(this.identityRequest != null) it validates fine. Did something change
between 4.0.7 and 5.1.0 that I’m missing or do I have error somewhere that
goes undetected outside the guvnor?
--
View this message in context: http://www.nabble.com/Guvnor-fails-to-vaildate-rule%2C-though-same-rule-c...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 8 months
forall/from/eval/contains: odd DRL syntax error
by Wolfgang Laun
A rule has to ascertain that all elements in a List<ElemBoxStatus>in a
Collector occur in the matching BoxResponse's Set<ElemBoxStatus>. There is
just one BoxResponse per Collector.
This here works fine:
rule matchCollectorResponse
when
$c : Collector( $ebsList : elemBoxStatusList, $gsSet :
globalStatusSet )
$b : BoxResponse( collector == $c, globalStatusSet == $gsSet,
$ebsSet : elemBoxStatusSet )
forall( $ebs : ElemBoxStatus() from $ebsList
BoxResponse( collector == $c, elemBoxStatusSet contains $ebs
) )
then
...
end
Thinking that $ebs is already available from the second pattern ($b:...), I
tried
rule matchCollectorResponse
when
$c : Collector( $ms : message, $ebsList : elemBoxStatusList, $gsSet
: globalStatusSet )
$b : BoxResponse( collector == $c, globalStatusSet == $gsSet,
$ebsSet : elemBoxStatusSet )
forall( $ebs : ElemBoxStatus() from $ebsList
eval( $ebsSet.contains( $ebs ) ) )
then
...
end
but the compiler came back with
Line ...:55 no viable alternative at input '$ebs' in rule
matchCollectorResponse in pattern eval
Defining a suitable function isIn(...) and using this within eval() produces
the same result. This
and other experiments seems to indicate that bindings in the first pattern
of forall() are not
passed in to an eval() later in the forall.
JIRA?
-W
16 years, 8 months