|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
JESS: Interfaces and classes with shadow factsHello,
I'm having some problems to use interfaces in Jess. I had make a search in the mailing list, and although there were some messages over the topic, i still was not able to really understand how the process works. The problem is basic: I have a set of classes C, and a respective set of interfaces I. I'm creating objects of classes C and adding to the working memory. I would like use the interfaces I to access this objects (in Jess). How? Solutions: a) should i declare the classes, and work with the classes, leaving the interfaces behind; b) declare the interfaces as (deftemplate I_name (declare (from-class C_name)); Doesn't work, because when i try to match in a rule, I_name is not the same as C_name, then Jess don't match c) have a combination of declarations of interfaces and classes, like Russ did in a previous message "r.eval("(defclass IInterface1 IInterface1)"); r.eval("(defclass IInterface2 IInterface2 extends IInterface1)"); r.eval("(defclass AbstractClassA AbstractClassA extends IInterface2)"); r.eval("(defclass ClassB ClassB extends AbstractClassA)"); r.eval("(defclass ClassC ClassC extends AbstractClassA)"); r.eval("(defclass ClassD ClassD extends IInterface2)");" , which i have tried but haven't worked. Any ideas? Joao -unclassified ------------------------------------------------------------------------------------------------------------ Disclaimer: If you are not the intended recipient of this email, please notify the sender and delete it. Any unauthorized copying, disclosure or distribution of this email or its attachment(s) is forbidden. Thales Nederland BV will not accept liability for any damage caused by this email or its attachment(s). Thales Nederland BV is seated in Hengelo and is registered at the Chamber of Commerce under number 06061578. ------------------------------------------------------------------------------------------------------------ begin:vcard fn;quoted-printable:Jo=C3=A3o Mour=C3=A3o n;quoted-printable;quoted-printable:Mour=C3=A3o;Jo=C3=A3o org:Thales;Above Water Systems adr:;;;Hengelo;;;Netherlands email;internet:joao.mourao@... title:THALES NETHERLANDS B.V. tel;work:2640 note:-unclassified mail- version:2.1 end:vcard |
|
|
Re: JESS: Interfaces and classes with shadow factsJess treats classes and interfaces the same. Template inheritance
models a single-inheritance tree, and each object can be in working memory just once, so there's no way to create multiple different trees of templates to match the same set of facts. The basic idea of what you've shown below should work fine; is there a specific problem with it that I can help you with? On Nov 3, 2009, at 8:40 AM, Joao Carlos Mourao wrote: > Hello, > > I'm having some problems to use interfaces in Jess. I had make a > search > in the mailing list, and although there were some messages over the > topic, i still was not able to really understand how the process > works. > The problem is basic: I have a set of classes C, and a respective > set of > interfaces I. I'm creating objects of classes C and adding to the > working memory. I would like use the interfaces I to access this > objects > (in Jess). How? > > Solutions: > a) should i declare the classes, and work with the classes, leaving > the interfaces behind; > b) declare the interfaces as (deftemplate I_name (declare > (from-class C_name)); Doesn't work, because when i try to match in a > rule, I_name is not the same as C_name, then Jess don't match > c) have a combination of declarations of interfaces and classes, > like Russ did in a previous message > "r.eval("(defclass IInterface1 IInterface1)"); > r.eval("(defclass IInterface2 IInterface2 extends > IInterface1)"); > r.eval("(defclass AbstractClassA AbstractClassA extends > IInterface2)"); > r.eval("(defclass ClassB ClassB extends > AbstractClassA)"); > r.eval("(defclass ClassC ClassC extends > AbstractClassA)"); > r.eval("(defclass ClassD ClassD extends > IInterface2)");" > , which i have tried but haven't worked. > > Any ideas? > > > Joao > > -unclassified > > > ------------------------------------------------------------------------------------------------------------ > Disclaimer: > > If you are not the intended recipient of this email, please notify > the sender and delete it. > Any unauthorized copying, disclosure or distribution of this email > or its attachment(s) is forbidden. > Thales Nederland BV will not accept liability for any damage caused > by this email or its attachment(s). > Thales Nederland BV is seated in Hengelo and is registered at the > Chamber of Commerce under number 06061578. > ------------------------------------------------------------------------------------------------------------ > > <joao.mourao.vcf> --------------------------------------------------------- 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: Interfaces and classes with shadow factsWhat i would like to make, is to tell jess that Interface1 is the
interface of Class1, so when i try to match a fact from Class1 using Interface1, it works. But I guess, from your answer, Jess don't see any difference between interface and classes, so if the objects are inserted as Class1, then with Class1 should be matched and not with Interface1. Regards, Joao On 03-11-2009 17:17, Ernest Friedman-Hill wrote: > Jess treats classes and interfaces the same. Template inheritance > models a single-inheritance tree, and each object can be in working > memory just once, so there's no way to create multiple different trees > of templates to match the same set of facts. > > The basic idea of what you've shown below should work fine; is there a > specific problem with it that I can help you with? > > > On Nov 3, 2009, at 8:40 AM, Joao Carlos Mourao wrote: > >> Hello, >> >> I'm having some problems to use interfaces in Jess. I had make a search >> in the mailing list, and although there were some messages over the >> topic, i still was not able to really understand how the process works. >> The problem is basic: I have a set of classes C, and a respective set of >> interfaces I. I'm creating objects of classes C and adding to the >> working memory. I would like use the interfaces I to access this objects >> (in Jess). How? >> >> Solutions: >> a) should i declare the classes, and work with the classes, leaving >> the interfaces behind; >> b) declare the interfaces as (deftemplate I_name (declare >> (from-class C_name)); Doesn't work, because when i try to match in a >> rule, I_name is not the same as C_name, then Jess don't match >> c) have a combination of declarations of interfaces and classes, >> like Russ did in a previous message >> "r.eval("(defclass IInterface1 IInterface1)"); >> r.eval("(defclass IInterface2 IInterface2 extends >> IInterface1)"); >> r.eval("(defclass AbstractClassA AbstractClassA extends >> IInterface2)"); >> r.eval("(defclass ClassB ClassB extends >> AbstractClassA)"); >> r.eval("(defclass ClassC ClassC extends >> AbstractClassA)"); >> r.eval("(defclass ClassD ClassD extends IInterface2)");" >> , which i have tried but haven't worked. >> >> Any ideas? >> >> >> Joao >> >> -unclassified >> >> >> ------------------------------------------------------------------------------------------------------------ >> >> Disclaimer: >> >> If you are not the intended recipient of this email, please notify >> the sender and delete it. >> Any unauthorized copying, disclosure or distribution of this email or >> its attachment(s) is forbidden. >> Thales Nederland BV will not accept liability for any damage caused >> by this email or its attachment(s). >> Thales Nederland BV is seated in Hengelo and is registered at the >> Chamber of Commerce under number 06061578. >> ------------------------------------------------------------------------------------------------------------ >> >> >> <joao.mourao.vcf> > > --------------------------------------------------------- > 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@.... > -------------------------------------------------------------------- > ------------------------------------------------------------------------------------------------------------ Disclaimer: If you are not the intended recipient of this email, please notify the sender and delete it. Any unauthorized copying, disclosure or distribution of this email or its attachment(s) is forbidden. Thales Nederland BV will not accept liability for any damage caused by this email or its attachment(s). Thales Nederland BV is seated in Hengelo and is registered at the Chamber of Commerce under number 06061578. ------------------------------------------------------------------------------------------------------------ begin:vcard fn;quoted-printable:Jo=C3=A3o Mour=C3=A3o n;quoted-printable;quoted-printable:Mour=C3=A3o;Jo=C3=A3o org:Thales;Above Water Systems adr:;;;Hengelo;;;Netherlands email;internet:joao.mourao@... title:THALES NETHERLANDS B.V. tel;work:2640 note:-unclassified mail- version:2.1 end:vcard |
|
|
RE: JESS: Interfaces and classes with shadow factsIn the case I was using, I have a couple of classes that all implement the same interface (this is Java, independent of Jess) E.g.
ClassA implements IMyInterface ClassB extends ClassA ClassC implements IMyInterface My simple IMyInterface implements a getName function. In Jess, you would declare the inheritence tree like: (defclass IMyInterface IMyInterface) (defclass ClassA ClassA extends IMyInterface) (defclass ClassB ClassB extends ClassA) (defclass ClassC ClassC extends IMyInterface) In your Java code, you would create instance of the classes as needed ClassA a = new ClassA(); ClassB b = new ClassB(); ClassC c = new ClassC(); Rete r = new Rete(); r.add(a); r.add(b); r.add(c); A rule like this will match all 3 objects, because they ultimately implement the same interface r.eval("(defrule find-an-i1 \n" + "?x <- (IInterface1 (name ?x_name) (OBJECT ?x_obj))\n" + "=>" + "(printout t \"Found an IInterface1 called \" ?x_name crlf)\n" + ")" ); It is a single inheritence tree, so you can't have (defclass ClassA ClassA extends IMyInteface, ISomeOtherInterface) You might need to create an interface which is a combination of two or more other interfaces so that there is a single path to the root. -Russ -----Original Message----- From: owner-jess-users@... [mailto:owner-jess-users@...] On Behalf Of Joao Carlos Mourao Sent: Thursday, November 05, 2009 2:39 AM To: jess-users@... Subject: Re: JESS: Interfaces and classes with shadow facts What i would like to make, is to tell jess that Interface1 is the interface of Class1, so when i try to match a fact from Class1 using Interface1, it works. But I guess, from your answer, Jess don't see any difference between interface and classes, so if the objects are inserted as Class1, then with Class1 should be matched and not with Interface1. Regards, Joao On 03-11-2009 17:17, Ernest Friedman-Hill wrote: > Jess treats classes and interfaces the same. Template inheritance > models a single-inheritance tree, and each object can be in working > memory just once, so there's no way to create multiple different trees > of templates to match the same set of facts. > > The basic idea of what you've shown below should work fine; is there a > specific problem with it that I can help you with? > > > On Nov 3, 2009, at 8:40 AM, Joao Carlos Mourao wrote: > >> Hello, >> >> I'm having some problems to use interfaces in Jess. I had make a >> search in the mailing list, and although there were some messages >> over the topic, i still was not able to really understand how the process works. >> The problem is basic: I have a set of classes C, and a respective set >> of interfaces I. I'm creating objects of classes C and adding to the >> working memory. I would like use the interfaces I to access this >> objects (in Jess). How? >> >> Solutions: >> a) should i declare the classes, and work with the classes, >> leaving the interfaces behind; >> b) declare the interfaces as (deftemplate I_name (declare >> (from-class C_name)); Doesn't work, because when i try to match in a >> rule, I_name is not the same as C_name, then Jess don't match >> c) have a combination of declarations of interfaces and classes, >> like Russ did in a previous message >> "r.eval("(defclass IInterface1 IInterface1)"); >> r.eval("(defclass IInterface2 IInterface2 extends >> IInterface1)"); >> r.eval("(defclass AbstractClassA AbstractClassA >> extends IInterface2)"); >> r.eval("(defclass ClassB ClassB extends >> AbstractClassA)"); >> r.eval("(defclass ClassC ClassC extends >> AbstractClassA)"); >> r.eval("(defclass ClassD ClassD extends IInterface2)");" >> , which i have tried but haven't worked. >> >> Any ideas? >> >> >> Joao >> >> -unclassified >> >> >> --------------------------------------------------------------------- >> --------------------------------------- >> >> Disclaimer: >> >> If you are not the intended recipient of this email, please notify >> the sender and delete it. >> Any unauthorized copying, disclosure or distribution of this email or >> its attachment(s) is forbidden. >> Thales Nederland BV will not accept liability for any damage caused >> by this email or its attachment(s). >> Thales Nederland BV is seated in Hengelo and is registered at the >> Chamber of Commerce under number 06061578. >> --------------------------------------------------------------------- >> --------------------------------------- >> >> >> <joao.mourao.vcf> > > --------------------------------------------------------- > 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@.... > -------------------------------------------------------------------- > ------------------------------------------------------------------------------------------------------------ Disclaimer: If you are not the intended recipient of this email, please notify the sender and delete it. Any unauthorized copying, disclosure or distribution of this email or its attachment(s) is forbidden. Thales Nederland BV will not accept liability for any damage caused by this email or its attachment(s). Thales Nederland BV is seated in Hengelo and is registered at the Chamber of Commerce under number 06061578. ------------------------------------------------------------------------------------------------------------ -------------------------------------------------------------------- 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: Interfaces and classes with shadow factsThanks for the answers given. I'll try the suggestions referred. Thanks
again. Joao On 05-11-2009 13:43, rrogers@... wrote: > In the case I was using, I have a couple of classes that all implement the same interface (this is Java, independent of Jess) E.g. > ClassA implements IMyInterface > ClassB extends ClassA > ClassC implements IMyInterface > > My simple IMyInterface implements a getName function. > > In Jess, you would declare the inheritence tree like: > (defclass IMyInterface IMyInterface) > (defclass ClassA ClassA extends IMyInterface) > (defclass ClassB ClassB extends ClassA) > (defclass ClassC ClassC extends IMyInterface) > > In your Java code, you would create instance of the classes as needed > ClassA a = new ClassA(); > ClassB b = new ClassB(); > ClassC c = new ClassC(); > Rete r = new Rete(); > r.add(a); > r.add(b); > r.add(c); > > A rule like this will match all 3 objects, because they ultimately implement the same interface > r.eval("(defrule find-an-i1 \n" + > "?x <- (IInterface1 (name ?x_name) (OBJECT ?x_obj))\n" + > "=>" + > "(printout t \"Found an IInterface1 called \" ?x_name crlf)\n" + > ")" > ); > > It is a single inheritence tree, so you can't have > (defclass ClassA ClassA extends IMyInteface, ISomeOtherInterface) > You might need to create an interface which is a combination of two or more other interfaces so that there is a single path to the root. > > -Russ > > -----Original Message----- > From: owner-jess-users@... [mailto:owner-jess-users@...] On Behalf Of Joao Carlos Mourao > Sent: Thursday, November 05, 2009 2:39 AM > To: jess-users@... > Subject: Re: JESS: Interfaces and classes with shadow facts > > What i would like to make, is to tell jess that Interface1 is the interface of Class1, so when i try to match a fact from Class1 using Interface1, it works. But I guess, from your answer, Jess don't see any difference between interface and classes, so if the objects are inserted as Class1, then with Class1 should be matched and not with Interface1. > Regards, > > Joao > > On 03-11-2009 17:17, Ernest Friedman-Hill wrote: > >> Jess treats classes and interfaces the same. Template inheritance >> models a single-inheritance tree, and each object can be in working >> memory just once, so there's no way to create multiple different trees >> of templates to match the same set of facts. >> >> The basic idea of what you've shown below should work fine; is there a >> specific problem with it that I can help you with? >> >> >> On Nov 3, 2009, at 8:40 AM, Joao Carlos Mourao wrote: >> >> >>> Hello, >>> >>> I'm having some problems to use interfaces in Jess. I had make a >>> search in the mailing list, and although there were some messages >>> over the topic, i still was not able to really understand how the process works. >>> The problem is basic: I have a set of classes C, and a respective set >>> of interfaces I. I'm creating objects of classes C and adding to the >>> working memory. I would like use the interfaces I to access this >>> objects (in Jess). How? >>> >>> Solutions: >>> a) should i declare the classes, and work with the classes, >>> leaving the interfaces behind; >>> b) declare the interfaces as (deftemplate I_name (declare >>> (from-class C_name)); Doesn't work, because when i try to match in a >>> rule, I_name is not the same as C_name, then Jess don't match >>> c) have a combination of declarations of interfaces and classes, >>> like Russ did in a previous message >>> "r.eval("(defclass IInterface1 IInterface1)"); >>> r.eval("(defclass IInterface2 IInterface2 extends >>> IInterface1)"); >>> r.eval("(defclass AbstractClassA AbstractClassA >>> extends IInterface2)"); >>> r.eval("(defclass ClassB ClassB extends >>> AbstractClassA)"); >>> r.eval("(defclass ClassC ClassC extends >>> AbstractClassA)"); >>> r.eval("(defclass ClassD ClassD extends IInterface2)");" >>> , which i have tried but haven't worked. >>> >>> Any ideas? >>> >>> >>> Joao >>> >>> -unclassified >>> >>> >>> --------------------------------------------------------------------- >>> --------------------------------------- >>> >>> Disclaimer: >>> >>> If you are not the intended recipient of this email, please notify >>> the sender and delete it. >>> Any unauthorized copying, disclosure or distribution of this email or >>> its attachment(s) is forbidden. >>> Thales Nederland BV will not accept liability for any damage caused >>> by this email or its attachment(s). >>> Thales Nederland BV is seated in Hengelo and is registered at the >>> Chamber of Commerce under number 06061578. >>> --------------------------------------------------------------------- >>> --------------------------------------- >>> >>> >>> <joao.mourao.vcf> >>> >> --------------------------------------------------------- >> 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@.... >> -------------------------------------------------------------------- >> >> > > > ------------------------------------------------------------------------------------------------------------ > Disclaimer: > > If you are not the intended recipient of this email, please notify the sender and delete it. > Any unauthorized copying, disclosure or distribution of this email or its attachment(s) is forbidden. > Thales Nederland BV will not accept liability for any damage caused by this email or its attachment(s). > Thales Nederland BV is seated in Hengelo and is registered at the Chamber of Commerce under number 06061578. > ------------------------------------------------------------------------------------------------------------ > > > > -------------------------------------------------------------------- > 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@.... > -------------------------------------------------------------------- > > ------------------------------------------------------------------------------------------------------------ Disclaimer: If you are not the intended recipient of this email, please notify the sender and delete it. Any unauthorized copying, disclosure or distribution of this email or its attachment(s) is forbidden. Thales Nederland BV will not accept liability for any damage caused by this email or its attachment(s). Thales Nederland BV is seated in Hengelo and is registered at the Chamber of Commerce under number 06061578. ------------------------------------------------------------------------------------------------------------ begin:vcard fn;quoted-printable:Jo=C3=A3o Mour=C3=A3o n;quoted-printable;quoted-printable:Mour=C3=A3o;Jo=C3=A3o org:Thales;Above Water Systems adr:;;;Hengelo;;;Netherlands email;internet:joao.mourao@... title:THALES NETHERLANDS B.V. tel;work:2640 note:-unclassified mail- version:2.1 end:vcard |
| Free embeddable forum powered by Nabble | Forum Help |