Hi,
Thank you for your reply. I will use the Knowledge API going forward.
Can you please explain what you mean by "deviate from the constraint syntax
as defined with 5.1.1"? What's an example of 5.1.1 syntax, and what's an
example of a deviation?
-Matt
On Tue, Sep 27, 2011 at 5:12 AM, laune [via Drools] <
ml-node+s46999n3372058h45(a)n3.nabble.com> wrote:
Please use the new "knowledge" API for compiling and
building a knowledge
(not: rule) base.
This bug has been fixed for 5.3.0. It is one of several that may occur when
you use 5.2.0 and deviate from the constraint syntax as defined with 5.1.1.
-W
On 26 September 2011 22:51, matvey1414 <[hidden
email]<http://user/SendEmail.jtp?type=node&node=3372058&i=0>
> wrote:
> Hi,
>
> I am working with Drools to implement a high-profile rules-engine. I have
> two rules defined. Clearly, only the first should fire, but both do. Here
> is
> my DRL:
>
>
> package com.sample
>
> import com.sample.DroolsTest.Request;
>
> rule "ExpensiveCanonShopper0"
> when
> Request( attributeMap["camera0"] == "canon" &&
> attributeMap["price0"] >= 500 )
> then
> System.out.println("ExpensiveCanonShopper0");
> end
>
> rule "ExpensiveCanonShopper1"
> when
> Request( attributeMap["camera1"] == "canon" &&
> attributeMap["price1"] >= 500 )
> then
> System.out.println("ExpensiveCanonShopper1");
> end
>
> And the Java class to execute it:
>
> public class DroolsTest {
>
> @SuppressWarnings({ "rawtypes", "unchecked" })
> public static final void main(String[] args) {
> try {
> //Loading the Rules
> System.out.println("Loading rules");
> RuleBase ruleBase = readRule();
> StatelessSession workingMemory =
> ruleBase.newStatelessSession();
>
> System.out.println("Firing rules");
>
> Map map = new HashMap();
> map.put("camera0", "canon");
> map.put("price0", 600);
>
> Request request = new Request();
> request.setAttributeMap(map);
> workingMemory.execute(request);
>
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
>
> /**
> * Please note that this is the “low level” rule assembly API.
> */
> private static RuleBase readRule() throws Exception {
> //read in the source
> Reader source = new FileReader(new File("drl",
> "Generated.drl"));
>
> //optionally read in the DSL (if you are using it).
> //Reader dsl = new InputStreamReader(
> DroolsTest.class.getResourceAsStream( “/mylang.dsl” ) );
>
> //Use package builder to build up a rule package.
> //An alternative lower level class called “DrlParser” can
> also be used…
>
> PackageBuilder builder = new PackageBuilder();
>
> //this wil parse and compile in one step
> //NOTE: There are 2 methods here, the one argument one is
> for normal DRL.
> builder.addPackageFromDrl( source );
> if (builder.hasErrors()) {
> PackageBuilderErrors errors = builder.getErrors();
> throw new RuntimeException("Error adding package to
> builder: " + errors.toString());
> }
>
> //Use the following instead of above if you are using a
> DSL:
> //builder.addPackageFromDrl( source, dsl );
>
> //get the compiled package (which is serializable)
> Package pkg = builder.getPackage();
>
> //add the package to a rulebase (deploy the rule package).
> RuleBase ruleBase = RuleBaseFactory.newRuleBase();
> ruleBase.addPackage( pkg );
> return ruleBase;
> }
>
> public static class Request {
> private Map attributeMap;
>
> public Map getAttributeMap() {
> return attributeMap;
> }
>
> public void setAttributeMap(Map attributeMap) {
> this.attributeMap = attributeMap;
> }
> }
> }
>
> The output is this, meaning both rules fired:
> Loading rules
> Firing rules
> ExpensiveCanonShopper1
> ExpensiveCanonShopper0
>
> I have two questions:
>
> 1. Is this a bug, or am I doing something wrong? Only
> "ExpensiveCanonShopper0" should fire.
>
> 2. I am pretty sure this is somehow related to the fact that I'm using Map
> attributes, and not POJO to get "price0" and "camera0". My issue
is that I
> won't know the parameters in advance (they are coming in a URL), so I
> can't
> pre-declare them, and thus need something dynamic like a Map. Is this how
> Drools is intended to be used? The documentation appears very
> POJO-centric.
>
> I am using Drools 5.2
>
> Thank you!
> -Matt
>
> --
> View this message in context:
>
http://drools.46999.n3.nabble.com/Unsatisfied-rule-fires-Drools-bug-tp337...
> Sent from the Drools: User forum mailing list archive at
Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> [hidden email] <
http://user/SendEmail.jtp?type=node&node=3372058&i=1>
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email] <
http://user/SendEmail.jtp?type=node&node=3372058&i=2>
https://lists.jboss.org/mailman/listinfo/rules-users
------------------------------
If you reply to this email, your message will be added to the discussion
below:
http://drools.46999.n3.nabble.com/Unsatisfied-rule-fires-Drools-bug-tp337...
To unsubscribe from Unsatisfied rule fires - Drools bug?, click
here<http://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=...;.