General rule engine behavior question
by Barry Blister
I'm seeing some unexpected behavior, although, it's certainly possible I'm not using drools 4 properly.Once a rule has fired, it won't fire again on subsequent invocations of fireAllRules(). In the past, on a different project, I have used drools 3 and all rule firing would occur on every rule (as long as it was true). What am I missing?
_________________________________________________________________
Make every IM count. Download Windows Live Messenger and join the i’m Initiative now. It’s free.
http://im.live.com/messenger/im/home/?source=TAGWL_June07
17 years, 5 months
expected release date for 4.0?
by Eric Miles
When is the expected release date for 4.0? I have looked all over the
site, the JIRA roadmap, etc and haven't found this information.
Thanks so much.
17 years, 5 months
NullPointerException: org.drools.base.extractors.BaseObjectClassFieldExtractor.getLongValue(BaseObjectClassFieldExtractor.java:103)
by Jian Li
Hi,
The following problem encountered:
I have a rule defintion :
----------------------------------------------dpd.drl
package ruletest;
import ruletest.IndividualNok;
rule Female_NOK_sex_401
//when (IndividualNok(nokRelationship==401) || IndividualNok(nokRelationship==402))
when (IndividualNok(nokRelationship==401) || IndividualNok(nokRelationship==402) || IndividualNok(nokRelationship==403))
then
System.out.println("abc");
end
------------------------------------------------
When I tried the commented out LSH, it works, however, when i add one more expression to it , it fails with the following exceptions:
Exception in thread "main" java.lang.NullPointerException
at org.drools.base.extractors.BaseObjectClassFieldExtractor.getLongValue(BaseObjectClassFieldExtractor.java:103)
at org.drools.base.ClassFieldExtractor.getLongValue(ClassFieldExtractor.java:144)
at org.drools.reteoo.CompositeObjectSinkAdapter$HashKey.setValue(CompositeObjectSinkAdapter.java:467)
at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:292)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:183)
at org.drools.reteoo.Rete.assertObject(Rete.java:121)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:201)
at org.drools.reteoo.ReteooWorkingMemory.doAssertObject(ReteooWorkingMemory.java:70)
at org.drools.common.AbstractWorkingMemory.assertObject(AbstractWorkingMemory.java:724)
at org.drools.common.AbstractWorkingMemory.assertObject(AbstractWorkingMemory.java:548)
Any idea about this? is it a bug
When I tried to create an additional rule with the 2 expression, it still fails. This error can be reproduced with the followng code:
-------------------------the Main Class's main method
public static void main(String[] args) {
// TODO code application logic here
final PackageBuilder builder = new PackageBuilder();
try {
builder.addPackageFromDrl( new InputStreamReader( Main.class.getResourceAsStream( "dpd.drl" ) ) );
} catch (DroolsParserException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
try {
ruleBase.addPackage( builder.getPackage() );
} catch (Exception ex) {
ex.printStackTrace();
}
final StatefulSession session = ruleBase.newStatefulSession();
IndividualNok individualNok = new IndividualNok();
session.assertObject(individualNok);
session.fireAllRules();
session.dispose();
}
-------------------------------------------------
-------------------------------------------------Person class: requried by individualNok, a simple POJO
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
/**
*
* @author Jian.Li
*/
public class Person implements java.io.Serializable {
// Fields
private Long personId;
private Integer nationality;
private Integer race;
private String firstName;
private String lastName;
private String midName;
private Date birthdate;
private Integer occupation;
private Integer religion;
private Integer primaryLanguage;
private Integer veteransStatus;
private String idNo;
private Integer idType;
private String mobileNo;
private String email;
private Integer ethnicgroupcountry;
private Integer ethnicgroupstate;
private Integer ethnicgroupcity;
private Integer sex;
private Integer maritalStatus;
private Date lud;
private String lub;
private Set individualNoksForNokPersonId = new HashSet(0);
private Set careproviders = new HashSet(0);
private Set residentialAddresses = new HashSet(0);
private Set individualNoksForPersonId = new HashSet(0);
// Constructors
/** default constructor */
public Person() {
}
/** minimal constructor */
public Person(String firstName, String lastName, Date birthdate,
Integer sex, Integer maritalStatus, Date lud) {
this.firstName = firstName;
this.lastName = lastName;
this.birthdate = birthdate;
this.sex = sex;
this.maritalStatus = maritalStatus;
this.lud = lud;
}
/** full constructor */
public Person(Integer nationality, Integer race, String firstName,
String lastName, String midName, Date birthdate,
Integer occupation, Integer religion, Integer primaryLanguage,
Integer veteransStatus, String idNo, Integer idType,
String mobileNo, String email, Integer ethnicgroupcountry,
Integer ethnicgroupstate, Integer ethnicgroupcity, Integer sex,
Integer maritalStatus, Date lud, String lub,
Set individualNoksForNokPersonId, Set careproviders,
Set residentialAddresses, Set individualNoksForPersonId) {
this.nationality = nationality;
this.race = race;
this.firstName = firstName;
this.lastName = lastName;
this.midName = midName;
this.birthdate = birthdate;
this.occupation = occupation;
this.religion = religion;
this.primaryLanguage = primaryLanguage;
this.veteransStatus = veteransStatus;
this.idNo = idNo;
this.idType = idType;
this.mobileNo = mobileNo;
this.email = email;
this.ethnicgroupcountry = ethnicgroupcountry;
this.ethnicgroupstate = ethnicgroupstate;
this.ethnicgroupcity = ethnicgroupcity;
this.sex = sex;
this.maritalStatus = maritalStatus;
this.lud = lud;
this.lub = lub;
this.individualNoksForNokPersonId = individualNoksForNokPersonId;
this.careproviders = careproviders;
this.residentialAddresses = residentialAddresses;
this.individualNoksForPersonId = individualNoksForPersonId;
}
// Property accessors
public Long getPersonId() {
return this.personId;
}
public void setPersonId(Long personId) {
this.personId = personId;
}
public Integer getNationality() {
return this.nationality;
}
public void setNationality(Integer nationality) {
this.nationality = nationality;
}
public Integer getRace() {
return this.race;
}
public void setRace(Integer race) {
this.race = race;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getMidName() {
return this.midName;
}
public void setMidName(String midName) {
this.midName = midName;
}
public Date getBirthdate() {
return this.birthdate;
}
public void setBirthdate(Date birthdate) {
this.birthdate = birthdate;
}
public Integer getOccupation() {
return this.occupation;
}
public void setOccupation(Integer occupation) {
this.occupation = occupation;
}
public Integer getReligion() {
return this.religion;
}
public void setReligion(Integer religion) {
this.religion = religion;
}
public Integer getPrimaryLanguage() {
return this.primaryLanguage;
}
public void setPrimaryLanguage(Integer primaryLanguage) {
this.primaryLanguage = primaryLanguage;
}
public Integer getVeteransStatus() {
return this.veteransStatus;
}
public void setVeteransStatus(Integer veteransStatus) {
this.veteransStatus = veteransStatus;
}
public String getIdNo() {
return this.idNo;
}
public void setIdNo(String idNo) {
this.idNo = idNo;
}
public Integer getIdType() {
return this.idType;
}
public void setIdType(Integer idType) {
this.idType = idType;
}
public String getMobileNo() {
return this.mobileNo;
}
public void setMobileNo(String mobileNo) {
this.mobileNo = mobileNo;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getEthnicgroupcountry() {
return this.ethnicgroupcountry;
}
public void setEthnicgroupcountry(Integer ethnicgroupcountry) {
this.ethnicgroupcountry = ethnicgroupcountry;
}
public Integer getEthnicgroupstate() {
return this.ethnicgroupstate;
}
public void setEthnicgroupstate(Integer ethnicgroupstate) {
this.ethnicgroupstate = ethnicgroupstate;
}
public Integer getEthnicgroupcity() {
return this.ethnicgroupcity;
}
public void setEthnicgroupcity(Integer ethnicgroupcity) {
this.ethnicgroupcity = ethnicgroupcity;
}
public Integer getSex() {
return this.sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public Integer getMaritalStatus() {
return this.maritalStatus;
}
public void setMaritalStatus(Integer maritalStatus) {
this.maritalStatus = maritalStatus;
}
public Date getLud() {
return this.lud;
}
public void setLud(Date lud) {
this.lud = lud;
}
public String getLub() {
return this.lub;
}
public void setLub(String lub) {
this.lub = lub;
}
public Set getIndividualNoksForNokPersonId() {
return this.individualNoksForNokPersonId;
}
public void setIndividualNoksForNokPersonId(Set individualNoksForNokPersonId) {
this.individualNoksForNokPersonId = individualNoksForNokPersonId;
}
public Set getCareproviders() {
return this.careproviders;
}
public void setCareproviders(Set careproviders) {
this.careproviders = careproviders;
}
public Set getResidentialAddresses() {
return this.residentialAddresses;
}
public void setResidentialAddresses(Set residentialAddresses) {
this.residentialAddresses = residentialAddresses;
}
public Set getIndividualNoksForPersonId() {
return this.individualNoksForPersonId;
}
public void setIndividualNoksForPersonId(Set individualNoksForPersonId) {
this.individualNoksForPersonId = individualNoksForPersonId;
}
}
----------------------------------------------------------------------------------------------------
-------------------------------------IndividualNok class : a simple POJO
public class IndividualNok implements java.io.Serializable {
// Fields
private Long individualNokId;
private Person personByPersonId;
private Person personByNokPersonId;
private Integer nokRelationship;
private Integer emgcycntctInd;
// Constructors
/** default constructor */
public IndividualNok() {
}
/** minimal constructor */
public IndividualNok(Integer nokRelationship) {
this.nokRelationship = nokRelationship;
}
/** full constructor */
public IndividualNok(Person personByPersonId, Person personByNokPersonId,
Integer nokRelationship, Integer emgcycntctInd) {
this.personByPersonId = personByPersonId;
this.personByNokPersonId = personByNokPersonId;
this.nokRelationship = nokRelationship;
this.emgcycntctInd = emgcycntctInd;
}
// Property accessors
public Long getIndividualNokId() {
return this.individualNokId;
}
public void setIndividualNokId(Long individualNokId) {
this.individualNokId = individualNokId;
}
public Person getPersonByPersonId() {
return this.personByPersonId;
}
public void setPersonByPersonId(Person personByPersonId) {
this.personByPersonId = personByPersonId;
}
public Person getPersonByNokPersonId() {
return this.personByNokPersonId;
}
public void setPersonByNokPersonId(Person personByNokPersonId) {
this.personByNokPersonId = personByNokPersonId;
}
public Integer getNokRelationship() {
return this.nokRelationship;
}
public void setNokRelationship(Integer nokRelationship) {
this.nokRelationship = nokRelationship;
}
public Integer getEmgcycntctInd() {
return this.emgcycntctInd;
}
public void setEmgcycntctInd(Integer emgcycntctInd) {
this.emgcycntctInd = emgcycntctInd;
}
}
---------------------------------------End of IndividualNok
____________________________________________________
Yahoo! Singapore Answers
Real people. Real questions. Real answers. Share what you know at http://answers.yahoo.com.sg
17 years, 5 months
DRL authoring help
by Smitha Bhat
Hi,
I am new to JBoss rules. I have a .drl as given below:
rule "Rule1"
when
$Position1 : Position()
eval($Position1.getName() contains "POS-RPT_0_1")
then
util.setColor($Position1, "red");
end
Before firing the rules, I assert my object as
posIn = new Position(name,
id,
symbolCode,
lonDouble,
latDouble,
elevDouble,
reportDate,
this);
workingMemory.assertObject( posIn );
workingMemory.fireAllRules();
I get the following error.
org.drools.rule.InvalidRulePackage: Rule Compilation error The left-hand side of an assignment must be a variable Syntax error on token "contains", invalid AssignmentOperator
at org.drools.rule.Package.checkValidity(Unknown Source)
at org.drools.common.AbstractRuleBase.addPackage(Unknown Source)
What is wrong with my drl? I have a Utilities class that I have defined as global.
Thanks
---------------------------------
Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
17 years, 5 months
Stateful Session
by Shai Bentin
Can anyone explain to me why I would want to hold a reference to my working memory in the ruleBase?
The way we use the rules in our application is that we load all the copiled packages at the begining (we have API in place to replace, remove or add packages in runtime). The users invoke operations on different objects that get evaluated by the rules. Each time we call onto our factory get the correspondiong rulebase and invoke 'newStatefulSession()'. If I understand this correctly each time we create a new WorkingMemory instance which will not be garbage collected when were done since there is a reference to it?
What is the difference between Stateful and Stateless sessions?
Is there a way to reuse working memory from a ruleBase?
thnx
17 years, 5 months
[drools 4] firing a partial set of rules and consequences
by Geoffrey De Smet
Can I fire a partial set of rules?
Say I have 3 rules: fastRuleA, fastRuleB, slowRuleC.
What's the best way to only fire the group of fastRule1 and fastRule2?
AgendaFilter looks like a good way of doing this, but:
If between 2 rule fires, I change a fact, but change it back to it's
original state, will the rule be not refire, just like if I hadn't
changed it temporary? for example fact1 is used in slowRuleC:
fireAllRules(); // fires slowRuleC
fact1.a++;
fact1.a--;
fireAllRules(); // does not fire slowRuleC?
Does still apply if I fire other rules meanwhile?
fireAllRules(); // fires slowRuleC
fact1.a++;
fireAllRules(notSlowRuleCAgendaFilter); // slowRuleC is ignored
// if I did not filter it out it would have fired of course
fact1.a--;
fireAllRules(); // does not fire slowRuleC? or does it?
// a hasn't is the same since the last time slowRuleC was fired
--
With kind regards,
Geoffrey De Smet
17 years, 5 months
[drools 4] firing a partial set of rules and consequences
by Geoffrey De Smet
Can I fire a partial set of rules?
Say I have 3 rules: fastRuleA, fastRuleB, slowRuleC.
What's the best way to only fire the group of fastRule1 and fastRule2?
AgendaFilter looks like a good way of doing this, but:
If between 2 rule fires, I change a fact, but change it back to it's
original state, will the rule not refire, just like if I hadn't
changed it temporary? for example fact1 is used in slowRuleC:
fact1.a++;
fireAllRules(); // fires slowRuleC as it depends on fact1.a
fact1.a++;
fact1.a--;
fireAllRules(); // does not fire slowRuleC?
Does still apply if I fire other rules meanwhile?
fact1.a++;
fireAllRules(); // fires slowRuleC as it depends on fact1.a
fact1.a++;
fireAllRules(notSlowRuleCAgendaFilter); // slowRuleC is ignored
// if I did not filter it out it would have fired of course
fact1.a--;
fireAllRules(); // does not fire slowRuleC? or does it?
// a hasn't is the same since the last time slowRuleC was fired
Thanks for any help,
Geoffrey
17 years, 5 months
Inspecting Working Memory
by Yuri de Wit
I usually have thousands of facts in Working memory and at some points
I need to figure out why this or that wasnt activated or sometime I
just want to know (ad-hoc) if such and such fact is already asserted
into memory.
It would be great if I could at any point in time use a JBoss rules
console attached to a given working memory and issue ad hoc queries.
Just a thought.
thanks,
-- yuri
17 years, 5 months
Operators
by Yuri de Wit
I am using JBoss Rules 3.0.6 and in many situations I was forced to
use a Java snipped predicates ( p.property -> ( fn.doSomething(p, a))
which clutters the rules quite a bit ) to override or correct the
behaviour of some of the operators such as ==, !=, etc. It would be
nice if there was an easy way for me to override them by providing my
own implementation. I could then subclass the default one provided by
JBoss Rules and customized the ones I need.
I know that this sugestiong would allow us to modify the semantic of
the rules language operators but it at least would provide a nice way
out of issues (such as using == between a Short and a Integer) we come
accross, could help debugging predicate evaluations (I guess I could
always add a breakpoint to a specific class from the rules engine -
which class?).
On the same topic would it be possible to add new operators to the language?
thanks,
-yuri
17 years, 5 months
Problem Comparing to Character Fields
by BrianKE
After asserrting the following objects and performing the rule I get the error
shown
PersonSummary personSummary = new PersonSummary();
personSummary.setPrId(new Long(217));
personSummary.setCmpntCd(new Character('R'));
PersonSummary personSummary2 = new PersonSummary();
personSummary2.setPrId(new Long(217));
personSummary2.setCmpntCd(new Character('G'));
##################################
rule "Duplicate Projection for same processing date by another component"
when
$j : PersonSummary($prId : prId, $cmpntCd : cmpntCd)
exists PersonSummary(this != $j, cmpntCd == $cmpntCd)
then
System.out.println("Error Found in rule Duplicate Component
Code");
end
##################################
java.lang.ClassCastException:
org.drools.rule.VariableRestriction$ObjectVariableContextEntry
at
org.drools.base.evaluators.CharacterFactory$CharacterEqualEvaluator.evaluateCac
hedRight(CharacterFactory.java:99)
at org.drools.rule.VariableRestriction.isAllowedCachedRight
(VariableRestriction.java:78)
at org.drools.rule.VariableConstraint.isAllowedCachedRight
(VariableConstraint.java:78)
at org.drools.common.DoubleBetaConstraints.isAllowedCachedRight
(DoubleBetaConstraints.java:149)
If I change the exists rule to:
exists PersonSummary(this != $j, cmpntCd == 'A')
it works fine.
Is there something I have to do to compare two char objects.
Thanks
17 years, 5 months