Problem with Banking Tutorial
by Stefan Schuster
Hello,
I have a problem with the banking tutorial number 3, which is part of the
examples of drools expert.
It simply adds some Numbers as facts, and retracts them in an increasing
order.
It is very short, therefore I post the whole Code:
BankingExample3.java
_________________________________________________
package org.drools.tutorials.banking;
public class BankingExample3 {
public static void main(String[] args) {
Number[] numbers = new Number[] {wrap(3), wrap(1), wrap(4),
wrap(1), wrap(5)};
new RuleRunner().runRules( new String[] { "Example3.drl" },
numbers );
}
private static Integer wrap(int i) {
return new Integer(i);
}
}
_________________________________________________
Example3.drl:
_________________________________________________
package org.drools.tutorials.banking
rule "Rule 01"
when
$number : Number()
not Number( intValue < $number.intValue )
then
System.out.println("Number found with value: " + $number.intValue()
);
retract( $number );
end
_________________________________________________
Output:
_________________________________________________
Loading file: Example3.drl
Inserting fact: 3
Inserting fact: 1
Inserting fact: 4
Inserting fact: 1
Inserting fact: 5
Number found with value: 1
Number found with value: 1
Number found with value: 3
Number found with value: 4
Number found with value: 5
_________________________________________________
that seams absolute logically to me.
But now I alter the Numbers in the Java-Part:
Number[] numbers = new Number[] {wrap(3), wrap(1), wrap(2)};
and the output destroys everything I thought I understood:
Loading file: Example3.drl
Inserting fact: 3
Inserting fact: 1
Inserting fact: 2
Number found with value: 1
Number found with value: 3
Number found with value: 2
Can someone reproduce this behavior?? It seams absolutely strange to me. I
would have expected the order 1,2,3. Any explanations?
Thanks in advance for helping me!
11 years, 6 months
Guvnor: Accessing Bound Variable in "Then" Statement
by Vann_the_Red
Hello. I started with a search and didn't find an answer. I apologize if my
search-fu was lacking today.
I'm a non-developer tasked with rules creation and testing using guvnor. I
have found some scenarios where I can bind a variable to either the whole
input model or a fact in the input model and then later access those in the
output model by selecting "Bound Variable" from the popup box in the Then
statement. In other scenarios, "Bound Variable" is not an option (only
Literal or Formula). What must I do to be able to access the bound
variables from the When statement(s) in the Then statement(s)?
TIA,
Vann
This is a repost because I wasn't on the mailing list yet and I gather most
didn't see it. Apologies again.
--
View this message in context: http://drools.46999.n3.nabble.com/Guvnor-Accessing-Bound-Variable-in-Then...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 6 months
Guvnor-5.5
by Ricardo
Is any one tried guvnor-5.5 in websphere application server?
What happen to the conponents.xml?
Why guvnor is tightly coupled with jbossAS even each version (jbossAS) got
separate war file?
this seems a big impediment for using guvnor as rule authoring tools.
Is one knows well aware these and already know how to deal this, please
advise me?
-----
with kind regards,
--
View this message in context: http://drools.46999.n3.nabble.com/Guvnor-5-5-tp4022096.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 6 months
filtering object having max value
by mohan
Hi folks,
I want to filter object instance in WM when max value of an object field
(rental ) is less than X (reloadValue) . X will vary over time.
I tried to use below query but I couldn't get expected results. Could anyone
please help me?
Thanks.
--------------------------------------------
rule "Insuf-Balance-Reload Alert"
dialect "java"
when
$re : ReloadEvent($rechargeNum : rechargedNumber,$reloadVal :
reloadValue ) from entry-point "RELOAD-EVENT"
InsufBalFailFact(mobileNo == $rechargeNum,$reloadVal > rental, $pkgId :
pkgId,$rental : rental)
not InsufBalFailFact(mobileNo == $rechargeNum, rental > $rental)
then
System.out.println($rechargeNum+","+$pkgId +","+$rental);
end
--
View this message in context: http://drools.46999.n3.nabble.com/filtering-object-having-max-value-tp402...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 6 months
Unable to resolve knowledgebase from classpath in JBoss 7 (VFS)
by dastraub
ClasspathKieProject isn't able to resolve knowledgebase from a JBoss 7
deployments :
17:34:02,419 INFO [stdout] (MSC service thread 1-5) kmodules:
vfs:/content/rtm-cep-impl.war/WEB-INF/classes/META-INF/kmodule.xml
17:34:39,089 ERROR
[org.drools.compiler.kie.builder.impl.ClasspathKieProject] (MSC service
thread 1-5) Unable to build index of kmodule.xml
url=vfs:/content/rtm-cep-impl.war/WEB-INF/classes/META-INF/kmodule.xml
null
To fix this (I have a presentation about a project prototype on monday ...),
I made the following changes:
After some NPE-Fixes in the same class, the ClasspathKieProject is able to
resolve the rules
--
View this message in context: http://drools.46999.n3.nabble.com/Unable-to-resolve-knowledgebase-from-cl...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 6 months
Translate Drools to CLIPS rules
by Stadin, Benjamin
Hi,
I'm interested in possibilities to convert (one-way) Drools to CLIPS rules. I've followed the discussion about the canceled support for the CLIPS parser in Drools ("Drools Clips", last reply 2 Feb 2013). However, are there any options left to make a one-way conversion?
My interest in this is that I currently do a little research about how to fill the gap between central business rule engines and business process implementation and execution on smartphones / tablets (iOS, Android, Windows Phone 8). Currently I'm under the opinion that good old CLIPS could theoretically be a common denominator to enable common rule definition, and partial execution of these on mobile devices.
Regards,
Benjamin Stadin
11 years, 7 months
Drools 6.0.0.2 Beta uses different dependencies to antlr version
by dastraub
mvn dependency:tree
...
INFO] +- org.drools:drools-compiler:jar:6.0.0.Beta2:provided
[INFO] | +- org.drools:drools-core:jar:6.0.0.Beta2:provided
[INFO] | | +- org.kie:kie-api:jar:6.0.0.Beta2:provided
[INFO] | | \- org.kie:kie-internal:jar:6.0.0.Beta2:provided
[INFO] | +- org.antlr:antlr-runtime:jar:3.3:provided
[INFO] | +- org.antlr:antlr:jar:3.3:provided
[INFO] | +- org.antlr:stringtemplate:jar:3.2.1:provided
[INFO] | +- antlr:antlr:jar:2.7.7:provided
Is this correct ?
As far as I know, antlr 2.7 and 3.3 has different package names, so it's not
a problem to use both versions.
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-6-0-0-2-Beta-uses-different-depe...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 7 months
NullpointerException in Multithreading at KnowledgeBuilde
by Bojan Janisch
Hi everyone,
I'm using Drools in a multithreaded environment where I need to create multiple KnowledgeBuilders, which each contains a different rule. But if I want to add the rule to the builder I'm getting the following exception:
-----------------------------------------------------------------------
Exception in thread "ECJ Evaluation Thread 3" java.lang.NullPointerException
at org.drools.rule.builder.dialect.mvel.MVELDialect.addStaticPackageImport(MVELDialect.java:416)
at org.drools.rule.builder.dialect.mvel.MVELDialect.addStaticImport(MVELDialect.java:372)
at org.drools.compiler.DialectCompiletimeRegistry.addStaticImport(DialectCompiletimeRegistry.java:96)
at org.drools.compiler.PackageRegistry.addStaticImport(PackageRegistry.java:94)
at org.drools.compiler.PackageBuilder.processFunctions(PackageBuilder.java:1270)
at org.drools.compiler.PackageBuilder.processOtherDeclarations(PackageBuilder.java:1225)
at org.drools.compiler.PackageBuilder.mergePackage(PackageBuilder.java:1220)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:829)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:467)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:673)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:45)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:34)
at rulevolution.RulEvolution.getSession(RulEvolution.java:195)
at rulevolution.RulEvolution.runDrools(RulEvolution.java:159)
at rulevolution.RulEvolution.evaluate(RulEvolution.java:106)
at ec.simple.SimpleEvaluator.evalPopChunk(SimpleEvaluator.java:259)
at ec.simple.SimpleEvaluator$SimpleEvaluatorThreadCG.run(SimpleEvaluator.java:341)
at ec.util.ThreadPool$PoolThread.run(ThreadPool.java:57)
-----------------------------------------------------------------------
I'm getting the same exception in each thread so I only copied thread 3.
The Code I'm using to initiate my Session is the following:
-----------------------------------------------------------------------
public synchronized StatefulKnowledgeSession getSession(byte[] array){
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(array), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (!errors.isEmpty()) {
for (KnowledgeBuilderError knowledgeBuilderError : errors) {
logger.log(Level.SEVERE, "error while parsing grammmars in "+knowledgeBuilderError.getResource().toString()+":: "
+ knowledgeBuilderError.getMessage());
}
try {
throw new Exception();
} catch (Exception e) {
e.printStackTrace();
}
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase.newStatefulKnowledgeSession();
}
-----------------------------------------------------------------------
This method is called for each Rule I create one time. The rules are created
automatically and are syntactically correct, here is an example:
-----------------------------------------------------------------------
import function de.fraunhofer.scai.bio.uima.droolutils.FactChecker.*;
import function de.fraunhofer.scai.bio.uima.droolutils.ODMAnswerManager.*;
global org.apache.uima.util.impl.JSR47Logger_impl log
global org.apache.uima.jcas.JCas aJCas
rule '2'
when
$0: CoreAnnotation(
label_0:getActivityProvenance().toString(),
getConcept().identifierSource.contains('de.cloud4health.odm.eprd.bodySide'))
$1: CoreAnnotation(
label_1:getActivityProvenance().toString(),
getConcept().identifierSource.contains('de.cloud4health.odm.eprd.anatomy'))
$2: NormalizedNamedEntity(
label_2:getConcept().getPrefLabel().value,
getConcept().identifierSource.contains('de.cloud4health.odm.eprd.anatomy'))
eval (hasSameInstance($0, $1, $2))
eval (areEqual($0, $1, $2))
then
int start = getStart($0,$1,$2);
int ende = getEnd($0,$1,$2);
String attribute = label_0+label_1+label_2;
log.log(Level.FINE, 'Inserted de.cloud4health.odm.eprd.itemGroup.anatomy');
insert(annotate(aJCas, 'de.cloud4health.odm.eprd.itemGroup.anatomy', attribute, start, ende, null, null));
end
-----------------------------------------------------------------------
I appreciate any help. Thank you.
Bojan
11 years, 7 months