Re: [rules-users] @key declarations for a type - What's under the hood?
Forgot the rule that creates the output :-) rule isConnected when $r1: Room() $r2: Room( this != $r1 ) $d: Door( fromRoom == $r1, toRoom == $r2 ) then System.out.println( $d + " connects " + $r1 + " and " + $r1 ); end -W On 27/02/2014, Wolfgang Laun wrote: > Works as you'd exprect it - and here we go: > > declare Thing >size : int > end > > // A room is also a thing > declare Room extends Thing > name : String @key > end > > // A door is a pathway between two rooms > declare Door extends Thing >fromRoom : Room @key >toRoom : Room @key > end > > rule "startup" > when > then >Room kit = new Room("kitchen"); >kit.setSize( 10 ); >insert( kit ); >Room off = new Room("office"); >kit.setSize( 15 ); >insert( off ); >Door kitoff = new Door( kit, off ); >insert( kitoff ); > end > > Output: > > Door( size=0, fromRoom=Room( size=15, name=kitchen ), toRoom=Room( > size=0, name=office ) ) connects Room( size=15, name=kitchen ) and > Room( size=15, name=kitchen ) > > -W > > > > On 27/02/2014, Matthew Versaggi wrote: >> But what if you now have 2 declare statements in which one defines itself >> in terms of the other ... >> >> // A room is also a thing >> declare Room extends Thing >> name : String @key >> end >> >> One would instantiate an object like this: >> Room room = new Room("office"); >> >> >> // A door is a pathway between two rooms >> declare Door extends Thing >>fromRoom : Room @key >>toRoom : Room @key >> end >> >> How would one instantiate an object of 'Door' ? >> >> >> >> On Wed, Feb 26, 2014 at 5:11 PM, Edson Tirelli >> wrote: >> >>> >>>Drools bytecode generates these beans without generating java source >>> code (if you are using the declare, not the data modeller). Having said >>> that, it is very simple: >>> >>> declare Here >>> location: String @key >>> end >>> >>>Generates a java class roughly equivalent to: >>> >>> public class Here implements Serializable { >>>private String location; >>> >>>public Here() {} >>> >>>public Here( String location ) { >>> this.location = location; >>>} >>> >>>public String getLocation() { return location; } >>>public void setLocation(String location) { this.location = location; >>> } >>> >>>// generates a toString() >>> >>>// generates a hashCode()/equals() method that use the location's >>> hashcode()/equals() >>> } >>> >>>I did this from memory, but it is pretty much all it does. Nothing >>> complex there, just a javabean really. >>> >>>The difference to not using @key is that the hashCode()/equals() >>> methods would not take "location" in consideration, and in this case, >>> since >>> there are no other attributes, would then rely on system identity. >>> >>>Edson >>> >>> >>> >>> >>> >>> On Wed, Feb 26, 2014 at 2:23 PM, profversaggi >>> wrote: >>> I was looking for something along the lines of a method of inspecting the resulting code of any arbitrary @key declarations I might want to deploy. Is there such a way? -- View this message in context: http://drools.46999.n3.nabble.com/key-declarations-for-a-type-What-s-under-the-hood-tp4028343p4028346.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users >>> >>> >>> >>> -- >>> Edson Tirelli >>> Principal Software Engineer >>> Red Hat Business Systems and Intelligence Group >>> >>> >>> ___ >>> rules-users mailing list >>> rules-users@lists.jboss.org >>> https://lists.jboss.org/mailman/listinfo/rules-users >>> >> >> >> >> -- >> # >> Matthew R. Versaggi, President & CEO >> Versaggi Information Systems, Inc. >> Adjunct Professor of eBusiness DePaul University >> Email: mailto:m...@versaggi.com, profversa...@gmail.com >> M: 630-292-8422 >> LinkedIn: http://www.linkedin.com/in/versaggi >> # >> > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] @key declarations for a type - What's under the hood?
Works as you'd exprect it - and here we go: declare Thing size : int end // A room is also a thing declare Room extends Thing name : String @key end // A door is a pathway between two rooms declare Door extends Thing fromRoom : Room @key toRoom : Room @key end rule "startup" when then Room kit = new Room("kitchen"); kit.setSize( 10 ); insert( kit ); Room off = new Room("office"); kit.setSize( 15 ); insert( off ); Door kitoff = new Door( kit, off ); insert( kitoff ); end Output: Door( size=0, fromRoom=Room( size=15, name=kitchen ), toRoom=Room( size=0, name=office ) ) connects Room( size=15, name=kitchen ) and Room( size=15, name=kitchen ) -W On 27/02/2014, Matthew Versaggi wrote: > But what if you now have 2 declare statements in which one defines itself > in terms of the other ... > > // A room is also a thing > declare Room extends Thing > name : String @key > end > > One would instantiate an object like this: > Room room = new Room("office"); > > > // A door is a pathway between two rooms > declare Door extends Thing >fromRoom : Room @key >toRoom : Room @key > end > > How would one instantiate an object of 'Door' ? > > > > On Wed, Feb 26, 2014 at 5:11 PM, Edson Tirelli > wrote: > >> >>Drools bytecode generates these beans without generating java source >> code (if you are using the declare, not the data modeller). Having said >> that, it is very simple: >> >> declare Here >> location: String @key >> end >> >>Generates a java class roughly equivalent to: >> >> public class Here implements Serializable { >>private String location; >> >>public Here() {} >> >>public Here( String location ) { >> this.location = location; >>} >> >>public String getLocation() { return location; } >>public void setLocation(String location) { this.location = location; } >> >>// generates a toString() >> >>// generates a hashCode()/equals() method that use the location's >> hashcode()/equals() >> } >> >>I did this from memory, but it is pretty much all it does. Nothing >> complex there, just a javabean really. >> >>The difference to not using @key is that the hashCode()/equals() >> methods would not take "location" in consideration, and in this case, >> since >> there are no other attributes, would then rely on system identity. >> >>Edson >> >> >> >> >> >> On Wed, Feb 26, 2014 at 2:23 PM, profversaggi >> wrote: >> >>> I was looking for something along the lines of a method of inspecting >>> the >>> resulting code of any arbitrary @key declarations I might want to >>> deploy. >>> Is >>> there such a way? >>> >>> >>> >>> -- >>> View this message in context: >>> http://drools.46999.n3.nabble.com/key-declarations-for-a-type-What-s-under-the-hood-tp4028343p4028346.html >>> Sent from the Drools: User forum mailing list archive at Nabble.com. >>> ___ >>> rules-users mailing list >>> rules-users@lists.jboss.org >>> https://lists.jboss.org/mailman/listinfo/rules-users >>> >> >> >> >> -- >> Edson Tirelli >> Principal Software Engineer >> Red Hat Business Systems and Intelligence Group >> >> >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > > > > -- > # > Matthew R. Versaggi, President & CEO > Versaggi Information Systems, Inc. > Adjunct Professor of eBusiness DePaul University > Email: mailto:m...@versaggi.com, profversa...@gmail.com > M: 630-292-8422 > LinkedIn: http://www.linkedin.com/in/versaggi > # > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] @key declarations for a type - What's under the hood?
There are no fancy hidden things in this bean generator, so your Door would have an empty constructor and a constructor with two Room parameters: Door door = new Door( fromRoom, toRoom ); Edson On Thu, Feb 27, 2014 at 11:24 AM, Matthew Versaggi wrote: > But what if you now have 2 declare statements in which one defines itself > in terms of the other ... > > // A room is also a thing > declare Room extends Thing > name : String @key > end > > One would instantiate an object like this: > Room room = new Room("office"); > > > // A door is a pathway between two rooms > declare Door extends Thing >fromRoom : Room @key >toRoom : Room @key > end > > How would one instantiate an object of 'Door' ? > > > > On Wed, Feb 26, 2014 at 5:11 PM, Edson Tirelli wrote: > >> >>Drools bytecode generates these beans without generating java source >> code (if you are using the declare, not the data modeller). Having said >> that, it is very simple: >> >> declare Here >> location: String @key >> end >> >>Generates a java class roughly equivalent to: >> >> public class Here implements Serializable { >>private String location; >> >>public Here() {} >> >>public Here( String location ) { >> this.location = location; >>} >> >>public String getLocation() { return location; } >>public void setLocation(String location) { this.location = location; } >> >>// generates a toString() >> >>// generates a hashCode()/equals() method that use the location's >> hashcode()/equals() >> } >> >>I did this from memory, but it is pretty much all it does. Nothing >> complex there, just a javabean really. >> >>The difference to not using @key is that the hashCode()/equals() >> methods would not take "location" in consideration, and in this case, since >> there are no other attributes, would then rely on system identity. >> >>Edson >> >> >> >> >> >> On Wed, Feb 26, 2014 at 2:23 PM, profversaggi wrote: >> >>> I was looking for something along the lines of a method of inspecting the >>> resulting code of any arbitrary @key declarations I might want to >>> deploy. Is >>> there such a way? >>> >>> >>> >>> -- >>> View this message in context: >>> http://drools.46999.n3.nabble.com/key-declarations-for-a-type-What-s-under-the-hood-tp4028343p4028346.html >>> Sent from the Drools: User forum mailing list archive at Nabble.com. >>> ___ >>> rules-users mailing list >>> rules-users@lists.jboss.org >>> https://lists.jboss.org/mailman/listinfo/rules-users >>> >> >> >> >> -- >> Edson Tirelli >> Principal Software Engineer >> Red Hat Business Systems and Intelligence Group >> >> >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > > > > -- > # > Matthew R. Versaggi, President & CEO > Versaggi Information Systems, Inc. > Adjunct Professor of eBusiness DePaul University > Email: mailto:m...@versaggi.com, profversa...@gmail.com > M: 630-292-8422 > LinkedIn: http://www.linkedin.com/in/versaggi > # > > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > -- Edson Tirelli Principal Software Engineer Red Hat Business Systems and Intelligence Group ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] @key declarations for a type - What's under the hood?
But what if you now have 2 declare statements in which one defines itself in terms of the other ... // A room is also a thing declare Room extends Thing name : String @key end One would instantiate an object like this: Room room = new Room("office"); // A door is a pathway between two rooms declare Door extends Thing fromRoom : Room @key toRoom : Room @key end How would one instantiate an object of 'Door' ? On Wed, Feb 26, 2014 at 5:11 PM, Edson Tirelli wrote: > >Drools bytecode generates these beans without generating java source > code (if you are using the declare, not the data modeller). Having said > that, it is very simple: > > declare Here > location: String @key > end > >Generates a java class roughly equivalent to: > > public class Here implements Serializable { >private String location; > >public Here() {} > >public Here( String location ) { > this.location = location; >} > >public String getLocation() { return location; } >public void setLocation(String location) { this.location = location; } > >// generates a toString() > >// generates a hashCode()/equals() method that use the location's > hashcode()/equals() > } > >I did this from memory, but it is pretty much all it does. Nothing > complex there, just a javabean really. > >The difference to not using @key is that the hashCode()/equals() > methods would not take "location" in consideration, and in this case, since > there are no other attributes, would then rely on system identity. > >Edson > > > > > > On Wed, Feb 26, 2014 at 2:23 PM, profversaggi wrote: > >> I was looking for something along the lines of a method of inspecting the >> resulting code of any arbitrary @key declarations I might want to deploy. >> Is >> there such a way? >> >> >> >> -- >> View this message in context: >> http://drools.46999.n3.nabble.com/key-declarations-for-a-type-What-s-under-the-hood-tp4028343p4028346.html >> Sent from the Drools: User forum mailing list archive at Nabble.com. >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > > > > -- > Edson Tirelli > Principal Software Engineer > Red Hat Business Systems and Intelligence Group > > > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > -- # Matthew R. Versaggi, President & CEO Versaggi Information Systems, Inc. Adjunct Professor of eBusiness DePaul University Email: mailto:m...@versaggi.com, profversa...@gmail.com M: 630-292-8422 LinkedIn: http://www.linkedin.com/in/versaggi # ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] @key declarations for a type - What's under the hood?
Awesome! Thank you! :-) On Wed, Feb 26, 2014 at 5:11 PM, Edson Tirelli wrote: > >Drools bytecode generates these beans without generating java source > code (if you are using the declare, not the data modeller). Having said > that, it is very simple: > > declare Here > location: String @key > end > >Generates a java class roughly equivalent to: > > public class Here implements Serializable { >private String location; > >public Here() {} > >public Here( String location ) { > this.location = location; >} > >public String getLocation() { return location; } >public void setLocation(String location) { this.location = location; } > >// generates a toString() > >// generates a hashCode()/equals() method that use the location's > hashcode()/equals() > } > >I did this from memory, but it is pretty much all it does. Nothing > complex there, just a javabean really. > >The difference to not using @key is that the hashCode()/equals() > methods would not take "location" in consideration, and in this case, since > there are no other attributes, would then rely on system identity. > >Edson > > > > > > On Wed, Feb 26, 2014 at 2:23 PM, profversaggi wrote: > >> I was looking for something along the lines of a method of inspecting the >> resulting code of any arbitrary @key declarations I might want to deploy. >> Is >> there such a way? >> >> >> >> -- >> View this message in context: >> http://drools.46999.n3.nabble.com/key-declarations-for-a-type-What-s-under-the-hood-tp4028343p4028346.html >> Sent from the Drools: User forum mailing list archive at Nabble.com. >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > > > > -- > Edson Tirelli > Principal Software Engineer > Red Hat Business Systems and Intelligence Group > > > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > -- # Matthew R. Versaggi, President & CEO Versaggi Information Systems, Inc. Adjunct Professor of eBusiness DePaul University Email: mailto:m...@versaggi.com, profversa...@gmail.com M: 630-292-8422 LinkedIn: http://www.linkedin.com/in/versaggi # ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] @key declarations for a type - What's under the hood?
Drools bytecode generates these beans without generating java source code (if you are using the declare, not the data modeller). Having said that, it is very simple: declare Here location: String @key end Generates a java class roughly equivalent to: public class Here implements Serializable { private String location; public Here() {} public Here( String location ) { this.location = location; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } // generates a toString() // generates a hashCode()/equals() method that use the location's hashcode()/equals() } I did this from memory, but it is pretty much all it does. Nothing complex there, just a javabean really. The difference to not using @key is that the hashCode()/equals() methods would not take "location" in consideration, and in this case, since there are no other attributes, would then rely on system identity. Edson On Wed, Feb 26, 2014 at 2:23 PM, profversaggi wrote: > I was looking for something along the lines of a method of inspecting the > resulting code of any arbitrary @key declarations I might want to deploy. > Is > there such a way? > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/key-declarations-for-a-type-What-s-under-the-hood-tp4028343p4028346.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > -- Edson Tirelli Principal Software Engineer Red Hat Business Systems and Intelligence Group ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] @key declarations for a type - What's under the hood?
In recent versions, knowledge bases allow to retrieve "fact types" by package and class name. Those may be the descriptor classes that you are looking for On 02/26/2014 08:23 PM, profversaggi wrote: > I was looking for something along the lines of a method of inspecting the > resulting code of any arbitrary @key declarations I might want to deploy. Is > there such a way? > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/key-declarations-for-a-type-What-s-under-the-hood-tp4028343p4028346.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] @key declarations for a type - What's under the hood?
I was looking for something along the lines of a method of inspecting the resulting code of any arbitrary @key declarations I might want to deploy. Is there such a way? -- View this message in context: http://drools.46999.n3.nabble.com/key-declarations-for-a-type-What-s-under-the-hood-tp4028343p4028346.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] @key declarations for a type - What's under the hood?
The declare results in a bean, with constructors according to what you have written, with getters and setters, and methods overriding toText, equals and hashCode. -W On 26/02/2014, profversaggi wrote: > Is there any way to interrogate exactly, as in get a printed representation > of what goes on under the hood for one of these type of declarations ? > > As an example: (as per the docs) for a declared type like the following: > > declare Person > *firstName : String @key* > *lastName : String @key* > age : int > end > > The compiler will implicitly generate 3 constructors: one without > parameters, > one with the @key fields, and one with all fields. > > Person() // parameterless constructor > Person( String firstName, String lastName ) > Person( String firstName, String lastName, int age ) > > ...creating an instance using the @key constructor > > /Person person = new Person( "John", "Doe" );/ > > > > So lets say I do the following: > > > declare Here > location: String @key > end > > I understand that it does the above, but it *also* lets me do this as well: > > *Here here = new Here("kitchen"); > System.out.println( here ); > System.out.println( here.getLocation(); ); > $lh : Here (location == "kitchen") > System.out.println( "You are in the " + $lh.getLocation() );* > > And get ... > > *Here( location=kitchen ) > kitchen > You are in the kitchen* > > ... from various rules I've created ... so there is a lot going on under > the > hood, I just want to get a complete inventory of what that is and how I > inspect it for more complex type declarations. > > Any ideas? > > > -matt > > > > > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/key-declarations-for-a-type-What-s-under-the-hood-tp4028343.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] @key declarations for a type - What's under the hood?
Is there any way to interrogate exactly, as in get a printed representation of what goes on under the hood for one of these type of declarations ? As an example: (as per the docs) for a declared type like the following: declare Person *firstName : String @key* *lastName : String @key* age : int end The compiler will implicitly generate 3 constructors: one without parameters, one with the @key fields, and one with all fields. Person() // parameterless constructor Person( String firstName, String lastName ) Person( String firstName, String lastName, int age ) ...creating an instance using the @key constructor /Person person = new Person( "John", "Doe" );/ So lets say I do the following: declare Here location: String @key end I understand that it does the above, but it *also* lets me do this as well: *Here here = new Here("kitchen"); System.out.println( here ); System.out.println( here.getLocation(); ); $lh : Here (location == "kitchen") System.out.println( "You are in the " + $lh.getLocation() );* And get ... *Here( location=kitchen ) kitchen You are in the kitchen* ... from various rules I've created ... so there is a lot going on under the hood, I just want to get a complete inventory of what that is and how I inspect it for more complex type declarations. Any ideas? -matt -- View this message in context: http://drools.46999.n3.nabble.com/key-declarations-for-a-type-What-s-under-the-hood-tp4028343.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users