[rules-users] Beginner question about Dynamic Beans

2008-07-02 Thread fmarchioni

Hi all drools users!
I'm just learning Drools from the manual, I have a question about Dynamic
Beans. I have added PropertyChangeSupport and listeners to my Beans: I can
see that inside my rule, if I change
one property the bean.

rule Check Age

salience 20
   
  when
 b : Buyer (age 18)
  then
  bankApp.addMessage(Messages.AGE_UNDER_18);
  b.setCash(4); // CHANGE OF PROPERTY
end

..then all rules are fired back again. Is it the correct behaviour ? is
there a way to re-evaluate only some of the Rules back again ?
thanks a lot
Francesco
-- 
View this message in context: 
http://www.nabble.com/Beginner-question-about-Dynamic-Beans-tp18232282p18232282.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] Beginner question about Dynamic Beans

2008-07-02 Thread Marcus Ilgner
Hi Francesco,

On Wed, Jul 2, 2008 at 10:28 AM, fmarchioni [EMAIL PROTECTED] wrote:

 Hi all drools users!
 I'm just learning Drools from the manual, I have a question about Dynamic
 Beans. I have added PropertyChangeSupport and listeners to my Beans: I can
 see that inside my rule, if I change
 one property the bean.

 rule Check Age

 salience 20

  when
 b : Buyer (age 18)
  then
  bankApp.addMessage(Messages.AGE_UNDER_18);
  b.setCash(4); // CHANGE OF PROPERTY
 end

 ..then all rules are fired back again. Is it the correct behaviour ? is
 there a way to re-evaluate only some of the Rules back again ?
 thanks a lot
 Francesco
 --

that's strange. From my experience, only those rules that depend on
the cash property should be fired if the new value triggers an
activation that wouldn't have been triggered for the old value. Could
you post the code of your PropertyChangeSupport implementation?

Here's some sample code from one of my projects:

public abstract class BindObject { /* simple proxy */
private PropertyChangeSupport propertyChangeSupport = new
PropertyChangeSupport(this);

public void addPropertyChangeListener(PropertyChangeListener _listener) {
propertyChangeSupport.addPropertyChangeListener(_listener);
}

public void addPropertyChangeListener(String _propertyName,
PropertyChangeListener _listener) {
propertyChangeSupport.addPropertyChangeListener(_propertyName,
_listener);
}

public void removePropertyChangeListener(PropertyChangeListener _listener) {
propertyChangeSupport.removePropertyChangeListener(_listener);
}

public void removePropertyChangeListener(String _propertyName,
PropertyChangeListener _listener) {
propertyChangeSupport.removePropertyChangeListener(_propertyName,
_listener);
}

protected void firePropertyChange(String _propertyName, Object
_oldValue, Object _newValue) {
propertyChangeSupport.firePropertyChange(_propertyName,
_oldValue, _newValue);
}

protected void firePropertyChange(String _propertyName, int
_oldValue, int _newValue) {
propertyChangeSupport.firePropertyChange(_propertyName,
_oldValue, _newValue);
}

protected void firePropertyChange(String _propertyName, boolean
_oldValue, boolean _newValue) {
propertyChangeSupport.firePropertyChange(_propertyName,
_oldValue, _newValue);
}
}

Now I simply inherit my classes from BindObject and write my setters like this:

public final static String PROPERTY_ARTICLE_NUMBER = articleNumber;
public void setArticleNumber(String _articleNumber) {
String oldValue = _articleNumber;
articleNumber = _articleNumber;
firePropertyChange(PROPERTY_ARTICLE_NUMBER, oldValue, articleNumber);
}

This has been working great for me so far.

HTH
Marcus
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] simple rule takes long time

2008-07-02 Thread ygaurav

Hi All 

I have few changes to my data class as suggested above and rule and it seems
to work. But that brings me to another question. Here is my new data class

Data class

