Re: [rules-users] Setting value in LHS for access in RHS
by Stephen Masters
Apologies for the overly brief explanation ... am at a bank where only internet access is on my phone. Additional apologies if I suffer from auto-correct errors. :)
[condition][] validate "{exposureType:ENUM:exposure types}" = AccountExposure($exp : {exposure type});
[consequence][] Create limit check = insert(new LimitCheck($exp);
Now, dependent on what exposure type I select, I need to use a different value to perform conversions between amounts and percentages. So it would keep things clean if I could pass the property name selected in the LHS to the object inserted on the RHS.
I could do it by having different DSL phrases for consequences, but my audience is very non technical so I'm trying to keep the language as minimal as possible.
Hope that explains it!
Steve
Mauricio Salatino <salaboy(a)gmail.com> wrote:
>_______________________________________________
>rules-users mailing list
>rules-users(a)lists.jboss.org
>https://lists.jboss.org/mailman/listinfo/rules-users
11 years, 12 months
Setting value in LHS for access in RHS
by Stephen Masters
Stephen Masters <stephen.masters(a)me.com> wrote:
>Hi folks,
>
>I'm trying to set up rules where the RHS is able to refer to a value set in the LHS so that it can perform its logics slightly differently.
>
>I'm able to use $var to pick out fields from facts in working memory. However as far as I can tell I'm not able to set a new value.
>
>I'm setting up a DSL to drive guided rules in guvnor and in the RHS I need to know which value was picked from a drop down list in the LHS.
>
>Cheers
>
>Steve
11 years, 12 months
Banking Example 4 to 6 - sorting incorrect
by Peter Gould
Hi,
I'm new to Drools and just working my way through the examples / tutorials
in the Drools Expert PDF. I'm using the 5.5.0 Final runtime. When I run the
BankingExamples 4 - 6 the results are not ordered in date order as the
tutorial suggests they should be.
This is easily resolved by changing the conditionals from:
date < $date
to:
date.time < $date.time
in the rules packages, but it worries me that the examples seem to suggest
that the sorting should be correct as is.
A colleague of mine has also run the examples with the same (incorrect)
results. Does anyone have any idea what's happening here? Is this something
that used to work in a previous version of the runtime but has regressed,
or a mistake in the example code, or something else entirely?
Regards,
Pete
11 years, 12 months
keep only one, retract all other
by Martin Minka
I want to keep only 1 fact with id=="aaaa". But this is not working:
rule "leave only one"
when
$removeUs : java.util.List(size>1)
from collect(Fact(id=="aaaa")
then
size = $removeUs.size();
for (int i=1; i < size; i++) {
retract($removeUs.get(i));
}
end
11 years, 12 months
Problem with rule when loaded as PKG
by Markus Undhagen
Hi
I have have a file with some rules. When I load the rules as a drl-file all my junit-tests work. But when I load the rules as PKG one of the rule is failing.
This is the rule causing the problem
rule "Lookup synonym" when $normalization : NormalizationFact(valid, resultFact == null) NormalizerMetadataService(synonymNames contains $normalization.type ) $synonymService : SynonymService() then System.out.println(drools.getRule().getName()); modify($normalization) { setResultFact(new ResultFact($synonymService.getValue($normalization.getType(), $normalization.getValue()))) }end
After some investigation I can reduce the problem to
setResultFact(new ResultFact("")) <------------------------- WorkingsetResultFact(new ResultFact(null)) <------------------------- Not working, see log below
This is the code executed in ResultFact
public class ResultFact { private final String result; private final boolean valid;
public ResultFact(String result) { this(result, true); }
public ResultFact(String result, Boolean valid) { super(); this.result = result; this.valid = valid; }
other methods ...}
The exception I get is
Exception executing consequence for rule "Lookup synonym" in normalization: [Error: $normalization.setResultFact(new ResultFact(null)): array index out of bounds.][Near : {... $normalization.setResultFact(n ....}] ^[Line: 1, Column: 1] at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39) at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297) at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221) at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456) at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710) at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674) at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230) at com.mawell.normalize.service.rule.DroolsRuleEvaluatorImpl.evaluate(DroolsRuleEvaluatorImpl.java:62) at com.mawell.normalize.service.infrastructure.util.backend.SynonymServiceTest.execute(SynonymServiceTest.java:126) at com.mawell.normalize.service.infrastructure.util.backend.SynonymServiceTest.execute(SynonymServiceTest.java:115) at com.mawell.normalize.service.infrastructure.util.backend.SynonymServiceTest.ShouldNotTranslate_q(SynonymServiceTest.java:75) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)Caused by: [Error: $normalization.setResultFact(new ResultFact(null)): array index out of bounds.][Near : {... $normalization.setResultFact(n ....}] ^[Line: 1, Column: 1] at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:424) at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:143) at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159) at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115) at org.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:42) at org.mvel2.ast.WithNode$ParmValuePair.eval(WithNode.java:278) at org.mvel2.ast.WithNode.getReducedValueAccelerated(WithNode.java:67) at org.mvel2.ast.InterceptorWrapper.getReducedValueAccelerated(InterceptorWrapper.java:40) at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85) at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123) at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119) at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113) at org.mvel2.MVEL.executeExpression(MVEL.java:930) at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:104) at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287) ... 32 moreCaused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(String.java:1931) at java.lang.String.substring(String.java:1904) at org.mvel2.util.ErrorUtil.rewriteIfNeeded(ErrorUtil.java:12) at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:959) at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:377) ... 46 more
I'm running version 5.5.0.Final of both Drools and Guvnor.
regardsMarkus
11 years, 12 months
Inconsistent behavior of a rule
by dec
See attached DRL. input is: condFt="supportedValue"
I have a rule with the following 'when' part which will not hit, though it
should:
$supportFT: supportFT()
condFT(value == $supportFT.getValue())
$conclusion: testInferred()
while the following one will hit, even though the two seems equivalent:
$supportFT: supportFT(value == null || value !=null)
condFT(value == $supportFT.getValue())
$conclusion: testInferred()
another one that seems equivalent that will hit:
$supportFT: supportFT()
supportFT(value == $condFt.getValue())
$conclusion: testInferred()
Not sure if it is indeed a bug, or a misuse on my part,
but I can't understand why the first rule will not hit. And even stranger,
why the second and third which seems the same will.
testInferred3.drl
<http://drools.46999.n3.nabble.com/file/n4021003/testInferred3.drl>
--
View this message in context: http://drools.46999.n3.nabble.com/Inconsistent-behavior-of-a-rule-tp40210...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 12 months
Re: [rules-users] Drools Guvnor: java.lang.ClassCastException: [Lorg.drools.rule.Package; cannot be cast to org.drools.rule.Package
by Michael Anstis
I suspect the version of drools and guvnor you are using are not identical.
Use of RuleAgent is most certainly not helping. Did you look at the
/droolsjbpm/guvnor/guvnor-examples demonstration using KnowledgeAgent?
On 29 November 2012 12:59, Hushen Savani <hushen.savani(a)elitecore.com>wrote:
> *Hi Team, *
>
> * *
>
> * **I'm a newbie to Drools. Please help me here. *
>
> * *
>
> *1. I have created a Package named "org.sample". *
>
> * *
>
> *2. I have created a Model named "TestModel" in the same package. *
>
> * *
>
> *3. I have created a Fact named "Number" in the same Model. *
>
> * *
>
> *4. "Number" fact is as following: *
>
> ** **
>
> [image: Fact]****
>
> ** **
>
> *5. Then I have created a category named "TestCategory". *
>
> * *
>
> *6. Then created a sample Rule named "ruletest" in that category. *
>
> * *
>
> *7. Rule is created as following:*
>
> ** **
>
> *rule "numberone is equal to numbertwo"*
>
> * when*
>
> * n : Number(numberone == numbertwo);*
>
> * then*
>
> * n.setMessage("numberone is equal to numbertwo");*
>
> *end *
>
> * *
>
> *rule "numberone is greater than numbertwo"*
>
> * when*
>
> * n : Number(numberone > numbertwo);*
>
> * then*
>
> * n.setMessage("numberone is greater than
> numbertwo");*
>
> *end*
>
> * *
>
> *rule "numberone is less than numbertwo"*
>
> * when*
>
> * n : Number(numberone < numbertwo);*
>
> * then*
>
> * n.setMessage("numberone is less than numbertwo");
> *
>
> *end*
>
> * *
>
> * 8. Built the package and created the snapshot. *
>
> * *
>
> *9. Wrote a JAVA POJO client as following: *
>
> * *
>
> *package* org.sample;****
>
> ** **
>
> *import* org.drools.RuleBase;****
>
> *import* org.drools.WorkingMemory;****
>
> *import* org.drools.agent.RuleAgent;****
>
> *import* org.drools.definition.type.FactType;****
>
> ** **
>
> *public* *class* DroolGuvnor {****
>
> *public* *static* *void* main(String[] args) *throws*InstantiationException, IllegalAccessException {
> ****
>
> RuleAgent ruleAgent = RuleAgent.*newRuleAgent*(
> "/Guvnor.properties");****
>
> RuleBase ruleBase = ruleAgent.getRuleBase();****
>
> ****
>
> FactType factType = ruleBase.getFactType("org.sample.Number");
> ****
>
> Object obj = factType.newInstance();****
>
> ****
>
> factType.set(obj, "numberone", 2);****
>
> factType.set(obj, "numbertwo", 1);****
>
> ****
>
> WorkingMemory workingMemory = ruleBase.newStatefulSession();**
> **
>
> workingMemory.insert(obj);****
>
> workingMemory.fireAllRules();****
>
> ****
>
> System.*out*.println(factType.get(obj, "message"));****
>
> }****
>
> }****
>
> * *
>
> * *
>
> * 10. The "guvnor.properties" file is as following: *
>
> * *
>
> url=
> http://localhost:10080/guvnor-5.5.0.Final-tomcat-6.0/org.drools.guvnor.Gu...
> ****
>
> enableBasicAuthentication=true****
>
> username=*admin*****
>
> password=*admin*****
>
> name=*drooltest***
>
> * *
>
> * 11. But, when I run the client, I get following exception: *
>
> * *
>
> SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".****
>
> SLF4J: Defaulting to no-operation (NOP) logger implementation****
>
> SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
> details.****
>
> Exception in thread "main" *java.lang.ClassCastException*:
> [Lorg.drools.rule.Package; cannot be cast to org.drools.rule.Package****
>
> at org.drools.agent.HttpClientImpl.fetchPackage(*
> HttpClientImpl.java:86*)****
>
> at org.drools.agent.URLScanner.readPackage(*URLScanner.java:171*)***
> *
>
> at org.drools.agent.URLScanner.getChangeSet(*URLScanner.java:143*)**
> **
>
> at org.drools.agent.URLScanner.loadPackageChanges(*
> URLScanner.java:119*)****
>
> at org.drools.agent.RuleAgent.checkForChanges(*RuleAgent.java:431*)*
> ***
>
> at org.drools.agent.RuleAgent.refreshRuleBase(*RuleAgent.java:383*)*
> ***
>
> at org.drools.agent.RuleAgent.configure(*RuleAgent.java:368*)****
>
> at org.drools.agent.RuleAgent.init(*RuleAgent.java:268*)****
>
> at org.drools.agent.RuleAgent.newRuleAgent(*RuleAgent.java:208*)****
>
> at org.drools.agent.RuleAgent.newRuleAgent(*RuleAgent.java:168*)****
>
> at org.drools.agent.RuleAgent.newRuleAgent(*RuleAgent.java:277*)****
>
> at org.sample.DroolGuvnor.main(*DroolGuvnor.java:10*)****
>
> ** **
>
> *Please help on this. Thanks. *
>
> * *
>
> * *
>
> *Best Regards, *
>
> *Hushen Savani*
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
11 years, 12 months
Drools Guvnor: java.lang.ClassCastException: [Lorg.drools.rule.Package; cannot be cast to org.drools.rule.Package
by hushen.savani
Hi Team, I'm a newbie to Drools. Please help me here. 1. I have
created a Package named "org.sample". 2. I have created a Model named
"TestModel" in the same package. 3. I have created a Fact named "Number"
in the same Model. 4. "Number" fact is as following:
<http://drools.46999.n3.nabble.com/file/n4021008/01_Fact.bmp> 5. Then I
have created a category named "TestCategory". 6. Then created a sample
Rule named "ruletest" in that category. 7. Rule is created as
following:*rule "numberone is equal to numbertwo" when n : Number(numberone
== numbertwo); then n.setMessage("numberone is equal to numbertwo");end
rule "numberone is greater than numbertwo" when n : Number(numberone >
numbertwo); then n.setMessage("numberone is greater than
numbertwo");endrule "numberone is less than numbertwo" when n :
Number(numberone < numbertwo); then n.setMessage("numberone is less than
numbertwo");end* 8. Built the package and created the snapshot. 9.
Wrote a JAVA POJO client as following:*package org.sample;import
org.drools.RuleBase;import org.drools.WorkingMemory;import
org.drools.agent.RuleAgent;import org.drools.definition.type.FactType;public
class DroolGuvnor { public static void main(String[] args) throws
InstantiationException, IllegalAccessException { RuleAgent ruleAgent =
RuleAgent.newRuleAgent("/Guvnor.properties"); RuleBase ruleBase =
ruleAgent.getRuleBase(); FactType factType =
ruleBase.getFactType("org.sample.Number"); Object obj =
factType.newInstance(); factType.set(obj, "numberone", 2);
factType.set(obj, "numbertwo", 1); WorkingMemory workingMemory =
ruleBase.newStatefulSession(); workingMemory.insert(obj);
workingMemory.fireAllRules(); System.out.println(factType.get(obj,
"message")); }}* 10. The "guvnor.properties" file is as
following:*url=http://localhost:10080/guvnor-5.5.0.Final-tomcat-6.0/org.drools.guvnor.Guvnor/package/org.sample/TestSnapshotenableBasicAuthentication=trueusername=adminpassword=adminname=drooltest*
10. When I run the client, I get following exception:*SLF4J: Failed to load
class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Defaulting to no-operation
(NOP) logger implementationSLF4J: See
http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details.Exception in thread "main" java.lang.ClassCastException:
[Lorg.drools.rule.Package; cannot be cast to org.drools.rule.Package at
org.drools.agent.HttpClientImpl.fetchPackage(HttpClientImpl.java:86) at
org.drools.agent.URLScanner.readPackage(URLScanner.java:171) at
org.drools.agent.URLScanner.getChangeSet(URLScanner.java:143) at
org.drools.agent.URLScanner.loadPackageChanges(URLScanner.java:119) at
org.drools.agent.RuleAgent.checkForChanges(RuleAgent.java:431) at
org.drools.agent.RuleAgent.refreshRuleBase(RuleAgent.java:383) at
org.drools.agent.RuleAgent.configure(RuleAgent.java:368) at
org.drools.agent.RuleAgent.init(RuleAgent.java:268) at
org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:208) at
org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:168) at
org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:277) at
org.sample.DroolGuvnor.main(DroolGuvnor.java:10)*Please help on this.
Thanks.Best Regards,Hushen Savani
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Guvnor-java-lang-ClassCastExcept...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 12 months