Drools: how do I compare two fields in a Decision Table
by David Smith
Hi,
How do I compare two fields in a decision table e.g.
transactionDate==attachmentDate
I can create a rule that has a restriction using two fields such as
rule "check if risk is active"
when
$risk : Risk(transactionDate==attachmentDate)
then
...
end
I can do this using an eval statement in a decision table
Condition
$risk:Risk
eval($risk.getAttachmentDate().equals($risk.getTransactionDate()))
How do I write this without an eval?
I want to write something similar to the rule above:
Condition
$risk:Risk
attachmentDate == transactionDate
Thanks
David
13 years, 9 months
timer and duration
by OlliSee
Hello there.
I seem to have trouble with the "timer" operator which is documented to have
superseded the "duration" operator for use in the rule body. I might have
something to do with the "not" operator I use in my rule.
Scenario: A is a fact, B is an event
When I write something like this
rule "test"
timer(int: 5s 5s)
when
$a : A()
not (exists B(a == $a))
then
insert(new B($a)); // which means in the new B object: B.a
= $a
end
I expect this rule to fire every 5 seconds if and only if the LHS is true.
I just insert a few A objects at the beginning.
So I expect this rule to fire ONCE, because it will insert the B event which
makes this rule's LHS evaluate to false in the future.
BUT, reality is, this rule fires every 5 seconds, no matter what.
Using the deprecated duration operator with "duration(5s)" instead of the
timer operator, it works as expected.
I assume, that timer works differently compared to duration. So I conclude
that duration should coexist. Or am I missing something here on the usage of
the timer operator?
Thanks in advance.
Oliver
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/timer-and-duration-tp...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 9 months
Accumulating over a list of collected events (bug?)
by OlliSee
Hi folks, another bug discovered here?
This rule yields a really nice exception
rule "Test"
when
$list : List() from collect ( A() over window:time(5s) )
Number($avg : doubleValue) from accumulate( A($num : num)
from $list, average($num))
then
...
end
whereas
Number($avg : doubleValue) from accumulate( A($num : num) over
window:time(5s), average($num))
works fine.
So it seems I can't accumulate over the list. But would be quite handy if I
had more than one accumulation to do and didn't want to rewrite all the
constraints in each accumulation statement. I could just use the list, but
that results in the exception below.
Exception in thread "Thread-5" org.drools.RuntimeDroolsException: Unexpected
exception executing action
org.drools.rule.SlidingTimeWindow$BehaviorExpireWMAction@46fef3
at
org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1473)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1159)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1123)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:917)
at
org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:251)
at trafficsys.SessionInterface.insertAndFire(SessionInterface.java:144)
at
trafficsys.cep.SensorEventGenerator.generateEvents(SensorEventGenerator.java:80)
at de.trafficsimulation.MicroStreet.update(MicroStreet.java:393)
at de.trafficsimulation.SimCanvas.run(SimCanvas.java:401)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at org.drools.reteoo.AccumulateNode.getFirstMatch(AccumulateNode.java:967)
at org.drools.reteoo.AccumulateNode.splitList(AccumulateNode.java:920)
at
org.drools.reteoo.AccumulateNode.removePreviousMatchesForLeftTuple(AccumulateNode.java:874)
at
org.drools.reteoo.AccumulateNode.retractLeftTuple(AccumulateNode.java:205)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.doPropagateRetractLeftTuple(CompositeLeftTupleSinkAdapter.java:238)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.propagateRetractLeftTupleDestroyRightTuple(CompositeLeftTupleSinkAdapter.java:138)
at
org.drools.reteoo.AccumulateNode.retractLeftTuple(AccumulateNode.java:212)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateRetractLeftTuple(SingleLeftTupleSinkAdapter.java:217)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateRetractLeftTuple(SingleLeftTupleSinkAdapter.java:91)
at
org.drools.reteoo.AccumulateNode.evaluateResultConstraints(AccumulateNode.java:648)
at
org.drools.reteoo.AccumulateNode.removePreviousMatchesForRightTuple(AccumulateNode.java:903)
at
org.drools.reteoo.AccumulateNode.retractRightTuple(AccumulateNode.java:303)
at
org.drools.rule.SlidingTimeWindow.expireTuples(SlidingTimeWindow.java:167)
at
org.drools.rule.SlidingTimeWindow$BehaviorExpireWMAction.execute(SlidingTimeWindow.java:329)
at
org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1471)
... 9 more
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Accumulating-over-a-l...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 9 months
Drools: Compound Value Restriction in Decision Table
by David Smith
Hi,
I am pocing/learning drools and I am trying to implements Compound Value
Restrictions using 'In' in a decision table.
I can do this in a rule like
rule "CoverType Example"
when
$risk : Data( coverType in ("A","B", "C", "D"))
then
result.add("CoverType was one of A, B C or D");
end
I can also implement this in a decision table in a long winded fashion
Condition, Action
Data, result
coverType, add("$param")
A, CoverType was one of A, B C or D
B, CoverType was one of A, B C or D
C, CoverType was one of A, B C or D
D, CoverType was one of A, B C or D
Is there a compact way to do this using a Compound Value Restriction using
in?
Something like:
Condition, Action
Data, result
coverType in, add("$param")
"A,B,C,D", CoverType was one of A, B C or D
What goes in the script part "coverType in"?
The number of items in the list can be variable, so don't want to write
something that has $1, $2, $3, $4
Thanks
David
13 years, 9 months
Find facts in partially matching LHS
by David Jacobsson
Hi,
I'm currently working with a system where we have customers with different status flags. This could look something like:
customer has bought a car and a bicycle -> "wheel" status
customer has bought a tent, a jacket and food -> "camper" status
Since these rules can be quite complex and change often using Drools would be a good way so solve the problem. The problem now is that we want to answer the question, what's needed to achieve "camper" status? When it comes to DRL this becomes that we want to know which LHS facts that are missing for the "camper" rule to fire, i.e. so we can tell the customer that in order to achieve "camper" status you also need to buy a tent when he/she already have bought a jacket and food.
The solution we have so far is to add a number of "negative" rules in DRL that can identify the missing facts. Our concern though is that this doesn't scale since these extra rules become several more then the base rules that define the statuses.
Is it possible to solve this in a general way with Drools, i.e. to find missing facts leading to a specific conclusion?
And example of status rule in DRL would look something like:
-----
when
BoughtCar( $c : customer )
BoughtBicycle( customer == $c )
then
insert( new WheelStatus( $c ) );
end
-----
The example above is of course just an example and not actual rules from our system.
Regards,
David
13 years, 9 months
Can we use Multiple dsl in a dslr
by Bala
Hi,
Can we use multiple dsl files in a dslr i.e. expander dsl1.dsl expander
dsl2.dsl
Since my dsl file is going to be large, I find it difficult to store in
database.
Is there a way to split the dsl files and store. and combine back to the
original dsl for better use?
If i am going to keep my dsl file as a binary object and add that to the
builder, how can i specify the expander in dslr?
-----
Thanks,
Bala
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Can-we-use-Multiple-d...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 9 months
Simple Disjunction Question
by thomas.polzin@gmail.com
Hi there
Assume we have a rule like this:
when
$a : A(a==1)
or
($b : B(b==1) and $c : C(c==1))
then
do($a)
do($b)
do($c)
end
Assuming also, that for some reason I do not want to split this rule into
two.
Then, I get a NullPointer exception because either $a or $b and $c are not
defined.
Is there a way to catch or check for this.
Thanks so much for any help
Thomas
13 years, 9 months
"Rule Engine Development with JBoss Drools" Training in Phoenix, Feb 22-23
by Brian Sam-Bodden
*
Integrallis Software (http://www.integrallis.com) is proud to announce our
upcoming 2-day Java training class “Rule Engine Development with JBoss
Drools” <http://tekspike.com/camp/agenda/11> in Phoenix, Arizona on Tuesday
February 22 and Wednesday February 23.
Rule Engine Development with JBoss Drools
This course is aimed at Java and Java EE developers looking to understand
and apply a Rule Engine to solve problems typically (and painfully)
addressed with traditional programming techniques. In this course you will
learn how to build lean applications using Test-Driven Development
Techniques in conjunction with jBoss’ Drools Rule Engine to streamline,
simplify and minimize the maintenance burden of a growing application in a
rapidly changing business environment
This is a hands on course for developers so bring your laptop and be
prepared to write a lot of code!
Contents at a glance:
JBoss Drools Foundations:
- Business Rules: Separating Policy from Code
- Declarative Programming in Rule Engines
- Understanding Rules in the context of a Rule Engine
- Expert Systems and Expert Shells
- Forward and Backward Chaining Explained
- Architecture of a Rule Based System
- Introducing Drools 5.0
- Eclipse and the Drools IDE
- Drools Expert: Rule Basics and Rule Syntax
- Working with the KnowledgeRuntime interface
- Working with Facts: Inserting, Updating, Retracting
- Self-cleaning facts with InsertLogical
- Querying the Engine
- Unit Testing with Drools
- Using JUnit 4 to Test your Rules
- Exploring Drools Architecture
- Drools and Maven
Problem Solving with Drools:
- Reasons to use Rule-based systems / Common Rule Technology Uses
- Efficient Pattern Matching: The Magic Behind a Rule Engine
- Fact Combinations and Permutations (cross product)
- Ordering Conditions
- Basic Conflict Resolution: Dealing with Clashing Rules
- Salience
- Rule Families and Message Passing
- Deep into the Rule Language
- Using DRL files, organizing into domains and namespaces
- Property Change Listeners (when to use them)
- Globals
- Understanding the Agenda
- NoLoop
- Operators and Elements
- Eval and Inline Eval
- Test-Driven Development with Drools
- Using JUnit 4 to Test Rules
- Developing the Loan Calculator using TDD
- Rule Systems Design Considerations
- Rules as first class citizens
- Domain Object versus Rule Engine Objects
- Using Rules in a Web Environment
- Synchronous versus Asynchronous Rule Engine Usage
- Stateless versus Stateful Knowledge Sessions
Advanced Topics:
- Human Readable Rules: Domain Specific Languages in Drools
- Integrating Processes and Rules using Rule Flows (Drools Flow)
- Decision Tables
- Storing and Managing your Rules with Drools Guvnor
- Technical Rules and Business Rules
- Rule Packages and the Global Package
- Importing Rules
- Creating Test Scenarios and using the QA module
- Overview of Drools Deployment in a Java EE Environment
- Options and Gotchas on Specific Application Servers and Frameworks
(EJB3, Spring, Seam)
- Drools Execution Server
- Spring Framework Integration
- Recipe Finder: A Java EE Web Drools Application (A Guided Lab)
- Integrating Rules with EJB 3 Stateless Session Beans
- Design Principles for Building Better Rule Systems
- When and when not to use a Rule Engine
* The course is open to 25 students at cost of $499.99
The course registration <http://tekspike.com/camp/agenda/11> is open at the
Integrallis TekSpike http://tekspike.com/camp/agenda/11
site. The course runs from __9am to 6pm__.
Audience
This course is aimed at Java/Java EE developers with 2/3 years of
programming experience looking to learn how to solve complex problems with
the use of Rule Engine Technology
Training Day Overview
The course follows the approach “I do, we do, you do”. Each section
starts with a 20/30 minute lecture, followed by either an instructor
lead example or a follow-along exercise. After 2 to 3 sections the
students are presented with a Lab Exercise to be performed either
individually or in small groups based on complexity.
Each day includes 2 to 3 follow along exercises and 4 to 5 Labs.
Your Instructor
Brian Sam-Bodden<http://www.nofluffjuststuff.com/conference/speaker/brian_sam-bodden>is
a developer, author, trainer and well-known
speaker that has spent over fifteen years working with object
technologies. He is the president and chief software architect for
Integrallis http://www.integrallis.com, where he focuses on building
great applications with Java, Ruby and Groovy. Brian has worked as an
architect, developer, mentor, and trainer for several Fortune 500
companies in a myriad of industries. Brian is the author of "Beginning
POJOs: Spring, Hibernate, JBoss and Tapestry" and has also co-authored
the Apress Java title "Enterprise Java Development on a Budget:
Leveraging Java Open Source Technologies" and contributed to
O'reilly's "97 Things Every Project Manager Should Know"
*
13 years, 9 months
Questions concerning Java and rules / Flexibility
by Martin Richardsen
I am a complete novice concerning Drools and have some basic questions,
which arised after studying the drools documentation and some examples as well.
As far as I got it right, you have two possibilities to work with drools
1) You write a java program, rules / actions are hard coded inline or saved
in text files / excel sheets / XML files etc. After importing the necessary
drools classes you call the drools interface routines, with the following
functionalities:
load rules, providing working memory, adding facts und finally starting the rule
engine (e.g. firing rules).
2) You use the capabilities of the Drools GUI tools (such as Guvnor), which
allows entering rules, objects and actions via GUI tools.
Here, I don't get the point whether a part of the java code is generated
automatically, or whether you have to write your java classes by yourself, as
presented in possibility 1 (above), but without coding the rules by yourself in
the source code / external input files.
I would be very pleased, if anyone could explain me the essential difference
between the two approaches and accordingly tell me what the advantage of using
method 2) would be in contrast to method 1), particularly concerning the
necessary java coding.
---
Well and there would be another question, if you write down your rules and the
corresponding software, which accesses the rules, is it possible to add some
rules later, without rewriting/recompiling your software?
Thanks in advance!
Cheers, Martin.
13 years, 9 months