Immo Feldkamp | 2 Sep 13:31 2004
Picon

[drools-dev] drools.modifyObjects and Collections (Bug?)

Hi there,

I get an NullPointerException when I use drools.modifyObject on
java.util.Map (Lists also) types in following scenario:
- win32
- drools 2.0 beta 18
- java version 1.4.1-b21

BugTest.drl:
<?xml version="1.0"?>
<rule-set name="BugTester"
          xmlns="http://drools.org/rules"
          xmlns:java="http://drools.org/semantics/java">
    <rule name="BugTest">
        <parameter identifier="testMap">
            <java:class>java.util.Map</java:class>
        </parameter>
        <java:condition>testMap.containsKey("BUG") ==
false</java:condition>
        <java:consequence>
            testMap.put("BUG", Boolean.TRUE);
            drools.modifyObject(testMap);
        </java:consequence>
    </rule>
</rule-set>

BugTester.java:
package test;
import org.drools.FactHandle;
import org.drools.RuleBase;
(Continue reading)

Mark Proctor | 9 Sep 11:26 2004

[drools-dev] janino 2.0.9 and unparse visitor

Janino 2.0.9 is now available with a working unparse visitor, this builds on the work in current CVS, so users can now see what the "synthetic" java looks like. This is where we take the users condition/consequence and add imports and make application data and declarations available as variables automagically.

To give you an idea of what the resulting code looks like when its run I have included some outputs from examples fibonacci, state and petstore; the petstore example also shows application data being used.

Mark

/**
 * Fibonacci
 */
import org.drools.examples.fibonacci.Fibonacci;
public class DroolsConsequence implements org.drools.semantics.java.Expr$ConditionScript {
  public boolean invoke(final org.drools.spi.Tuple tuple,
                        final org.drools.rule.Declaration[] decls,
                        final org.drools.spi.KnowledgeHelper drools,
                        final java.util.Map applicationData)
    throws java.lang.Exception
  {
    final org.drools.examples.fibonacci.Fibonacci f3 = (org.drools.examples.fibonacci.Fibonacci) tuple.get(decls[0]);
    return (f3.getValue() == -1);
  }
}

/**
 * State
 */