public class Data {


private int id =0;
public boolean isCheck = false;
public String name = ;
public Data(int id) {
this.id = id;
name = name+(int)(this.hashCode());
System.out.println(id is +id+ name is +name);   
}

public int getId() {
return id;
}

public void setIsCheck() {
isCheck = true;
}

public boolean getIsCheck() {
return isCheck;
}

public String getName() {
return name;
}
}



rule Unique data
no-loop
salience 10
when
$data1: Data( $id1: id,isCheck == false)
$data2: Data( isCheck == true, id == $id1)
then 
log.log( data are not unique:+ $data1.getName() + and
+$data2.getName()+  id is +$data2.getId()+ +$data1.getId());
end

rule Change data
no-loop
when
$data: Data(isCheck == false)
then 
$data.setIsCheck();
update($data);
end


So you can see from above that I set value false at the start and then set
it to true in a different rule. Now it takes only less then a second to
execute the rule. I was not aware of the fact that each time i insert a rule
it start executing it. 

Now my question is 

Is it possible to stop working memory to start processing when I am
inserting data ? So don't execute anything untill I am finished adding all
the data and then fireAllrules 

thanks  ( also thanks to Scott Reed-3 who led to this solution) 
Gaurav



-- 
View this message in context: 
http://www.nabble.com/simple-rule-takes-long-time-tp18192098p18233804.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] Beginner question about Dynamic Beans

2008-07-02 Thread fmarchioni



 that's strange. From my experience, only those rules that depend on
 the cash property should be fired if the new value triggers an
 activation that wouldn't have been triggered for the old value. Could
 you post the code of your PropertyChangeSupport implementation?
 
Hi Marcus,
thanks for your reply, well my Bean implementation is:

public class Buyer {
   int age;
   double yearlyIncome;
   double cash;
   
   private final PropertyChangeSupport changes = new PropertyChangeSupport(
this );
   
   public void addPropertyChangeListener(final PropertyChangeListener l) {
this.changes.addPropertyChangeListener( l );
}

public void removePropertyChangeListener(final PropertyChangeListener 
l) {
this.changes.removePropertyChangeListener( l );
}

public int getAge() {
return age;
}
public void setAge(int newAge) {
int oldAge = this.age;
this.age = newAge;
this.changes.firePropertyChange(age, oldAge, newAge);
}
public double getCash() {
return cash;
}
public void setCash(double newCash) {
double oldCash = this.cash;
this.cash = newCash;
 System.out.println([Buyer ] cash is  + this.cash);
this.changes.firePropertyChange(cash, oldCash, newCash);
}
public double getYearlyIncome() {
return yearlyIncome;
}
public void setYearlyIncome(double newYearlyIncome) {

double oldYearlyIncome = this.yearlyIncome;
this.yearlyIncome = newYearlyIncome;
this.changes.firePropertyChange(yearlyIncome, oldYearlyIncome,
newYearlyIncome);

 
}
   
}

And my complete Rule file is:

global drools.BankApplication bankApp;

rule Check Age
   
  when
 b : Buyer (age 18)
  then
  System.out.println([Rule.drl] Checking age);
  bankApp.addMessage(Messages.AGE_UNDER_18);
  b.setCash(4);
end

rule Check Cash
   
  when
 b : Buyer (cash 5000)
  then
  System.out.println([Rule.drl] Checking cash);
  System.out.println([Rule.drl] cash is  + b.getCash());
  bankApp.addMessage(Messages.CASH_LOW );
end

rule Check Income
   
  when
 b : Buyer (yearlyIncome 5)
  then
  System.out.println([Rule.drl] Checking income);
  bankApp.addMessage(Messages.INCOME_LOW );
end

And facts are passed to the Working memory this way:

Buyer buyer = new Buyer();
BankApplication bankApp = new BankApplication();

buyer.setAge(15);
buyer.setCash(1000);
buyer.setYearlyIncome(3);

workingMemory.setGlobal(bankApp, bankApp);
workingMemory.insert(buyer,true);

workingMemory.fireAllRules(); 

Looking at the log file:

