Thanks..
From:
rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Edson Tirelli
Sent: 15 July 2009 14:57
To: Rules Users List
Subject: Re: [rules-users] Getting
hold of the Evaluator Registry
Yes, you are in the right track, and I understand this is a bit
confusing at first. One more reason for people to go to the October Rules Fest
2009 where I will give a presentation on all the ways to extend the engine to
solve specific problems. It will be interesting I hope (last year was awesome)
and even Charles Forgy will be there doing a presentation on Parallel Rete. :)
Meanwhile I will write a tutorial on this, but just to help
you there, your approach is correct, except that you don't need to setup the
option for each operator. It works like this:
* One EvaluatorDefinition class implements support to one or more evaluators,
defined by the method public String[] getEvaluatorIds().
* All you need to do, then, is wire you class once and the engine will pick-up
all the IDs supported by that class. When you have your class wired, you give
it a unique string identifier, so that if you ever need to replace it, or
remove it, you will use that id. Sometimes we use the operator as the ID, but
usually it is something that reminds you of the kind of evaluators that class
define. For instance, drools registers the ComparableEvaluatorsDefinition in
this way:
drools.evaluator.comparable =
org.drools.base.evaluators.ComparableEvaluatorsDefinition
So in this case, "comparable" is the identifier. Finally, from
my previous e-mail you will see that the reason that the eclipse IDE is still
giving you errors is that you are using the API to configure the evaluators.
Just move the configuration to the configuration file and the IDE will pick it
up.
[]s
Edson
2009/7/15 Asif Iqbal <Asif.Iqbal@infor.com>
Edson,
What I have done so far is created a
CustomComparableEvaluatorsDefinition, which is exactly the same as the default
ComparableEvaluatorsDefinition apart form having support for strings, which I
have done by creating StringGreaterOrEqualEvaluators and added that in my
custom class, using the addEvaluatorFunction :-
addEvaluator( ValueType.SHORT_TYPE,
Operator.GREATER,
ShortGreaterEvaluator.INSTANCE );
addEvaluator(
ValueType.SHORT_TYPE,
Operator.GREATER_OR_EQUAL,
ShortGreaterOrEqualEvaluator.INSTANCE );
addEvaluator( ValueType.PSHORT_TYPE,
Operator.LESS,
ShortLessEvaluator.INSTANCE );
addEvaluator( ValueType.PSHORT_TYPE,
Operator.LESS_OR_EQUAL,
ShortLessOrEqualEvaluator.INSTANCE );
addEvaluator( ValueType.PSHORT_TYPE,
Operator.GREATER,
ShortGreaterEvaluator.INSTANCE );
addEvaluator( ValueType.PSHORT_TYPE,
Operator.GREATER_OR_EQUAL,
ShortGreaterOrEqualEvaluator.INSTANCE );
//Custom additions
addEvaluator( ValueType.STRING_TYPE,
Operator.LESS,
StringLessEvaluator.INSTANCE );
addEvaluator( ValueType.STRING_TYPE,
Operator.LESS_OR_EQUAL,
StringLessOrEqualEvaluator.INSTANCE );
addEvaluator( ValueType.STRING_TYPE,
Operator.GREATER,
StringGreaterEvaluator.INSTANCE );
addEvaluator( ValueType.STRING_TYPE,
Operator.GREATER_OR_EQUAL,
StringGreaterOrEqualEvaluator.INSTANCE );
Now Im am trying to wire it, with the following..
CustomComparableEvaluatorsDefinition MyCustomComparable custom = new CustomComparableEvaluatorsDefinition();
KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
EvaluatorOption option = EvaluatorOption.get(Operator.LESS.toString(), custom);
EvaluatorOption option2 = EvaluatorOption.get(Operator.LESS_OR_EQUAL.toString(), custom);
EvaluatorOption option3 = EvaluatorOption.get(Operator.GREATER.toString(), custom);
EvaluatorOption option4 = EvaluatorOption.get(Operator.GREATER_OR_EQUAL.toString(), custom);
config.setOption(option);
config.setOption(option2);
config.setOption(option3);
config.setOption(option4);
Firstly is this the correct approach?....
The problem im having is that in my drl files still flag
errors, when I do “test” > “test2” , am I missing something?
Regards
From: rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org]
On Behalf Of Asif Iqbal
Sent: 15 July 2009 08:20
To: Rules Users List
Subject: RE: [rules-users] Getting
hold of the Evaluator Registry
Edson,
Thanks for your replies they have really helped.
1) I am still not sure about creating a new operator, since the
‘>=’ operator already exists it just does not cater for strings, which I
want to add. So would creating a new operator cause the existing one to be
overrriden when added to the registry?
2) Having looked at the examples and tests you emailed, I am still
unsure how to actually wire in the changes, say for example I have replaced the
existing ‘>=’ evaluator or created a new evaluator so that ‘>=’ now
handles strings. When writing rules will the engine pick this up?.. or do I
need to create a new jar by building?.. or do I need to update a configuration
file?... im just not sure…
3) Wouldn’t the following also add the evaluator definition by
replacing the existing one..
PackageBuilderConfiguration pkgb = new PackageBuilderConfiguration();
pkgb.getEvaluatorRegistry().addEvaluatorDefinition(new ComparableEvaluatorsDefinition());
PackageBuilder builder = new PackageBuilder(pkgb);
builder.addPackageFromDrl(source);
Package pkg = builder.getPackage();
// Add the
package to a rulebase (deploy the rule package).
rules = RuleBaseFactory.newRuleBase();
rules.addPackage(pkg);
Thanks for your help…
From: rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org]
On Behalf Of Edson Tirelli
Sent: 14 July 2009 23:05
To: Rules Users List
Subject: Re: [rules-users] Getting
hold of the Evaluator Registry
I am working in one example of drools features where I implement a
custom evaluator here:
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/contrib/lotrc/src/main/java/org/drools/examples/lotrc/evaluators/IsAdjacentToEvaluatorDefinition.java
I use the configuration file instead of API in the example:
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/contrib/lotrc/src/main/resources/META-INF/drools.packagebuilder.conf
[]s
Edson
2009/7/14
Edson Tirelli <tirelli@post.com>
Asif,
My recommendation is create a new operator for you instead of
overriding existing ones. Although if you really want to replace the existing
ones, setting the property or calling the API to register a new operator will
override the default.
See:
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/builder/KnowledgeBuilderConfigurationTest.java
Test method:
testEvaluatorConfiguration()
[]s
Edson
2009/7/14
Asif Iqbal <Asif.Iqbal@infor.com>
Hi,
What
I need to do is modify one of the evaluator classes specifically ‘<=’, so
that it can handle strings. Now I know I need to create a class similar to
ComparableEvaluatorDefinition. But what I want to do is replace the existing
one in the evaluator registry with my implementation which will include the
additional String capability.
From
my understanding that should be all that is required. Unless im missing
something… now all I need to know is how do I get hold of the evaluator
registry?
Cheers
I
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
JBoss by Red Hat @ www.jboss.com
--
Edson Tirelli
JBoss Drools Core Development
JBoss by Red Hat @ www.jboss.com
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
JBoss by Red Hat @ www.jboss.com