|
View:
New views
11 Messages
—
Rating Filter:
Alert me
|
|
|
JESS: Accessing Java objects fields from a defruleHi there,
I have a little question for you I can't fix by myself: how to access the fields of a java Object that is itself a field of an other java object? Here is a tiny sample : Object Door + int weight + String color Object House + Door myDoor Now I give the House to the Rete engine, how can I access (and manipulate) for example the weight of my door? By now I just can display it like this: (defrule mydoor (House (myDoor ?myDoor)) => (printout t "Weight of my house's door :" ?myDoor.weight crlf) ) But the thing I want to do is to catch that weight to make some checks on it, then displaying the checks' results (for examples, is my door heavier than 25kg). Thanks for help Romain Van der Keilen -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- |
|
|
Re: JESS: Accessing Java objects fields from a defruleFirst, you bind to the contained object, and then you locate the containing object.
(defrule mydoor ?door <- (Door (weight ?weight)(color ?color)) (House (myDoor ?door)(owner "Mick")) => (printout t "Weight of Mick's door :" ?weight crlf) ) Restrictions on weight or color, e.g., to paint red doors black ;-) can be added in the usual way. -W On Fri, Aug 21, 2009 at 12:12 PM, Romain Van der Keilen <Romain.VanderKeilen@...> wrote: Hi there, |
|
|
Re: JESS: Accessing Java objects fields from a defruleAre you asking how to write a rule that performs some test on the weight of a door? The "dotted variable" notation is a recently- introduce shorthand that won't work on the left-hand-sides of rules; but you can use the older "get-member" function: (defrule mydoor (House (myDoor ?myDoor&:(> (get-member ?myDoor weight) 25))) => (printout t "Weight of my house's door :" ?myDoor.weight crlf) ) The name "get-member" is quite unwieldly, and you might want to replace it with a custom "weight" function like (deffunction weight (?door) (return (get-member ?door weight))) Then you could write the pattern as (House (myDoor ?myDoor&:(> (weight ?myDoor) 25))) On Aug 21, 2009, at 6:12 AM, Romain Van der Keilen wrote: > Hi there, > > I have a little question for you I can't fix by myself: how to > access the fields of a java Object that is itself a field of an > other java object? > Here is a tiny sample : > > Object Door > + int weight > + String color > > Object House > + Door myDoor > > Now I give the House to the Rete engine, how can I access (and > manipulate) for example the weight of my door? > > By now I just can display it like this: > (defrule mydoor > (House (myDoor ?myDoor)) > => > (printout t "Weight of my house's door :" ?myDoor.weight crlf) > ) > But the thing I want to do is to catch that weight to make some > checks on it, then displaying the checks' results (for examples, is > my door heavier than 25kg). > > Thanks for help > > Romain Van der Keilen > > -------------------------------------------------------------------- --------------------------------------------------------- Ernest Friedman-Hill Informatics & Decision Sciences Phone: (925) 294-2154 Sandia National Labs PO Box 969, MS 9012 ejfried@... Livermore, CA 94550 http://www.jessrules.com -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- |
|
|
RE: JESS: Accessing Java objects fields from a defruleThanks for the response, You’ve exactly put the finger on what I wish do, but I just
tried that and I’ve no output :s From: owner-jess-users@...
[mailto:owner-jess-users@...] On Behalf Of Wolfgang Laun First, you bind to the
contained object, and then you locate the containing object. On Fri, Aug 21, 2009 at 12:12 PM, Romain Van der Keilen <Romain.VanderKeilen@...>
wrote: Hi there, |
|
|
RE: JESS: Accessing Java objects fields from a defruleHere is the exact code I use:
(import be.uniway.rvk.jesstest.model.*) (deftemplate VirtualSite (declare (from-class VirtualSite))) (deftemplate InetModem (declare (from-class InetModem))) (defrule validate-virtualsite "Just put the validate attribute to true!" ?inetModem <- (InetModem (publicIpAddress ?publicIpAddress)) (VirtualSite (inetModem ?inetModem)) => (printout t "Internet modem address: " ?publicIpAddress crlf) ) Using: VirtualSite + private InetModem inetModem InetModem + private String publicIpAddress Maybe the private fields are disturbing Jess? Regards, Romain Van der Keilen. From: owner-jess-users@... [mailto:owner-jess-users@...] On Behalf Of Romain Van der Keilen Sent: vendredi 21 août 2009 16:15 To: jess-users@... Subject: RE: JESS: Accessing Java objects fields from a defrule Thanks for the response, You've exactly put the finger on what I wish do, but I just tried that and I've no output :s From: owner-jess-users@... [mailto:owner-jess-users@...] On Behalf Of Wolfgang Laun Sent: vendredi 21 août 2009 15:41 To: jess-users@... Subject: Re: JESS: Accessing Java objects fields from a defrule First, you bind to the contained object, and then you locate the containing object. (defrule mydoor ?door <- (Door (weight ?weight)(color ?color)) (House (myDoor ?door)(owner "Mick")) => (printout t "Weight of Mick's door :" ?weight crlf) ) Restrictions on weight or color, e.g., to paint red doors black ;-) can be added in the usual way. -W On Fri, Aug 21, 2009 at 12:12 PM, Romain Van der Keilen <Romain.VanderKeilen@...> wrote: Hi there, I have a little question for you I can't fix by myself: how to access the fields of a java Object that is itself a field of an other java object? Here is a tiny sample : Object Door + int weight + String color Object House + Door myDoor Now I give the House to the Rete engine, how can I access (and manipulate) for example the weight of my door? By now I just can display it like this: (defrule mydoor (House (myDoor ?myDoor)) => (printout t "Weight of my house's door :" ?myDoor.weight crlf) ) But the thing I want to do is to catch that weight to make some checks on it, then displaying the checks' results (for examples, is my door heavier than 25kg). Thanks for help Romain Van der Keilen -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- |
|
|
Re: JESS: Accessing Java objects fields from a defruleNormally, slots in Jess templates are based on JavaBeans properties -- i.e., a method named "getInetModem" will give rise to a slot named "inetModem". If you include the "include-variables TRUE" declaration, then slots will also be created based on *public* member variables. Under no circumstances will Jess create slots based on private member variables. On Aug 21, 2009, at 10:39 AM, Romain Van der Keilen wrote: > Here is the exact code I use: > > (import be.uniway.rvk.jesstest.model.*) > (deftemplate VirtualSite (declare (from-class VirtualSite))) > (deftemplate InetModem (declare (from-class InetModem))) > > (defrule validate-virtualsite > "Just put the validate attribute to true!" > ?inetModem <- (InetModem (publicIpAddress ?publicIpAddress)) > (VirtualSite (inetModem ?inetModem)) > => > (printout t "Internet modem address: " ?publicIpAddress crlf) > ) > > > Using: > > VirtualSite > + private InetModem inetModem > > InetModem > + private String publicIpAddress > > Maybe the private fields are disturbing Jess? > > Regards, > > Romain Van der Keilen. > > > > From: owner-jess-users@... [mailto:owner-jess- > users@...] On Behalf Of Romain Van der Keilen > Sent: vendredi 21 août 2009 16:15 > To: jess-users@... > Subject: RE: JESS: Accessing Java objects fields from a defrule > > Thanks for the response, > > You've exactly put the finger on what I wish do, but I just tried > that and I've no output :s > > From: owner-jess-users@... [mailto:owner-jess- > users@...] On Behalf Of Wolfgang Laun > Sent: vendredi 21 août 2009 15:41 > To: jess-users@... > Subject: Re: JESS: Accessing Java objects fields from a defrule > > First, you bind to the contained object, and then you locate the > containing object. > > (defrule mydoor > ?door <- (Door (weight ?weight)(color ?color)) > (House (myDoor ?door)(owner "Mick")) > => > (printout t "Weight of Mick's door :" ?weight crlf) > ) > > Restrictions on weight or color, e.g., to paint red doors black ;-) > can be added in the usual way. > > -W > On Fri, Aug 21, 2009 at 12:12 PM, Romain Van der Keilen <Romain.VanderKeilen@... > > wrote: > Hi there, > > I have a little question for you I can't fix by myself: how to > access the fields of a java Object that is itself a field of an > other java object? > Here is a tiny sample : > > Object Door > + int weight > + String color > > Object House > + Door myDoor > > Now I give the House to the Rete engine, how can I access (and > manipulate) for example the weight of my door? > > By now I just can display it like this: > (defrule mydoor > (House (myDoor ?myDoor)) > => > (printout t "Weight of my house's door :" ?myDoor.weight crlf) > ) > But the thing I want to do is to catch that weight to make some > checks on it, then displaying the checks' results (for examples, is > my door heavier than 25kg). > > Thanks for help > > Romain Van der Keilen > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users > you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@... > . > -------------------------------------------------------------------- > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users > you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@... > . > -------------------------------------------------------------------- --------------------------------------------------------- Ernest Friedman-Hill Informatics & Decision Sciences Phone: (925) 294-2154 Sandia National Labs PO Box 969, MS 9012 ejfried@... Livermore, CA 94550 http://www.jessrules.com -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- |
|
|
RE: JESS: Accessing Java objects fields from a defruleAll getters and setters are present, respecting the jababeans conventions:
Those methods are in Virtualsite public InetModem getInetModem() { return inetModem; } public void setInetModem(InetModem inetModem) { this.inetModem = inetModem; } And those are in InetModem public String getPublicIpAddress() { return publicIpAddress; } public void setPublicIpAddress(String publicIpAddress) { this.publicIpAddress = publicIpAddress; } So I don't really see what's wrong ... Thanks, Romain Van der Keilen. -----Original Message----- From: owner-jess-users@... [mailto:owner-jess-users@...] On Behalf Of Ernest Friedman-Hill Sent: vendredi 21 août 2009 16:54 To: jess-users Subject: Re: JESS: Accessing Java objects fields from a defrule Normally, slots in Jess templates are based on JavaBeans properties -- i.e., a method named "getInetModem" will give rise to a slot named "inetModem". If you include the "include-variables TRUE" declaration, then slots will also be created based on *public* member variables. Under no circumstances will Jess create slots based on private member variables. On Aug 21, 2009, at 10:39 AM, Romain Van der Keilen wrote: > Here is the exact code I use: > > (import be.uniway.rvk.jesstest.model.*) > (deftemplate VirtualSite (declare (from-class VirtualSite))) > (deftemplate InetModem (declare (from-class InetModem))) > > (defrule validate-virtualsite > "Just put the validate attribute to true!" > ?inetModem <- (InetModem (publicIpAddress ?publicIpAddress)) > (VirtualSite (inetModem ?inetModem)) > => > (printout t "Internet modem address: " ?publicIpAddress crlf) > ) > > > Using: > > VirtualSite > + private InetModem inetModem > > InetModem > + private String publicIpAddress > > Maybe the private fields are disturbing Jess? > > Regards, > > Romain Van der Keilen. > > > > From: owner-jess-users@... [mailto:owner-jess- > users@...] On Behalf Of Romain Van der Keilen > Sent: vendredi 21 août 2009 16:15 > To: jess-users@... > Subject: RE: JESS: Accessing Java objects fields from a defrule > > Thanks for the response, > > You've exactly put the finger on what I wish do, but I just tried > that and I've no output :s > > From: owner-jess-users@... [mailto:owner-jess- > users@...] On Behalf Of Wolfgang Laun > Sent: vendredi 21 août 2009 15:41 > To: jess-users@... > Subject: Re: JESS: Accessing Java objects fields from a defrule > > First, you bind to the contained object, and then you locate the > containing object. > > (defrule mydoor > ?door <- (Door (weight ?weight)(color ?color)) > (House (myDoor ?door)(owner "Mick")) > => > (printout t "Weight of Mick's door :" ?weight crlf) > ) > > Restrictions on weight or color, e.g., to paint red doors black ;-) > can be added in the usual way. > > -W > On Fri, Aug 21, 2009 at 12:12 PM, Romain Van der Keilen <Romain.VanderKeilen@... > > wrote: > Hi there, > > I have a little question for you I can't fix by myself: how to > access the fields of a java Object that is itself a field of an > other java object? > Here is a tiny sample : > > Object Door > + int weight > + String color > > Object House > + Door myDoor > > Now I give the House to the Rete engine, how can I access (and > manipulate) for example the weight of my door? > > By now I just can display it like this: > (defrule mydoor > (House (myDoor ?myDoor)) > => > (printout t "Weight of my house's door :" ?myDoor.weight crlf) > ) > But the thing I want to do is to catch that weight to make some > checks on it, then displaying the checks' results (for examples, is > my door heavier than 25kg). > > Thanks for help > > Romain Van der Keilen > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users > you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@... > . > -------------------------------------------------------------------- > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users > you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@... > . > -------------------------------------------------------------------- --------------------------------------------------------- Ernest Friedman-Hill Informatics & Decision Sciences Phone: (925) 294-2154 Sandia National Labs PO Box 969, MS 9012 ejfried@... Livermore, CA 94550 http://www.jessrules.com -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- |
|
|
Re: JESS: Accessing Java objects fields from a defruleAh, OK, here's the thing: your patterns
?inetModem <- (InetModem (publicIpAddress ?publicIpAddress)) (VirtualSite (inetModem ?inetModem)) are checking that the jess.Fact object representing the InetModem in working memory is in the inetModem slot of the VirtualSite fact -- but it's not. The inetModem slot contains the actual Java InetModem object. You get at that object by using the OBJECT slot, not by binding the whole fact: (InetModem (publicIpAddress ?publicIpAddress) (OBJECT ?inetModem) (VirtualSite (inetModem ?inetModem)) That should do you. On Aug 21, 2009, at 11:04 AM, Romain Van der Keilen wrote: > All getters and setters are present, respecting the jababeans > conventions: > > Those methods are in Virtualsite > public InetModem getInetModem() { > return inetModem; > } > public void setInetModem(InetModem inetModem) { > this.inetModem = inetModem; > } > And those are in InetModem > public String getPublicIpAddress() { > return publicIpAddress; > } > public void setPublicIpAddress(String publicIpAddress) { > this.publicIpAddress = publicIpAddress; > } > > So I don't really see what's wrong ... > > Thanks, > > Romain Van der Keilen. > > -----Original Message----- > From: owner-jess-users@... [mailto:owner-jess- > users@...] On Behalf Of Ernest Friedman-Hill > Sent: vendredi 21 août 2009 16:54 > To: jess-users > Subject: Re: JESS: Accessing Java objects fields from a defrule > > > Normally, slots in Jess templates are based on JavaBeans properties -- > i.e., a method named "getInetModem" will give rise to a slot named > "inetModem". If you include the "include-variables TRUE" declaration, > then slots will also be created based on *public* member variables. > Under no circumstances will Jess create slots based on private member > variables. > > > > On Aug 21, 2009, at 10:39 AM, Romain Van der Keilen wrote: > >> Here is the exact code I use: >> >> (import be.uniway.rvk.jesstest.model.*) >> (deftemplate VirtualSite (declare (from-class VirtualSite))) >> (deftemplate InetModem (declare (from-class InetModem))) >> >> (defrule validate-virtualsite >> "Just put the validate attribute to true!" >> ?inetModem <- (InetModem (publicIpAddress ?publicIpAddress)) >> (VirtualSite (inetModem ?inetModem)) >> => >> (printout t "Internet modem address: " ?publicIpAddress crlf) >> ) >> >> >> Using: >> >> VirtualSite >> + private InetModem inetModem >> >> InetModem >> + private String publicIpAddress >> >> Maybe the private fields are disturbing Jess? >> >> Regards, >> >> Romain Van der Keilen. >> >> >> >> From: owner-jess-users@... [mailto:owner-jess- >> users@...] On Behalf Of Romain Van der Keilen >> Sent: vendredi 21 août 2009 16:15 >> To: jess-users@... >> Subject: RE: JESS: Accessing Java objects fields from a defrule >> >> Thanks for the response, >> >> You've exactly put the finger on what I wish do, but I just tried >> that and I've no output :s >> >> From: owner-jess-users@... [mailto:owner-jess- >> users@...] On Behalf Of Wolfgang Laun >> Sent: vendredi 21 août 2009 15:41 >> To: jess-users@... >> Subject: Re: JESS: Accessing Java objects fields from a defrule >> >> First, you bind to the contained object, and then you locate the >> containing object. >> >> (defrule mydoor >> ?door <- (Door (weight ?weight)(color ?color)) >> (House (myDoor ?door)(owner "Mick")) >> => >> (printout t "Weight of Mick's door :" ?weight crlf) >> ) >> >> Restrictions on weight or color, e.g., to paint red doors black ;-) >> can be added in the usual way. >> >> -W >> On Fri, Aug 21, 2009 at 12:12 PM, Romain Van der Keilen <Romain.VanderKeilen@... >>> wrote: >> Hi there, >> >> I have a little question for you I can't fix by myself: how to >> access the fields of a java Object that is itself a field of an >> other java object? >> Here is a tiny sample : >> >> Object Door >> + int weight >> + String color >> >> Object House >> + Door myDoor >> >> Now I give the House to the Rete engine, how can I access (and >> manipulate) for example the weight of my door? >> >> By now I just can display it like this: >> (defrule mydoor >> (House (myDoor ?myDoor)) >> => >> (printout t "Weight of my house's door :" ?myDoor.weight crlf) >> ) >> But the thing I want to do is to catch that weight to make some >> checks on it, then displaying the checks' results (for examples, is >> my door heavier than 25kg). >> >> Thanks for help >> >> Romain Van der Keilen >> >> >> >> -------------------------------------------------------------------- >> To unsubscribe, send the words 'unsubscribe jess-users >> you@...' >> in the BODY of a message to majordomo@..., NOT to the list >> (use your own address!) List problems? Notify owner-jess-users@... >> . >> -------------------------------------------------------------------- >> >> >> >> -------------------------------------------------------------------- >> To unsubscribe, send the words 'unsubscribe jess-users >> you@...' >> in the BODY of a message to majordomo@..., NOT to the list >> (use your own address!) List problems? Notify owner-jess-users@... >> . >> -------------------------------------------------------------------- > > --------------------------------------------------------- > Ernest Friedman-Hill > Informatics & Decision Sciences Phone: (925) 294-2154 > Sandia National Labs > PO Box 969, MS 9012 ejfried@... > Livermore, CA 94550 http://www.jessrules.com > > > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users > you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@... > . > -------------------------------------------------------------------- > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users > you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@... > . > -------------------------------------------------------------------- --------------------------------------------------------- Ernest Friedman-Hill Informatics & Decision Sciences, Sandia National Laboratories PO Box 969, MS 9012, Livermore, CA 94550 http://www.jessrules.com -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- |
|
|
Re: JESS: Accessing Java objects fields from a defruleOne more item that is needed. When shadow facts are created, the fact
variable, in your case ?inetModem is not InetModem instance, but the fact instance. Eacxh shadow fact has a slot called OBJECT that stores corresponding Jave instance. Your rule should be something like: (defrule validate-virtualsite "Just put the validate attribute to true!" ?inetModem <- (InetModem (publicIpAddress ?publicIpAddress) (OBJECT ?modemObj) (VirtualSite (inetModem ?modemObj)) => (printout t "Internet modem address: " ?publicIpAddress crlf) ) Dusan Sormaz Romain Van der Keilen wrote: > All getters and setters are present, respecting the jababeans conventions: > > Those methods are in Virtualsite > public InetModem getInetModem() { > return inetModem; > } > public void setInetModem(InetModem inetModem) { > this.inetModem = inetModem; > } > And those are in InetModem > public String getPublicIpAddress() { > return publicIpAddress; > } > public void setPublicIpAddress(String publicIpAddress) { > this.publicIpAddress = publicIpAddress; > } > > So I don't really see what's wrong ... > > Thanks, > > Romain Van der Keilen. > > -----Original Message----- > From: owner-jess-users@... [mailto:owner-jess-users@...] On Behalf Of Ernest Friedman-Hill > Sent: vendredi 21 août 2009 16:54 > To: jess-users > Subject: Re: JESS: Accessing Java objects fields from a defrule > > > Normally, slots in Jess templates are based on JavaBeans properties -- > i.e., a method named "getInetModem" will give rise to a slot named > "inetModem". If you include the "include-variables TRUE" declaration, > then slots will also be created based on *public* member variables. > Under no circumstances will Jess create slots based on private member > variables. > > > > On Aug 21, 2009, at 10:39 AM, Romain Van der Keilen wrote: > > >> Here is the exact code I use: >> >> (import be.uniway.rvk.jesstest.model.*) >> (deftemplate VirtualSite (declare (from-class VirtualSite))) >> (deftemplate InetModem (declare (from-class InetModem))) >> >> (defrule validate-virtualsite >> "Just put the validate attribute to true!" >> ?inetModem <- (InetModem (publicIpAddress ?publicIpAddress)) >> (VirtualSite (inetModem ?inetModem)) >> => >> (printout t "Internet modem address: " ?publicIpAddress crlf) >> ) >> >> >> Using: >> >> VirtualSite >> + private InetModem inetModem >> >> InetModem >> + private String publicIpAddress >> >> Maybe the private fields are disturbing Jess? >> >> Regards, >> >> Romain Van der Keilen. >> >> >> >> From: owner-jess-users@... [mailto:owner-jess- >> users@...] On Behalf Of Romain Van der Keilen >> Sent: vendredi 21 août 2009 16:15 >> To: jess-users@... >> Subject: RE: JESS: Accessing Java objects fields from a defrule >> >> Thanks for the response, >> >> You've exactly put the finger on what I wish do, but I just tried >> that and I've no output :s >> >> From: owner-jess-users@... [mailto:owner-jess- >> users@...] On Behalf Of Wolfgang Laun >> Sent: vendredi 21 août 2009 15:41 >> To: jess-users@... >> Subject: Re: JESS: Accessing Java objects fields from a defrule >> >> First, you bind to the contained object, and then you locate the >> containing object. >> >> (defrule mydoor >> ?door <- (Door (weight ?weight)(color ?color)) >> (House (myDoor ?door)(owner "Mick")) >> => >> (printout t "Weight of Mick's door :" ?weight crlf) >> ) >> >> Restrictions on weight or color, e.g., to paint red doors black ;-) >> can be added in the usual way. >> >> -W >> On Fri, Aug 21, 2009 at 12:12 PM, Romain Van der Keilen <Romain.VanderKeilen@... >> >>> wrote: >>> >> Hi there, >> >> I have a little question for you I can't fix by myself: how to >> access the fields of a java Object that is itself a field of an >> other java object? >> Here is a tiny sample : >> >> Object Door >> + int weight >> + String color >> >> Object House >> + Door myDoor >> >> Now I give the House to the Rete engine, how can I access (and >> manipulate) for example the weight of my door? >> >> By now I just can display it like this: >> (defrule mydoor >> (House (myDoor ?myDoor)) >> => >> (printout t "Weight of my house's door :" ?myDoor.weight crlf) >> ) >> But the thing I want to do is to catch that weight to make some >> checks on it, then displaying the checks' results (for examples, is >> my door heavier than 25kg). >> >> Thanks for help >> >> Romain Van der Keilen >> >> >> >> -------------------------------------------------------------------- >> To unsubscribe, send the words 'unsubscribe jess-users >> you@...' >> in the BODY of a message to majordomo@..., NOT to the list >> (use your own address!) List problems? Notify owner-jess-users@... >> . >> -------------------------------------------------------------------- >> >> >> >> -------------------------------------------------------------------- >> To unsubscribe, send the words 'unsubscribe jess-users >> you@...' >> in the BODY of a message to majordomo@..., NOT to the list >> (use your own address!) List problems? Notify owner-jess-users@... >> . >> -------------------------------------------------------------------- >> > > --------------------------------------------------------- > Ernest Friedman-Hill > Informatics & Decision Sciences Phone: (925) 294-2154 > Sandia National Labs > PO Box 969, MS 9012 ejfried@... > Livermore, CA 94550 http://www.jessrules.com > > > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@.... > -------------------------------------------------------------------- > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@.... > -------------------------------------------------------------------- > > > -- *************************************************** * Dusan Sormaz, PhD, Associate Professor * Ohio University * Department of Industrial and Systems Engineering * 284 Stocker Center, Athens, OH 45701-2979 * phone: (740) 593-1545 * fax: (740) 593-0778 * e-mail: sormaz@... * url: http://www.ent.ohiou.edu/~sormaz *************************************************** -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- |
|
|
RE: JESS: Accessing Java objects fields from a defruleI understand the principle.
That's true the following code give me an access to the java object: (defrule validate-virtualsite (VirtualSite (inetModem ?inetModem)) => (printout t "Virtual site: " ?inetModem crlf) ) With the following output : Virtual site: <Java-Object:be.uniway.rvk.jesstest.model.InetModem> But (because there's sadly a but) The notation with the Object slot doesn't seems to work. Eclipse warn me with this message if it can help: Created implied ordered template at token 'OBJECT' I'm completely lost :/ Thanks for your help! Romain Van der Keilen. -----Original Message----- From: owner-jess-users@... [mailto:owner-jess-users@...] On Behalf Of Ernest Friedman-Hill Sent: vendredi 21 août 2009 17:14 To: jess-users Subject: Re: JESS: Accessing Java objects fields from a defrule Ah, OK, here's the thing: your patterns ?inetModem <- (InetModem (publicIpAddress ?publicIpAddress)) (VirtualSite (inetModem ?inetModem)) are checking that the jess.Fact object representing the InetModem in working memory is in the inetModem slot of the VirtualSite fact -- but it's not. The inetModem slot contains the actual Java InetModem object. You get at that object by using the OBJECT slot, not by binding the whole fact: (InetModem (publicIpAddress ?publicIpAddress) (OBJECT ?inetModem) (VirtualSite (inetModem ?inetModem)) That should do you. On Aug 21, 2009, at 11:04 AM, Romain Van der Keilen wrote: > All getters and setters are present, respecting the jababeans > conventions: > > Those methods are in Virtualsite > public InetModem getInetModem() { > return inetModem; > } > public void setInetModem(InetModem inetModem) { > this.inetModem = inetModem; > } > And those are in InetModem > public String getPublicIpAddress() { > return publicIpAddress; > } > public void setPublicIpAddress(String publicIpAddress) { > this.publicIpAddress = publicIpAddress; > } > > So I don't really see what's wrong ... > > Thanks, > > Romain Van der Keilen. > > -----Original Message----- > From: owner-jess-users@... [mailto:owner-jess- > users@...] On Behalf Of Ernest Friedman-Hill > Sent: vendredi 21 août 2009 16:54 > To: jess-users > Subject: Re: JESS: Accessing Java objects fields from a defrule > > > Normally, slots in Jess templates are based on JavaBeans properties -- > i.e., a method named "getInetModem" will give rise to a slot named > "inetModem". If you include the "include-variables TRUE" declaration, > then slots will also be created based on *public* member variables. > Under no circumstances will Jess create slots based on private member > variables. > > > > On Aug 21, 2009, at 10:39 AM, Romain Van der Keilen wrote: > >> Here is the exact code I use: >> >> (import be.uniway.rvk.jesstest.model.*) >> (deftemplate VirtualSite (declare (from-class VirtualSite))) >> (deftemplate InetModem (declare (from-class InetModem))) >> >> (defrule validate-virtualsite >> "Just put the validate attribute to true!" >> ?inetModem <- (InetModem (publicIpAddress ?publicIpAddress)) >> (VirtualSite (inetModem ?inetModem)) >> => >> (printout t "Internet modem address: " ?publicIpAddress crlf) >> ) >> >> >> Using: >> >> VirtualSite >> + private InetModem inetModem >> >> InetModem >> + private String publicIpAddress >> >> Maybe the private fields are disturbing Jess? >> >> Regards, >> >> Romain Van der Keilen. >> >> >> >> From: owner-jess-users@... [mailto:owner-jess- >> users@...] On Behalf Of Romain Van der Keilen >> Sent: vendredi 21 août 2009 16:15 >> To: jess-users@... >> Subject: RE: JESS: Accessing Java objects fields from a defrule >> >> Thanks for the response, >> >> You've exactly put the finger on what I wish do, but I just tried >> that and I've no output :s >> >> From: owner-jess-users@... [mailto:owner-jess- >> users@...] On Behalf Of Wolfgang Laun >> Sent: vendredi 21 août 2009 15:41 >> To: jess-users@... >> Subject: Re: JESS: Accessing Java objects fields from a defrule >> >> First, you bind to the contained object, and then you locate the >> containing object. >> >> (defrule mydoor >> ?door <- (Door (weight ?weight)(color ?color)) >> (House (myDoor ?door)(owner "Mick")) >> => >> (printout t "Weight of Mick's door :" ?weight crlf) >> ) >> >> Restrictions on weight or color, e.g., to paint red doors black ;-) >> can be added in the usual way. >> >> -W >> On Fri, Aug 21, 2009 at 12:12 PM, Romain Van der Keilen <Romain.VanderKeilen@... >>> wrote: >> Hi there, >> >> I have a little question for you I can't fix by myself: how to >> access the fields of a java Object that is itself a field of an >> other java object? >> Here is a tiny sample : >> >> Object Door >> + int weight >> + String color >> >> Object House >> + Door myDoor >> >> Now I give the House to the Rete engine, how can I access (and >> manipulate) for example the weight of my door? >> >> By now I just can display it like this: >> (defrule mydoor >> (House (myDoor ?myDoor)) >> => >> (printout t "Weight of my house's door :" ?myDoor.weight crlf) >> ) >> But the thing I want to do is to catch that weight to make some >> checks on it, then displaying the checks' results (for examples, is >> my door heavier than 25kg). >> >> Thanks for help >> >> Romain Van der Keilen >> >> >> >> -------------------------------------------------------------------- >> To unsubscribe, send the words 'unsubscribe jess-users >> you@...' >> in the BODY of a message to majordomo@..., NOT to the list >> (use your own address!) List problems? Notify owner-jess-users@... >> . >> -------------------------------------------------------------------- >> >> >> >> -------------------------------------------------------------------- >> To unsubscribe, send the words 'unsubscribe jess-users >> you@...' >> in the BODY of a message to majordomo@..., NOT to the list >> (use your own address!) List problems? Notify owner-jess-users@... >> . >> -------------------------------------------------------------------- > > --------------------------------------------------------- > Ernest Friedman-Hill > Informatics & Decision Sciences Phone: (925) 294-2154 > Sandia National Labs > PO Box 969, MS 9012 ejfried@... > Livermore, CA 94550 http://www.jessrules.com > > > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users > you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@... > . > -------------------------------------------------------------------- > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users > you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@... > . > -------------------------------------------------------------------- --------------------------------------------------------- Ernest Friedman-Hill Informatics & Decision Sciences, Sandia National Laboratories PO Box 969, MS 9012, Livermore, CA 94550 http://www.jessrules.com -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- |
|
|
Re: JESS: Accessing Java objects fields from a defruleLooks like my code is missing a parenthesis; you must've added it back
in the wrong place, so that OBJECT looked like its own pattern, and not like a slot: (InetModem (publicIpAddress ?publicIpAddress) (OBJECT ?inetModem)) The very last parenthesis on the line is the new one. SOrry about that! On Aug 21, 2009, at 11:24 AM, Romain Van der Keilen wrote: > I understand the principle. > That's true the following code give me an access to the java object: > (defrule validate-virtualsite > (VirtualSite (inetModem ?inetModem)) > => > (printout t "Virtual site: " ?inetModem crlf) > ) > With the following output : > Virtual site: <Java-Object:be.uniway.rvk.jesstest.model.InetModem> > > But (because there's sadly a but) > > The notation with the Object slot doesn't seems to work. Eclipse > warn me with this message if it can help: > Created implied ordered template at token 'OBJECT' > > I'm completely lost :/ > > Thanks for your help! > > Romain Van der Keilen. > > -----Original Message----- > From: owner-jess-users@... [mailto:owner-jess- > users@...] On Behalf Of Ernest Friedman-Hill > Sent: vendredi 21 août 2009 17:14 > To: jess-users > Subject: Re: JESS: Accessing Java objects fields from a defrule > > Ah, OK, here's the thing: your patterns > > > ?inetModem <- (InetModem (publicIpAddress ?publicIpAddress)) > (VirtualSite (inetModem ?inetModem)) > > are checking that the jess.Fact object representing the InetModem in > working memory is in the inetModem slot of the VirtualSite fact -- but > it's not. The inetModem slot contains the actual Java InetModem > object. You get at that object by using the OBJECT slot, not by > binding the whole fact: > > > (InetModem (publicIpAddress ?publicIpAddress) (OBJECT ?inetModem) > (VirtualSite (inetModem ?inetModem)) > > That should do you. > > > > On Aug 21, 2009, at 11:04 AM, Romain Van der Keilen wrote: > >> All getters and setters are present, respecting the jababeans >> conventions: >> >> Those methods are in Virtualsite >> public InetModem getInetModem() { >> return inetModem; >> } >> public void setInetModem(InetModem inetModem) { >> this.inetModem = inetModem; >> } >> And those are in InetModem >> public String getPublicIpAddress() { >> return publicIpAddress; >> } >> public void setPublicIpAddress(String publicIpAddress) { >> this.publicIpAddress = publicIpAddress; >> } >> >> So I don't really see what's wrong ... >> >> Thanks, >> >> Romain Van der Keilen. >> >> -----Original Message----- >> From: owner-jess-users@... [mailto:owner-jess- >> users@...] On Behalf Of Ernest Friedman-Hill >> Sent: vendredi 21 août 2009 16:54 >> To: jess-users >> Subject: Re: JESS: Accessing Java objects fields from a defrule >> >> >> Normally, slots in Jess templates are based on JavaBeans properties >> -- >> i.e., a method named "getInetModem" will give rise to a slot named >> "inetModem". If you include the "include-variables TRUE" declaration, >> then slots will also be created based on *public* member variables. >> Under no circumstances will Jess create slots based on private member >> variables. >> >> >> >> On Aug 21, 2009, at 10:39 AM, Romain Van der Keilen wrote: >> >>> Here is the exact code I use: >>> >>> (import be.uniway.rvk.jesstest.model.*) >>> (deftemplate VirtualSite (declare (from-class VirtualSite))) >>> (deftemplate InetModem (declare (from-class InetModem))) >>> >>> (defrule validate-virtualsite >>> "Just put the validate attribute to true!" >>> ?inetModem <- (InetModem (publicIpAddress ?publicIpAddress)) >>> (VirtualSite (inetModem ?inetModem)) >>> => >>> (printout t "Internet modem address: " ?publicIpAddress crlf) >>> ) >>> >>> >>> Using: >>> >>> VirtualSite >>> + private InetModem inetModem >>> >>> InetModem >>> + private String publicIpAddress >>> >>> Maybe the private fields are disturbing Jess? >>> >>> Regards, >>> >>> Romain Van der Keilen. >>> >>> >>> >>> From: owner-jess-users@... [mailto:owner-jess- >>> users@...] On Behalf Of Romain Van der Keilen >>> Sent: vendredi 21 août 2009 16:15 >>> To: jess-users@... >>> Subject: RE: JESS: Accessing Java objects fields from a defrule >>> >>> Thanks for the response, >>> >>> You've exactly put the finger on what I wish do, but I just tried >>> that and I've no output :s >>> >>> From: owner-jess-users@... [mailto:owner-jess- >>> users@...] On Behalf Of Wolfgang Laun >>> Sent: vendredi 21 août 2009 15:41 >>> To: jess-users@... >>> Subject: Re: JESS: Accessing Java objects fields from a defrule >>> >>> First, you bind to the contained object, and then you locate the >>> containing object. >>> >>> (defrule mydoor >>> ?door <- (Door (weight ?weight)(color ?color)) >>> (House (myDoor ?door)(owner "Mick")) >>> => >>> (printout t "Weight of Mick's door :" ?weight crlf) >>> ) >>> >>> Restrictions on weight or color, e.g., to paint red doors black ;-) >>> can be added in the usual way. >>> >>> -W >>> On Fri, Aug 21, 2009 at 12:12 PM, Romain Van der Keilen <Romain.VanderKeilen@... >>>> wrote: >>> Hi there, >>> >>> I have a little question for you I can't fix by myself: how to >>> access the fields of a java Object that is itself a field of an >>> other java object? >>> Here is a tiny sample : >>> >>> Object Door >>> + int weight >>> + String color >>> >>> Object House >>> + Door myDoor >>> >>> Now I give the House to the Rete engine, how can I access (and >>> manipulate) for example the weight of my door? >>> >>> By now I just can display it like this: >>> (defrule mydoor >>> (House (myDoor ?myDoor)) >>> => >>> (printout t "Weight of my house's door :" ?myDoor.weight crlf) >>> ) >>> But the thing I want to do is to catch that weight to make some >>> checks on it, then displaying the checks' results (for examples, is >>> my door heavier than 25kg). >>> >>> Thanks for help >>> >>> Romain Van der Keilen >>> >>> >>> >>> -------------------------------------------------------------------- >>> To unsubscribe, send the words 'unsubscribe jess-users >>> you@...' >>> in the BODY of a message to majordomo@..., NOT to the list >>> (use your own address!) List problems? Notify owner-jess-users@... >>> . >>> -------------------------------------------------------------------- >>> >>> >>> >>> -------------------------------------------------------------------- >>> To unsubscribe, send the words 'unsubscribe jess-users >>> you@...' >>> in the BODY of a message to majordomo@..., NOT to the list >>> (use your own address!) List problems? Notify owner-jess-users@... >>> . >>> -------------------------------------------------------------------- >> >> --------------------------------------------------------- >> Ernest Friedman-Hill >> Informatics & Decision Sciences Phone: (925) 294-2154 >> Sandia National Labs >> PO Box 969, MS 9012 ejfried@... >> Livermore, CA 94550 http://www.jessrules.com >> >> >> >> >> >> -------------------------------------------------------------------- >> To unsubscribe, send the words 'unsubscribe jess-users >> you@...' >> in the BODY of a message to majordomo@..., NOT to the list >> (use your own address!) List problems? Notify owner-jess-users@... >> . >> -------------------------------------------------------------------- >> >> >> >> -------------------------------------------------------------------- >> To unsubscribe, send the words 'unsubscribe jess-users >> you@...' >> in the BODY of a message to majordomo@..., NOT to the list >> (use your own address!) List problems? Notify owner-jess-users@... >> . >> -------------------------------------------------------------------- > > --------------------------------------------------------- > Ernest Friedman-Hill > Informatics & Decision Sciences, Sandia National Laboratories > PO Box 969, MS 9012, Livermore, CA 94550 > http://www.jessrules.com > > > > > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users > you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@... > . > -------------------------------------------------------------------- > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users > you@...' > in the BODY of a message to majordomo@..., NOT to the list > (use your own address!) List problems? Notify owner-jess-users@... > . > -------------------------------------------------------------------- --------------------------------------------------------- Ernest Friedman-Hill Informatics & Decision Sciences Phone: (925) 294-2154 Sandia National Labs PO Box 969, MS 9012 ejfried@... Livermore, CA 94550 http://www.jessrules.com -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users you@...' in the BODY of a message to majordomo@..., NOT to the list (use your own address!) List problems? Notify owner-jess-users@.... -------------------------------------------------------------------- |
| Free embeddable forum powered by Nabble | Forum Help |