14:23:47,109 INFO  [STDOUT]  [Buyer ]  Setted cash with 1000.0
14:23:47,109 INFO  [STDOUT] [Rule.drl] Checking income
14:23:47,125 INFO  [STDOUT] [Rule.drl] Checking cash
14:23:47,125 INFO  [STDOUT]  [Rule.drl] cash is 1000.0
14:23:47,125 INFO  [STDOUT] [Rule.drl] Checking age
14:23:47,125 INFO  [STDOUT]  [Buyer ]  Setted cash with 4.0
14:23:47,125 INFO  [STDOUT] [Rule.drl] Checking income
14:23:47,125 INFO  [STDOUT]  [Rule.drl] Checking age
14:23:47,125 INFO  [STDOUT]  [Buyer ]Setted cash with 4.0

I can see that the Rule income has been invoked twice: why if it doesn't
use the cash attribute in it ?
Thanks a lot for your time
Francesco

-- 
View this message in context: 
http://www.nabble.com/Beginner-question-about-Dynamic-Beans-tp18232282p18236520.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] New rules in source file not loaded when application redeployed

2008-07-02 Thread Keith Bennett
I am packaging my rules as a drl source file in a jar that is then
bundled in a war file that is then deployed to Tomcat. In my
implementation, the rulebase is cached the first time it is used in my
application, but when I add new rules to the source file and rebuild
my application then redeploy it on Tomcat, the new version of the
rules don't get loaded into the rulebase.

Why and how is an older version of the rules being loaded into the
rulebase when I redeploy my application in Tomcat?  As FYI, I have
developed a business rules service that initializes the rulebase upon
a Spring container startup by loading the drl file from the classpath.
 Is there an internal Drools static cache that is scoped to something
other than my application?  The only thing I can do to load the new
rules is restart Tomcat.  When I do this, the new version of the drl
source file is loaded and used, so I'm thinking the problem I'm having
is somehow related to the class loaders Tomcat uses, but I can't find
information about what Drools might be doing internally with a static
cache or something like that.

Can anyone explain what might be happening and how to configure Drools
and/or my application to get around this problem I'm having?  I
definitely appreciate any help you can provide!

Keith
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Function Compilation Error when using JANINO

2008-07-02 Thread Mark Proctor

Janino is only JDK1.4 compatible, so I dont think it supports that for loop.

Mark
Garde, Varun (Equity Linked Technology) wrote:

Hello,
I am trying to use JANINO with drools 4.0.7. 
In my rule file I have a function definition, which is throwing a

compilation error with JANINO but works perfectly with ECLIPSE compiler.
The only janino in my classpath is v 2.5.10.
Want to make sure I am not doing something stupid here.

/* Drool File snippet */
function List getFieldsFromDelimiter(String value, String delimiter) {
List fieldList = new ArrayList();
String[] values = value.split(delimiter);
for(String val: values){
fieldList.add(new Field(val));
}
return fieldList;
}

/* Exception trace */
org.drools.rule.InvalidRulePackage: [ getFieldsFromDelimiter : Function
Compilation error
getFieldsFromDelimiter (line:26): File
com/elt/saturn/enumerations/GetFieldsFromDelimiter.java, Line 28, Column
18: Operator ; expected
 
]com.elt.saturn.enumerations.GetFieldsFromDelimiter.getFieldsFromDelimit

er
at org.drools.rule.Package.checkValidity(Package.java:424)
at
org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:394)
at
com.ml.elt.saturn.core.functionality.enumerations.DroolsChainComponent.
init(DroolsChainComponent.java:63)

/* Class extract from dump directory */
public class GetFieldsFromDelimiter {
private static final long serialVersionUID  = 400L;

public static List getFieldsFromDelimiter(String value,String

delimiter) throws Exception {

	List fieldList = new ArrayList();

String[] values = value.split(delimiter);
for(String val: values){//this is line 28
fieldList.add(new Field(val));
}
return fieldList;

}  
}
/*  


/* Configurations supplied to the PackageBuilderConf */
drools.dialect.java.compiler = JANINO
drools.dialect.java.compiler.lnglevel= 1.5


