Locating facts via slot values
by Wolfgang Laun
Given a working memory containing a large number of rather static facts
which are from several subclasses (Ape, Bear, Crocodile,...) of some base
class (Animal) and a single fact of class Hunter with a field target of type
Animal, the shooting of an animal might be written with a rule like this:
rule shoot-1
when
?h : Hunter( ?target : target )
?a : Animal()
eval(?target == ?a)
then
?h.shoot( ?a );
retract( ?a );
end
Avoiding eval (which is said to be inefficient), it could also be written as
rule shoot-2
when
?a: Animal()
?h : Hunter( target == ?a )
then
?h.shoot( ?a );
retract( ?a );
end
This, however, places the pattern with many instances up front, which is
(AFAIK) not so good in a Rete implementation.
Which one is to be preferred in Drools?
Ideally, one might want to write
rule shoot-3
when
?h : Hunter( ?target : target )
?a == ?target : Animal() ### not valid DRL
then
?h.shoot( ?a );
retract( ?a );
end
This avoids eval, has the single instance fact up front, but it isn't
available.
-W
15 years, 7 months
Debugging Drools when/then using breakpoints
by lightbulb432
(I can't use Eclipse's debug as "Drools Application" feature because the
Drools application I'm using is embedded within a larger deployed web
application, so I must use breakpoints.)
Where can I set breakpoints in my IDE to know exactly when the when/then
sides of a rule are evaluated? I know that the "then" side of a rule is
executed when DefaultAgenda.fireActivation(Activation) method is run, so
every time that breakpoint is hit I know that a rule's "then" side is about
to be fired.
However, I don't know where to set the breakpoint for the "when" side of the
rule - where is this?
Assuming I have 10 rules in total but in a particular scenario only 1 of
those is actually fired successfully after executing the "when" tests, what
I'd like to see is 10 "when" breakpoints being hit and only 1 "then"
breakpoint being hit.
--
View this message in context: http://www.nabble.com/Debugging-Drools-when-then-using-breakpoints-tp2336...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 7 months
JSR-94 API - adding an event listener
by Meny Kobel
Hi,
Does the JSR-94 API includes a method for adding an event listener to the
rule session?
If not any hack I can use?
I'm using drools version 4.0.7.
Thanks
Meny
15 years, 7 months
What does the arrow ("->") mean in a rule file?
by lightbulb432
What does the arrow ("->") mean in a rule file? I've searched on Google,
looked through the Drools documentation, and haven't been able to find out
what it does.
It appears in the autocomplete of my IDE for Drools, and I've seen it in an
example in the JBoss Seam documentation, but am unable to tell what it does:
rule InsertMemberBlog
no-loop
activation-group "permissions"
when
principal: Principal()
memberBlog: MemberBlog(member : member ->
(member.getUsername().equals(principal.getName())))
check: PermissionCheck(target == memberBlog, action == "insert", granted
== false)
then
check.grant();
end;
--
View this message in context: http://www.nabble.com/What-does-the-arrow-%28%22-%3E%22%29-mean-in-a-rule...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 7 months
Rules question
by Armaghan Mahmud
I'm new to the mailing list so I'll start off by saying hello to everyone.
I've recently started using DROOLS and I seem to have hit a dead end. I'm
trying to pass in an enum and a list into the working memory one at a time
but I would like my rule to first see if it the enum matches a hard coded
enum value. Additionally, I would also like the rule to see if the enum
value that is being passed to the working memory happens to fall in the list
or not. First of all, is it possible to do that in one rule? I've been
trying to do that using "&&" and "contains" keywords but I'm not getting
anywhere. I don't have the code in front of me or I would've pasted it but I
hope you can understand my point. Any help that I can get in this matter
will be greatly appreciated.
Thanks,
Armaghan
15 years, 7 months
CEP functionality
by David Boaz
Dear all,
We posted this question two weeks ago, but with no replies. please forgive
me for posting it again.
In our business, most of the facts have time-stamp attributes. For example,
each laboratory test (a fact) has the time stamp when the sample was taken,
and when the machine produced the result value. In our business-logic, we
often analyze the relation between facts using these attributes.
For example:
1) finding two adjacent labResults with an increasing value
2) checking whether 3 facts are consecutive
3) counting the number of facts fulfilling a specific constraint within a
specific time window.
We were happy to read (in the blog) about the new CEP feature which is about
to be added to drools 5.0.
* Where can we find a more detailed description of CEP functionality in
drools?
* Is it a good idea to use CEP for analyzing historic data (retrieved from
the database)? or is it best for online data.
* Can we use CEP in a stateless session?
* As we understand, CEP attaches to each fact a temporal attribute of the
assertion time. Can we define that a particular attribute (e.g.,
LabResult.samplingDate) will be used as the time stamp? Or, should we assert
the facts by their temporal order, and advance the session-clock
appropriately?
* Can we use CEP to analyze the data in the examples above?
Many thanks for the help, David
--
View this message in context: http://www.nabble.com/CEP-functionality-tp19020709p19020709.html
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 7 months
Stateless session and rule flows
by Yoni Mazar
Hi Guys,
We are trying to work with drools with stateless session (Sequential) and to
apply rule flows.
we use the following code:
//define diagnosis and patient here
...
StatelessSession session = ruleBase.newStatelessSession();
//Here we would like to use: session.startProcess("ruleflow id") but this is
a method which belongs to
//StatefullSession only.
session.execute(new Object[] {diagnosis, patient});
How can we do that in steteless mode?
Thanks,
Yoni
--
View this message in context: http://www.nabble.com/Stateless-session-and-rule-flows-tp17863849p1786384...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 7 months
NullPointerException for Integer null
by techy
Hello,
For following rule, NullPointerException is thrown for null id in 4.x. is
this expected? Please clarify.
Foo{
Integer id;
}
Rule "null check"
foo : Foo(id==null)
then
end
stack trace:
java.lang.NullPointerException
at
org.drools.base.extractors.BaseObjectClassFieldExtractor.getIntValue(BaseObjectClassFieldExtractor.java:95)
at
org.drools.base.ClassFieldExtractor.getIntValue(ClassFieldExtractor.java:197)
at
org.drools.base.evaluators.IntegerFactory$IntegerLessEvaluator.evaluate(IntegerFactory.java:241)
at
org.drools.rule.VariableRestriction.isAllowed(VariableRestriction.java:73)
at org.drools.rule.VariableConstraint.isAllowed(VariableConstraint.java:67)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:137)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:318)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:162)
at org.drools.reteoo.Rete.assertObject(Rete.java:175)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at
org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:911)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:883)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:684)
at
org.drools.reteoo.ReteooStatelessSession.execute(ReteooStatelessSession.java:160)
--
View this message in context: http://www.nabble.com/NullPointerException-for-Integer-null-tp23286041p23...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 7 months
need some advice in defining rules
by Brody bach
Hi all,
I'm having difficulty in defining a rule for the following problem:
We need to check if within a week there are more than 5 objects of type
Reminder inserted into Memory.
(one day corresponds to one object)
The number of the inserted objects depends on the usage of the application.
That means there could be nothing, 1, 2, or any number of the objects.
Before, within a session, I inserted a list containg data from within one
week (7 days).
Than I can check using the rule:
when:
$list : list(size > 5)
Reminder() from $list
no String(trim == "limit reached");
then
System.out.println("This rule fires");
insert new String("limit reached");
Now I need to insert a list containing data from a whole month, but I still
need to check whether within one week there are more than 5 reminders exist.
so, the constraint list> 5 can't be used anymore for a single list. I tried
to break the whole list in several smaller list, where each list represents
one week.
Now the problem is, if the rule fires for a certain week, than it won't work
for the following weeks anymore.
My idea is then to insert an integer containing specific number to the
current list, i.e. the calendar week (i.e insert new Integer(52)) and then
to prove this in LHS; but the problem is now how to prove the week number in
LHS? as I remeber, a function can only be called within an eval statement
and in this case actually I should only prove the existence of an Integer
Hope my explanation is quite understandable and looking forward for any
hints
Regards
--
View this message in context: http://www.nabble.com/need-some-advice-in-defining-rules-tp23259683p23259...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 7 months