using BigDecimal in rules
by Marina
Hi,
I'm getting unexpected results when when using BigDecimal objects for matching in rules.
I'm generating DRL in my code, using freemaker.
I have a RuleEngineNumericFact object which has two attributes:
String propertyName
BigDecimal propertyValue
Below is an example of a rule where I try to match a RuleEngineNumericFact object based on the two attributes:
rule "aaa"
agenda-group "r1"
dialect "java"
when
(RuleEngineNumericFact( propertyName == "somename" , propertyValue == 10.8 ))
then
String ruleId = drools.getRule().getName();
firedRuleIDs.add(ruleId);
end
Then I create a new RuleEngineNumericFact object and set its propertyValue as following:
String stringValue = "10.8";
BigDecimal propertyValue = new BigDecimal(stringValue, new MathContext(10));
(I also tried to use default precision settings by creating the BigDecimal value as:
BigDecimal propertyValue = new BigDecimal(stringValue);
)
When I insert this fact into the rule engine - the rule does not get fired, so the fact does not match.
One note: if the values are integeres (like, propertyValue == 100) - the rule gets fired. So, it is only the floating point numbers that do not match.
I generate the DRL in my Java code, using freemaker, and I specify the
value that will be used in the rule for matching by calling toString()
method on a BigDecimal object that I get from my business code. The toString() representation ends up to be the "10.8" value (for example).
According to the BigDecimal documentation, marshalling from/to the same string representation shoudl still produce BigDecimal objects that will return TRUE from the equals() method when compared.
any ideas why this is not working here?
How does Drools compare values of objects like BigDecimal?
thanks,
Marina
15 years, 8 months
Localization in DSL
by Shigeaki Wakizaka
Hello.
I'd like to use Japanese in DSL.
Is it possible?
Do you have a plan to do the localize-thing with DSL and
brand-new BRMS?
Thanks in advance
Shige
15 years, 8 months
RuleAgent question
by J Michael Dean
Two questions. I am interested in using RuleAgent but with the file
or dir property rather than the URL. However, it is not clear to me
where the directories or files must actually be located. If I use
dir=/
then the DirectoryScanner is invoked and claims to have found some
number of files, but I have no idea WHERE it is scanning. If I add
anything like dir=/foo then I get an invalid directory exception.
If I try file=/foo.pkg then I get exception that this is invalid file.
Question 1 - is there an example somewhere that can help me understand
where I am going off the track? I am working Eclipse environment.
Question 2 - if using the BRMS and URL, can there be a backup dir,
file, or cache option that is in the classpath rather than a specific
directory? I would like to distribute an Eclipse application that has
a rule package deployed, but that overrides this with the URL if
available.
Thanks.
- Mike
15 years, 8 months
Adding Rules and Packages to existing rule base (4.0.7)
by cfili
What is the proper way to add rules to existing packages that are already
part of a rule base?
When adding rules to the package directly, those rules are listed in the
rule base however they do not seem to be "active" and will never trigger. I
get the same results if I add rules to a package that was created by the
PackageBuilder but not part of an existing rule base. Allowing Drools to
"merge" the packages also seems to yield a similar result where the first
set of rules are active, but what was added later or merged will not be
active.
I know that this type of activity is supported I just want to make sure I do
it the right way.
Thanks.
--
View this message in context: http://www.nabble.com/Adding-Rules-and-Packages-to-existing-rule-base-%28...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 10 months
how to specify classpath dependencies in .drl files.
by Godmar Back
My question is how to manage a rule base that is composed from sets of
rules drawn from different sources.
Our goal is to supply sets of rules as .jar files - each .jar file
containing a related set of rules. For instance, consider an expert
system where different experts could export their expertise in such a
jar file. Such a .jar file would contain one or more .drl files and a
set of supporting .java classes. We'd like to be able to refer to
these .jar files using a URLClassLoader and/or JarURLConnection so
they can be referred to without a user having to download them prior
to starting their application.
Users should be able to combine those provided rules (that is, the
rules of those experts whose knowledge they wish to exploit) with
their own rules in their own .drl files.
My question is whether drools supports such a setup easily.
Specifically, is there a way for a user to import external .jar files
in their .drl files? A statement such as
use jar:http://expertbase.com/expert1/knowledge5.jar
which would instruct the rule compiler to load the classes from this
jar to its compile class path, and which would instruct the class
loader used to load the user's classes to delegate to the loader used
to load the jar file's classes? [Note that a given expert's knowledge
should only be loaded by one classloader.]
I browsed through the API and discovered that the package builder
configuration allows the specification of a class loader. Does this
mean the rule compiler will attempt to load related classes through
this loader as well? If so, it would need to use reflection to examine
those classes (which I'd find unlikely). If not, is there a way to
control the rule compiler's compiler classpath?
In our current prototype, we need to load everything through the
application classpath to avoid compile errors.
- Godmar
15 years, 10 months
Newbie API Question
by Bhamidi Krishna
Hi,
how can one access the logical inserts from my java code?
In my rules, I have a couple of logicalInserts. How can I access the logical inserts from my calling class after the ruleset execution has completed?
Thank you,
Krishna
_________________________________________________________________
See how Windows Mobile brings your life together—at home, work, or on the go.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093182mrt/direct/01/
15 years, 11 months
function problem
by Charlie Holland
I'm fairly new to Drools so there may be an easier way to do this. I need to
check to see if any one of a list of tags on an object are in another list
of tags and am trying to do that with a function. the compiler tells me it
can't compile my eval function:
#list any import classes here.
**
*import* com.cp.services.rules.sources.Person;
**
*import* com.cp.services.rules.actions.PersonActions;
**
*import* com.cp.rules.TagCodes;
**
*import* java.util.List;
#declare any global variables here
**
*global* com.cp.services.rules.actions.PersonActions personActions;
**
*function* *boolean* hasOneOf(List list1, String[] list2){
*for* (Object obj : list1) {
String string = (String)obj;
*for* (*int* j = 0; j < list2.length; j++) {
*if* (string != *null* && string.equals(list2[j])) {
*return* *true*;
}
}
}
*return* *false*;
}
**
*rule* "Engineering"
*dialect* "mvel"
*when*
**
#conditions
Person( ageInYears >= 18 ) *and*
*eval* ( hasOneOf(Person(tagList), TagCodes(engrTags)) )
*then*
#actions
personActions.addAction("EngineeringGroup");
*
end
*
15 years, 11 months
NullPointerException with float field
by techy
I have rule that logical comparison with two Float fields(like price <
bidPrice || price >= bidPrice ). I get following exception if one of field
is null. Is this expected behaviour? Please clarify. Thanks
Caused by: java.lang.NullPointerException
at
org.drools.base.extractors.BaseObjectClassFieldExtractor.getFloatValue(BaseObjectClassFieldExtractor.java:84)
at
org.drools.base.ClassFieldExtractor.getFloatValue(ClassFieldExtractor.java:191)
at
org.drools.base.evaluators.FloatFactory$FloatLessEvaluator.evaluate(FloatFactory.java:250)
at
org.drools.rule.VariableRestriction.isAllowed(VariableRestriction.java:73)
at org.drools.rule.VariableConstraint.isAllowed(VariableConstraint.java:67)
at org.drools.rule.AndConstraint.isAllowed(AndConstraint.java:47)
at org.drools.rule.OrConstraint.isAllowed(OrConstraint.java:50)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:137)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:145)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:318)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:145)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:145)
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.update(AbstractWorkingMemory.java:1287)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:103)
--
View this message in context: http://www.nabble.com/NullPointerException-with-float-field-tp20740799p20...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 11 months
StatefulSessionSnapshotter and full serialization mode
by Michal Bali
Hi,
Is it possible to use full serialization mode
(SerializablePlaceholderResolverStrategy) with StatefulSessionSnapshotter?
It seems that StatefulSessionSnapshotter uses the default which is identity
(IdentityPlaceholderResolverStrategy). Is is possible to change this?
I have a web application that has a long running drools flow. I am trying to
persist this droolsflow using the SingleSessionCommandService from project
drools-process-enterprise.
Thanking you in advance.
Best Regards,
Michal
15 years, 12 months
Oring conditions
by Waleed Zedan
Hi All,
I have this requirment : Rule A -> Condition 1 AND
(Condition 2 OR
Condition 3 OR
Condition 4)
The problem is that OR (||) operators in drools are not a short circuiting
operators like in Java.
May you please tell me an approach to handle this situation , i have already
tried splitting it on multiple rules ,but i am searching for better
approach.
I am using Drools 4.0.7.
Thanks.
Best Regards,
--
Waleed Zedan
15 years, 12 months