2011/9/28 matvey1414 <span dir="ltr"><<a href="mailto:matvey1414@gmail.com">matvey1414@gmail.com</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>Hi,</div><div><br></div><div>Thank you for your reply. I will use the Knowledge API going forward.</div><div><br></div><div>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, </div>
</blockquote><div><br>For a complete picture, get the Expert manual of 5.1.1. Most constraint have to be written as <br> <field> <comp-op> <value><br>and there's a restrictive list of what is permitted as a <value>, e.g.<br>
field == (one + 2) // parens are required<br>or<br> field > 42 // OK<br>and so on. <br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>and what's an example of a deviation?</div></blockquote><div><br>For instance:<br> 42 < field<br>or<br> field == one + 2<br>and so on.<br><br>HTH<br>-W<br> <br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><br></div><div>-Matt</div><br><div class="gmail_quote"><div class="im">On Tue, Sep 27, 2011 at 5:12 AM, laune [via Drools] <span dir="ltr"><<a href="http://user/SendEmail.jtp?type=node&node=3376645&i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>></span> wrote:<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">
        Please use the new "knowledge" API for compiling and building a knowledge (not: rule) base.<br><br>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.<br>
<br>-W<br><br><br></div><div class="gmail_quote"><div><div></div><div class="h5">On 26 September 2011 22:51, matvey1414 <span dir="ltr"><<a href="http://user/SendEmail.jtp?type=node&node=3372058&i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>></span> wrote:<br>
</div></div><blockquote style="border-left: 2px solid rgb(204, 204, 204); padding: 0pt 1em;" class="gmail_quote"><div><div></div><div class="h5">
Hi,<br>
<br>
I am working with Drools to implement a high-profile rules-engine. I have<br>
two rules defined. Clearly, only the first should fire, but both do. Here is<br>
my DRL:<br>
<br>
<br>
package com.sample<br>
<br>
import com.sample.DroolsTest.Request;<br>
<br>
rule "ExpensiveCanonShopper0"<br>
when<br>
Request( attributeMap["camera0"] == "canon" &&<br>
attributeMap["price0"] >= 500 )<br>
then<br>
System.out.println("ExpensiveCanonShopper0");<br>
end<br>
<br>
rule "ExpensiveCanonShopper1"<br>
when<br>
Request( attributeMap["camera1"] == "canon" &&<br>
attributeMap["price1"] >= 500 )<br>
then<br>
System.out.println("ExpensiveCanonShopper1");<br>
end<br>
<br>
And the Java class to execute it:<br>
<br>
public class DroolsTest {<br>
<br>
@SuppressWarnings({ "rawtypes", "unchecked" })<br>
public static final void main(String[] args) {<br>
try {<br>
//Loading the Rules<br>
System.out.println("Loading rules");<br>
RuleBase ruleBase = readRule();<br>
StatelessSession workingMemory =<br>
ruleBase.newStatelessSession();<br>
<br>
System.out.println("Firing rules");<br>
<br>
Map map = new HashMap();<br>
map.put("camera0", "canon");<br>
map.put("price0", 600);<br>
<br>
Request request = new Request();<br>
request.setAttributeMap(map);<br>
workingMemory.execute(request);<br>
<br>
} catch (Throwable t) {<br>
t.printStackTrace();<br>
}<br>
}<br>
<br>
/**<br>
* Please note that this is the “low level” rule assembly API.<br>
*/<br>
private static RuleBase readRule() throws Exception {<br>
//read in the source<br>
Reader source = new FileReader(new File("drl",<br>
"Generated.drl"));<br>
<br>
//optionally read in the DSL (if you are using it).<br>
//Reader dsl = new InputStreamReader(<br>
DroolsTest.class.getResourceAsStream( “/mylang.dsl” ) );<br>
<br>
//Use package builder to build up a rule package.<br>
//An alternative lower level class called “DrlParser” can<br>
also be used…<br>
<br>
PackageBuilder builder = new PackageBuilder();<br>
<br>
//this wil parse and compile in one step<br>
//NOTE: There are 2 methods here, the one argument one is<br>
for normal DRL.<br>
builder.addPackageFromDrl( source );<br>
if (builder.hasErrors()) {<br>
PackageBuilderErrors errors = builder.getErrors();<br>
throw new RuntimeException("Error adding package to<br>
builder: " + errors.toString());<br>
}<br>
<br>
//Use the following instead of above if you are using a DSL:<br>
//builder.addPackageFromDrl( source, dsl );<br>
<br>
//get the compiled package (which is serializable)<br>
Package pkg = builder.getPackage();<br>
<br>
//add the package to a rulebase (deploy the rule package).<br>
RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br>
ruleBase.addPackage( pkg );<br>
return ruleBase;<br>
}<br>
<br>
public static class Request {<br>
private Map attributeMap;<br>
<br>
public Map getAttributeMap() {<br>
return attributeMap;<br>
}<br>
<br>
public void setAttributeMap(Map attributeMap) {<br>
this.attributeMap = attributeMap;<br>
}<br>
}<br>
}<br>
<br>
The output is this, meaning both rules fired:<br>
Loading rules<br>
Firing rules<br>
ExpensiveCanonShopper1<br>
ExpensiveCanonShopper0<br>
<br>
I have two questions:<br>
<br>
1. Is this a bug, or am I doing something wrong? Only<br>
"ExpensiveCanonShopper0" should fire.<br>
<br>
2. I am pretty sure this is somehow related to the fact that I'm using Map<br>
attributes, and not POJO to get "price0" and "camera0". My issue is that I<br>
won't know the parameters in advance (they are coming in a URL), so I can't<br>
pre-declare them, and thus need something dynamic like a Map. Is this how<br>
Drools is intended to be used? The documentation appears very POJO-centric.<br>
<br>
I am using Drools 5.2<br>
<br>
Thank you!<br>
-Matt<br>
</div></div><font color="#888888"><div><div></div><div class="h5"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Unsatisfied-rule-fires-Drools-bug-tp3370653p3370653.html" rel="nofollow" link="external" target="_blank">http://drools.46999.n3.nabble.com/Unsatisfied-rule-fires-Drools-bug-tp3370653p3370653.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
</div></div><a href="http://user/SendEmail.jtp?type=node&node=3372058&i=1" rel="nofollow" link="external" target="_blank">[hidden email]</a><div class="im"><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" rel="nofollow" link="external" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></font></blockquote></div><br>
<br>_______________________________________________
<br>rules-users mailing list
<br><a href="http://user/SendEmail.jtp?type=node&node=3372058&i=2" rel="nofollow" link="external" target="_blank">[hidden email]</a>
<br><div class="im"><a href="https://lists.jboss.org/mailman/listinfo/rules-users" rel="nofollow" link="external" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
        
        <br>
        <br>
        </div><hr noshade size="1" color="#cccccc">
        <div style="color: rgb(68, 68, 68); font-family: tahoma,geneva,helvetica,arial,sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal;">
                <div style="font-weight: bold;">If you reply to this email, your message will be added to the discussion below:</div>
                <a href="http://drools.46999.n3.nabble.com/Unsatisfied-rule-fires-Drools-bug-tp3370653p3372058.html" rel="nofollow" link="external" target="_blank">http://drools.46999.n3.nabble.com/Unsatisfied-rule-fires-Drools-bug-tp3370653p3372058.html</a>
        </div>
        <div style="color: rgb(102, 102, 102); font-family: tahoma,geneva,helvetica,arial,sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 11px; line-height: normal; font-size-adjust: none; font-stretch: normal; margin-top: 0.4em;">
                
                To unsubscribe from Unsatisfied rule fires - Drools bug?, <a rel="nofollow" link="external">click here</a>.
        </div></blockquote></div><br><font color="#888888"><br clear="all"><div><br></div>-- <br><a href="http://www.calcmachine.com" rel="nofollow" link="external" target="_blank">www.calcmachine.com</a> - easy online calculator.<br>
        
<br><hr width="300" align="left">
View this message in context: <a href="http://drools.46999.n3.nabble.com/Unsatisfied-rule-fires-Drools-bug-tp3370653p3376645.html" target="_blank">Re: [rules-users] Unsatisfied rule fires - Drools bug?</a></font><div><div>
</div><div class="h5"><br>
Sent from the <a href="http://drools.46999.n3.nabble.com/Drools-User-forum-f47000.html" target="_blank">Drools: User forum mailing list archive</a> at Nabble.com.<br></div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>