import org.drools.examples.state.State;
public class DroolsConsequence implements org.drools.semantics.java.BlockConsequence$Script {
  public void invoke(final org.drools.spi.Tuple tuple,
                     final org.drools.rule.Declaration[] decls,
                     final org.drools.spi.KnowledgeHelper drools,
                     final java.util.Map applicationData)
    throws java.lang.Exception
  {
      final org.drools.examples.state.State b = (org.drools.examples.state.State) tuple.get(decls[0]);
      final org.drools.examples.state.State d = (org.drools.examples.state.State) tuple.get(decls[1]);
      System.out.println(d.getName() + " finished");
      d.setState("FINISHED");
      drools.modifyObject(d);
  }
}
/**
 * Petstore
 */
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import org.drools.examples.petstore.ShoppingCart;
public class DroolsConsequence implements org.drools.semantics.java.BlockConsequence$Script {
  public void invoke(final org.drools.spi.Tuple tuple,
                     final org.drools.rule.Declaration[] decls,
                     final org.drools.spi.KnowledgeHelper drools,
                     final java.util.Map applicationData)
    throws java.lang.Exception
  {
    final org.drools.examples.petstore.ShoppingCart cart = (org.drools.examples.petstore.ShoppingCart) tuple.get(decls[0]);
    final javax.swing.JFrame frame = (javax.swing.JFrame) applicationData.get("frame");
    Object[] options = new Object[] {
      "Yes",
      "No",
    };
    int n = JOptionPane.showOptionDialog(frame,
      "Would you like to buy a tank for your " +
      cart.getItems("Gold Fish").size() + " fish?",
      "Purchase Suggestion",
      JOptionPane.YES_NO_OPTION,
      JOptionPane.QUESTION_MESSAGE,
      null,
      options,
      options[0]);
      System.out.print("SUGGESTION: Would you like to buy a tank for your "
        + cart.getItems("Gold Fish").size() + " fish? - ");
      if (n == 0) {
        cart.addItem(new org.drools.examples.petstore.CartItem("Fish Tank", 25.0D));
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
      cart.setState("Suggested Fish Tank", true
    );
    drools.modifyObject(cart);
  }
}

/**
 * Fibonacci
 */
import org.drools.examples.fibonacci.Fibonacci;
public class DroolsConsequence implements org.drools.semantics.java.Expr$ConditionScript {
  public boolean invoke(final org.drools.spi.Tuple tuple,
                        final org.drools.rule.Declaration[] decls,
                        final org.drools.spi.KnowledgeHelper drools,
                        final java.util.Map applicationData)
    throws java.lang.Exception
  {
    final org.drools.examples.fibonacci.Fibonacci f3 = (org.drools.examples.fibonacci.Fibonacci) tuple.get(decls[0]);
    return (f3.getValue() == -1);
  }
}

/**
 * State
 */
import org.drools.examples.state.State;
public class DroolsConsequence implements org.drools.semantics.java.BlockConsequence$Script {
  public void invoke(final org.drools.spi.Tuple tuple,
                     final org.drools.rule.Declaration[] decls,
                     final org.drools.spi.KnowledgeHelper drools,
                     final java.util.Map applicationData)
    throws java.lang.Exception
  {
      final org.drools.examples.state.State b = (org.drools.examples.state.State) tuple.get(decls[0]);
      final org.drools.examples.state.State d = (org.drools.examples.state.State) tuple.get(decls[1]);
      System.out.println(d.getName() + " finished");
      d.setState("FINISHED");
      drools.modifyObject(d);
  }
}
/**
 * Petstore
 */
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import org.drools.examples.petstore.ShoppingCart;
public class DroolsConsequence implements org.drools.semantics.java.BlockConsequence$Script {
  public void invoke(final org.drools.spi.Tuple tuple,
                     final org.drools.rule.Declaration[] decls,
                     final org.drools.spi.KnowledgeHelper drools,
                     final java.util.Map applicationData)
    throws java.lang.Exception
  {
    final org.drools.examples.petstore.ShoppingCart cart =
(org.drools.examples.petstore.ShoppingCart) tuple.get(decls[0]);
    final javax.swing.JFrame frame = (javax.swing.JFrame) applicationData.get("frame");
    Object[] options = new Object[] {
      "Yes",
      "No",
    };
    int n = JOptionPane.showOptionDialog(frame,
      "Would you like to buy a tank for your " +
      cart.getItems("Gold Fish").size() + " fish?",
      "Purchase Suggestion",
      JOptionPane.YES_NO_OPTION,
      JOptionPane.QUESTION_MESSAGE,
      null,
      options,
      options[0]);
      System.out.print("SUGGESTION: Would you like to buy a tank for your "
        + cart.getItems("Gold Fish").size() + " fish? - ");
      if (n == 0) {
        cart.addItem(new org.drools.examples.petstore.CartItem("Fish Tank", 25.0D));
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
      cart.setState("Suggested Fish Tank", true
    );
    drools.modifyObject(cart);
  }
}
Mark Proctor | 10 Sep 04:03 2004

[drools-dev] escalation and trouble ticket

New example "escalation" in cvs for java that demonstrates the Duration 
semantic, which I just got working again. Any volunteers to convert to 
groovy and python, likewise docs for this in the normal step by step 
fashion would be great :) Base Semantic Module docs also need updating 
to detail the Duration element.

Mark

Mark Proctor | 13 Sep 13:22 2004

[drools-dev] CVS Progress Update

I have put together a progress updating for most of the work in CVS 
since the last beta, which will be included in the next upcoming beta.

-Robust Janino implementation in drools-java for application data and 
indentifier variables.
-Python fixes
-Bug fix for recency conflict resolution strategy, breadth/depth were 
wrong way around
-Fact based recency now implemented, along side the existing activation 
based recency.
-DefaultConflictResolution now implements OPS5 LEX strategy (salience, 
rency, complexity,  loadorder)
-ConditionException and ExtractionException now have methods to get the 
Rule the exception occured in, along with the text for the given expression.
-ConsequenceException now reports the Rule the exception occured in

Regards

Mark

Mark Proctor | 13 Sep 13:25 2004

[drools-dev] Re: CVS Progress Update

Sorry forgot to add that <duration .../> now works and a new example has 
been added "elevation-java" to demonstrate this; documentation on this 
will be added shortly.

Mark
Mark Proctor wrote:

> I have put together a progress updating for most of the work in CVS 
> since the last beta, which will be included in the next upcoming beta.
>
> -Robust Janino implementation in drools-java for application data and 
> indentifier variables.
> -Python fixes
> -Bug fix for recency conflict resolution strategy, breadth/depth were 
> wrong way around
> -Fact based recency now implemented, along side the existing 
> activation based recency.
> -DefaultConflictResolution now implements OPS5 LEX strategy (salience, 
> rency, complexity,  loadorder)
> -ConditionException and ExtractionException now have methods to get 
> the Rule the exception occured in, along with the text for the given 
> expression.
> -ConsequenceException now reports the Rule the exception occured in
>
> Regards
>
> Mark
>
>

Mark Proctor | 14 Sep 11:18 2004

[drools-dev] Re: [drools-user] reference customers / success stories

I know of several parties who are asking management if they can issues 
statements on their usuage of drools, I will start pushing this when we 
reach the release candidate stage.

On that note, if you are using drools successfully in a product, 
internal or external, then please let me know. Send me a summary of who 
you are and how  you are using it, technical/architectural overviews are 
very welcome; even better send a tutorial on how to achieve the more 
interesting aspects of your implementation. I think everyone is 
interested in the different ways in which drools is being used, so dont 
be shy :)

