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
StatefulKnowledgeSession insert Fact using Dynamic option ?
by Remi Barraquand
Hi everyone,
Well i'm trying to upgrade my project to use the last Drools 5.0 API
(5.0.0.M4) and i don't understand something, where is the insert(Object
object, boolean dynamic) method gone ?
In the project i'm working on, one important aspect is to be able to change
the properties of a fact both from Java side and from Drools side. That is
calling
myFact.setPropertyName(theValue);
on the java side should modify the fact in the working memory and of course
doing
modify( $myFact ) {
property = theValue
}
in a rule should modify the value of that fact on the java side.
In the 4.0.7 version of drools i was using firePropertyChange in each setter
to propagate the change, and i inserted each fact in the working memory
using the insert(myFact, true) method. However in the new 5.0 API this
function is gone from the StatefulKnowledgeSession class
(WorkingMemoryEntryPoint).
How could i use dynamic fact using Drools 5.0 ? what should i need to
change, or what i did i miss ? :)
Thanks a lot for any help.
Rémi
-----
________________________________________
Rémi Barraquand, PhD I.N.P.G
Projet PRIMA - Laboratoire LIG
INRIA Grenoble Rhones-Alpes Research Centre
655 Ave de l'Europe
38330 Montbonnot, France
http://barraquand.fr Barraquand
http://bois-chauffage.fr Bois de Chauffage
http://ecoboisenergie.fr Eco Bois Energie
http://venteboisdechauffage.com Vente Bois de Chauffage
--
View this message in context: http://www.nabble.com/StatefulKnowledgeSession-insert-Fact-using-Dynamic-...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 9 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
Problem with (examples for )Guvnor M3 (mortgage, advertisement)
by psentosa
Dear all,
I'm testing Guvnor for the first time (M3, never tried the previous
versions) and try to run the mortgage example first.
In the example folder, there's a .txt file which describes how to run it.
So I imported the repository and wanted to take a look at the rules. When I
clicked on the name of the category (from AssetView) or any asset (from
Package view), it displayed "Please wait..loading data", which unfortunately
didn't progress further. So I have to cancel it by clicking on the x to get
back to the previous screen.
On the console there's the report
"Checking access for...*name of the category*" (for clicking on a category)
and
"INFO [STDOUT] DEBUG 08-12 18:03:33,390
(ServiceImplementation.java:listAssets:883) time for asset list load: 0"
(for clicking on an asset type from the Package view).
So I thought maybe I should defined the access right in the Administration
page (this is also described in the .txt file); So I create a user
permission with admin right, shut down the server, set the property "enable
role-based-authorization" to true, repack, re-run the server and try again.
Still I experience the same problem.
For the other example Advertising I also experienced the same problem.
Several questions I have:
- Should I always define the acces right to be able to browse through the
categories/asset? But apparently I still have problems although user
permissions are defined. Or maybe I progress in a wrong way to use the
Guvnor?
- In the example mortgage, I saw that the client has drools-core-5.0.0.MR2
and mvel-2.0M2. Could it be the problem, that the example was created using
GuvnorM2 so it didn't work for M3?
Unfortunately the documentation of M3 is for some part already out-of-date.
Would be nice to have the most actual one :)
Many thanks for any reply!
regards
--
View this message in context: http://www.nabble.com/Problem-with-%28examples-for-%29Guvnor-M3-%28mortga...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 10 months
Guvnor - How to define custom accumulate function
by Srinivasan Muthu
I have a custom accumulate function written in java which I use in my rules.
To make this work in eclipse, I had to define this function in
drools.packagebuilder.conf file and put that in the root of the project.
Drools.packagebuilder.conf file content:
drools.accumulate.function.groupCount =
com.company.analysis.accumulators.GroupByAccumulateFunction
When I try the same in guvnor, I am not sure where to define this custom
function (similar to drools.packagebuilder.conf file) so that my rules will
get built into a package. Currently when I build the package from guvnor, I
get the following error:
Unable to build expression for 'accumulate' : No accumulator function found
for identifier: groupCount
This is because the drl file doesn't know how to interpret the "groupCount"
function as its not defined anywhere.
I looked up the documentation and the mailing list and couldn't find any
solution. I also tried importing the whole drools.packagebuilder.conf file
into guvnor and that doesn't seem to work as well.
Thanks for your help,
Srini
15 years, 10 months
Delimited Number groups filtering ?
by Maxim Veksler
Hello,
The dataModel is as following:
class AgeRange() {
Integer code;
int minAge;
int maxAge;
}
Campaign() {
List<Integer> listOfAgeRangeCodes;
}
Subscriber() {
int age;
}
AgeRange()'s and Campaign()'s are pre-populated into the WM.
Subscriber() is asserted right before fireAllRules is called.
I need a rule that would allow me to check if Subscriber() is within one of
the defined on the Campaign() AgeRange()'s.
What would be the most efficient way to enforce this constraint?
The other possibility I see is to store the list of AgeRange()'s in each
Campaign() and then use eval() to iterate over the list...
Advice and ideas are appreciated.
Thank you,
Maxim.
--
Cheers,
Maxim Veksler
"Free as in Freedom" - Do u GNU ?
15 years, 10 months
How to serialize a KnowledgeBase?
by David Boaz
Hi all,
Im currently developing a new application using drools 5.0 M4. Im using this
style (from KnowledgeBuilder javadoc):
1- KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
2- kbuilder.add( ResourceFactory.newUrlResource( "file://myrules.drl" ),
ResourceType.DRL);
3- assertFalse( kbuilder.hasErrors() );
4- KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
Now, for optimization reasons, I want to save kbase. The problem is that it
is not serializable.
Probably, Im trying to serialize the wrong object.
can someone please guide me how to do that?
BTW, I have another question, How the KBFactory on line 4 knows the builder
used in lines 1 and 2? Will it actually work?
Thanks, David
--
View this message in context: http://www.nabble.com/How-to-serialize-a-KnowledgeBase--tp21231939p212319...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 11 months