On 4 Jun 2013, at 17:00, [email protected] wrote: > Send rules-users mailing list submissions to > [email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > https://lists.jboss.org/mailman/listinfo/rules-users > or, via email, send a message with subject or body 'help' to > [email protected] > > You can reach the person managing the list at > [email protected] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of rules-users digest..." > > > Today's Topics: > > 1. ClassCastException due to binding (bdolbeare) > 2. Re: Setting a value in LHS (Michael Anstis) > 3. Re: ClassCastException due to binding (Davide Sottara) > 4. Re: Setting a value in LHS (Stephen Masters) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Tue, 4 Jun 2013 08:12:09 -0700 (PDT) > From: bdolbeare <[email protected]> > Subject: [rules-users] ClassCastException due to binding > To: [email protected] > Message-ID: <[email protected]> > Content-Type: text/plain; charset=us-ascii > > We have a need to support binds for conditional or elements so that we can > describe why a rule fired in the then clause of a rule. The following DRL > is a simple example of what we are trying to do. There are two versions of > our rule in the DRL: > > *rule "WORKING: find with or"*: works but only because the first variable > we try to bind in the or expression is of type "target" which is a super > class of the other elements in the or expression. > > *rule "BROKEN: find with or"*: causes a class cast exception when the > "bar" pattern is matched because the then clause tries to store the bar > object in handle "x" which it thinks is of type "foo". > > Is there a way to define the object type for the bind variable? > > Is there any other way to make something like this work? > > > > package tests > > import org.apache.log4j.Logger; > > global Logger log > > declare target > notreal : boolean > end > > declare foo extends target > foovalue : String > end > > declare bar extends target > barvalue : String > end > > rule "insertdata" > when > then > insert(new foo(false, "a")); > insert(new bar(false, "b")); > end > > rule "WORKING: find with or" > when > ( or x: target(notreal) > x: foo(foovalue == "a") > x: bar(barvalue == "b") > ) > then > log.info("i found object: " + x); > end > > rule "BROKEN: find with or" > when > ( or > x: foo(foovalue == "a") > x: bar(barvalue == "b") > ) > then > log.info("i found object: " + x); > end > > > > Exception executing consequence for rule "find with or" in tests: > java.lang.ClassCastException: tests.bar cannot be cast to tests.foo > at > org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39) > at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1283) > at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1209) > at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1442) > at > org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710) > at > org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674) > at > org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230) > at > org.drools.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:278) > at tests.DroolsTest.testStateless(DroolsTest.java:120) > at tests.DroolsTest.runTest(DroolsTest.java:74) > at tests.DroolsTest.main(DroolsTest.java:59) > Caused by: java.lang.ClassCastException: tests.bar cannot be cast to > tests.foo > at > tests.Rule_find_with_or_411ee1c99de54340945b2b707ad0a576DefaultConsequenceInvoker.evaluate(Unknown > Source) > at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1273) > ... 9 more > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/ClassCastException-due-to-binding-tp4024115.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > > > ------------------------------ > > Message: 2 > Date: Tue, 4 Jun 2013 16:33:11 +0100 > From: Michael Anstis <[email protected]> > Subject: Re: [rules-users] Setting a value in LHS > To: "stephen.masters" <[email protected]>, Rules Users List > <[email protected]> > Message-ID: > <CAAG9P0uZO_-sskN_1V1uQFXzWuAxCosx=v+i+svfz0vhysq...@mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > This would need to be provided by the tooling; I don't think it's something > that's even remotely possible at runtime (unless you stored the field name > in a Fact and used reflection on the RHS). > > That said (and you're going to guess my next comment) this is not provided > in the guided editors. Depending on how complex your DSLs are and whether > users need to combine DSL Sentences; IDK if a "cheat" works: > > [when]Do something with {field} and {value}=$f : Fact({field}=={value} then > $f.{field} = {value} > > I've not tried it; nor know whether it fits your requirements.. but a hack > worth trying? > > > On 3 June 2013 17:40, stephen.masters <[email protected]> wrote: > >> Hi folks, >> >> Is there a decent way to set a value in the LHS of a rule so that it's >> available in the RHS? >> >> Reason being I have a DSL driving the guided rules editor which will pluck >> out the value of a field, where the name of that field is driven by a drop >> down menu enumeration. >> >> A change I now have would be a lot easier if I could assign a string to a >> variable in the LHS, which could be read by the RHS. Otherwise I might need >> to extend the RHS DSLs to include the same enumeration as the LHS. Which >> looks a bit redundant for a business user wondering why the need to write >> the same thing twice. >> >> Any thoughts? >> >> Steve >> >> >> >> >> Sent from Samsung Mobile >> >> _______________________________________________ >> rules-users mailing list >> [email protected] >> https://lists.jboss.org/mailman/listinfo/rules-users > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > http://lists.jboss.org/pipermail/rules-users/attachments/20130604/fae2d8f8/attachment-0001.html > > > ------------------------------ > > Message: 3 > Date: Tue, 04 Jun 2013 17:50:58 +0200 > From: Davide Sottara <[email protected]> > Subject: Re: [rules-users] ClassCastException due to binding > To: [email protected] > Message-ID: <[email protected]> > Content-Type: text/plain; charset=ISO-8859-1 > > "Polymorphic bindings" are not supported, the fact that it's not > reported at compilation time, > but only throws an exception at runtime, is a bad bug (I'll open a ticket) > > This said, you can split your rule in two rules - which is what Drools > would do anyway: > > rule r1 when $x : Foo() then .. end > rule r2 when $x : Bar() then .. end > > I'd also encourage you to follow java conventions, using capital letters > for declared types. > > And there may be various alternatives to "describe why a rule fired", > both in and out the RHS of a rule. > To cite some, using AgendaEventListeners or "drools.getActivation()" in > the RHS. > Davide > > > On 06/04/2013 05:12 PM, bdolbeare wrote: >> We have a need to support binds for conditional or elements so that we can >> describe why a rule fired in the then clause of a rule. The following DRL >> is a simple example of what we are trying to do. There are two versions of >> our rule in the DRL: >> >> *rule "WORKING: find with or"*: works but only because the first variable >> we try to bind in the or expression is of type "target" which is a super >> class of the other elements in the or expression. >> >> *rule "BROKEN: find with or"*: causes a class cast exception when the >> "bar" pattern is matched because the then clause tries to store the bar >> object in handle "x" which it thinks is of type "foo". >> >> Is there a way to define the object type for the bind variable? >> >> Is there any other way to make something like this work? >> >> >> >> package tests >> >> import org.apache.log4j.Logger; >> >> global Logger log >> >> declare target >> notreal : boolean >> end >> >> declare foo extends target >> foovalue : String >> end >> >> declare bar extends target >> barvalue : String >> end >> >> rule "insertdata" >> when >> then >> insert(new foo(false, "a")); >> insert(new bar(false, "b")); >> end >> >> rule "WORKING: find with or" >> when >> ( or x: target(notreal) >> x: foo(foovalue == "a") >> x: bar(barvalue == "b") >> ) >> then >> log.info("i found object: " + x); >> end >> >> rule "BROKEN: find with or" >> when >> ( or >> x: foo(foovalue == "a") >> x: bar(barvalue == "b") >> ) >> then >> log.info("i found object: " + x); >> end >> >> >> >> Exception executing consequence for rule "find with or" in tests: >> java.lang.ClassCastException: tests.bar cannot be cast to tests.foo >> at >> org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39) >> at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1283) >> at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1209) >> at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1442) >> at >> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710) >> at >> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674) >> at >> org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230) >> at >> org.drools.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:278) >> at tests.DroolsTest.testStateless(DroolsTest.java:120) >> at tests.DroolsTest.runTest(DroolsTest.java:74) >> at tests.DroolsTest.main(DroolsTest.java:59) >> Caused by: java.lang.ClassCastException: tests.bar cannot be cast to >> tests.foo >> at >> tests.Rule_find_with_or_411ee1c99de54340945b2b707ad0a576DefaultConsequenceInvoker.evaluate(Unknown >> Source) >> at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1273) >> ... 9 more >> >> >> >> -- >> View this message in context: >> http://drools.46999.n3.nabble.com/ClassCastException-due-to-binding-tp4024115.html >> Sent from the Drools: User forum mailing list archive at Nabble.com. >> _______________________________________________ >> rules-users mailing list >> [email protected] >> https://lists.jboss.org/mailman/listinfo/rules-users > > > > ------------------------------ > > Message: 4 > Date: Tue, 04 Jun 2013 16:59:48 +0100 > From: Stephen Masters <[email protected]> > Subject: Re: [rules-users] Setting a value in LHS > To: Michael Anstis <[email protected]>, Drools List > <[email protected]> > Message-ID: <[email protected]> > Content-Type: text/plain; charset="iso-8859-1" > > Thanks for the cheat idea Mike. I wasn't really expecting any help from the > tooling itself. Just hoping that there might be some trickery within the DSL > that I could try, to generate some code which would set up a variable for me. > > Unfortunately I do need to combine LHS sentences and multiple RHS sentences, > so your idea isn't really an option in this case. :( > > As it is I have created a little enumeration in the RHS sentence, and it's > not looking too bad. At least, with some selective wording, it doesn't look > completely redundant! > > Steve > > > > On 4 Jun 2013, at 16:33, Michael Anstis <[email protected]> wrote: > >> This would need to be provided by the tooling; I don't think it's something >> that's even remotely possible at runtime (unless you stored the field name >> in a Fact and used reflection on the RHS). >> >> That said (and you're going to guess my next comment) this is not provided >> in the guided editors. Depending on how complex your DSLs are and whether >> users need to combine DSL Sentences; IDK if a "cheat" works: >> >> [when]Do something with {field} and {value}=$f : Fact({field}=={value} then >> $f.{field} = {value} >> >> I've not tried it; nor know whether it fits your requirements.. but a hack >> worth trying? >> >> >> On 3 June 2013 17:40, stephen.masters <[email protected]> wrote: >> Hi folks, >> >> Is there a decent way to set a value in the LHS of a rule so that it's >> available in the RHS? >> >> Reason being I have a DSL driving the guided rules editor which will pluck >> out the value of a field, where the name of that field is driven by a drop >> down menu enumeration. >> >> A change I now have would be a lot easier if I could assign a string to a >> variable in the LHS, which could be read by the RHS. Otherwise I might need >> to extend the RHS DSLs to include the same enumeration as the LHS. Which >> looks a bit redundant for a business user wondering why the need to write >> the same thing twice. >> >> Any thoughts? >> >> Steve >> >> >> >> >> Sent from Samsung Mobile >> >> _______________________________________________ >> rules-users mailing list >> [email protected] >> https://lists.jboss.org/mailman/listinfo/rules-users > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > http://lists.jboss.org/pipermail/rules-users/attachments/20130604/5bbde949/attachment-0001.html > > > ------------------------------ > > _______________________________________________ > rules-users mailing list > [email protected] > https://lists.jboss.org/mailman/listinfo/rules-users > > End of rules-users Digest, Vol 79, Issue 7 > ******************************************
_______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
