Re: [drools-user] Drools 3, RHS special names, indirect assert
Jurgen, want to take this to the dev list? As I know what you are trying to do, we should discuss there and come up with a design (without filling the inbox of the user list subscribers !). Cheers, Michael. On 4/14/06, Mark Proctor [EMAIL PROTECTED] wrote: Assert is just replaced with workingMemory.assertOjbect ( object ) anyway. It's just a bit of regexp we apply to make things easier for users. BTW this is what mandarax has to say about JSR94: A: Mandarax does not (yet) support JSR-94 http://www.jcp.org/jsr/detail/094.jsp. The reason is that this proposal is so general that it is almost useless. We are monitoring the JSR-94 efforts, and perhaps add support later. We support JSR94, but my feelings are just the same - just say NO! :) Mark Juergen wrote: Questions on assert in RHS: 1) is it the same to call special assert() in RHS vs. indirectly calling JSR 94 Rule session method addObject() (or WorkingMemory.assert()) in RHS? would the latter way of asserting interfere with the active rule execution? rule A when ... then assert(new String(A)) someMethodCallsThisEnginesWorkingMemoryAssert(new String(B)) someMethodCallsThisEnginesJSR94SessionAddObject(new String(C)) end 2) what other special names/objects/methods do exist, that can be used in a RHS code block (like special drools object in drools 2.5)? Haven't found much on that in current docu. My questions relate to the idea to wrapping assert with code to check for equality. Michael Neale wrote: if there is enough demand for it, we may be able to make it some working memory wide configuration option - certainly. Submit a JIRA request if you like, may come in handy (certainly will for you). But not as the default, as not everyone implements equals() correctly ! On 4/11/06, Juergen [EMAIL PROTECTED] wrote: Quick'n dirty I could make drools 3 do it the way I would prefer - in the context of my current problem and datastructures involved - by modifying: org.drools.reteoo.WorkingMemoryImpl, line 95f (rev. 3509): replace: /** Object-to-handle mapping. */ private Map identityMap = new IdentityMap(); by: /** Object-to-handle mapping. */ private Map identityMap = new java.util.HashMap(); (not considering side effects, identityMap type cast problems, ...) Then org.drools.reteoo.WorkingMemoryImpl, assertObject (line 422, rev. 3509): FactHandleImpl handle = (FactHandleImpl) this.identityMap.get( object ); would return first As handle when the second A is asserted, refering to the example in my former posting. I expected some way to customize the behaviour of the working memory, basically by choosing between either of the Maps. But as mentioned, such behaviour might not be desirable by others (they probably want A being asserted twice and handled as two different objects) and even if not customizable in drools itself, it can most likely be done by wrapping assertObject and managing your own object-to-handle map plus taking care not to use assert directly in RHS. I first wrongly thought logical assertions had something to do with this, but I guess that relates more to the 'logical' conditional element in jess and logical dependencies among facts. Michael Neale wrote: what is your expectations on how it should work? (everyone has different ideas it seems !) On 4/10/06, Juergen [EMAIL PROTECTED] wrote: I mean workingMemory.assertObject(new String(A)); workingMemory.assertObject(new String(A)); would currently assert both strings into working memory, whereas if it would check not for identityHashCode but with equals, the second assert would have no effect. When during experimentation with rule engines I switched from jess (where it is done with equals I think) to drools 2 I first experienced problems due to this differences (also did not find much in both engines docu), leading to my question if I could customize drools behaviour. As one can always write a wrapper for drools assertObject to make such checks, and lots of other users probably dont need, my request is not important. Juergen Michael Neale wrote: so you mean p1 : Person() p2 : Person() eval ( p1.equals(p2) ) (but presumably a shorthand form?) On 4/8/06, Mark Proctor [EMAIL PROTECTED] wrote: We hadn't planned it, not promising anything - but I'll see how things pan out, may be we will get time. Mark Juergen wrote: ad. Can object equality for assertion be customized? Drools 3 still seems to use IdentityMap with System.identityHashCode (). Is it planned to be customizeable e.g. with equals() in 3.0? Michael Neale wrote: Short answer, not easily with Drools 2. But yes, with Drools
Re: [drools-user] Drools 3, RHS special names, indirect assert
Questions on assert in RHS: 1) is it the same to call special assert() in RHS vs. indirectly calling JSR 94 Rule session method addObject() (or WorkingMemory.assert()) in RHS? would the latter way of asserting interfere with the active rule execution? rule A when ... then assert(new String(A)) someMethodCallsThisEnginesWorkingMemoryAssert(new String(B)) someMethodCallsThisEnginesJSR94SessionAddObject(new String(C)) end 2) what other special names/objects/methods do exist, that can be used in a RHS code block (like special drools object in drools 2.5)? Haven't found much on that in current docu. My questions relate to the idea to wrapping assert with code to check for equality. Michael Neale wrote: if there is enough demand for it, we may be able to make it some working memory wide configuration option - certainly. Submit a JIRA request if you like, may come in handy (certainly will for you). But not as the default, as not everyone implements equals() correctly ! On 4/11/06, Juergen [EMAIL PROTECTED] wrote: Quick'n dirty I could make drools 3 do it the way I would prefer - in the context of my current problem and datastructures involved - by modifying: org.drools.reteoo.WorkingMemoryImpl, line 95f (rev. 3509): replace: /** Object-to-handle mapping. */ private Map identityMap = new IdentityMap(); by: /** Object-to-handle mapping. */ private Map identityMap = new java.util.HashMap(); (not considering side effects, identityMap type cast problems, ...) Then org.drools.reteoo.WorkingMemoryImpl, assertObject (line 422, rev. 3509): FactHandleImpl handle = (FactHandleImpl) this.identityMap.get( object ); would return first As handle when the second A is asserted, refering to the example in my former posting. I expected some way to customize the behaviour of the working memory, basically by choosing between either of the Maps. But as mentioned, such behaviour might not be desirable by others (they probably want A being asserted twice and handled as two different objects) and even if not customizable in drools itself, it can most likely be done by wrapping assertObject and managing your own object-to-handle map plus taking care not to use assert directly in RHS. I first wrongly thought logical assertions had something to do with this, but I guess that relates more to the 'logical' conditional element in jess and logical dependencies among facts. Michael Neale wrote: what is your expectations on how it should work? (everyone has different ideas it seems !) On 4/10/06, Juergen [EMAIL PROTECTED] wrote: I mean workingMemory.assertObject(new String(A)); workingMemory.assertObject(new String(A)); would currently assert both strings into working memory, whereas if it would check not for identityHashCode but with equals, the second assert would have no effect. When during experimentation with rule engines I switched from jess (where it is done with equals I think) to drools 2 I first experienced problems due to this differences (also did not find much in both engines docu), leading to my question if I could customize drools behaviour. As one can always write a wrapper for drools assertObject to make such checks, and lots of other users probably dont need, my request is not important. Juergen Michael Neale wrote: so you mean p1 : Person() p2 : Person() eval ( p1.equals(p2) ) (but presumably a shorthand form?) On 4/8/06, Mark Proctor [EMAIL PROTECTED] wrote: We hadn't planned it, not promising anything - but I'll see how things pan out, may be we will get time. Mark Juergen wrote: ad. Can object equality for assertion be customized? Drools 3 still seems to use IdentityMap with System.identityHashCode (). Is it planned to be customizeable e.g. with equals() in 3.0? Michael Neale wrote: Short answer, not easily with Drools 2. But yes, with Drools 3. On 3/22/06, Juergen [EMAIL PROTECTED] wrote: I recently looked into drools after experimenting with JESS and got a few questions I could not look up in the drools documentation: - Exists a condition to test for non-existence of a matching object/fact? -- If yes, how to use it for own domain specific language conditions - How is sharing of conditions/nodes between productions implemented in drools, one of the main benefits of the rete algorithm? -- How is the equality of conditions defined for java smf? via textual equality of the condition's java code? -- How can equality of conditions for sharing be defined for domain specific language conditions? e.g. Conway's game of life (slightly modified dsl) rule name=kill the overcrowded conway:cellIsAlive cellName=cell/ conway:cellIsOverCrowded cellName=cell/ conway:killCell cellName=cell/ /rule rule name=kill the lonely conway:cellIsAlive cellName=cell/ conway:cellIsLonely
Re: [drools-user] Drools 3, RHS special names, indirect assert
Assert is just replaced with workingMemory.assertOjbect ( object ) anyway. It's just a bit of regexp we apply to make things easier for users. BTW this is what mandarax has to say about JSR94: A: Mandarax does not (yet) support JSR-94 http://www.jcp.org/jsr/detail/094.jsp. The reason is that this proposal is so general that it is almost useless. We are monitoring the JSR-94 efforts, and perhaps add support later. We support JSR94, but my feelings are just the same - just say NO! :) Mark Juergen wrote: Questions on assert in RHS: 1) is it the same to call special assert() in RHS vs. indirectly calling JSR 94 Rule session method addObject() (or WorkingMemory.assert()) in RHS? would the latter way of asserting interfere with the active rule execution? rule A when ... then assert(new String(A)) someMethodCallsThisEnginesWorkingMemoryAssert(new String(B)) someMethodCallsThisEnginesJSR94SessionAddObject(new String(C)) end 2) what other special names/objects/methods do exist, that can be used in a RHS code block (like special drools object in drools 2.5)? Haven't found much on that in current docu. My questions relate to the idea to wrapping assert with code to check for equality. Michael Neale wrote: if there is enough demand for it, we may be able to make it some working memory wide configuration option - certainly. Submit a JIRA request if you like, may come in handy (certainly will for you). But not as the default, as not everyone implements equals() correctly ! On 4/11/06, Juergen [EMAIL PROTECTED] wrote: Quick'n dirty I could make drools 3 do it the way I would prefer - in the context of my current problem and datastructures involved - by modifying: org.drools.reteoo.WorkingMemoryImpl, line 95f (rev. 3509): replace: /** Object-to-handle mapping. */ private Map identityMap = new IdentityMap(); by: /** Object-to-handle mapping. */ private Map identityMap = new java.util.HashMap(); (not considering side effects, identityMap type cast problems, ...) Then org.drools.reteoo.WorkingMemoryImpl, assertObject (line 422, rev. 3509): FactHandleImpl handle = (FactHandleImpl) this.identityMap.get( object ); would return first As handle when the second A is asserted, refering to the example in my former posting. I expected some way to customize the behaviour of the working memory, basically by choosing between either of the Maps. But as mentioned, such behaviour might not be desirable by others (they probably want A being asserted twice and handled as two different objects) and even if not customizable in drools itself, it can most likely be done by wrapping assertObject and managing your own object-to-handle map plus taking care not to use assert directly in RHS. I first wrongly thought logical assertions had something to do with this, but I guess that relates more to the 'logical' conditional element in jess and logical dependencies among facts. Michael Neale wrote: what is your expectations on how it should work? (everyone has different ideas it seems !) On 4/10/06, Juergen [EMAIL PROTECTED] wrote: I mean workingMemory.assertObject(new String(A)); workingMemory.assertObject(new String(A)); would currently assert both strings into working memory, whereas if it would check not for identityHashCode but with equals, the second assert would have no effect. When during experimentation with rule engines I switched from jess (where it is done with equals I think) to drools 2 I first experienced problems due to this differences (also did not find much in both engines docu), leading to my question if I could customize drools behaviour. As one can always write a wrapper for drools assertObject to make such checks, and lots of other users probably dont need, my request is not important. Juergen Michael Neale wrote: so you mean p1 : Person() p2 : Person() eval ( p1.equals(p2) ) (but presumably a shorthand form?) On 4/8/06, Mark Proctor [EMAIL PROTECTED] wrote: We hadn't planned it, not promising anything - but I'll see how things pan out, may be we will get time. Mark Juergen wrote: ad. Can object equality for assertion be customized? Drools 3 still seems to use IdentityMap with System.identityHashCode (). Is it planned to be customizeable e.g. with equals() in 3.0? Michael Neale wrote: Short answer, not easily with Drools 2. But yes, with Drools 3. On 3/22/06, Juergen [EMAIL PROTECTED] wrote: I recently looked into drools after experimenting with JESS and got a few questions I could not look up in the drools documentation: - Exists a condition to test for non-existence of a matching object/fact? -- If yes, how to use it for own domain specific language conditions - How is sharing of conditions/nodes between productions implemented in drools, one of the main benefits of the rete algorithm?