Mark
steve lau wrote:

>Thx for your great sharing, did you work with
>something like dynamic modifying rule or saving the
>rules ?
>
>Regards, 
>Steve
>
>
>
>--- Jason Bell <jasebell <at> ntlworld.com> wrote:
>
>  
>
>>Oh yeah, I forgot.
>>http://jasonbell.blog-city.com
>>
>>:)
>>
>>----- Original Message ----- 
>>From: "Jason Bell" <jasebell <at> ntlworld.com>
>>To: <user <at> drools.codehaus.org>
>>Sent: Monday, September 13, 2004 1:36 PM
>>Subject: Re: [drools-user] reference customers /
>>success stories
>>
>>
>>    
>>
>>>I just blogged something this morning, more of an
>>>      
>>>
>>observation than a
>>success
>>    
>>
>>>story.  Though I am implementing Drools in one of
>>>      
>>>
>>my products.
>>    
>>
>>>Regards
>>>Jason Bell
>>>
>>>----- Original Message ----- 
>>>From: "Karsten Priegnitz" <newsgroups <at> petoria.de>
>>>To: <user <at> drools.codehaus.org>
>>>Sent: Monday, September 13, 2004 1:18 PM
>>>Subject: [drools-user] reference customers /
>>>      
>>>
>>success stories
>>    
>>
>>>      
>>>
>>>>Hi drools-Team,
>>>>
>>>>are there any reference "customers" that use the
>>>>        
>>>>
>>drools engine or do you
>>    
>>
>>>know of success stories?
>>>      
>>>
>>>>My rules engine evaluation got kind of stuck (a
>>>>        
>>>>
>>little)...
>>    
>>
>>>>bye and thx,
>>>>Karsten/Germany
>>>>
>>>>
>>>>
>>>>        
>>>>
>>    
>>
>
>
>
>	
>		
>__________________________________
>Do you Yahoo!?
>New and Improved Yahoo! Mail - 100MB free storage!
>http://promotions.yahoo.com/new_mail 
>
>  
>

Mark Proctor | 14 Sep 22:21 2004

[drools-dev] Re: CVS Progress Update

Schemas are now available in CVS and validation is done at rule loading 
time.
Mark Proctor wrote:

> Sorry forgot to add that <duration .../> now works and a new example 
> has been added "elevation-java" to demonstrate this; documentation on 
> this will be added shortly.
>
> Mark
> Mark Proctor wrote:
>
>> I have put together a progress updating for most of the work in CVS 
>> since the last beta, which will be included in the next upcoming beta.
>>
>> -Robust Janino implementation in drools-java for application data and 
>> indentifier variables.
>> -Python fixes
>> -Bug fix for recency conflict resolution strategy, breadth/depth were 
>> wrong way around
>> -Fact based recency now implemented, along side the existing 
>> activation based recency.
>> -DefaultConflictResolution now implements OPS5 LEX strategy 
>> (salience, rency, complexity,  loadorder)
>> -ConditionException and ExtractionException now have methods to get 
>> the Rule the exception occured in, along with the text for the given 
>> expression.
>> -ConsequenceException now reports the Rule the exception occured in
>>
>> Regards
>>
>> Mark
>>
>>
>
>
>

peter royal | 16 Sep 17:02 2004

[drools-dev] Rules w/o Conditions

Any objections to allowing rules w/o Conditions?

Bob said it poses no problems.. Since a Fact can be multiple 
ObjectType's at the same time, that's an implicit condition..
-pete
Attachment (smime.p7s): application/pkcs7-signature, 3198 bytes
Andy Barnett | 16 Sep 21:29 2004

Re: [drools-dev] Rules w/o Conditions

No objections here.  I've had to code many rules with 
"<java:condition>true</java:condition>" to get around that limitation.
~Andy

On Sep 16, 2004, at 10:02 AM, peter royal wrote:

> Any objections to allowing rules w/o Conditions?
>
> Bob said it poses no problems.. Since a Fact can be multiple 
> ObjectType's at the same time, that's an implicit condition..
> -pete

Andy Barnett | 17 Sep 16:38 2004

[drools-dev] Rule-sets w/o Rules

Any objections to allowing Rule-Sets without Rules?  I know its a 
trivial condition, but I don't see any reason to disallow empty 
rule-sets.

I've found in my own work with XML files, it is often helpful to create 
such "empty" xml files when testing new code.

Also, the drools-examples primefactors-java example has a placeholder 
DRL file with all of its rules commented out, which causes a schema 
validation warning when a user runs that example.

~Andy


Gmane