No eval with backward chaining?
by Wolfgang Laun
Trying to use eval in a query for backward chaining causes a runtime
crash running Drools 5.5.0. Looks like a bug. The details:
Given some Integer objects as facts,
rule "find triple forward"
when
Integer( $a: intValue )
Integer( $b: intValue > $a )
Integer( $c: intValue > $b )
eval( $a*$a + $b*$b == $c*$c )
then
System.out.println( "fwd: " + $a + " " + $b + " " + $c );
end
finds Pythagorean triples.
But
query isTriple( Integer $a, Integer $b, Integer $c )
Integer( intValue == $a )
Integer( intValue == $b && > $a )
Integer( intValue == $c && > $b )
eval( $a*$a + $b*$b == $c*$c )
end
intended to be used in combination with
rule "find triple backward"
when
isTriple( $a, $b, $c; )
then
System.out.println( "bwd: " + $a + " " + $b + " " + $c );
end
causes a nasty runtime error (although DRL compilation succeeds):
Exception in thread "main" java.lang.NoSuchMethodError:
pythagoras.Rule_isTriple_17ac16f7237046ee9562afce35dfe174.eval0(III)Z
at pythagoras.Rule_isTriple_17ac16f7237046ee9562afce35dfe174Eval0InvokerGenerated.evaluate(Unknown
Source)
at pythagoras.Rule_isTriple_17ac16f7237046ee9562afce35dfe174Eval0Invoker.evaluate(Unknown
Source)
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:114)
at org.drools.reteoo.EvalConditionNode.assertLeftTuple(EvalConditionNode.java:176)
at org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:196)
at org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:71)
at org.drools.reteoo.JoinNode.propagateFromRight(JoinNode.java:159)
at org.drools.reteoo.JoinNode.assertObject(JoinNode.java:148)
at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)
at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:350)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:311)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:903)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:847)
at org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:269)
at pythagoras.Main.makeFacts(Main.java:94)
at pythagoras.Main.execute(Main.java:78)
at pythagoras.Main.main(Main.java:103)
-W
12 years, 8 months
sharing functions across namespaces
by Jeremy Ary
Anyone know of an elegant solution to sharing functions across packages?
As an example, given a single DRL containing all of functions:
package com.rules
and two rules files who both use those functions, yet live in separate
namespaces:
package com.rules.setOne
package com.rules.setTwo
Can both namespaces utilize the functions without changing all of my
rules files to the namespace com.rules? If worth noting, only one of
the namespaces will be present in the kbase at a time.
Thanks,
Jeremy
12 years, 8 months
drools 6 and osgi
by Florian.Pirchner
hi,
i got a question about osgi support.
is beta 3 already useable in osgi environments? could see that activators are registering v5 api as services.
is it possible to consume osgi services in the script tasks and rules by context? is this planned for version 6? would be a great feature.
thanks a lot for answer
florian
12 years, 8 months
Fire Rule in Stateless Knowledge Session
by snehils
Hi,
I am new in Drools. I am using Drools version 5.1.0
My requirement is kind of request response, where I have to perform some
checks for the request and respond the result. Hence, I decided to go with
stateless knowledge session.
I have prepared .DRL file and it contains set of rules. When some request
receives I have to identify the rule(s) belongs to that request and then
fire the rule(s).
I am not able to figure out how to categories the rules request wise in DRL
file? Also, how to fire only those rules which belongs to the category.
For example, there are three kinds of requests Rq1, Rq2 and Rq3. There are
rules in DRL file: R1, R2, R3, R4 and R5. R1, R2 belongs to Rq1, R3 belongs
to Rq2 and R4, R5 belongs to Rq3.
When some request receives only its belonging rules should be fired. For
example, on receiving of Rq2 only R3 should be fired.
Please provide me some code snipped or link.
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/Fire-Rule-in-Stateless-Knowledge-Sessio...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 8 months
Question : Camel + kie-spring (Drools6)
by Charles Moulliard
Hi,
I have some problems to understand the new way to create with Drools 6 a
knowledge base, kession.
For a kie-camel project by example we must use the following syntax :
<kie:ksession-ref id="ksession1">
<kie:batch>
<kie:set-global identifier="list" >
<bean class="java.util.ArrayList" />
</kie:set-global>
</kie:batch>
</kie:ksession-ref>
Question : How kbase and kcontainer are created in this case ?
So, why can't we use this one ?
<kie:kbase-ref id="drl_sample"/>
<kie:ksession id="kession1" kbase-ref="drl_sample"/>
Question : How kbase links info retrieved from kmodules ?
Hope that documentation will clarify that ?
Regards,
--
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com
12 years, 8 months
Cron Rule doesn't work
by Andy
*Issue 1*
Steps:
1. Add a Rule with cron + when condition always true.
2. FireAllRules
Expected: Cron to fire every 15 seconds
Rule:
"
rule "Rule 123" dialect "mvel"
timer (cron:0/15 * * * * ?)
when
eval(true)
then
System.out.println("Fired!");
end
"
Other Details:
"
...(initialized kagent using changeset)
kbase = kagent.getKnowledgeBase();
ksession = kbase.newStatefulKnowledgeSession();
ksession.fireAllRules();
"
The same rule works fine when I insert some object.
*Issue 2*
Inserting some object and then adding a second cron makes the previous cron
fire twice, then thrice and so on...
Is statefulknowledge session right choice for me?
Are there any known issues with cron rules?
Any help/advice is appreciated. Thx!
--
View this message in context: http://drools.46999.n3.nabble.com/Cron-Rule-doesn-t-work-tp4024399.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 8 months
property change listeners aren't working as described in the Expert Doc
by abasile
Hello,
The property change listener advise from the expert doc isn't working for
me.
http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html/...
(4.8.3.5)
- I've tried setting the configuration
KnowledgeBuilderConfiguration config =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
config.setOption(PropertySpecificOption.ALWAYS);
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(config);
- Tried added annotations to Java Class
@PropertyReactive, @Modifies
- Tried adding @watch to rule
FYI: We're using salience but not Agency Groups; also StatelessSession but
tried StatefulSesson as well.
Any suggestions? Reference to a working code sample would be great.
----------------------------------------------------------------------------
(snippet for creating knowledge base)
// Set Property Specific Evaluation
KnowledgeBuilderConfiguration config =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
config.setOption(PropertySpecificOption.ALWAYS);
//final KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(config);
addRulesToKBuilder(ruleFiles, logger, kbuilder);
// get the compiled packages (which are serializable)
final Collection<KnowledgePackage> pkgs =
kbuilder.getKnowledgePackages();
// add the packages to a knowledgebase (deploy the knowledge
packages).
kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( pkgs );
(snippet for adding rules to KBuilder)
for (String ruleFile : ruleFiles) {
// this will parse and compile in one step
kbuilder.add( ResourceFactory.newClassPathResource(ruleFile),
ResourceType.DRL );
if ( kbuilder.hasErrors() ) {
logger.error( kbuilder.getErrors().toString() );
throw new RuntimeException( "ERROR: Unable to compile " +
ruleFile );
}
}
(snippet for creating a stateless session)
public StatelessKnowledgeSession createStatelessSession(boolean isDebug) {
StatelessKnowledgeSession ksession =
kbase.newStatelessKnowledgeSession();
if (isDebug) {
ksession.addEventListener(new DebugWorkingMemoryEventListener());
ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new DebugProcessEventListener());
}
return ksession;
}
(snippet for rule)
dialect "java"
salience 1350
rule "Initial Normalization: Bid Size - Remove Unwanted Characters"
when
$md : MarketDataRow (
candidate,
hasValue( bidSize ),
bidSize not matches "123"//,
)
then
System.out.println( String.format( "%s; Row %d: '%s';",
drools.getRule().getName(), $md.getRowNumber(), $md.getBidSize() ) );
modify( $md ) {
setBidSize( "678m" );
}
end
Thank you in advance,
Alex
--
View this message in context: http://drools.46999.n3.nabble.com/property-change-listeners-aren-t-workin...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 8 months
Updating object model dynamically
by ashish6276
Hi
I have a requirement where we have xsds as our object model. We use jaxb
to get java object model and create a jar. That jar we upload in guvnor. Now
We have a major change in xsd. where some of previous elements are renamed
and some of previous elements are removed and some new element are added. So
now is there any way to dynamically update all the objects. Like
refractoring. So that there should not be any rework in writing all rules
again.
--
View this message in context: http://drools.46999.n3.nabble.com/Updating-object-model-dynamically-tp402...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 8 months
Identity Mode?
by rjr201
If I have a rule such as:
When
Person()
Person()
Then
System.out.println("There are two people!")
End
I only want this to fire if there are two (or more) Person objects inserted
into the session, however as default drools will fire even when there is
just one Person object inserted (i.e. both Person patterns get matched to
the same fact).
I seem to remember there is a flag I can set that swaps between these two
types of behavior, and seem to remember it's to do with Identity/Equality
mode. However, I can't remember how or where to do this.
Any help on this would be greatly appreciated..
Cheers,
Rich.
P.S I realise that I could add constraints to the patterns to explicitly
check that the facts aren't the same.. however I'd rather not have to do
that as I'm trying to make it as simple as possible for users to create
rules..
--
View this message in context: http://drools.46999.n3.nabble.com/Identity-Mode-tp4024428.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 8 months