Re: [rules-users] DSL: Problem of having 2 DSL statements that endsdiffer
by Matt Geis
Minor correction:
>>Drools stops on the first DSL sentence it can map to.
[false]
>>If you want it to work, you have to be careful about the order you write sentences in your DSL : write them from the most restricitive to the less.
[depends on what you want to accomplish]
Drools actually does not stop until it hits the end of the DSL entry list. For each domain specific block of text it has to turn back into DRL, it tries to match/replace on every DSL mapping entry. So, if you DRL file has 10 lines of conditions (the "when" block) spread across n rules, 6 lines of consequences (the "then" block), and your DSL file has 10 lines, 4 for "any", 3 "when", and 3 "then", you will have 70+24 = 94 different attempts to match/replace. The engine will not stop at the first match, as subsequent matches may apply.
Some people take this behavior into account when building their DSLs.
In short, you aren't really writing a simple name/value pair list. You're writing a transformation engine, through which any entry can be transformed at multiple points along the way. Raw entry A may not match DSL mapping entry 5, but after it matches entry 3, the replacement then matches entry 5.
Example:
start with input A
try to match a to entry 1, fail
try to match a to entry 2, fail
try to match a to entry 3, success, transform to B.
try to match b to entry 4, fail
try to match b to entry 5, success, transform to c.
Return c.
Hope that helps,
Matt
ps. If you start getting into this and find the expressiveness of the language you want to build a bit restrictive in Drools 4, give Drools 5 a test drive. You'll find that the implementation of DSLs in Drools 5 is a more complete implementation of the original design. Drools 5 DSL changes were a result of people pushing Drools 4 to and finally a bit past what it was capable of, when trying to realize exactly the kind of behavior you've been discussing.
15 years, 11 months
Unable to resolve token on function call with mvel dialect
by Olivier THIERRY
Hi,
I use drools 4.0.7 and I encounter a problem calling a function from a
rule written for mvel dialect.
The function I need to call has this signature :
function VOCounter createCounter(org.drools.spi.KnowledgeHelper
drools, String code, Number number)
When I call this function, I want to assign result to a variable, for
example to insert it to working memory later, or just to use it in
another function call.
So I wrote something like that (I am writing a DSL so part of the code is DSL ):
rule "CALCUL_RELICAT_CP"
salience 8
no-loop
when
not There is a counter called "RELICAT_CP"
There is a date called "startDate"
There is a date called "endDate"
There is a counter called "SOLDE_CP_CUM" with
- start date is last year
then
> VOCounter $relicat = createCounter(drools,"RELICAT_CP",$SOLDE_CP_CUM.value);
> insert($relicat);
Copy counter $SOLDE_CP_CUM to SOLDE_RELICAT_CP
end
But I have the following stack trace :
org.drools.spi.ConsequenceException:
org.mvel.UnresolveablePropertyException: unable to resolve token:
createCounter(drools,"RELICAT_CP",$SOLDE_CP_CUM.value)
at org.drools.base.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:13)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:558)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:518)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:475)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:439)
at fr.horoquartz.t4.test.drools.TestRuleBase.executeRuleWithDsl(TestRuleBase.java:120)
at fr.horoquartz.t4.test.drools.Test1.testDsl(Test1.java:39)
Caused by: org.mvel.UnresolveablePropertyException: unable to resolve
token: createCounter(drools,"RELICAT_CP",$SOLDE_CP_CUM.value)
at org.mvel.ast.PropertyASTNode.initializePropertyNode(PropertyASTNode.java:129)
at org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(PropertyASTNode.java:24)
at org.mvel.ExecutableAccessor.getValue(ExecutableAccessor.java:45)
at org.mvel.ast.TypedVarNode.getReducedValueAccelerated(TypedVarNode.java:43)
at org.mvel.MVELRuntime.execute(MVELRuntime.java:90)
at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
at org.mvel.MVEL.executeExpression(MVEL.java:235)
at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:48)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:554)
... 34 more
What is strange is that it works if I don't assign function call
result to a variable. For example the following works :
insert (createCounter(drools,"RELICAT_CP",$SOLDE_CP_CUM.value));
It also works if I assign $SOLDE_CP_CUM.value to a temporary variable
and use it for function call :
Number $val = $SOLDE_CP_CUM.value;
VOCounter $relicat = createCounter(drools,"RELICAT_CP",$val);
insert($relicat);
I had not this problem using java dialect. I understand nothing in
what happens ... Anyone has an idea what the problem is ?
Thanks in advance,
Olivier
15 years, 11 months
DSL: Problem of having 2 DSL statements that ends differently
by cmgoh
Hi,
Further working with DSL (btw, we are using Drools 4.0.7), I found out that
if there are two DSL statements such as:
This is a "{node1}"
This is a "{node1}" in "{tree}"
Drools will throw some errors:
Exception in thread "main" org.drools.rule.InvalidRulePackage: Rule
Compilation error : [Rule name=aC, agendaGroup=MAIN, salience=0,
no-loop=false]
org/doxa/rules/deployer/Rule_aC_0.java (25:1671) : in cannot be resolved
org/doxa/rules/deployer/Rule_aC_0.java (25:1674) : Syntax error on token
""tree3"", invalid AssignmentOperator
at org.drools.rule.Package.checkValidity(Package.java:424)
at org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:394)
at
org.doxa.rules.deployer.RuleRunnerWithDSL.runRules(RuleRunnerWithDSL.java:36)
at
org.doxa.rules.deployer.RuleRunnerWithDSL.main(RuleRunnerWithDSL.java:118)
Is this a bug? It took me almost 1 day to discover this. Hope this will
provide other DSL users some light.
Best regards
Eric
--
View this message in context: http://www.nabble.com/DSL%3A-Problem-of-having-2-DSL-statements-that-ends...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 11 months
Global variables thread safety
by Waleed Zedan
Hi,
I am developing a web service that evaluates risks on a certain fact, I
accumulate the risks in the working memory (stateless working memory), but i
need to return the asserted risks from the web service
the web method signature is like public Risks assertFact(Fact fact)
where Risks:
factId
Risk[]
The operation of insertion of a fact into the working memory is thread safe
(there is a lock object invoked in the execute or insert operation). I need
to know if i called workingMemory.executeWithResults() and getting the
global variable , are these results thread safe ?
public Risks assertFact(Fact fact){
...
synchronized(workingMemory){
StatelessSessionResult result = workingMemory.executeWithResults(fact);
risks = result.getGlobal("xyz");
}
...
return risks
}
it would be better to remove the synchronized block , but I don't know if
this is okay or not.
Thanks in advance.
Best regards,
--
Waleed Zedan
15 years, 11 months
Associate Agenda Group with Guvnor Category
by David Sinclair
I don't believe this is currently supported, but is there an "easy" way to
associate rules within a category to an agenda group? For example, if I have
a category named Validation Rules, I would like to have the burden removed
from the user for placing the rule in the Validation agenda group.
thanks
15 years, 11 months
which libraries to use api or core
by Brody Bach
Hi drools-developers,
I'd like to integrate drools in my application.
I read in some threads that the structure of the libs has been changed in the newest version, so that same classes exist in several jars.
So, if I am to use a class from the old one (core), is it safe enough for my appl? I mean will it run later when the libraries are completely separated?
Or would it be preferable to use directly the new ones (from drools-api)?
Thanks for advise
BB
15 years, 11 months
Report
by The Post Office
���c�S��W��r�F8f�/��O����QR�u6L�x6�N(�mj��4�\������>�LKu~dgQ5�d�-���|��[���C�_
����[���hm
���\�*L)eT��,
�xf���xE�;����i��9���|v#������x��!�f��m�t��oj��^���X�3��2��X���5��P�]e���
�S!.{X���:W������%�^�al��K��r4�m�����
15 years, 11 months
shadow proxy nullpointerexception
by Trägenap
Hello,
I got some problems with shadowproxy.
I have a couple of instances of class "FirstObj". The objects contains
some other objects like "innerObj" and have a method "computesomething",
which returns boolean and use the "innerObj" to compute the result.
I try to access this object with the following rule:
rule "doIt"
when
$firstobj : FirstObj(computesomething == true)
then
// take a break...
System.out.println("be happy");
I debug the programm and figure out that the innerObj is not null.
Instead of my original object "firstobj", there I found a
FirstObjShadowProxy which offers a field called "innerObj" which is null.
Isnt it possible to get access to "computed" fields? What is wrong here?
Thanks
Thorsten
15 years, 11 months
DSL: concatenating DSLs using "and" and "or"
by Chong Minsk Goh
Hi,
We are currently using Drools to enable conditional routing for our
application. We are using DSLs to make it more user friendly.
Using Eclipse DSL editor, I noticed that there is an error (Duplicate
Declaration of variable) if I use "and" to concatenate 2 DSL statements
using the same variable name but this error does not appear if I use "or"
For example,
DSL Statement
[when]there is an "{id}"=$node: Node(nodeId=="{id}")
Using "and"
(there is an "{id}") and (there is an "{id}")
Using "or"
(there is an "{id}") or (there is an "{id}")
With the brackets, each DSL statement should be isolated right? But it is
kinda tricky as if we need to use 2 or more DSL statements together using
the same variable name.
Also, is there any means to create unique variables for use in DSL,
especially when joining for 2 or more DSL statements is required.
Best regards
Eric
15 years, 11 months