Any help would be much appreciated.

Thanks,
Varun.


This message w/attachments (message) may be privileged, confidential or 
proprietary, and if you are not an intended recipient, please notify the 
sender, do not use or share it and delete it. Unless specifically indicated, 
this message is not an offer to sell or a solicitation of any investment 
products or other financial product or service, an official confirmation of any 
transaction, or an official statement of Merrill Lynch. Subject to applicable 
law, Merrill Lynch may monitor, review and retain e-communications (EC) 
traveling through its networks/systems. The laws of the country of each 
sender/recipient may impact the handling of EC, and EC may be archived, 
supervised and produced in countries other than the country in which you are 
located. This message cannot be guaranteed to be secure or error-free. This 
message is subject to terms available at the following link: 
http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you 
consent to the foregoing.


___
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] nqueens or puzzle16 problems

2008-07-02 Thread Paul Fodor
Dear Sir,

I am new to Drools and I wonder if any of the classic declarative
problems, such as, nqueens, puzzle16 were implemented in Drools by
anyone. I realize that might be hard because of the bottom-up
evaluation.

Regards,
 Paul Fodor
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] wordnet in drools

2008-07-02 Thread Paul Fodor
Dear Sir,

I am new to Drools and I wonder if anyone used WordNet from Drools.
Basically, I want to make some simple joins, such as, find words that
are in the same synset, all hypernyms of a word, hyponyms, meronyms of
verbs, adjectives, etc.

 Regards,
  Paul Fodor
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] wordnet in drools

2008-07-02 Thread Mark Proctor

Paul Fodor wrote:

Dear Sir,

I am new to Drools and I wonder if anyone used WordNet from Drools.
Basically, I want to make some simple joins, such as, find words that
are in the same synset, all hypernyms of a word, hyponyms, meronyms of
verbs, adjectives, etc.
  
I haven't heard of it being applied with Drools. Do let me know your 
findings if you produce anything interesting.

 Regards,
  Paul Fodor
___
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] how to find the rule name

2008-07-02 Thread Steven Williams
try
String ruleName = ...

On Thu, Jul 3, 2008 at 7:09 AM, Marina [EMAIL PROTECTED] wrote:

 Hello,

 I need to know the rule name of the rule that fired in the consequence part
 of the rule. I tried something like the following, just trying to see if I
 can get it this way:

 package mode.simple;
 import java.lang.String;
 import java.util.List;
 import com.emptoris.ecm.domain.ContractRulesData;

 global java.util.Set approverList;

 rule testOR_1
dialect java
when
$data : ContractRulesData (sum  500 || name matches .*important)
then
approverList.add(approver3, approver4, Level5);
ruleName = drools.getRule().getName();
System.out.println(ruleName +  is TRUE);

 end

 When I'm trying to compile the rule, I'm getting the following error:
 Builder errors:
 Rule Compilation error : [Rule name=testOR_1, agendaGroup=MAIN, salience=0,
 no-loop=false]
mode/simple/Rule_testOR_1_0.java (8:391) : ruleName cannot be resolved
mode/simple/Rule_testOR_1_0.java (9:452) : ruleName cannot be resolved
 java.lang.RuntimeException: Unable to compile rules file: testOR_1.drl

 I must be doing something wrong here... ?

 thanks!
 Marina
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users




-- 
Steven Williams

Supervising Consultant

Object Consulting
Office: 8615 4500 Mob: 0439 898 668 Fax: 8615 4501
[EMAIL PROTECTED]
www.objectconsulting.com.au

consulting | development | training | support
our experience makes the difference
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Feature request

2008-07-02 Thread Daniel Bevenius

Hi!

I am also looking for the feature of being able to define constants in a 
rules file, that is mentioned in this thread 
(http://www.mail-archive.com/rules-users@lists.jboss.org/msg05142.html).


Is this something that will be considered for a future release? I've 
been through the JIRA issues but could not find it :(


Thanks,

/Daniel
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users