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
13 years, 7 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
13 years, 7 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.
13 years, 7 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
>
>
13 years, 7 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.
13 years, 7 months
Re: [rules-users] rules-users Digest, Vol 72, Issue 55
by Gurvinder Narula1
Hi Mattias,
Thanks for the clarification. Appreciate the quick response.
Gurvinder
On 11/27/12 12:00 PM, "rules-users-request(a)lists.jboss.org"
<rules-users-request(a)lists.jboss.org> wrote:
>Send rules-users mailing list submissions to
> rules-users(a)lists.jboss.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
> https://lists.jboss.org/mailman/listinfo/rules-users
>or, via email, send a message with subject or body 'help' to
> rules-users-request(a)lists.jboss.org
>
>You can reach the person managing the list at
> rules-users-owner(a)lists.jboss.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of rules-users digest..."
>
>
>Today's Topics:
>
> 1. Drools response time (elMateo)
> 2. Re: Drools response time (Mauricio Salatino)
> 3. Re: Drools response time (Luk?? Petrovick?)
> 4. Re: Drools response time (elMateo)
> 5. Re: Question about drools-spring in a multi-treaded container
> (like tomcat). (Mattias Nilsson Grip)
> 6. Re: Inserting Different Objects Of Same Class ! (Greg Barton)
>
>
>----------------------------------------------------------------------
>
>Message: 1
>Date: Tue, 27 Nov 2012 16:06:58 +0100
>From: elMateo <soyelmateo(a)gmail.com>
>Subject: [rules-users] Drools response time
>To: Rules Users List <rules-users(a)lists.jboss.org>
>Message-ID:
> <CAKx6_9aEY2GEYoY0LmWUcW2DyyPYmX_sAAFr=Ou_u4dxuB4jmQ(a)mail.gmail.com>
>Content-Type: text/plain; charset="iso-8859-1"
>
>Dear all,
>
>I need to develop an Expert System for a new project and I want to use
>Drools, butI have some restrictions.
>
>The most important restriction: response time of the application must be
>less than one second. Also, the application access to one data base to
>retrieve some information and send it to the expert systetm.
>
>With this information, can anyone tell me, approximately, the response
>time
>of Drools? It is very important to can use Drools in this project. And we
>like very much to use it. (We use in other projects without these
>restrictions).
>
>Thank in advance.
>
>Best regards, Jes?s.
>
13 years, 7 months