RE: JESS: representation of deftemplate from deffacts
Hi all, Thanks a lot all for your great answers and suggestions. I have changed the template n corresponding as below, and both scenarios are working perfectly fine. First Test: With Un-ordered Facts, and I was looking for this. (deftemplate MAIN::opposite-of (slot entity-A) (slot entity-B)) (deffacts MAIN::opposites (opposite-of (entity-A shore-1) (entity-B shore-2)) (opposite-of (entity-A shore-2) (entity-B shore-1))) , and accordingly all rules having the opposite-of condition check (part of other condition check) (opposite-of (entity-A ?fs) (entity-B ?ns) Second Test: Explicit Ordered Template (As also mentioned inside the JESS document, and just wanted to know - how the template needs to be) (deftemplate MAIN::opposite-of (declare (ordered TRUE))) (deffacts MAIN::opposites (opposite-of shore-1 shore-2) (opposite-of shore-2 shore-1)) , and accordingly all rules having the opposite-of condition check (opposite-of ?fs ?ns) Thanks again. Regards DEBASISH DALUI (122816) --- BFS - Technology Solutions Group, Cognizant Technology Solutions, Cell: +91 9674069478 Office: +91-33-44306060; VNet: 306063 -Original Message- From: owner-jess-us...@sandia.gov [mailto:owner-jess-us...@sandia.gov] On Behalf Of Ernest Friedman-Hill Sent: Monday, November 22, 2010 7:33 PM To: jess-users Subject: Re: JESS: representation of deftemplate from deffacts On Nov 22, 2010, at 3:38 AM, debasish.da...@cognizant.com wrote: > Hi Jess-users, Note that Jess comes with a fairly detailed manual, and it's worth reading it all the way through. Everything I'll cover here is explained in the manual. > Just trying to understand, how the following deffacts can represent > in deftemplate? > > (deffacts MAIN::opposites > (opposite-of shore-1 shore-2) > (opposite-of shore-2 shore-1)) > There are two kinds of templates: ordered and unordered. These facts use an ordered template. You can tell because there are no slot names being used. > Jess is creating a *implied* template for this as below. > (deftemplate MAIN::opposite-of >"(Implied)" >(multislot __data)) Yes. Ordered templates are almost always created automatically by Jess, and their single multislot -- whose name is never normally displayed -- is named "__data". In fact, that's how Jess can tell which is an ordered template: because it has a single slot named __data. > > Here the term *__data* is not very much clear, since if I keep this > as template explicitly as follows - > (deftemplate MAIN::opposite-of >(multislot __data)) Not sure what's not clear -- that's the name of the slot. > > The ruleset is running fine as expected, and JESS is not creating > again the *implied* template in this case. Yes, because it already exists. > But, if I change it to some other name, say *data* instead of > *__data*, JESS engine throwing a exception (Jess reported an error > in routine Jesp.parseFact.)while parsing the above fact. Yes, because when Jess parses the facts, it expects to find an ordered template by that name, but it does not: it finds an unordered template whose single multislot has some other name. There's no slot named __data, and so Jess has no idea how to use this template in this situation. > > Also, if I create the template as follows using *slot*. > (deftemplate MAIN::opposite-of > (slot shore-1) >(slot shore-2)) This is now an unordered template. For this kind of template, the slots names are always shown in facts and in rule patterns. You have to change everything. > > But in this case, the deffacts needs to be defined as follows, which > seems not same as mentioned above, and the rule is not working as > expected. > Yes. If you change the data structure, then you have to change how the data is initialized, as well as changing the code that works with the data. This situation should be familiar in any programming language. - Ernest Friedman-Hill Informatics & Decision Sciences Phone: (925) 294-2154 Sandia National Labs PO Box 969, MS 9012ejfr...@sandia.gov Livermore, CA 94550 http://www.jessrules.com To unsubscribe, send the words 'unsubscribe jess-users y...@address.com' in the BODY of a message to majord...@sandia.gov, NOT to the list (use your own address!) List problems? Notify owner-jess-us...@sandia.gov. This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you
Re: JESS: representation of deftemplate from deffacts
You are mixing technical issues with questions about fact representation. Technically, the internal structure of an ordered fact is *defined* to be close to that of an ordered fact and the slot name "__data" just happens to be the stand-in for the (from a user's point of view) anonymous single multislot. Explicitly declaring an ordered fact to have a single multislot called "__data" is superfluous; you should do that by (deftemplate opposite-of (declare (ordered TRUE))) and not worry about internals. As for fact representation, I just wonder whether a proposition "White is the opposite of black" in addition (!) to "Black is the opposite of white" makes much sense. It may make sense if you associate some special meaning with the subject of the sentence, but otherwise it should be possible to write all rules with just a single fact asserting the contrasting things. If, however, there is a distinction to be made, using unordered facts should be considered; to use your example, a river's "left shore" would be the opposited of a "right shore" - but it would also have a special property, warranting a deftemplate such as (opposite-of (left shore-1) (right shore-2)) -W On 22 November 2010 06:36, wrote: > > Hi Jess-users, > > > > Just trying to understand, how the following deffacts can represent in > deftemplate? > > > > (deffacts MAIN::opposites > > (opposite-of shore-1 shore-2) > > (opposite-of shore-2 shore-1)) > > > > Jess is creating a *implied* template for this as below. > > (deftemplate MAIN::opposite-of > > "(Implied)" > > (multislot __data)) > > > > Here the term *__data* is not very much clear, since if I keep this as > template explicitly as follows – > > (deftemplate MAIN::opposite-of > > (multislot __data)) > > > > The ruleset is running fine as expected, and JESS is not creating again the > *implied* template in this case. But, if I change it to some other name, say > *data* instead of *__data*, JESS engine throwing a exception (Jess reported > an error in routine Jesp.parseFact.)while parsing the above fact. > > > > Also, if I create the template as follows using *slot*. > > (deftemplate MAIN::opposite-of > > (slot shore-1) > > (slot shore-2)) > > > > But in this case, the deffacts needs to be defined as follows, which seems > not same as mentioned above, and the rule is not working as expected. > > > > (deffacts MAIN::opposites > > (opposite-of (shore-1 shore-2)) > > (opposite-of (shore-2 shore-1))) > > > > OR > > > > (deffacts MAIN::initial-opposite-of > > (opposite-of (shore-1 shore-2) > > (shore-2 shore-1))) > > > > So, if anyone can clarify this. > > > > > > Regards > > > > DEBASISH DALUI (122816) > --- > > BFS - Technology Solutions Group, > > Cognizant Technology Solutions, > > Cell: +91 9674069478 > > Office: +91-33-44306060; VNet: 336063 > > > > This e-mail and any files transmitted with it are for the sole use of the > intended recipient(s) and may contain confidential and privileged information. > If you are not the intended recipient, please contact the sender by reply > e-mail and destroy all copies of the original message. > Any unauthorised review, use, disclosure, dissemination, forwarding, printing > or copying of this email or any action taken in reliance on this e-mail is > strictly > prohibited and may be unlawful. To unsubscribe, send the words 'unsubscribe jess-users y...@address.com' in the BODY of a message to majord...@sandia.gov, NOT to the list (use your own address!) List problems? Notify owner-jess-us...@sandia.gov.
Re: JESS: representation of deftemplate from deffacts
On Nov 22, 2010, at 3:38 AM, debasish.da...@cognizant.com wrote: Hi Jess-users, Note that Jess comes with a fairly detailed manual, and it's worth reading it all the way through. Everything I'll cover here is explained in the manual. Just trying to understand, how the following deffacts can represent in deftemplate? (deffacts MAIN::opposites (opposite-of shore-1 shore-2) (opposite-of shore-2 shore-1)) There are two kinds of templates: ordered and unordered. These facts use an ordered template. You can tell because there are no slot names being used. Jess is creating a *implied* template for this as below. (deftemplate MAIN::opposite-of "(Implied)" (multislot __data)) Yes. Ordered templates are almost always created automatically by Jess, and their single multislot -- whose name is never normally displayed -- is named "__data". In fact, that's how Jess can tell which is an ordered template: because it has a single slot named __data. Here the term *__data* is not very much clear, since if I keep this as template explicitly as follows – (deftemplate MAIN::opposite-of (multislot __data)) Not sure what's not clear -- that's the name of the slot. The ruleset is running fine as expected, and JESS is not creating again the *implied* template in this case. Yes, because it already exists. But, if I change it to some other name, say *data* instead of *__data*, JESS engine throwing a exception (Jess reported an error in routine Jesp.parseFact.)while parsing the above fact. Yes, because when Jess parses the facts, it expects to find an ordered template by that name, but it does not: it finds an unordered template whose single multislot has some other name. There's no slot named __data, and so Jess has no idea how to use this template in this situation. Also, if I create the template as follows using *slot*. (deftemplate MAIN::opposite-of (slot shore-1) (slot shore-2)) This is now an unordered template. For this kind of template, the slots names are always shown in facts and in rule patterns. You have to change everything. But in this case, the deffacts needs to be defined as follows, which seems not same as mentioned above, and the rule is not working as expected. Yes. If you change the data structure, then you have to change how the data is initialized, as well as changing the code that works with the data. This situation should be familiar in any programming language. - Ernest Friedman-Hill Informatics & Decision Sciences Phone: (925) 294-2154 Sandia National Labs PO Box 969, MS 9012ejfr...@sandia.gov Livermore, CA 94550 http://www.jessrules.com To unsubscribe, send the words 'unsubscribe jess-users y...@address.com' in the BODY of a message to majord...@sandia.gov, NOT to the list (use your own address!) List problems? Notify owner-jess-us...@sandia.gov.
RE: JESS: representation of deftemplate from deffacts
Debasish, If you want to create an explicit template, it should look like this: (deftemplate MAIN::opposite-of (slot entity-A) (slot entity-B)) Then the facts would be declared as: (opposite-of (entity-A shore-1) (entity-B shore-2)) However, you'd also have to assert (opposite-of (entity-A shore-2) (entity-B shore-1)) This will lead to problems with rules firing twice, once on each opposite-of assertion. To handle that, you can adopt a convention that all commutative relations, such as opposite-of, are expressed with arguments in canonical order (e.g., sorted alphabetically): (deftemplate MAIN::canonical-opposite-of (multislot entities)) This will result in facts of the form (canonical-opposite-of (entities shore-1 shore-2)) you will have to make sure that facts of the form (canonical-opposite-of (entities shore-2 shore-1)) ;;NOT CANONICAL are never asserted. Also, when you assert a fact you'll to make sure that the arguments are sorted in the right order (e.g., by applying a deffunction). Hope this helps. -John From: debasish.da...@cognizant.com [mailto:debasish.da...@cognizant.com] Sent: Monday, November 22, 2010 3:38 AM To: jess-users@sandia.gov Subject: JESS: representation of deftemplate from deffacts Hi Jess-users, Just trying to understand, how the following deffacts can represent in deftemplate? (deffacts MAIN::opposites (opposite-of shore-1 shore-2) (opposite-of shore-2 shore-1)) Jess is creating a *implied* template for this as below. (deftemplate MAIN::opposite-of "(Implied)" (multislot __data)) Here the term *__data* is not very much clear, since if I keep this as template explicitly as follows - (deftemplate MAIN::opposite-of (multislot __data)) The ruleset is running fine as expected, and JESS is not creating again the *implied* template in this case. But, if I change it to some other name, say *data* instead of *__data*, JESS engine throwing a exception (Jess reported an error in routine Jesp.parseFact.)while parsing the above fact. Also, if I create the template as follows using *slot*. (deftemplate MAIN::opposite-of (slot shore-1) (slot shore-2)) But in this case, the deffacts needs to be defined as follows, which seems not same as mentioned above, and the rule is not working as expected. (deffacts MAIN::opposites (opposite-of (shore-1 shore-2)) (opposite-of (shore-2 shore-1))) OR (deffacts MAIN::initial-opposite-of (opposite-of (shore-1 shore-2) (shore-2 shore-1))) So, if anyone can clarify this. Regards DEBASISH DALUI (122816) --- BFS - Technology Solutions Group, Cognizant Technology Solutions, Cell: +91 9674069478 Office: +91-33-44306060; VNet: 336063 This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Any unauthorised review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful.