Re: [rules-users] Does drools have any trigger?
Lindy, by default Drools will re-evaluate the rules as needed once facts are changed (and the engine is told about it), so when changed is actually the default behavior. The examples you give sound more like an event-processing scenario (reasoning over time) so you might want to have a look at drools-fusion. Rules can be updated by business users thru BRMS and Guvnor? The short answer yes. The long answer: Your milage may vary. It really depends on what type of rules and what type of business users. I don't think it's safe to just tick this box. That has not much to do with Guvnor's capabilities (allthough it is a new product) - I rather think that this is not true for any BRMS. -- Ingomar Am 24.04.2009 um 18:30 schrieb Lindy hagan: I was looking at Blaze Advisor documentation it has “when changed” operator that only fires when an attribute of an object changes. A business analyst might use it to watch for any important issue, such as a thermostat warning in a process plant or a particular stock reaching a certain price or volume. In similar way does Drools have this feature? Can any one correct if I am wrong: Rules can be updated by business users thru BRMS and Guvnor? (I did not get chance to go thru these) ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Does drools have any trigger?
2009/4/24 Lindy hagan lindyha...@gmail.com: I was looking at Blaze Advisor documentation it has “when changed” operator that only fires when an attribute of an object changes. A business analyst might use it to watch for any important issue, such as a thermostat warning in a process plant or a particular stock reaching a certain price or volume. In similar way does Drools have this feature? Can any one correct if I am wrong: Rules can be updated by business users thru BRMS and Guvnor? (I did not get chance to go thru these) Hi, you can register your business objects (facts) as dynamic facts. They will need to implement addPropertyChangeListener and related methods. That way, as soon as a property that is used in a rule changes, the rule will re-evaluate and fire if appropriate. See section 2.5.4.7. of the docs for more information on this feature. Best regards Marcus ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] need some advice in defining rules
Hi all, I'm having difficulty in defining a rule for the following problem: We need to check if within a week there are more than 5 objects of type Reminder inserted into Memory. (one day corresponds to one object) The number of the inserted objects depends on the usage of the application. That means there could be nothing, 1, 2, or any number of the objects. Before, within a session, I inserted a list containg data from within one week (7 days). Than I can check using the rule: when: $list : list(size 5) Reminder() from $list no String(trim == limit reached); then System.out.println(This rule fires); insert new String(limit reached); Now I need to insert a list containing data from a whole month, but I still need to check whether within one week there are more than 5 reminders exist. so, the constraint list 5 can't be used anymore for a single list. I tried to break the whole list in several smaller list, where each list represents one week. Now the problem is, if the rule fires for a certain week, than it won't work for the following weeks anymore. My idea is then to insert an integer containing specific number to the current list, i.e. the calendar week (i.e insert new Integer(52)) and then to prove this in LHS; but the problem is now how to prove the week number in LHS? as I remeber, a function can only be called within an eval statement and in this case actually I should only prove the existence of an Integer Hope my explanation is quite understandable and looking forward for any hints Regards -- View this message in context: http://www.nabble.com/need-some-advice-in-defining-rules-tp23259683p23259683.html Sent from the drools - user mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Bug in binary package generation?
I built a rule package in Guvnor and downloaded the binary. When I use: builder.add(ResourceFactory.newInputStreamResource(inStream), ResourceType.PKG); I get a NullPointerException. But, if I use Guvnor's view source, copy the source to a file, and use: builder.add(ResourceFactory.newInputStreamResource(inStream), ResourceType.DRL); the package is added without an exception and behaves as anticipated. It appears that the exception generated by the binary package is occurring in PackageBuilder.addKnowledgeResource (line 495). Am I using a valid technique for loading binary packages? I don't have drools source code to trace into the details with Eclipse. What's the standard procedure for getting drools source code? Any other suggestions for determining the cause of my problem? Any and all help is appreciated. -- View this message in context: http://www.nabble.com/Bug-in-binary-package-generation--tp23263551p23263551.html Sent from the drools - user mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Hibernate proxy objects equality tests failing in Drools 5
Chris, When you use == in a DRL field constraint (not eval), drools always translates it into an .equals() call. Having said that, there might be other problems, since drools must rely on object identity for some internal data structures... for instance, we use IdentityMaps for mapping FactHandles and the actual fact objects, etc. We would need to test this and see what can be done. Could you please open a JIRA and attach a test case so that we can reproduce the problem? Thanks, Edson 2009/4/26 CK chris...@gmail.com Hi, I'm testing out some simple codes using Hibernate and Drools 5 and I'm hitting an issue with hibernate proxy objects. With the newer version of hibernate, Javassist is used to proxy some hibernate objects. By doing this, hibernate objects essentially cannot use == comparisons, which is fine. However, this is causing issue in equality checks within Drools 5 LHS evaluations of hibernate persistent objects. Let's say for example I have the following Hibernate objects: class Parent { Child child; } class Child { String name; } normally, if you output Parent.child, it should be Child.class. But under Hibernate, the child property in Parent may be proxied and enhanced with Javassist, thus making Parent.child.class to be something like Child_$$_javassist_75. Inside Drools, in the LHS: when $child : Child() $parent : Parent(child == $child) then ... end Assume that I have insert separate Child instances here that were retrieved from an Hibernate query directly. Assume that I have also inserted Parent instances that were retrieved from a separate query without eager fetching. Given this particular case, the above rule would not match even though it technically should. Under normal java code, using equality, the parent's child is equal to the child. According to MVEL language, which Drools LHS may not necessarily be using, equality between two objects are compared using values. Not sure exactly what that means. Either way, this seems to be a rather unfortunate problem for using Drools to work with Hibernate objects. Older hibernate versions didn't cause this problem. It seemed like jBPM had a similar problem according to the following doc: http://www.jboss.org/community/docs/DOC-11169 Excerpt: Object identity and object equality MAKE SURE TO USE ALWAYS .equals AND NEVER == comparisons in the Java code. Typically, in the PVM Java objects, we want to use the default object identity as the object equality. But hibernate persistence breaks this (even within the scope of one hibernate session) because of the proxies. So we have to apply a trick in order to make the comparison between a persistent object and its proxy return true. See jBPM 3 class EqualsUtil for that trick. So my question is whether Drools uses equality or identity when it comes to comparing values in LHS constraints. Is there a way to get around this issue? -Chris ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users -- Edson Tirelli JBoss Drools Core Development JBoss, a division of Red Hat @ www.jboss.com ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] can't get samples to work from Drools 5 drools-doc-expert
Thanks :-) On 24/04/2009, at 11:19 PM, David Sinclair wrote: Darrin, You have it except for 1 important line of code kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); Need to add the built packages to the rule base :) 2009/4/24 Darrin Mison dmi...@redhat.com Hi, I'm very new to Drools and I'm trying to get code running based on the first sample code from the QuickStart chapter of the drools- doc-expert. It compiles and runs (tried on commandline in JBoss Dev Studio 2.0.0.GA) but does not work, ie it always says rejected instead of accepted. I've had to fill out a bit of code to get it to compile so I may be doing something completely wrong. I've included the code (rule, model, main) below. Any help would be really appreciated. Darrin #Sample.drl package com.company.license rule Is of valid age when $a : Applicant( age 18); then $a.setValid( true ); System.out.println(true); end //Applicant.java package com.company.license; public class Applicant { private String name; private int Age; private boolean valid; // getter and setter methods here public String getName() { return name; } public int getAge() { return Age; } public boolean getValid(){ return valid; } public void setName(String s){ this.name = s; } public void setAge(int i){ this.Age = i; } public void setValid(boolean v){ this.valid = v; } } //ruletest.java package com.company.license; import org.drools.builder.*; import org.drools.io.*; import org.drools.runtime.*; import org.drools.*; public class ruletest { public ruletest(){} public static void main(String args[]) { ruletest rt = new ruletest(); rt.go(); } public void go() { Applicant dude = new Applicant(); dude.setName(Rufus); dude.setAge(32); System.out.println(dude.getName()); System.out.println(test: +dude.getValid()); KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); Resource ruleResource = ResourceFactory.newClassPathResource( Sample.drl, getClass() ); kbuilder.add( ruleResource, ResourceType.DRL ); if ( kbuilder.hasErrors() ) System.err.println( kbuilder.getErrors().toString() ); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession(); System.out.println( dude.getValid() ); //should display false ksession.execute( dude ); if (dude.getValid()) System.out.println(Application approved); //should display due to hardcoded as of 32 else System.out.println(Application rejected); } } ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] how to use Array type in Drools
Hi, I am using Drools 4.0.7 GA. I want to use Array type in my rule condition. My drl is like below: package org.drools.examples.test; import org.drools.examples.HelloWorldExample.Message; rule check.array dialect java when m:Message( arr[0] == 1 ) then System.out.println( ===check array ok=== ); end arr is an int type array. When I run the test case, I meet below exception: Exception in thread main org.drools.RuntimeDroolsException: Exception executing predicate eval( arr[0] == 1 ) at org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:216) at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:137) at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22) at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:162) at org.drools.reteoo.Rete.assertObject(Rete.java:175) 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:911) at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:883) at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:684) at org.drools.examples.HelloWorldExample.main(HelloWorldExample.java:69) Caused by: org.mvel.CompileException: illegal use of []: unknown type: [I at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getCollectionProperty(ReflectiveAccessorOptimizer.java:482) at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:274) at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:110) at org.mvel.ASTNode.getReducedValueAccelerated(ASTNode.java:186) at org.mvel.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:21) at org.mvel.MVELRuntime.execute(MVELRuntime.java:90) at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111) at org.mvel.MVEL.executeExpression(MVEL.java:234) at org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.java:45) at org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:209) ... 10 more Can anyone kindly tell me how to use Array type in Drools? Thanks in advance! - Zeke ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] inconsistent behaviour with 'not' keyword
Hello Simplified version of my rule is given below. Since I want to run this rule once once, I control it using Bar() fact. This rule fired inconsistently(i.e sometime it fired, sometime it is not). I could not also reproduce. Does anybody have the clue for this? Thanks for the help. rule run once list : ArrayList(size 0) from collect(Foo()) not Bar() then insert(new Bar()); end -- View this message in context: http://www.nabble.com/inconsistent-behaviour-with-%27not%27-keyword-tp23282677p23282677.html Sent from the drools - user mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] need some advice in defining rules
Hi Brody, Can you put the week number on the reminder object and assert all the reminders into working memory? That would give you a lot more options. For example, if you were to do that, you could construct a rule like the following when Week($number : weekNumber) java.util.List(size 5) from collect (Reminder(weekNumber == $number)) then insert(new LimitedReach($number)); -- OR -- rule Create summaries no-loop true when Reminder($weekNumber :weekNumber) not (WeekSummary(weekNumber == $weekNumber) then insert(new WeekSummary($weekNumber)) rule Summarize Reminders no-loop true when Reminder($weekNumber : weekNumber) $sum : WeekSummary(weekNumber == $weekNumber) then int numberReminders = $sum.getTotalReminders() + 1 modify($sum) { totalReminders= numberReminders } then have a rule to enforce the Summaries aren't over the limit. More facts/attributes you have in WM to reason over, the more possible solutions you have. On Mon, Apr 27, 2009 at 12:08 PM, Brody bach brodyb...@yahoo.com wrote: Hi all, I'm having difficulty in defining a rule for the following problem: We need to check if within a week there are more than 5 objects of type Reminder inserted into Memory. (one day corresponds to one object) The number of the inserted objects depends on the usage of the application. That means there could be nothing, 1, 2, or any number of the objects. Before, within a session, I inserted a list containg data from within one week (7 days). Than I can check using the rule: when: $list : list(size 5) Reminder() from $list no String(trim == limit reached); then System.out.println(This rule fires); insert new String(limit reached); Now I need to insert a list containing data from a whole month, but I still need to check whether within one week there are more than 5 reminders exist. so, the constraint list 5 can't be used anymore for a single list. I tried to break the whole list in several smaller list, where each list represents one week. Now the problem is, if the rule fires for a certain week, than it won't work for the following weeks anymore. My idea is then to insert an integer containing specific number to the current list, i.e. the calendar week (i.e insert new Integer(52)) and then to prove this in LHS; but the problem is now how to prove the week number in LHS? as I remeber, a function can only be called within an eval statement and in this case actually I should only prove the existence of an Integer Hope my explanation is quite understandable and looking forward for any hints Regards -- View this message in context: http://www.nabble.com/need-some-advice-in-defining-rules-tp23259683p23259683.html Sent from the drools - user mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] need some advice in defining rules
Have you considered the simple fact that a month may have between four (full) and six (one or two fractional) weeks? Reminder objects ought to have a field identifying the week; if they have its easy to count them per week if they are simple facts in WM. Note that the identificaton of weeks by running number per year also has up to two fractional weeks. -W On Mon, Apr 27, 2009 at 6:08 PM, Brody bach brodyb...@yahoo.com wrote: Hi all, I'm having difficulty in defining a rule for the following problem: We need to check if within a week there are more than 5 objects of type Reminder inserted into Memory. (one day corresponds to one object) The number of the inserted objects depends on the usage of the application. That means there could be nothing, 1, 2, or any number of the objects. Before, within a session, I inserted a list containg data from within one week (7 days). Than I can check using the rule: when: $list : list(size 5) Reminder() from $list no String(trim == limit reached); then System.out.println(This rule fires); insert new String(limit reached); Now I need to insert a list containing data from a whole month, but I still need to check whether within one week there are more than 5 reminders exist. so, the constraint list 5 can't be used anymore for a single list. I tried to break the whole list in several smaller list, where each list represents one week. Now the problem is, if the rule fires for a certain week, than it won't work for the following weeks anymore. My idea is then to insert an integer containing specific number to the current list, i.e. the calendar week (i.e insert new Integer(52)) and then to prove this in LHS; but the problem is now how to prove the week number in LHS? as I remeber, a function can only be called within an eval statement and in this case actually I should only prove the existence of an Integer Hope my explanation is quite understandable and looking forward for any hints Regards -- View this message in context: http://www.nabble.com/need-some-advice-in-defining-rules-tp23259683p23259683.html Sent from the drools - user mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] NullPointerException for Integer null
Hello, For following rule, NullPointerException is thrown for null id in 4.x. is this expected? Please clarify. Foo{ Integer id; } Rule null check foo : Foo(id==null) then end stack trace: java.lang.NullPointerException at org.drools.base.extractors.BaseObjectClassFieldExtractor.getIntValue(BaseObjectClassFieldExtractor.java:95) at org.drools.base.ClassFieldExtractor.getIntValue(ClassFieldExtractor.java:197) at org.drools.base.evaluators.IntegerFactory$IntegerLessEvaluator.evaluate(IntegerFactory.java:241) at org.drools.rule.VariableRestriction.isAllowed(VariableRestriction.java:73) at org.drools.rule.VariableConstraint.isAllowed(VariableConstraint.java:67) at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:137) at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:318) at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:162) at org.drools.reteoo.Rete.assertObject(Rete.java:175) 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:911) at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:883) at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:684) at org.drools.reteoo.ReteooStatelessSession.execute(ReteooStatelessSession.java:160) -- View this message in context: http://www.nabble.com/NullPointerException-for-Integer-null-tp23286041p23286041.html Sent from the drools - user mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
RE: [rules-users] need some advice in defining rules
It looks like you have may have to start with a simple representation of the calendar, forall weeks in a given year. I am not sure exactly what you are trying to accomplish - you could generate these kinds of facts,as many as you need,from Java (or any other language) dynamically. You may need 52 weeks in a year or may need less (part of the year) or more (more than a year), depending on the application. Nevertheless, it is good you are seeking opinions from this good group! Ravi. Original Message Subject: Re: [rules-users] need some advice in defining rulesFrom: Wolfgang Laun wolfgang.l...@gmail.comDate: Tue, April 28, 2009 4:37 pmTo: Rules Users List rules-users@lists.jboss.orgHave you considered the simple fact that a month may have between four (full) and six (one or two fractional) weeks? Reminder objects ought to have a field identifying the week; if they have its easy to count them per week if they are simple facts in WM.Note that the identificaton of weeks by running number per year also has up to two fractional weeks.-W On Mon, Apr 27, 2009 at 6:08 PM, Brody bach brodyb...@yahoo.com wrote: Hi all,I'm having difficulty in defining a rule for the following problem:We need to check if within a week there are more than 5 objects of typeReminder inserted into Memory.(one day corresponds to one object)The number of the inserted objects depends on the usage of the application.That means there could be nothing, 1, 2, or any number of the objects.Before, within a session, I inserted a list containg data from within oneweek (7 days).Than I can check using the rule:when:$list : list(size 5)Reminder() from $listno String(trim == "limit reached");thenSystem.out.println("This rule fires");insert new String("limit reached");Now I need to insert a list containing data from a whole month, but I stillneed to check whether within one week there are more than 5 reminders exist.so, the constraint list 5 can't be used anymore for a single list. I triedto break the whole list in several smaller list, where each list representsone week.Now the problem is, if the rule fires for a certain week, than it won't workfor the following weeks anymore.My idea is then to insert an integer containing specific number to thecurrent list, i.e. the calendar week (i.e insert new Integer(52)) and thento prove this in LHS; but the problem is now how to prove the week number inLHS? as I remeber, a function can only be called within an eval statementand in this case actually I should only prove the existence of an IntegerHope my explanation is quite understandable and looking forward for anyhintsRegards--View this message in context: http://www.nabble.com/need-some-advice-in-defining-rules-tp23259683p23259683.htmlSent from the drools - user mailing list archive at Nabble.com.___rules-users mailing listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users ___rules-users mailing listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users