Can only reason over sub-objects if you use the From Conditional Element
by Aaron Dixon
It appears that you MUST use the From Condition Element to reason over
sub-objects.
I have a Person class. Person::getDetails() returns a Details
instance, which has the name and age of the person. (This is a
contrived example to demonstrate the issue.)
My rules are:
rule "30 is the new 20"
when
person : Person( details.age == 30 )
then
person.getDetails().setAge(20);
System.out.println( "Now 20 : " + person );
update( person );
end
rule "Older than 20 - Good"
salience -100
when
person : Person( )
Details( age > 20 ) from person.details
then
System.out.println( "Older than 20 (good) : " + person );
end
rule "Older than 20 - Bad"
salience -100
when
person : Person( details.age > 20 )
then
System.out.println( "Older than 20 (bad) : " + person );
end
I assert Abe, Bob, Cat, Don, and Eve with ages of 10, 20, 30, 40, and
50, respectively. The output is as follows.
Now 20 : Person(Details(Cat,20))
Older than 20 (good) : Person(Details(Eve,50))
Older than 20 (bad) : Person(Details(Eve,50))
Older than 20 (good) : Person(Details(Don,40))
Older than 20 (bad) : Person(Details(Don,40))
Older than 20 (bad) : Person(Details(Cat,20))
You can see that the "Bad" rule is more concise but it does not use
the From Conditional Element and therefore it doesn't work properly
(Cat is determined to be older than 20 when she is not.)
Why does Drools allow the "Bad" rule to be written and compiled when
it does not behave properly?
Thanks,
Aaron
16 years, 8 months
Re: drools 4.x branch build problems
by jack wu
i was on maven 2.0.7
all passed after upgrading to maven 2.0.8. many thanks.
jack.
---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
16 years, 8 months
Re: drools 4.x branch build problems
by jack wu
tested again with 1.5.0_03. failed.
D:\download\drools4x\4.0.x>java -version
java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode)
Running org.drools.integrationtests.DynamicRulesTest
org.drools.RuntimeDroolsException: Unable to load dialect 'org.drools.rule.builder.dialect.java.Java
DialectConfiguration:java'
at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.ja
va:160)
at org.drools.compiler.PackageBuilderConfiguration.buildDialectConfigurationMap(PackageBuild
erConfiguration.java:146)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:121
)
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:9
8)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:124)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:86)
at org.drools.integrationtests.DynamicRulesTest.testDynamicRulesAddRemove(DynamicRulesTest.j
ava:540)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at sun.reflect.GeneratedMethodAccessor33.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirecto
ryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestS
uite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
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:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:33
8)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
Caused by: java.lang.ClassCastException: org.drools.rule.builder.dialect.java.JavaDialectConfigurati
on
at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.ja
va:155)
... 31 more
org.drools.RuntimeDroolsException: Unable to load dialect 'org.drools.rule.builder.dialect.java.Java
DialectConfiguration:java'
at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.ja
va:160)
at org.drools.compiler.PackageBuilderConfiguration.buildDialectConfigurationMap(PackageBuild
erConfiguration.java:146)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:121
)
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:9
8)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:124)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:86)
at org.drools.integrationtests.DynamicRulesTest.testRuleBaseAddRemoveSubNetworks(DynamicRule
sTest.java:768)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at sun.reflect.GeneratedMethodAccessor33.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirecto
ryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestS
uite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Tests run: 16, Failures: 2, Errors: 7, Skipped: 0, Time elapsed: 1.344 sec <<< FAILURE!
Running org.drools.brms.modeldriven.ActionFieldValueTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:33
8)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
Caused by: java.lang.ClassCastException: org.drools.rule.builder.dialect.java.JavaDialectConfigurati
on
at org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.ja
va:155)
... 31 more
Running org.drools.brms.server.util.SuggestionCompletionEngineBuilderTest
---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
16 years, 8 months
Uploading the fact model to the DRools BRMS
by Felbecker, Tobias
Hi ,
I got the same problem and wonder if there is a solution for that yet.
I'am using
JBOSS: AS 4.2.2 GA
DBMR: 4.0.4
JAVA: 1.5.0_15
After uploading the jar, editing the import in the package configuration
and finally validating the package I get the following exception:
java.lang.reflect.InvocationTargetException at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at
org.jboss.seam.util.Reflections.invoke(Reflections.java:21) at.....
The import statement should and the packaging of the jar file seems to
be correct. Otherwise there would be a Class not found error but no
exception.
I tried all kinds of packaging: binaries, source and binaries, creating
the jar through eclipse and from cmd.
This is my very simple java class:
package test;
public class MyBean{
public MyBean(){
}
private int number;
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}
Cheers Tobi
16 years, 8 months
Re: drools 4.x branch build problems
by jack wu
i was using 1.5.0_14.
D:\download\drools4x\4.0.x>java -version
java version "1.5.0_14"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
Java HotSpot(TM) Client VM (build 1.5.0_14-b03, mixed mode)
---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
16 years, 8 months
drools 4.x branch build problems
by jack wu
i checked out the 4.x branch this afternoon but was not able to build it.
Failed tests:
testDynamicRulesAddRemove(org.drools.integrationtests.DynamicRulesTest)
testRuleBaseAddRemoveSubNetworks(org.drools.integrationtests.DynamicRulesTest)
Tests run: 621, Failures: 2, Errors: 33, Skipped: 0
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.
Please refer to D:\download\drools4x\4.0.x\drools-compiler\target\surefire-reports for the individual test results.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 minutes 7 seconds
[INFO] Finished at: Mon Mar 17 17:12:13 PDT 2008
[INFO] Final Memory: 7M/38M
[INFO] ------------------------------------------------------------------------
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
16 years, 8 months
Missing Values for a Dymanic Rule......
by Nikhil_dev
rule "Rule_decimal_1"
dialect "mvel"
when
$a : ApplyRuleBean()
m : ApplyRuleBean ( eval ( ( adultFare + childFare ) < 500 ) )
then
$a.GrossFare = ( $a.NettPayable * 0.10 )
end
Consider the above Rule it has been dynamically generated.....
when i supply values to the above Rule, proper calculated Gross Fare is
given as output
if i dont provide any one of the variable values.... then no error is given
from drool......
the process gets terminated..... is there any ways to identify which values
are not provided in the Rule....
I hope my query is understood.... and waiting for reply...
-----
Regards,
:working:Nikhil
--
View this message in context: http://www.nabble.com/Missing-Values-for-a-Dymanic-Rule......-tp16091335p...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 8 months
Using memberOf in Decision Tables
by Mike Love
Hi,
I have the following rules that I am trying to implement in a decision table
rule "Payment greater 5m"
agenda-group "txnPricing"
salience 5
when
payment : Collection() from bc.getPaymentTransactionTypes()
t : Transaction(customer == c,
transactionType memberOf payment,
transactionAmount >= 5000000)
then
t.setBaseFee(36.00);
t.setFeeDiscount(0.00);
end
rule "Payment less 5m"
agenda-group "txnPricing"
salience 5
when
payment : Collection() from bc.getPaymentTransactionTypes()
t : Transaction(customer == c,
transactionType memberOf payment,
transactionAmount < 5000000)
then
t.setBaseFee(60.00);
t.setFeeDiscount(0.00);
end
I have attached the Decision Table for reference. Basically, I have two
condition columns representing the 2 conditions respectively. When the
xls is processed the generated DSL has the two statements reversed as
indicated below, and hence the exceptions.
package za.co.fnb.billing;
#generated from Decision Table
import java.util.Collection;
import za.co.fnb.billing.Customer;
import za.co.fnb.billing.Transaction;
import za.co.fnb.billing.BillingConstraints;
global Customer c;
global BillingConstraints bc;
#From row number: 12
rule "Payments_12"
when
t: Transaction(customer == c, t.transactionAmount >= 0,
t.transactionAmount <5000000, transactionType memberOf $payments)
$payment : Collection() from
bc.getTransactionTypesForGroup("Payments")
then
t.setBaseFee(60.00);
t.setFeeDiscount(0.00);
end
#From row number: 13
rule "Payments_13"
when
t: Transaction(customer == c, t.transactionAmount >= 5000000,
t.transactionAmount <9999999999, transactionType memberOf $payments)
$payment : Collection() from
bc.getTransactionTypesForGroup("Payments")
then
t.setBaseFee(36.00);
t.setFeeDiscount(0.00);
end
org.drools.rule.InvalidRulePackage: Unable to return Declaration for
identifier '$payments' : [Rule name=Payments_12, agendaGroup=MAIN,
salience=0, no-loop=false]
Unable to create restriction '[VariableRestriction: memberOf $payments
]' for field 'transactionType' in the rule 'Payments_12' : [Rule
name=Payments_12, agendaGroup=MAIN, salience=0, no-loop=false]
Unable to return Declaration for identifier '$payments' : [Rule
name=Payments_13, agendaGroup=MAIN, salience=0, no-loop=false]
Unable to create restriction '[VariableRestriction: memberOf $payments
]' for field 'transactionType' in the rule 'Payments_13' : [Rule
name=Payments_13, agendaGroup=MAIN, salience=0, no-loop=false]
at org.drools.rule.Package.checkValidity(Package.java:424)
at
org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:384)
at
za.co.fnb.billing.TxnVolDecisionTableTest.readDecisionTable(TxnVolDecisionTableTest.java:164)
at
za.co.fnb.billing.TxnVolDecisionTableTest.executeExample(TxnVolDecisionTableTest.java:62)
at
za.co.fnb.billing.TxnVolDecisionTableTest.main(TxnVolDecisionTableTest.java:33)
Thanks,
Mike
16 years, 8 months
Interesting null pointer exception when inserting a fact.
by Jason Partyka
Hi,
This is in relation to drools 4.0.4
I have an interesting problem. I am getting a null pointer exception when I am inserting a fact into a StatefulSession object. What is odd about this NPE is that, as far as I can tell (and I have inserted a breakpoint right before I insert the fact) that all the properties in the object are initialized, and there are no rules accessing any thing that could be null.
So here's my exception trace (just first few lines to get context):
Exception in thread "AWT-EventQueue-0" org.drools.RuntimeDroolsException: java.lang.NullPointerException
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:76)
at org.drools.reteoo.EvalConditionNode.assertTuple(EvalConditionNode.java:145)
at org.drools.reteoo.SingleTupleSinkAdapter.createAndPropagateAssertTuple(SingleTupleSinkAdapter.java:55)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:116)
at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
at org.drools.reteoo.Rete.assertObject(Rete.java:177)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:886)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:858)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:659)
at com.hightower.drools.executablerules.Rules.setTemplate(Rules.java:112)
....
Caused by: java.lang.NullPointerException
at org.drools.base.mvel.MVELEvalExpression.evaluate(MVELEvalExpression.java:39)
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:72)
... 39 more
(that setTemplate method is not a drools template)
Any ideas?
Thanks,
Jason
16 years, 8 months
Cant seem to fire a dynamically added rule
by samirsss
Hi,
Here's the source code of the rule I am trying to add:
public void testDynamicRules()
{
//Create a rule dynamically and check if it fired from log statements
RuleBase ruleBase = wm.getRuleBase();
Package[] pkg = ruleBase.getPackages();
if(pkg[0] != null)
{
logger.warn("Package size before adding the rule :
"+pkg[0].getRules().length);
//Building a new package
final PackageDescr packageDescr = new PackageDescr(pkg[0].getName() );
//Building ruleDescriptor
RuleDescr ruleDescr = null;
String consequence = "mediator.addedNewRule();\n";
//String consequence = "logger.warn(\"New rule just got fired\");";
ruleDescr = new RuleDescr( "Added new Rule");
AndDescr lhs = new AndDescr();
ruleDescr.setLhs( lhs );
final PatternDescr pattern = new PatternDescr(
ApplicationEvent.class.getName(),
"newAppEvent");
lhs.addDescr( pattern );
final LiteralRestrictionDescr restrictionMessage = new
LiteralRestrictionDescr("==", "Test2", LiteralRestrictionDescr.TYPE_STRING);
final FieldConstraintDescr returnValue = new FieldConstraintDescr(
"messageId" );
returnValue.addRestriction(restrictionMessage);
pattern.addConstraint(returnValue);
ruleDescr.setConsequence( consequence );
List attributes = new ArrayList<AttributeDescr>();
attributes.add(new AttributeDescr("salience", "98"));
attributes.add(new AttributeDescr("enabled", "true"));
ruleDescr.addAttribute( new AttributeDescr("dialect", "java") );
ruleDescr.setAttributes(attributes);
Package defaultPackage = pkg[0];
PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
PackageBuilder builder = new PackageBuilder( defaultPackage, conf );
//Adding rule to the package
packageDescr.addRule( ruleDescr );
builder.addPackage(packageDescr);
int errors = builder.getErrors().getErrors().length;
if(errors > 0)
{
//TODO remove the recently added rule or reload all the rules from
the DRL file
logger.warn("Error while adding a rule");
}
else
{
Rule newRule = builder.getPackage().getRule(ruleDescr.getName());
//String ruleFlowName = newRule.getRuleFlowGroup()
//newRule.get
//Check is the rule got added
logger.warn("Package size after adding the rule :
"+pkg[0].getRules().length);
}
}
else
{
logger.warn("Error getting default package for adding rules");
}
}
public void addedNewRule()
{
//Just testing addition of new rules.
logger.warn("New rule just got fired");
}
I cant seem to get the consequence to get fired. I have a similar rule in my
drl file where the messageID == "Test" and it works fine.
Any help is really helpful here cause I am stuck at this point and might
have to go to creating xml files for the rules and parsing that.
Thanks
Samir
--
View this message in context: http://www.nabble.com/Cant-seem-to-fire-a-dynamically-added-rule-tp158101...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 8 months