Just found a way to stop fact insert time evaluation (tested in 5.5)
by Sonata
Originally I was asking for a method to stop LHS evaluation for a bunch of
rules in some other agenda-groups which I am not intended to trigger. But it
turned out that agenda-group filtering will only happen when you fire your
rules. *ALL* rules in *ANY* agenda-groups are evaluated anyway when you are
inserting fact.
Then according to this post
http://drools.46999.n3.nabble.com/Agenda-group-in-fact-insert-time-tp4023...,
Wolfgang suggested to use an extra object to control the LHS evaluation by
changing the value, e.g. Focus( value == "one" ). After many tests in
5.5.0.Final, this has no effect.
Say if you have a rule:
public static class MyClass {
private Integer i;
public MyClass(Integer i) {
this.i = i;
}
public Integer getMyInteger() {
System.out.println("getMyInteger is called for " + i);
return i;
}
}
rule test agenda-group "one"
when
String ( toString == "agenda-group one")
MyClass ( myInteger == 10 )
then end
when you call ksession.insert(new MyClass(10)); in your java code, no matter
what the value of Focus() is, or even you dont have Focus() object inserted,
getMyInteger() of MyClass is still called/evaluated to match with == 10.
This is highly undesired when you actually only want to trigger rules in
agenda-group "two".
And then finally I found that if you use the keyword "from", it seems it is
way smarter because *it will not be evaluated unless all the preceding
conditions are matched!*
Try the following example:
rule try agenda-group "one"
when
not Object() from System.out.println(1)
MyClass ( myInteger == 10 )
not Object() from System.out.println(2)
MyClass ( myInteger == 9 )
not Object() from System.out.println(3)
then end
If you call ksession.insert(new MyClass(10)), you will only see the output
1, 2 but not 3 because MyClass ( myInteger == 9 ) does not match. This is
really smart!
Now we just need a dummy function to return us the object we want then we
can use the agenda-group blocker to stop "fact insert time evaluation" as
follow:
function Object dummy(Object o) {
return o;
}
rule smart agenda-group "one"
when
String ( toString == "agenda-group one")
m : MyClass()
MyClass ( myInteger == 10 ) from dummy(m)
then end
rule blocker agenda-group "one"
when
then
insert(new String("agenda-group one"));
end
There! No more unwanted evaluations during fact insert time! In fact, all
the evaluations are pushed back to rule firing time and that can be *truly*
filtered by agenda-group.
Please let me know if I am doing stupid thing or if there is a big price or
consequence to pay for when I use this technique?
Thank you
--
View this message in context: http://drools.46999.n3.nabble.com/Just-found-a-way-to-stop-fact-insert-ti...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 7 months
entry-point and accumulate in a guided rule (BRL)
by Ravi Gupta
See screenshot, I want to combine an entry-point and an accumulate function
such as (the below is DRL, which works)
*rule "GSS-Sev1-Monitor"*
* no-loop true*
* dialect "mvel"*
* when*
* $ticketStatistics : TicketStatistics( $ID : ID == null )*
* accumulate($supportTicket:SupportTicket( ticketStatisticsID ==
$ID , severity == "Sev-1" ) over window:time (5m) from entry-point
"gss-support-stream", $num : count( $supportTicket ))*
* then*
* $ticketStatistics.currentTicketCount = $num;*
* update( $ticketStatistics );*
* end*
I can't seem to re-create this in Guvnor (BRL)
12 years, 7 months
Delete a List of Facts
by Weiss, Wolfgang
Hi,
I want to delete a list of facts from the working memory and therefore created following rule:
rule "delete rule"
agenda-group "evaluation"
salience 50
no-loop true
when
$facts : ArrayList(size > 0) from collect (Fact())
then
logger.info("delete rule, number of facts in list: " + $facts.size());
for (int i = 0; i < $facts.size(); i++) {
Fact f = (Fact)$facts.get(i);
logger.info("retract fact id: " + f.getId());
retract(f);
}
end
When inserting 10 facts with IDs 1 to 10 and then fire all rules, I get following result:
delete rule, number of facts in list: 10
retract fact id: 1
retract fact id: 3
retract fact id: 5
retract fact id: 7
retract fact id: 9
but, the facts 2, 4, 6, 8 and 10 are not deleted. I would have expected to set "no-loop" to true, as I do some modification of facts and don't want that this rule is fired again with the same facts. When I set "no-loop" to false, I get following result:
delete rule, number of facts in list: 10
retract fact id: 1
retract fact id: 3
retract fact id: 5
retract fact id: 7
retract fact id: 9
delete rule, number of facts in list: 5
retract fact id: 2
retract fact id: 6
retract fact id: 10
delete rule, number of facts in list: 2
retract fact id: 4
delete rule, number of facts in list: 1
retract fact id: 8
now, all facts are deleted but the "delete rule" was fired 4 times. Is this the intended behavior of Drools? Is there a way to fire a rule only once and delete a list of facts?
I can reproduce this behavior with Drools 5.5.0.Final and 6.0.0.Beta2 but did not try any other version.
Best Regards,
Wolfgang
12 years, 7 months
Benefits of pluggable operators
by Thomas Grayson
What are the benefits of using pluggable operators (implementations of org.drools.base.evaluators.EvaluatorDefinition such str, matches, or before) versus simply making an equivalent function call? I've read the Creating pluggable operators<http://blog.athico.com/2010/06/creating-pluggable-oprators.html> blog post. Apart from saying that the Eclipse plugin can recognize these operators, it doesn't really make a case for why I'd want to create my own implementation. One might argue that operators enhance reusability, but a static method offers much the same benefit. Does a pluggable operator have any optimization, caching, or other advantage?
For example, here are two ways to match the start of a string in a property of a fact, one using the "str[startsWith]" operator and another with Java's String.startsWith method:
declare Fact
key : String @key
end
rule "Use operator"
when
Fact(key str[startsWith] "abc")
then
// do something
end
rule "Use method"
when
Fact(key.startsWith("abc"))
then
// do something
end
Does one of these perform better than the other?
Best wishes,
Tom
12 years, 7 months
Guvnor 5.5 deployment error on WAS8
by mbrameshkumar
Hi,
I am trying to deploy drools guvnor 5.5 on was8.0 through admin console. It
fails with NullPointerException.
Could you please suggest me the changes required in tomcat version of
guvnor war to deploy it in WAS 8 environment. Do I need to rebuild the war
file with different configurations for WAS env?
Please guide me to proceed on this.
Thanks in advance
Best regards
Ramesh
--
View this message in context: http://drools.46999.n3.nabble.com/Guvnor-5-5-deployment-error-on-WAS8-tp4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 7 months
Error deserializing Knowledge Package in Drools 5.5.0
by Narkha
Hello
I'm getting an exception when adding a Collection<KnowledgePackage> after
read it from a file with readObject()
java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at
org.drools.base.ClassObjectType.isAssignableFrom(ClassObjectType.java:180)
at
org.drools.reteoo.builder.PatternBuilder.attachPattern(PatternBuilder.java:95)
at org.drools.reteoo.builder.PatternBuilder.build(PatternBuilder.java:80)
at
org.drools.reteoo.builder.GroupElementBuilder$AndBuilder.build(GroupElementBuilder.java:112)
at
org.drools.reteoo.builder.GroupElementBuilder.build(GroupElementBuilder.java:70)
at
org.drools.reteoo.builder.ReteooRuleBuilder.addSubRule(ReteooRuleBuilder.java:161)
at
org.drools.reteoo.builder.ReteooRuleBuilder.addRule(ReteooRuleBuilder.java:134)
at org.drools.reteoo.ReteooBuilder.addRule(ReteooBuilder.java:113)
at org.drools.reteoo.ReteooRuleBase.addRule(ReteooRuleBase.java:445)
at org.drools.common.AbstractRuleBase.addRule(AbstractRuleBase.java:952)
at
org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:629)
*at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:472)*
at
org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:149)
at
andanta.conversacion.DroolsEmpresa.readKnowledgeBaseFromMemoryFile(DroolsEmpresa.java:304)
at
andanta.comunicacion.ServidorMR.cargaInfoConocimiento(ServidorMR.java:483)
at andanta.test.Tester.main(Tester.java:127)
The code for serialize the object is
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(
fileName ) );
out.writeObject( kbuilder.getKnowledgePackages());
out.close();
And the code for deserialize is
ObjectInputStream in = new ObjectInputStream( new FileInputStream(
fileName) );
Collection<KnowledgePackage> kpkgs =
(Collection<KnowledgePackage>)in.readObject();
in.close();
kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kpkgs );
My environment is eclipse 3.7, java 7.0.21 y drools 5.5.0.
I thought this error may be due to a rule, but if I run
kbase.addKnowledgePackages after reading the rules from drl file, there will
be no exception.
Best Regards.
--
View this message in context: http://drools.46999.n3.nabble.com/Error-deserializing-Knowledge-Package-i...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 7 months
Reading a Guvnor PKG from drools API
by abhinay_agarwal
Hey,
I was trying to read a package(ResourceType.PKG), which i downloaded from
Guvnor, using KnowledgeBuilder, but I consistently get the following error
while trying to access the file.
Here's my code and the error,
**Code**
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "Goal Creation
Charges.pkg", getClass() ), ResourceType.PKG );
if ( kbuilder.hasErrors() ) {
System.err.println( kbuilder.getErrors().toString() );
}
kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
**Error**
java.lang.RuntimeException: java.io.StreamCorruptedException: invalid stream
header: 7061636B
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:724)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)
at
com.infosys.fps.drools.adapter.DroolsAdapter.readKnowledgeBase(DroolsAdapter.java:80)
at com.infosys.fps.drools.adapter.DroolsAdapter.main(DroolsAdapter.java:20)
Caused by: java.io.StreamCorruptedException: invalid stream header: 7061636B
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
at
org.drools.common.DroolsObjectInputStream.<init>(DroolsObjectInputStream.java:68)
at
org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:205)
at
org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:189)
at
org.drools.compiler.PackageBuilder.addPackageFromInputStream(PackageBuilder.java:819)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:711)
... 4 more
I have tried using both binary and source from guvnor, but neither of them
works. I get the same error. Is there something m doing wrong ?
Thanks,
Abhinay
--
View this message in context: http://drools.46999.n3.nabble.com/Reading-a-Guvnor-PKG-from-drools-API-tp...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 7 months