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!
12 years, 8 months
6.0.0-Beta3: Fibonacci example
by Wolfgang Laun
FibonacciExample.java:28
KieContainer kc = KieServices.Factory.get().getKieClasspathContainer();
How can I tell - without running eclipse and whatnot - which file(s)
from the unzipped and unjarred sources are part of this?
-W
12 years, 8 months
Applying complex condition in excel while importing into drool
by ashish6276
Hi,
We are importing excel in drool by using drool API. we are facing issue in
applying multiple condition into
various columns. Defined excel rule for one particular column but we are not
able to get condition or rule in
.drl file.below is the code.
public class DroolExcelDemo {
public static final void main(final String[] args) {
// Create knowledge builder
final KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
// Create drl file from excel sheet
InputStream is =null;
try {
is= new FileInputStream("C:/POCExcel.xls");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// Create compiler class instance
SpreadsheetCompiler sc = new SpreadsheetCompiler();
// Compile the excel to generate the (.drl) file
StringBuffer drl=new StringBuffer(sc.compile(is,InputType.XLS));
// Insert dialect value into drl file
drl.insert(drl.indexOf("DROOLS")+40,"dialect \"mvel\""+"\n");
// Check the generated drl file
System.out.println("Generate DRL file is showing below–: ");
System.out.println("Value of xls in drl"+drl);
// writing string into a drl file
try {
BufferedWriter out = new BufferedWriter(new FileWriter("C:/rules.drl"));
out.write(drl.toString());
out.close();
//System.out.println("print content"+out.append(csq, start, end));
}
catch (IOException e){
System.out.println("Exception ");
}
// Wait before using the drl file in the next section.
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("testing");
// End creation of drl file from excel sheet
// Using DRL file
kbuilder.add(ResourceFactory.newClassPathResource("rules.drl",DroolMessage.class),ResourceType.DRL
);
// Check the builder for errors
if ( kbuilder.hasErrors() ) {
System.out.println("kbuilder has errors");
System.out.println( kbuilder.getErrors().toString());
}
// get the compiled packages (which are serializable)
final Collection pkgs = kbuilder.getKnowledgePackages();
can anyone help on this. Thanks in advance
--
View this message in context: http://drools.46999.n3.nabble.com/Applying-complex-condition-in-excel-whi...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 8 months
dfreeman@gio.com.au
by FREEMAN, Darrell
Darrell Freeman
Architect, CD General Insurance
Suncorp Business Services
Phone +61 (02) 8121 0115 IPC 2BT080
Email: Darrell.freeman(a)suncorp.com.au<mailto:Darrell.freeman@suncorp.com.au>
Address, Level 7 Metcentre, 60 Margaret St, Sydney, Australia
________________________________
This e-mail is sent by GIO General Limited ABN 22 002 861 583 ("GIO").
GIO may be contacted at Level 18, 36 Wickham Terrace, Brisbane or on 13 10 10.
The content of this e-mail is the view of the sender or stated author and does not necessarily reflect the view of GIO. The content, including attachments, is a confidential communication between GIO and the intended recipient. If you are not the intended recipient, any use, interference with, disclosure or copying of this e-mail, including attachments, is unauthorised and expressly prohibited. If you have received this e-mail in error please contact the sender immediately and delete the e-mail and any attachments from your system.
If this e-mail constitutes a commercial message of a type that you no longer wish to receive please reply to this e-mail by typing Unsubscribe in the subject line.
12 years, 8 months
Rule Templates and Array Handling
by Jason Allen
Hi All,
I'm trying to determine if it's possible to process arrays of data using Rule Templates. An example of what I'm trying to accomplish.
Spreadsheet of rules, with one of the columns being valid colors. Valid colors contains comma separated data and is variable length.
For example
It might contain: "Blue, Green, Red" or "Blue", or "Red, Green, Purple, Silver" Any number of entries.
I then need to process incoming fact values against this list of colors, using either CONTAINS or IN.
For example:
template header
desc
valid_colors[]
package org.drools.examples.templates
global com.sample.Product product;
template "ColorTestTemplate"
rule "ColorRule_(a){row.rowNumber}"
when
product1 : Product (Color in @{valid_colors});
then
product1.setDesc("@{desc}");
end
end template
I know the following doesn't work: product1 : Product (Color in @{valid_colors});
However, I wanted to depict what I'm trying to accomplish.
The challenge is with valid_colors being a variable length array, I can't refer to the individual values using constants i.e. valid_colors0, valid_colors1, valid_colors3, etc to build my array list.
ie Color in ("@{valid_colors0}", "@{valid_colors1}", "@{valid_colors2}")
Is there a way to iterate through a variable length array in a template?
Any thoughts on how I could build an array list i.e. ("Blue", "Green", "Red") when the column contains a variable length array?
Thanks in advance,
Jason
12 years, 9 months
Guvnor 6.0.0.Beta2 on Tomcat 7 - should problems be reported?
by kappert
I have deployed guvnor-6.0.0.Beta2-tomcat7.0.war on Tomcat 7 in Jelastic (a
cloud provider).
The guided rule editor does not come up and this is an exception I have
found in catalina.out:
org.jboss.errai.marshalling.client.api.exceptions.MarshallingException:
class is not available to the marshaller framework:
org.jboss.errai.bus.server.QueueUnavailableException
at
org.jboss.errai.marshalling.server.MappingContextSingleton$4.getMarshaller(MappingContextSingleton.java:292)
at
org.jboss.errai.marshalling.client.api.AbstractMarshallingSession.getMarshallerInstance(AbstractMarshallingSession.java:67)
at
org.jboss.errai.marshalling.client.util.MarshallUtil.getMarshaller(MarshallUtil.java:125)
...
Has the time already come to discuss such problems? Is this the right place
to do so?
And, of course , does anybody have an idea how to fix this specific problem?
--
View this message in context: http://drools.46999.n3.nabble.com/Guvnor-6-0-0-Beta2-on-Tomcat-7-should-p...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 9 months
Exception jitting
by Bojan Janisch
Hello everyone,
recently I'm using Drools in a multi-threaded environment.
Since then I get sometimes RuntimeExceptions like this:
Exception in thread "Thread-10" java.lang.RuntimeException: Exception jitting: getConcept().identifierSource.toLowerCase.contains("anatomy")
at org.drools.rule.constraint.MvelConstraint.executeJitting(MvelConstraint.java:219)
at org.drools.rule.constraint.MvelConstraint.access$000(MvelConstraint.java:41)
at org.drools.rule.constraint.MvelConstraint$1.run(MvelConstraint.java:201)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.NoClassDefFoundError: [Lorg/drools/rule/Declaration;
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2416)
at java.lang.Class.getConstructor0(Class.java:2726)
at java.lang.Class.getConstructor(Class.java:1676)
at org.drools.rule.builder.dialect.asm.ClassGenerator.newInstance(ClassGenerator.java:173)
at org.drools.rule.constraint.ASMConditionEvaluatorJitter.jitEvaluator(ASMConditionEvaluatorJitter.java:53)
at org.drools.rule.constraint.MvelConstraint.executeJitting(MvelConstraint.java:217)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.drools.rule.Declaration
at java.lang.ClassLoader.findClass(ClassLoader.java:373)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 12 more
The rule which produces the exception, is always another and there's also always another cause (so getConcept()... works fine). I've got the error message
with this rule:
import function rulevolution.utils.FactChecker.*;
import function rulevolution.utils.ODMAnswerManager.*;
global org.apache.uima.util.impl.JSR47Logger_impl log
global org.apache.uima.jcas.JCas aJCas
rule '129'
when
$0:NormalizedNamedEntity(
ct_0:CoveredText,
cp_0:Concept,
label_0:getConcept().getPrefLabel().value,
getConcept().identifierSource.toLowerCase.contains("bodyside"))
not $1:NormalizedNamedEntity(
ct_1:CoveredText,
cp_1:Concept,
label_1:getConcept().getPrefLabel().value,
getConcept().identifierSource.toLowerCase.contains("anatomy"))
$2:NormalizedNamedEntity(
ct_2:CoveredText,
cp_2:Concept,
label_2:getConcept().getPrefLabel().value,
endsWith($0,$2))
not $3:NormalizedNamedEntity(
ct_3:CoveredText,
cp_3:Concept,
label_3:getConcept().getPrefLabel().value,
endsWith($0,$2))
not $4:NormalizedNamedEntity(
ct_4:CoveredText,
cp_4:Concept,
label_4:getConcept().getPrefLabel().value,
endsWith($2,$0))
$5:NormalizedNamedEntity(
ct_5:CoveredText,
cp_5:Concept,
label_5:getConcept().getPrefLabel().value,
endsWith($0,$2))
not $6:NormalizedNamedEntity(
ct_6:CoveredText,
cp_6:Concept,
label_6:getConcept().getPrefLabel().value,
isBetween($6,$0,$5))
not $7:NormalizedNamedEntity(
ct_7:CoveredText,
cp_7:Concept,
label_7:getConcept().getPrefLabel().value,
getConcept().identifierSource.toLowerCase.contains("anatomy"))
$8:NormalizedNamedEntity(
ct_8:CoveredText,
cp_8:Concept,
label_8:getConcept().getPrefLabel().value,
endsWith($8,$0))
then
int start = getStart($0,$2,$5,$8);
int ende = getStop($0,$2,$5,$8);
String attribute = label_0+" "+label_2+" "+label_5+" "+label_8;
insert(annotate(aJCas, "de.cloud4health.odm.eprd.itemGroup.operation", 0, attribute, start, ende, "", attribute));
end
Like you see it is a huge rule, but it's created automatically with genetic evolution so I haven't written it actually.
If I use this rule in a single threaded environment, everything runs fine, so could there be a multi-threading problem
with Drools itself?
Greetings
Bojan
12 years, 9 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.
12 years, 9 months