Re: [rules-users] How to reuse a result of a rule in an other rule
by mjohansen
Basically, you can either update an object with the results of the first
rule, or create a new object.
Like:
rule "Hungry"
when
$person : Person(hoursSinceLunch>2 || donutsOnDesk==0 ||
candybarsInDrawer==0)
then
$person.setHungry(true);
update($person);
end
rule "Food"
when
$person : Person(hungry==true)
then
$person.lookForFood()
end
or
rule "Hungry"
when
$person : Person(hoursSinceLunch>2 || donutsOnDesk==0 ||
candybarsInDrawer==0)
then
$hungry=new Hungry();
$hungry.setPerson($person);
insert($hungry);
end
rule "Food"
when
$person : Person()
$hungry : Hungry(person==$person)
then
$person.lookForFood()
end
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-reuse-a-result-of-a-rule-in-an-o...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months
temporal operator "includes" not working
by Neelesh Deo Dani
Hi,
I've following event declarations and rule:
declare Event
@role(event)
@timestamp(datetime)
datetime : Date
name : String
end
declare Contest
@role(event)
@timestamp (startTimestamp)
startTimestamp : Date
endTimestamp : Date
end
rule "Contest"
no-loop
when
$e : Event(name == "event1")
$contest : Contest(this includes $e)
then
System.out.println("rule Contest fired");
end
The timestamps with Event and Contest objects are set as follows (before insert in state-full session):
// for Contest object
Calendar c = Calendar.getInstance();
c.set(2011, 7, 1);
contestType.set(contest, "startTimestamp", new Date(c.getTimeInMillis()));
c.set(2011, 7, 31);
contestType.set(contest, "endTimestamp", new Date(c.getTimeInMillis()));
// for Event object
c.set(2011, 7, 3);
eventType.set(event, "datetime", new Date(c.getTimeInMillis()));
The condition "this includes $e" in LHS doesn't get evaluated to true and RHS doesn't get executed.
If I change it to "$contest.startTimestamp before $e,
$contest.endTimestamp after $e" which has the same meaning then it
works fine.
Please help in resolving the issue.
Thanks & Regards,
Neelesh
13 years, 4 months
accumlator and BigDecimal
by mjohansen
I'm trying to create an accumulator to sum a BigDecimal. Here's what I wrote:
$upcharge : BigDecimal( )
from accumulate( GroupUpcharges( row>$gb.row && row<=$gu.row, $value :
upcharge),
init( BigDecimal total = BigDecimal.ZERO; ),
action( total=total.add($value); ),
reverse( total=total.subtract($value); ),
result( total ) )
$gb and $gu are set earlier in the WHEN clause.
When I run this, it compiles successfully, but then flows up at run time
with a null pointer exception. What am I doing wrong?
--
View this message in context: http://drools.46999.n3.nabble.com/accumlator-and-BigDecimal-tp3185872p318...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months
match longest matching Long in WM
by esstrata
Hi,
I hope you can help me out here with a way to implement this rule:
1) I have String WM
2) I have beans in WM with a property called 'code'
public class MyBean {
private String code;
...
3) I want a rule of the type "Process MyBean with the longest-matching,
not-null code"
Let explain myself a little further with an example.
I have the following MyBean objects in WM with the given code properties:
MyBean [code = 44]
MyBean [code = 443]
MyBean [code = 4432]
MyBean [code = 36]
MyBean [code = 7]
What I want to get is a rule where the following samples would assign to a
variable the given results shown:
4411111 gives MyBean [code = 44]
4433333 gives MyBean [code = 443]
22222 gives null
I think the rule could start like:
rule "Process MyBean with the longest-matching, not-null code"
dialect "mvel"
when
$s : String()
$m : MyBean($s matches /the longest not-null possible MyBean.code/)
then
......
Thank you
--
View this message in context: http://drools.46999.n3.nabble.com/match-longest-matching-Long-in-WM-tp318...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months
Using functions to derive values in "accumulate" (LHS)
by Christian Heupel
Hello,
I am trying to write a rule for my drools engine. It is (as far as i get it
right), almost a total standard rule, however I'm having troubles with it
and was hoping you could point me into the right direction (as i was
surprised to see no similar question, I hope it is not too basic).
To give you an understanding of what i want to do: I want to calculate a
number of costs a person had on a series of trips. For each trip, a function
getCost() calculates the total amount of money spent (such as hotel, bar,
...). If the total amount of money spent is higher then the person's maximum
money, we take action. I am trying to use the accumulate function, but it
seems as if I'm not able to call the getCost() function there. The rule
looks like this:
-----------------
rule "Total Costs"
when
$person : Person( eval ($person.maxMoney != null ) )
$totalCost : Number()
from accumulate( $trip : Trip( $cost : $trip.getCost() )
from $person.getTrips(),
sum( $cost )
)
then
// take action
end
-------------------
I have tried it with and without the $trip-variable (since I thought I might
have to use it to call its function).
The error I get looks like this:
Error INTERNAL_ERROR: Error: unknown:70:54 Unexpected token ')'
java.lang.Exception: Error: unknown:70:54 Unexpected token ')'
at
com.fluidops.coremgmt.ruleengine.PolicyTask.readRule(PolicyTask.java:489)
at
com.fluidops.coremgmt.ruleengine.PolicyTask.readRule(PolicyTask.java:419)
I would be very thankful if one of you could help me out here :)
Best regards,
Christian
PS: I already had this question in the drools forum, it was, however not
forwarded to this mailing list, so please forgive me if it is a double post.
13 years, 4 months
Problem with running examples from drools-distribution-5.2.0
by Scholz. Ulrich
Dear all,
I try to run the examples given in http://download.jboss.org/drools/release/5.2.0.Final/drools-distribution-... (Drools 5.2.0 final downloads)
I've installed the plugin and the example as given in ReadMeDrools.txt
Nevertheless, I get many Eclipse errors (1913) and cannot run the example. For example, the first error is
Description Resource Path Location Type
[ERR 102] Line 56:49 mismatched input '&&' expecting ')' in rule "Free Fish Food Sample" PetStore.drl /drools-examples/src/main/resources/org/drools/examples/petstore line 56 Drools Error
If I run the example despite the errors, I get the message "Could not find the main class: org.drools.examples.DroosExamplesApp. Program will exit."
What could I do?
Thanks, Ulrich
--
Eclipse Java EE IDE for Web Developers.
Version: Indigo Release
Build id: 20110615-0604
(c) Copyright Eclipse contributors and others 2005, 2011. All rights reserved.
Visit http://www.eclipse.org/webtools
--
Graphical Editing Framework GEF 3.7.0.v20110425-2050-777D-81B2Bz0685C3A6E34272 org.eclipse.gef.feature.group Eclipse Modeling Project
Graphical Editing Framework Draw2d 3.7.0.v20110425-2050-46-7w3122153603161 org.eclipse.draw2d.feature.group Eclipse Modeling Project
JBoss Drools Core 5.2.0.v20110116-0638-H14 org.drools.eclipse.feature.feature.group JBoss by Red Hat
JBoss Drools Guvnor 5.2.0.v20110116-0638-H14 org.guvnor.tools.feature.feature.group JBoss by Red Hat
JBoss Drools Task 5.2.0.v20110116-0638-H14 org.drools.eclipse.task.feature.feature.group JBoss by Red Hat
--
...
SEEBURGER AG Vorstand/Seeburger Executive Board:
Sitz der Gesellschaft/Registered Office: Bernd Seeburger, Axel Haas, Michael Kleeberg
Edisonstr. 1
D-75015 Bretten Vorsitzender des Aufsichtsrats/Chairperson of the Seeburger Supervisory Board:
Tel.: 07252 / 96 - 0 Dr. Franz Scherer
Fax: 07252 / 96 - 2222
Internet: http://www.seeburger.de Registergericht/Commercial Register:
e-mail: info(a)seeburger.de HRB 240708 Mannheim
Dieses E-Mail ist nur f?r den Empf?nger bestimmt, an den es gerichtet ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungs?u?erung ist die des Autors und stellt nicht notwendigerweise die Ansicht oder Meinung der SEEBURGER AG dar. Sind Sie nicht der Empf?nger, so haben Sie diese E-Mail irrt?mlich erhalten und jegliche Verwendung, Ver?ffentlichung, Weiterleitung, Abschrift oder jeglicher Druck dieser E-Mail ist strengstens untersagt. Weder die SEEBURGER AG noch der Absender ( Scholz. Ulrich ) ?bernehmen die Haftung f?r Viren; es obliegt Ihrer Verantwortung, die E-Mail und deren Anh?nge auf Viren zu pr?fen.
The present email addresses only the addressee which it targets and may contain confidential material that may be protected by the professional secret. The opinions reflected herein are not necessarily the one of the SEEBURGER AG. If you are not the addressee, you have accidentally got this email and are not enabled to use, publish, forward, copy or print it in any way. Neither SEEBURGER AG , nor the sender (Scholz. Ulrich) are liable for viruses, being your own responsibility to check this email and its attachments for this purpose.
13 years, 4 months
Globals from functions...
by bob.breitling
I have a global defined and I am trying to use it from a function. When my
rule gets loaded into my knowledge base, I always get an error complaining
about the global not being resolved.
---- simplified snippet ----
global int x;
function void foo(int n) {
x = n;
}
------------------------------
I get this kind of error "Function Compilation error: foo (line:20) x can
not resolved".
Should this work?
TIA,
Bob
--
View this message in context: http://drools.46999.n3.nabble.com/Globals-from-functions-tp3186882p318688...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months
[Drools4]: Filter executed rules by *.drl file
by magendo
Before I start do explain my problem I should say that I have already
searched through the older posts and found similiar problems but not exactly
the following one:
My Application has multiple RuleFiles (*.drl each with its own package)
which can be dynamically added/removed. Based on a context (lets say String
foo = "bar") only the rulepackage which fits to "bar" should be executed.
Usually that isnt a problem, because drools just executes the rules with the
fitting facts. But in this case all the rules in the rulepackages check the
same type of facts.
Currently I am using an AgendaFilter (if rulepackage == xyz { accept =
true}) to achieve this goal, but firstly it doesnt effect inserting of facts
(LHS of every rule is executed) and secondly I have read that it should only
be used for unit testing, since it couples java code with rule behavior.
While reading older posts I have found two possible solutions that could
work:
1. Using a contextObject which has foo and is checked in the first rule of
each rulepackage. This first rule and the remaining rules in the rulepackage
have the same agenda group. So if the first rule doesnt fit, the other rules
wont be executed, either (does this really work? ;)).
2. Putting every rulepackge in its own rulebase. Then I would check the
context in java and execute the fitting rulebase.
Let's say I have about 300 *.drl files. Which solution would be better?
Maybe there is a better solution 3) of which I didnt think yet. Then dont
hesitate and tell it to me :)
Thanks in advance for any help.
--
View this message in context: http://drools.46999.n3.nabble.com/Drools4-Filter-executed-rules-by-drl-fi...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months
Unexpected variable binding behavior and conditional logic
by ChrisG
Apologies if this has been addressed elsewhere: I couldn't find anything
quite like my issue.
My (greatly simplified and completely made-up) example:
Let's say I have this java class:
public class BaseballPitcher
{
public String getName();
public boolean isRightHanded();
public boolean isKnuckleBaller();
}
Multiple instances of this class are created with a variety of combinations
for the name and two boolean parameters.
Now I have a rule:
rule "Match pitchers: righties or knuckle-ballers"
when
$kbPitcher1 : BaseballPitcher($name: name, $righty: rightHanded == true
||
$knuckleballer: knuckleBaller == true)
$kbPitcher2: BaseballPitcher(name != $name, rightHanded == $righty,
knuckleBaller == $knuckleballer)
then
// Do something with these two pitchers $kbPitcher1 and $kbPitcher2
end
I am getting the curious result that this rule fires its conclusion when
$kbPitcher1 is in fact NEITHER right-handed nor a knuckle-baller (i.e.
rightHanded == false && knuckleBaller == false).
I've worked around this by changing the first condition in either of the
following two ways:
*// eval() the condition*
$kbPitcher1 : BaseballPitcher($name: name, $righty: rightHanded,
$knuckleballer: knuckleBaller,
*eval(isRightHanded() == true || isKnuckleBaller() == true)*)
...or....
*// bind the variables before checking values*
$kbPitcher1 : BaseballPitcher($name: name, $righty: rightHanded,
$knuckleballer: knuckleBaller,
*rightHanded == true || knuckleBaller == true*)
Does this make sense? Both are easy workarounds, and I believe the second
option (i.e. the one NOT using the eval) is the better solution from a
performance perspective, allowing the engine to index the these facts rather
than dynamically evaluate the condition every time.
But I'm a little surprised the first approach didn't work. Any ideas why
not?
--
View this message in context: http://drools.46999.n3.nabble.com/Unexpected-variable-binding-behavior-an...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 4 months