This file is part of: AT&T Bell Laboratories and University of Pittsburgh CLASSIC Knowledge Representation System Tutorial Copyright AT&T and University of Pittsburgh 1994 ASG1.TXT INTRODUCTION ------------ This file contains your first CLASSIC assignment. With the help of the explanations and the code in this and other files you will build a knowledge base (KB) of wines and food. The more advanced lessons will show you how to use this knowledge base to support various reasoning tasks, such as how to select appropriate wines for different kinds of food or how to put together an appropriate meal. The goal of these assignments is to familiarize you with the CLASSIC knowledge representation system, and to provide an idea of the types of reasoning and knowledge representation that can be done using CLASSIC. CLASSIC is a fairly complex system that provides logical completions which, sometimes, are non-obvious. This first assignment is intended to be a hands-on tutorial introduction to CLASSIC. It is intentionally fairly mechanical; the purpose is to accustom you to the system and command language. You will practice using useful functions to modify and inspect the KB. In later assignments you will go on to explore some of the subtleties of the system. To better understand this first module of the tutorial, you should read the "Concept" section under "Description of CLASSIC Types" in the Classic Manual (section 2.1 in version 2.2 of the manual). All the functions mentioned in this file are documented in the appendix called "Classic Function and Variable Descriptions" (appendix D in version 2.2) in the manual. NOTATION -------- We will use the following conventions to make our definitions clearer: KB entities: concept names are in upper case, e.g., RED-WINE individual names are capitalized, e.g., Forman, Forman-Chardonnay role/attribute names are in lower case, e.g., food partition names (for disjoint primitives) are in lower case, e.g., type indices (for primitives and disjoint primitives) are also in lower case CLASSIC system: CLASSIC function names are in lower case, e.g., cl-define-concept CLASSIC language keywords are in upper case, e.g., AT-MOST LISP: LISP built-in functions and primitives are in lower case, e.g., defun LISP user functions are capitalized, e.g., No-Winery WHAT YOU NEED TO DO ------------------- The following text will tell you what to do at each point. You will be asked to type in some concept definitions and to use several CLASSIC functions to inspect the KB. In some cases you will be asked to write your own definitions. For some of these problems, we have provided answers, although you are encouraged to try to solve them yourself before giving up; for others you are on your own. Failing to solve a problem for which no solution has been provided will not critically impair continuing the work that follows the problem. You should follow the directions given by the text with respect to typing in definitions or function calls. You should also type in any lines of CLASSIC code that are prefixed by >>>. You should also follow directions with respect to the "dribble" files that log your work. Every time a written answer is required, remember to comment it using ";;", so that it will be easily recognizable in the dribble file. Finally, note that the assignment has been broken up into modules, so that you don't have to do it all in one session. Each module will start with a brief recapitulation of past work and instructions for files to load in order to "recover state". Your life will be easier if you try to get through a whole module before you take a break. WHAT TO TURN IN --------------- You will need to turn in evidence that you have gone through the assignment, i.e., log file(s) that record you going through the tutorial. In general: To record your work in a file use the Common Lisp function dribble. To start recording: (dribble "") To stop recording: (dribble) CAREFUL!! Use different filenames for different "dribble" files, or you will overwrite your previous work. LOADING FILES ------------- At several points in the assignment you will be told to load files. Some of these files contain CLASSIC definitions for building the KB. We have provided these because the KB is quite large. Other files can be used to "clean-up state", i.e., to remove mistakes you may have made in working through the assignment while insuring that all the needed definitions are loaded. These "recovery" files can also be used to resume working on the assignment if you don't get it done in one session. In most places below you will be using the function "lload" to load files, instead of "load". "lload" looks for files in the Helper or Recover sub-directories relative *topdir*, either the default top-level directory or the one that you have established. (See the assignment handout). When you see a filename like "/Helper/", or "/" substitute in the right name of the top-level directory you're using (that is the directory that you put the tutorial files into .. in fact the directory that this file is in). ------- Here we go. If you haven't started up classic-lisp yet, do so according to the instructions in the assignment handout. Make sure your work is being recorded in a file starting now. >>> (dribble "your-file1.log") First load the file "/Customize.lisp", i.e. >>> (load "/Customize.lisp") INITIALIZING CLASSIC -------------------- The function cl-startup initializes the KB. If you have just loaded CLASSIC, you don't need to call it, but if you have been working in CLASSIC for a while and are loading a new KB or you have made changes to the KB code and are reloading, you need to call it. The function cl-startup removes all concepts and individual definitions except THING, CLASSIC-THING, HOST-THING, and a few other built-in concepts. Since concepts cannot be changed within a KB, you will find that when you want to redefine a concept, you will need to re-initialize the KB as well. >>> (cl-startup) Turn off warning messages, if you want less feedback from the system. Default normally is t. >>> (cl-set-classic-warn-mode nil) DISJOINT-PRIMITIVE CONCEPTS --------------------------- We will now start building the first part of the hierarchy shown in the file "/classic-thing.ps" , i.e., the immediate children of CLASSIC-THING. There are four disjoint primitive concepts at the top level: WINE-PROPERTY, WINE-REGION, WINERY and CONSUMABLE-THING, all in the disjoint grouping "type". Such an organization of concepts is typical: A CLASSIC application will usually have primitives in the highest tiers of the hierarchy. NOTE 1: The picture in the file "classic-thing.ps" shows another child of CLASSIC-THING, CONCEPT. This is a predefined CLASSIC class, you can ignore it. NOTE 2: The pictures of the KB do not explicitly show disjoint groupings. You may want to add them by hand, using the notation shown in Figure 1, which is in the section called "Defined, Primitive, Disjoint Primitive and Temporary Concepts" in the Classic Manual (in version 2.2 it is in section 2.1.6). PRIMITIVES AND DISJOINT PRIMITIVES All concepts, including primitive, disjoint-primitive and non-primitive concepts, have at least one parent. If the parent is not specified in the definition, and the concept does not fit under a more specific concept, then it is classified under one of the built-in concepts, HOST-THING or CLASSIC-THING. A non-primitive concept definition specifies both the necessary and sufficient conditions that an individual must satisfy in order to be an instance of the concept. (Necessary conditions are the conditions that an instance of the concept must meet. Sufficient conditions are conditions that only instances of the concept meet; i.e., if an individual satisfies sufficient conditions, then it must be an instance of the concept.) Since you usually will be either unable or unwilling to specify all the sufficient conditions for very general concepts (e.g. WINE), or for concepts that are learned by example, you should be prepared to treat some concepts as primitives. On the other hand, CLASSIC obtains much of its reasoning power from well structured definitions. Whenever you can fully specify a concept by a definition, you should define it as a non-primitive concept. For example, the definition of the concept VEGETARIAN is someone who eats only vegetables. This definition fully specifies the concept. Thus, you should define VEGETARIAN as a non-primitive concept so that any individual that eats only vegetables will automatically get classified as a VEGETARIAN. See "Living with CLASSIC" for useful advice on this matter. A primitive concept definition (including a disjoint primitive concept definition) specifies the necessary but not the sufficient conditions that an individual must satisfy in order to be an instance of the concept. There may be additional information associated with primitive concepts, in the form of roles and restrictions. For instance, later we will introduce a disjoint primitive concept MEAL-COURSE with the roles food and drink, which must have fillers meeting certain conditions. If we know that Meal-Course-134 is a MEAL-COURSE, then we can infer, that Meal-Course-134 will have its food and drink roles filled by individuals that meet these conditions. (But, since a MEAL-COURSE is primitive, we cannot infer that an individual is a MEAL-COURSE if its food and drink role fillers meet the conditions since MEAL-COURSE is primitive.) The effect of making a concept P a primitive is that, even if a concept C has compatible restrictions or an individual Ind happens to satisfy P's restrictions, the system will not place C or Ind under P unless it is explicitly told to do so in the concept or individual definition. Now, using the function "cl-define-disjoint-primitive-concept" defined in the reference manual, create the disjoint primitive concepts WINE-PROPERTY, CONSUMABLE-THING, WINERY and WINE-REGION as children of CLASSIC-THING within a disjoint grouping called classic-thing-type. ---------------- The four disjoint primitive concepts that you have just defined create a partition or disjoint grouping (called "classic-thing-type") in the space of concepts under CLASSIC-THING. The four concepts are disjoint in the sense that any individual belonging to any one of them cannot also belong to any of the others. See the CLASSIC reference manual for other examples and more explanation of disjoint primitives and disjoint groupings. For example, CLASSIC-THING and HOST-THING are also defined as disjoint primitives under THING. Thus, CLASSIC will not allow you to create an individual that belongs to both a HOST-THING and CLASSIC-THING. The following statements try to violate the disjoint grouping. Try them and see what happens. They should fail to create anything, and return an error message. ; an incoherent concept >>> (cl-define-concept 'C '(AND WINE-PROPERTY WINE-REGION)) ; an inconsistent individual >>> (cl-create-ind 'Ind '(AND CLASSIC-THING HOST-THING)) TURNING OFF VERBOSE DEBUGGING INFORMATION So far, every time you have defined a concept, CLASSIC has printed out lots of information about its results. If you are loading large KB's this can get pretty verbose. CLASSIC has a "debug-mode" flag that you can set to different levels from 0 (no classification data) to 3 (lots of debugging information). The output you saw above results from the default. Let's turn it off and use other functions to find out how concepts get classified. >>> (cl-set-classic-debug-level 0) INSPECTING AND NAVIGATING THE KB -------------------------------- Now let's practice using some of the commands CLASSIC provides for inspecting the knowledge base. This will let you browse the information that has already been created for purposes of this exercise. Most of the CLASSIC functions that use concepts, individuals, and roles as arguments expect you to use a particular format for indicating these arguments. The only situation in which you can use a quoted symbol (e.g., 'C in the above concept definition) is if the argument is a . For , and arguments such as the concept person, the individual Joe and the role age need to use the following: @c{person} @i{Joe} @r{age} The short form @ will also work if there is no ambiguity, i.e., if you have not used the same name for a concept, individual, or role. (Note: CLASSIC itself does not distinguish between upper and lower case.) The functions cl-named-concept and cl-named-ind also take a symbol argument and return a concept or role respectively. Try typing: >>> (cl-named-concept 'WINERY) >>> @WINERY To print the contents of the concept WINE-REGION, type one of the following: >>> (cl-print-concept @c{WINE-REGION}) >>> (cl-print-concept @WINE-REGION) You can also use the more generic function cl-print-object: >>> (cl-print-object @c{WINE-REGION}) >>> (cl-print-object @WINE-REGION) All of these functions print the same information in the same format. Here is what the output should look like: *@c{WINE-REGION}* -> Derived Information: Parents: (@c{CLASSIC-THING}) Ancestors: (@c{THING}) @c{WINE-REGION} The output is easy to interpret. The `*' around the concept name indicates that this is a primitive or disjoint primitive CLASSIC-THING is the only parent (WINE-REGION was declared as a primitive under it) CLASSIC-THING is the most general concept in the domain of non-host objects: every individual created in the CLASSIC knowledge base will be a CLASSIC-THING. Thus, CLASSIC-THING will be an ancestor of every CLASSIC individual and concept. If you want to see more detailed information about an object, use the keyword parameters to the cl-print-concept function. If :told is non-nil, cl-print-concept will print all the information you have told CLASSIC about the object. Try typing: >>> (cl-print-concept @c{WINE-REGION} :told T) Remember how we defined @c{WINE-REGION}: (cl-define-disjoint-primitive-concept 'wine-region 'classic-thing 'classic-thing-type) Here's the output when :told is non-nil: *@c{WINE-REGION}* -> Derived Information: Parents: (@c{CLASSIC-THING}) Ancestors: (@c{THING}) Told Information: Member of decomposition(s): CLASSIC-THING-TYPE Parents: (@tc{CLASSIC-THING}) Here the Told Information includes information that this is a disjoint primitive on parent CLASSIC-THING. (Notice the @tc{} notation. This means that the object is a "told concept.") The Told Information also includes that it is in the disjoint grouping labeled classic-thing-type. (Recall that the disjoint grouping serves as a label of the decomposition of the parent concept to which the child concept belongs.) You can use almost anything as a name for a disjoint grouping. The names you choose are in most cases not particularly important, since they are only needed in cases when there are multiple decompositions of a parent concept; and they are often suppressed in the information that CLASSIC reports. But it is important to choose unique names for disjoint groupings. More complex concepts will have correspondingly more information associated with them. We will see some examples below. You can see what the hierarchy looks like so far, without printing out ALL the information associated with a concept or individual, by using the following CLASSIC functions, which are documented in the CLASSIC reference manual in the sections entitled "Retrieval Functions for Derived Concepts" and "Retrieval Functions for Derived Objects" (in version 2.2 of the manual they are section numbers D.6.2.4 and D.5.2). cl-concept-parents cl-concept-children cl-concept-ancestors cl-concept-descendants cl-bottom-concepts cl-top-concepts cl-primitives To get some practice in using the above functions to browse through a Classic hierarchy, try the following: Print the children of THING: (cl-concept-children @c{THING}) Starting from HOST-THING, use the above functions to get to INTEGER and verify that this concept has no children. Print the parents and the ancestors of WINE-REGION. Print the primitive ancestors of WINERY. See the section called "Retrieval Functions for both Concepts and Individuals" (in section D.5 in version 2.2) of the Classic Manual. PRACTICE WITH DISJOINT PRIMITIVES --------------------------------- Now let's define some more disjoint concepts in our KB. We'll work on the concepts below CONSUMABLE-THING in "/classic-thing.ps", that is, EDIBLE-THING and POTABLE-LIQUID. These should be disjoint concepts under CONSUMABLE-THING. Following the pattern we used above for CONSUMABLE-THING, WINE-PROPERTY, etc., define the two concepts EDIBLE-THING and POTABLE-LIQUID as disjoint primitives under CONSUMABLE-THING within a disjoint grouping called consumable-thing-type (remember, you will need to provide unique names for each disjoint grouping). You can look up the definitions of the primitive concepts defined up to now in "/Recover/after-consumable-thing.lisp" ---------------------------------------------------- We switch our attention now to subclasses of the primitive concept WINE-PROPERTY, as shown at the top of "/classic-thing.ps" and in more detail in "/wine-property.ps". The first thing we'll do is to create the four concepts WINE-COLOR, WINE-BODY, WINE-FLAVOR and WINE-SUGAR, under WINE-PROPERTY. These are not primitive concepts. They will be defined as enumerative concepts, i.e., concepts that are totally defined by their parents and a set of user-defined direct instances. Enumerative concepts are created using the ONE-OF restriction which is explained in the section entitled "ONE-OF" in the Classic Manual (section 2.1.4.3 in version 2.2 of the manual). We want each of the new concepts to be a WINE-PROPERTY whose remaining definition is simply to be one of the instances listed under it in "/wine-property.ps". So try to define the concept: 1. WINE-COLOR: Is a WINE-PROPERTY and is one of White, Rose, or Red. You might be surprised to see the result of using the cl-concept-instances command on WINE-COLOR. Use the command to see what the instances of WINE-COLOR are. You should have gotten NIL. This happens because the individuals White, Rose, and Red did not exist prior to the definition of WINE-COLOR. CLASSIC created these individuals, but since nothing else is specified about them, they are just classified as CLASSIC-THINGs. If WINE-COLOR was defined as "(ONE-OF White Rose Red)", and did not include the primitive concept WINE-PROPERTY in its definition, the individuals in the ONE-OF would be classified under it. However, it contains the primitive concept WINE-PROPERTY in its definition, so the WINE-COLOR individuals won't get classified under WINE-COLOR unless we specify that they are instances of WINE-COLOR. The command cl-populate is used to put them in their proper place, e.g. >>> (cl-populate 'WINE-COLOR '(White Rose Red)) Note that individuals are one thing that CLASSIC will automatically create if they haven't been mentioned before, unlike concepts and roles which have to be defined before they are used. CLASSIC can create an individual without knowing anything about it since information can be added to it at a later time. In contrast, role and concept definitions are not modifiable. Now create and populate the following concepts: WINE-BODY: Is a WINE-PROPERTY and is one of Light, Medium, or Full. WINE-FLAVOR: Is a WINE-PROPERTY and is one of Delicate, Moderate, or Strong WINE-SUGAR: Is a WINE-PROPERTY and is one of Sweet, Off-Dry, or Dry. You can use the KB navigation commands to make sure all the individuals are properly classified. Now that your knowledge base is populated with some individuals, you can browse the individuals, as well as the concepts. Some useful functions for retrieving information about individuals are: cl-ind-parents cl-ind-ancestors cl-concept-direct-instances cl-concept-instances Try the following: Print the direct instances of CLASSIC-THING. Print the instances of THING. Print the direct instances of WINE-PROPERTY. Print the direct instances of WINE-COLOR. Print the parents of the individual Sweet. Print the ancestors of the individual Strong. You can compare your definitions of the WINE-PROPERTY's subclasses with the ones in the file "/Recover/after-wine-properties.lisp". Load this file if you want to recover from errors you made in your definitions. DEFINITION OF CONCEPTS THROUGH ROLES and ATTRIBUTES ==================================================== Now that we have created the concept WINE-PROPERTY and its subconcepts, we can use them to define the concept WINE. We want to define WINE as a POTABLE-LIQUID with attributes color, body, flavor, sugar and grape. In order to do this, we need to create the necessary attributes first. Read the "Roles" section of the Classic Manual (section 2.5 in version 2.2) for more information about roles. For example, let's create the attribute 'color' >> (cl-define-primitive-role 'color :attribute t) Use the same construct to create the attributes 'body', 'flavor', 'sugar' and 'grape'. Now everything we need to define the concept WINE is in the KB. We want to define a WINE as a POTABLE-LIQUID that has: 1) exactly one 'color', which is a WINE-COLOR. 2) exactly one 'body', which is a WINE-BODY. 3) exactly one 'flavor', which is a WINE-FLAVOR. 4) exactly one 'sugar', which is a WINE-SUGAR. 5) exactly one 'grape', which is an EDIBLE-THING. Remember that Classic provides constructs for defining number restrictions on roles. For further information about this read the section called "Number (AT-LEAST, AT-MOST) Restrictions" (section 2.1.3.2 in version 2.2 of the manual). For example, to specify that WINE has exactly one color, you may combine an "AT-LEAST 1" and "AT-MOST 1" number restriction. But if a role is defined to be an attribute, an "AT-MOST 1" restriction is automatically established, while the default AT-LEAST restriction of an attribute and a regular role is set to 0. Therefore, if you have defined color, body, flavor, sugar and grape as attributes, only AT-LEAST number restrictions must be specified in the definition of the WINE concept. Also remember that in saying that there is one of something and it has a particular value, ALL (one) of those things has that value. Define the concept WINE now. To look at the newly defined concept, use >>> (cl-print-concept @wine :told t) What difference do you notice between the description of the Role Restrictions in the derived information and the one in the told information? Why does the difference exist? Comment out your answer using semi-colons (;;), so that it will be easily recognizable in your log file. -------------------- At this point, we want to add to our knowledge base the concept of MEAL-FOOD which is an EDIBLE-THING that can be served during a meal. Instances of MEAL-FOOD can be, for example, Pasta or Fries, while Flour is an EDIBLE-THING which is not a MEAL-FOOD, because raw flour will never be served during a meal. The purpose of the knowledge base that we are building is to plan meals in which the foods and wines that are served go together. Thus, the information about which wines go with a particular food has to be entered at some place in the knowledge base. We will use the role appropriate-drink for this purpose, which will later be used to attach appropriate drinks to each MEAL-FOOD in the knowledge base. Create the role appropriate-drink, and define the concept MEAL-FOOD so that every MEAL-FOOD: 1) is an EDIBLE-THING 2) has at least 1 appropriate-drink 3) any appropriate-drink is a WINE. If you are in trouble, you can find the definitions of WINE and MEAL-FOOD in "/Recover/after-meal-food.lisp" The remainder of the hierarchy under MEAL-FOOD is shown in "/edible-thing.ps" It's not very interesting, just many disjoint concept definitions. If you want to see some meal definitions, you may look at the following file, but PLEASE DO NOT load it: "/Helper/meal-foods.lisp". ROLE RESTRICTIONS ------------------- Now let's see how the restrictions defined on the roles of the WINE concept influence the creation of WINE individuals. Try to create an individual W1 that is a WINE and has sugar Dry. Notice what happens when you try to create a new individual W2 that is a WINE and has grape semillon and riesling. Remember that we defined the grape role to be an attribute, meaning that there could be only one grape per wine. Classic reminds you of this in the error message by creating a new individual (which you can examine) with the string "-*INCOHERENT*" in its name. The error message also states that it occurred along the "role-path (@r{GRAPE})", pointing out that the new value for the role does not work. You cannot access the error object by typing the name followed by "-*INCOHERENT*". You can access it by typing "(cl-error-object ')" as in "(cl-error-object 'Mary)". Create W2 again, this time choosing semillon as the only filler. Classic is not complaining about this second entry, and W2 is eventually created (make sure of this by printing W2, using cl-print-ind). Are you surprised about this? WINE has been defined as having at least one color, one flavor, one sugar and one body, but no fillers for these attributes have been assigned to W2. Why did Classic create W2 without complaining? If you have problems answering this question, watch how Classic complains when you try to type: >>> (cl-ind-close-role @W2 @color) Insert in your DRIBBLE file an explanation of what happened here. (Remember to comment out your explanation.) Type: (dribble) to close your log file now. --------------------------------------------------------------------------- END OF asg1.txt If you are going on, open the file "/asg2.txt" This file is part of: AT&T Bell Laboratories and University of Pittsburgh CLASSIC Knowledge Representation System Tutorial Copyright AT&T and University of Pittsburgh 1994 ASG2.TXT PRELIMINARIES Open a new log file: >>> (dribble "your-file2.log") If you are continuing from lab-asg1.txt in the same session, type: >>> (lload "Helper/meal-foods.lisp") otherwise type: >>> (load "/Customize.lisp") >>> (lload "Recover/after-meal-food.lisp") REVIEW OF asg1.txt In the previous module of this assignment we covered: 1. How to create disjoint-primitive concepts. Using this construct we created the concepts WINE-PROPERTY, CONSUMABLE-THING, WINERY, and WINE-REGION. We also constructed the concepts EDIBLE-THING, POTABLE-LIQUID, WINE-COLOR, WINE-BODY, WINE-SUGAR, WINE-FLAVOR, WINE and MEAL-FOOD. 2. How to set the level of debugging information that CLASSIC will supply when concepts and individuals are defined. 3. Commands for inspecting and navigating the KB. 4. How to define roles and attributes. 5. How to create individuals, and when role restrictions will make the description of an individual inconsistent. USEFUL REMINDER --------------- When a CLASSIC description is not called for and you need to refer to a concept, individual or role use the @ in front of the symbol name. When a CLASSIC description is called for, do NOT use the @ inside of the description, just use the symbol name. For instance, (cl-create-ind 'temp-wine '(AND WINE (FILL color red))) (cl-ind-remove @temp-wine 'WINE). Thus the @ was needed in cl-ind-remove to get the individual with the name temp-wine, but no @ was needed in the expression which defines temp-wine. Notice that a quote is needed in front of both the symbol and the description required in cl-create-ind. The quote is needed when you are creating an object and giving it its name or when you are entering a CLASSIC description. MORE INDIVIDUAL CREATION ------------------------ The next parts of the KB we will start fleshing out are the WINE-REGIONs and the WINERYs, as represented in "/wine-region.ps" and "/wineries.ps". The two concepts are structurally very simple: WINE-REGIONs and WINERYs are simply individuals that belong to WINE-REGION or WINERY, respectively. The following is typical of the definitions of WINE-REGIONs: >>> (cl-create-ind 'Medoc 'WINE-REGION) Type this in. Now, create another WINE-REGION called Bordeaux. And another one called Napa-Valley. The WINERYs are created in a similar way. Create a WINERY called Kalin-Cellars and one called Forman. You can verify that the above individuals are in the KB using the CLASSIC function "cl-print-all-inds". Do it. Remember, you can never delete an individual from the KB, unless you decide to remove all the existing individuals using the function (cl-clear-kb) or you may remove all objects from the KB via the function "cl-startup." -- don't enter this command, unless you want to remove all the individuals that you have created so far. On the other hand, you can remove some information from selected individuals using the general function "cl-ind-remove", or more specific functions listed in the "Retraction" section in appendix "CLASSIC Function Variable Descriptions") of the CLASSIC Manual (section D.7.4 in version 2.2). Also refer to the "Retraction" section under the "Updates" section in the CLASSIC Manual (section 5.2 in version 2.2) for further explanation of the use of these functions. Whenever an individual is modified through deletion or addition of information, CLASSIC will reclassify it using the new definition. For instance, print the information that CLASSIC knows about the individual Medoc. Now, try to retract the fact that Medoc is a WINE-REGION. Once you are done, print Medoc again. You will see that its direct parent is now CLASSIC-THING instead of WINE-REGION. We will not go through the definition of all the instances of WINE-REGION, WINERY and MEAL-FOOD. They are in separate files which you will need to load; but you needn't look at the files unless you want to. Load the files now. >>> (lload "Helper/wineries-and-regions.lisp") >>> (lload "Helper/meal-food-instances.lisp") You can verify that the instances of WINERY and WINE-REGION have been created properly by using the "cl-concept-instances" command on WINERY and WINE-REGION. Try it. ADDING INTERMEDIATE CONCEPTS ---------------------------- Suppose we are not satisfied with the very flat classification of wineries that we now have, and would like them to be organized by region. We are going to do this in 3 steps: 1. We will first create subclasses of WINE-REGION. 2. Using these, we will create subclasses of WINERY. 3. Finally we will add some information to the individual wineries that will allow them to be classified by region. 1. SUBCLASSES OF WINE-REGION The goal is to refine the concept WINE-REGION into 3 subclasses: FRENCH-WINE-REGION, AMERICAN-WINE-REGION and OTHER-EUROPEAN-WINE-REGION. We want FRENCH-WINE-REGION to be a WINE-REGION that is one of Bordeaux, Bourgogne, Beaujolais, Loire, and Medoc. Try to define this new concept, using the "ONE-OF" construct. Now examine the instances of FRENCH-WINE-REGION. You should find the five regions listed. Let's pause for a moment to examine how enumerative definitions work. First, verify using "cl-classic-ind?" that there is no individual Charlie in your CLASSIC KB. Now, define a concept C1 using a slightly different version of the definition for the FRENCH-WINE-REGION concept, which contains Charlie as another member of the list of WINE-REGIONs. Notice that CLASSIC does not complain about your definition! Check the KB again with "cl-print-ind". What has CLASSIC done? (Put a brief commented answer in your file.) Evidently, CLASSIC can be accommodating about some definitions that invoke as-yet undefined individuals. Second, examine the instances of C1. Explain why Charlie is not an instance of C1. (Comment out your answer.) Third, define a new concept C2: C2 is a CLASSIC-THING that is one of Bordeaux, Bourgogne, Beaujolais, Loire, and Medoc. Examine this concept; note that CLASSIC knows that every possible instance of C2 is a WINE-REGION, but doesn't seem to know that C2 is a WINE-REGION. Can you give an account of what is going on here? (Comment out your answer.) Can you explain why CLASSIC doesn't classify C2 under WINE-REGION? (If you have trouble answering this, consult "Living with CLASSIC," Section 4.3, "Concepts and Individual Processing".) Now, let's continue building the knowledge base. AMERICAN-WINE-REGION is defined in a similar way to FRENCH-WINE-REGION, with the instances Napa-valley, Sonoma, Santa-Cruz-mountains, and Santa-Barbara. Define this concept before you go on. OTHER-EUROPEAN-WINE-REGION includes the regions that are not part of the other classifications. Since CLASSIC doesn't have a "NOT" construct, we will have to use exhaustive enumeration to capture the other regions, i.e. Alsace, Chianti, Piemont. Define the concept before going on. (If you haven't been able to define these concepts by yourself, look at file "/Recover/until-regional-winery.lisp".) Check that the non-French wine region instances were correctly classified under the newly created concepts. 2. SUBCLASSES OF WINERYs Next you'll create a concept REGIONAL-WINERY which is defined to be a WINERY with a region role filled by exactly one WINE-REGION and with an inverse role wineries. Remember that you need to define roles before you can use them and that CLASSIC provides a construct for declaring the inverse of a role within the definition of the role itself. See the role section of the CLASSIC Manual (Section 2.5 in version 2.2) for further explanation of roles and how to define them. Also remember that WINERY is a primitive, so REGIONAL-WINERY will have to be explicitly asserted to be a WINERY. Create REGIONAL-WINERY now. (If you are really lost about how to do it, see the file "/Recover/after-regional-winery.lisp".) Check that everything worked as it should by using the function cl-print-concept. The description that you get should look exactly like this. @c{REGIONAL-WINERY} -> Derived Information: Primitive ancestors: (@c{WINERY} @c{CLASSIC-THING}) Parents: (@c{WINERY}) Ancestors: (@c{THING} @c{CLASSIC-THING}) Role Restrictions: Region![1 ; 1] => @c{WINE-REGION} @c{REGIONAL-WINERY} Remember that there are two ways for imposing the required "exactly one" number restriction on the role region of REGIONAL-WINERY. 1) You can define region as an attribute. This will automatically set up an "AT-MOST 1" restriction for each concept that has region as a role. Thus, when you define a concept like REGIONAL-WINERY that should have one and only one region, you will only need to declare an "AT-LEAST 1" restriction in the definition; CLASSIC will automatically infer the "AT-MOST 1" restriction from the fact that region is an attribute. 2) You can define region as a role. This will require you to add appropriate "AT-MOST" restrictions in the definitions of concepts that have region as a role, as these definitions come up. The decision between the above alternatives depends upon whether different concepts may vary in the "AT-MOST" restrictions they impose on the role. In general, a certain role may function as an attribute for all concepts in the domain, or it may function as an attribute only for some. In our example, if we are sure that we will never add any multi-regional wineries (wineries that operate in more than one wine region) to the domain, we could safely declare the role region to be an attribute. But we have to be careful about such decisions; we do need to be very sure that we will never want to include multi-regional wineries in our knowledge base. If we ever decide to retract our decision to make region an attribute, we will have to go through the knowledge base by hand and rebuild it so that the desirable consequences that followed from making region an attribute are preserved in the new KB, while the undesirable ones are discarded. This may well be a complicated procedure if the KB is at all large, and we are liable to make mistakes. Other factors to take into consideration are: a) Whether the role must be inserted in a role hierarchy. (In CLASSIC, attributes cannot be part of role hierarchies.) b) Whether a "SAME-AS" restriction must be imposed on the role. (In CLASSIC, the "SAME-AS" construct is restricted to attributes.) In our KB, we are, in fact, very sure that all the wineries will have at most one associated region, and we will not use the role region for non-wineries. Therefore, we can define region as an attribute in order to avoid including the "AT-MOST 1" restriction in the definition of WINERY. You can check whether you made region an attribute typing >>> (cl-attribute? @r{region}). If you did not make region an attribute, you should change it, since the definitions supplied in our Helper files will assume that it is an attribute. To do this, you can type >>> (lload "Recover/after-regional-winery.lisp") You might want to look at the file "/Recover/until-wineries.lisp" to see what you would have needed to do if region had not been an attribute. CLASSIC will automatically infer that an instance of WINERY is a regional winery as long as it is able to show that the instance has at least one region. To illustrate this, first create an individual My-Winery, which is a WINERY with the region role filled by Chianti. Test that in fact CLASSIC classifies My-Winery as a regional winery. Second, try to create an individual Impossible-Winery that is a REGIONAL-WINERY and yet has no regions. Note the response that you get from CLASSIC when you try to do this. Now that we have the concept of REGIONAL-WINERY, let's use it. First, we will create several child concepts of REGIONAL-WINERY, namely FRENCH-WINERY, AMERICAN-WINERY and OTHER-EUROPEAN-WINERY, so that we can eventually classify all the wineries under these concepts. 1. A FRENCH-WINERY is a REGIONAL-WINERY with all its regions FRENCH-WINE-REGIONs. 2. An AMERICAN-WINERY is a REGIONAL-WINERY with all its regions AMERICAN-WINE-REGIONs. 3. An OTHER-EUROPEAN-WINERY is a REGIONAL-WINERY with all its regions OTHER-EUROPEAN-WINE-REGIONs. Define the three concepts now. (If you are really confused at this point, look at file "/Recover/until-wineries.lisp".) Once the concepts are defined, print one of them to make sure that CLASSIC is understanding you properly. In common sense language and reasoning, we often presuppose the existence of role fillers; if I tell you that all Jack's children are in college, for instance, you will assume that Jack has at least one child. But in logic, and in many logic-based KR systems, including CLASSIC, these so-called "existential presuppositions" will not be made by the system unless they are declared explicitly. (Recall that in First-Order Logic, "All Jack's children are in college" will be true if Jack has no children.) Because of this discrepancy between common sense and First-Order Logic, it's easy to forget to declare explicitly that an attribute must have some fillers. To drive this point home, create a temporary individual No-Regions that is a WINERY with at most 0 regions. Print the ancestors of this regionless winery. Briefly explain why CLASSIC returns the information that it does; in particular, why doesn't CLASSIC treat No-Regions as a REGIONAL-WINERY? Comment out your answer. You should now be able to tell why we defined FRENCH-WINERY as we did, rather than saying that a FRENCH-WINERY is a WINERY with all its region's FRENCH-WINE-REGIONs. CLASSIC would then not have classified FRENCH-WINERY under REGIONAL-WINERY. To test this, define a concept C3 to be a WINERY with all its regions FRENCH-WINE-REGIONs. Does CLASSIC place C3 under REGIONAL-WINERY? Verify this using CLASSIC. You shouldn't be surprised that it doesn't; explain why CLASSIC doesn't think that C3s are REGIONAL-WINERIES, commenting out your answer. (Hint: print the ancestors of No-Regions.) 3. CLASSIFYING THE WINERIES Now we have all the concepts we need to properly classify the instances of WINERY by region. In order to do this we will need to add region information to each instance of WINERY. Since there are lots of wineries, we'll only ask you to do this for a couple of them. There are a number of functions for adding information to an individual. The CLASSIC Manual shows these in the "Addition" sections under sections "Updates" and "Individuals" (sections 5.1, D.7.3. in version 2.2). Since we will need to add both a role and its filler, the correct one to use is either "cl-ind-add" or "cl-ind-add-fillers." Let's take the winery Forman as an example. We want to add the information that its region is Napa-Valley. Look at the documentation for cl-ind-add and try that now. (Hint: use FILLS.) If you absolutely can't do it by yourself, look at the file "/Helper/winery-region-info.lisp". After you have added the information to Forman, check that the system classifies it as an AMERICAN-WINERY. IMPORTANT: remember, you can always add information to or remove information from individuals, but you can never delete an individual from the KB or modify an existing concept, other than by reloading the knowledge base. For this reason, you have to be cautious when adding concepts to the CLASSIC KB. WHEN a ROLE has an INVERSE ============================ Now, print the individual Bordeaux, that we created as a FRENCH-WINE-REGION. As you can see, the printed information about Bordeaux does not contain any role restriction, since no roles were contained in the definition of Bordeaux, or any of its ancestors. Now, add to the winery Chateau-D-Ychem the filler Bordeaux for the role region. (Use either "cl-ind-add" or "cl-ind-add-fillers"). Print Chateau-D-Ychem and Bordeaux. As you can see, now the role wineries is attached to Bordeaux, and the role is filled with Chateau-D-Ychem. CLASSIC has derived this information from the fact that we have declared the role region to have inverse wineries. Print the concept FRENCH-WINE-REGION. You will notice that it does not contain any information about the role wineries, since the descriptions of classes don't change with the changes to individuals. Therefore, the definition of the inverse of a role affects only the individuals that become fillers of that role, not the concepts they belong to. The inverse of a role is a regular CLASSIC role and all the CLASSIC functions defined to inspect roles work on it. Try "cl-print-role" and "cl-role-inverse" on the wineries role. The same information about the inverse role was derived for the region Napa-Valley when it was added as the region of the Forman winery. Check this by printing Napa-Valley. Now, add Napa-Valley as the region of the winery Kalin-Cellars and use the function "cl-fillers" to inspect the content of Napa-Valley's role wineries. You will see that now Napa-Valley has two fillers for the role wineries. ---------------------------------------------------------------- We won't make you go through all the wineries. But you might look at the file "/Helper/winery-region-info.lisp" to see what's in it. Then type: >>> (lload "Helper/winery-region-info.lisp") Use CLASSIC functions to determine the instances of FRENCH-WINERY and of OTHER-EUROPEAN-WINERY. Write a lisp function that takes as input a WINE-REGION and returns all the individual WINERYs in that region. (If things get messed up and you want to recover the state up to this point, type: >>> (lload "Recover/after-wineries.lisp") ) Type: (dribble) to close your log file now. --------------------------------------------------------------------------- END OF asg2.txt If you are going on, open the file "/asg3.txt" This file is part of: AT&T Bell Laboratories and University of Pittsburgh CLASSIC Knowledge Representation System Tutorial Copyright AT&T and University of Pittsburgh 1994 ASG3.TXT PRELIMINARIES Open a new log file: >>> (dribble "your-file3.log") If you are continuing from asg2.txt in the same session, you may want to recover the state of the system (in case you erred at some point previously). To recover state type >>> (lload "Recover/after-wineries.lisp") Otherwise, if you are continuing from asg2.txt in the same session, you may want to skip down to the end of the review section. If you are starting this assignment in a new session, type: >>> (load "/Customize.lisp") >>> (lload "Recover/after-wineries.lisp") REVIEW OF asg1.txt and asg2.txt In the first module of this assignment we covered: 1. How to create "DISJOINT-PRIMITIVE" concepts. Using this construct we created the concepts WINE-PROPERTY, CONSUMABLE-THING, WINERY, and WINE-REGION. We also constructed the concepts EDIBLE-THING, POTABLE-LIQUID, WINE-COLOR, WINE-BODY, WINE-SUGAR, WINE-FLAVOR, WINE and MEAL-FOOD. 2. How to get more or less debugging information from Classic when concepts and individuals are defined. 3. Commands for inspecting and navigating the KB. 4. Definition of Roles and Attributes. 5. Creation of individuals and the effect of role restrictions on individuals. In the second module of this assignment we covered: 6. Adding concepts to the KB in such a way that existing concepts and instances get reclassified under them (we illustrated this with REGIONAL-WINERY and its children). 7. Use of the inverse of a role. You may want to review some of these ideas. Note that from this point in the tutorial, warnings will not be given before telling the user to do something that might cause an unexpected response. The user should now be familiar enough with Classic and its error messages to realize when an error message or unexpected response is being used to make a point. If Classic returns something unexpected, read it and read further in the tutorial to decipher whether it is making a point before trying to redo the command in order to get a "better" response. PRACTICE WITH A FEW DEFINED CONCEPTS ------------------------------------ We will now start developing the KB of wines. We'll begin with definitions of some generic wine subconcepts. You should be able to define them yourself from the following specifications: RED-WINE: Is a WINE with the color role filled by Red. ROSE-WINE: Is a WINE with the color role filled by Rose. WHITE-WINE: Is a WINE with the color role filled by White. WHITE-NON-SWEET-WINE: Is a WHITE-WINE with the sugar role restricted to be one of Dry or Off-Dry. FULL-BODIED-WINE: Is a WINE with Full body. DRY-WINE: Is a WINE with the sugar role filled by Dry. DRY-WHITE-WINE: Is a WHITE-WINE and a DRY-WINE. DRY-RED-WINE: Is a RED-WINE and a DRY-WINE. SWEET-WINE: Is a WINE with sugar role filled by Sweet. Try to define the concepts yourself first. If you can't or you want to check your definitions, look at "/Recover/after-generic-wines.lisp". Make sure these concepts are defined before going on. In the above definitions, you could have used "FILLS" or "ONE-OF". For instance, the alternative definitions are equivalent. >>> (cl-define-concept 'DELICATE-WINE1 '(AND WINE (FILLS flavor Delicate))) and >>> (cl-define-concept 'DELICATE-WINE2 '(AND WINE (ALL flavor (ONE-OF Delicate)) )) Enter the two definitions, and test for their equivalence. How can you tell that Classic identifies these two concepts? (Hint: Notice the object returned from the second definition. When Classic can prove two definitions equivalent, it doesn't create two concepts that are subsumed by each other. Instead, it adds the name of the second-defined concept to the list of non-primary names of the first-defined concept. Therefore, to test for equivalence between two concepts, you can either see if the both names are in the list of names for one of the concepts, or you can use the eql lisp function.) The equivalence of these two definitions depends on the fact that flavor is an attribute, and that WINEs were required by definition to have at least one flavor. To illustrate the difference between such definitions in general, recall the definition of MEAL-FOOD. (cl-define-concept 'MEAL-FOOD '(AND EDIBLE-THING (AT-LEAST 1 appropriate-drink) (ALL appropriate-drink WINE) ) (You do not need to enter this definition!) Now, suppose that we define FOOD-GOOD-WITH-FORMAN-CHARDONNAY to be any MEAL-FOOD whose appropriate-drink role is filled with Forman-Chardonnay. (Enter the definition.) And let's define FOOD-GOOD-ONLY-WITH-FORMAN-CHARDONNAY to be any MEAL-FOOD all of whose appropriate-drinks are ONE-OF Forman-Chardonnay. (Enter the definition.) Would you expect either of these concepts to be classified under the other? Does Classic give the answer that you expect? Comment out your response. If Classic does not deduce that one of these concepts subsumes the other, it should be possible to create an individual that is subsumed by the first concept but not the second. Create such individuals now, and test them. (For instance, if Classic does not classify FOOD-GOOD-ONLY-WITH-FORMAN-CHARDONNAY under FOOD-GOOD-WITH-FORMAN-CHARDONNAY, create a specific individual Food1 that has FOOD-GOOD-WITH-FORMAN-CHARDONNAY as an ancestor, but not FOOD-GOOD-ONLY-WITH-FORMAN-CHARDONNAY.) USING RULES IN CLASSIC ---------------------- In this section we will learn to use rules in Classic and at the same time fill out the rest of the KB under WINE. USING RULES TO ENHANCE CONCEPTS In this section we will consider the use of rules in concept definitions. Consider the following definition of the concept CHARDONNAY: >>> (cl-define-concept 'CHARDONNAY '(AND wine (FILLS grape Chardonnay) )) This says that by definition, a CHARDONNAY is a wine with its grape role filled by Chardonnay. Since our simple definition of grape requires it to be an attribute, this means that a CHARDONNAY wine will have Chardonnay as its only grape. But there's a lot more we know about Chardonnay wines, e.g., they are white, they usually have full or medium body, and they have strong or moderate flavor. However, these things are not part of the definition of CHARDONNAY, they are incidental properties that are typical of Chardonnay wines. To specify such properties, we use rules like the following: >>> (cl-add-rule 'chardonnay-color @c{chardonnay} '(fills color white)) >>> (cl-add-rule 'chardonnay-body @c{chardonnay} '(all body (one-of full medium))) >>> (cl-add-rule 'chardonnay-flavor @c{chardonnay} '(all flavor (one-of strong moderate))) Enter the concept definition of Chardonnay and then enter the rules. (The rules use the Chardonnay concept). These rules say that any individual that gets classified as a CHARDONNAY will also be given certain constraints. Rules can be added incrementally at any point in building a knowledge base and will affect both existing individuals and individuals created later. You may have noticed that when we defined WINE, we were not able to place an appropriately specific restriction on the grape role. As a reminder, we repeat the role information from the definition of WINE. Role Restrictions: Color![1 ; 1] => @c{WINE-COLOR} Body![1 ; 1] => @c{WINE-BODY} Flavor![1 ; 1] => @c{WINE-FLAVOR} Sugar![1 ; 1] => @c{WINE-SUGAR} Grape![1 ; 1] => @c{EDIBLE-THING} You would have expected a restriction to GRAPE in the Grape role, rather than to the less specific EDIBLE-THING. We had to be content with the definition that we used because Classic will not tolerate circularities in definitions. GRAPE is defined in our KB in a way that classifies it under MEAL-FOOD; browse in the KB to determine the chain of parent concepts that lead from GRAPE to MEAL-FOOD. But in our KB, MEAL-FOOD is a defined concept, and part of the definition is a restriction of the appropriate-drink role to WINE! It was to avoid this circle that we used EDIBLE-THING rather than GRAPE. We can repair this by adding a rule restricting the fillers of the grape role in WINE to GRAPE. Write this rule now. We also expect each WINE to have a maker (which is a WINERY), and a region (which is a WINE-REGION). In this domain, we can expect each WINE to have exactly one region, and exactly one maker. So we can treat these roles as attributes. (Remember that :attribute and :inverse are keywords for the function you will use to add these roles). Use that function to add them now, and write rules that attach them to WINE. Now, let's return to CHARDONNAY. Recall that we added rules to the definition of this wine, providing information about color, body, and flavor. Here is what the rule information looks like if you inspect the concept CHARDONNAY. >>> (cl-print-concept @C{CHARDONNAY}) @c{CHARDONNAY} -> Derived Information: Primitive ancestors: (@c{POTABLE-LIQUID} @c{CONSUMABLE-THING} @c{CLASSIC-THING}) Parents: (@c{WINE}) Ancestors: (@c{THING} @c{CLASSIC-THING} @c{CONSUMABLE-THING} @c{POTABLE-LIQUID}) Role Restrictions: Color![1 ; 1] => @c{WINE-COLOR} Body![1 ; 1] => @c{WINE-BODY} Flavor![1 ; 1] => @c{WINE-FLAVOR} Sugar![1 ; 1] => @c{WINE-SUGAR} Grape![1 ; 1] -> (@i{CHARDONNAY}) => @c{EDIBLE-THING} Rules: 1. @rule{WINE-GRAPE} -> Antecedent: @c{WINE} Consequent: Role Restrictions: Grape! => @c{GRAPE} 2. @rule{WINE-MAKER} -> Antecedent: @c{WINE} Consequent: Role Restrictions: Maker![1 ; 1] => @c{WINERY} 3. @rule{WINE-REGION} -> Antecedent: @c{WINE} Consequent: Role Restrictions: Region![1 ; 1] => @c{WINE-REGION} @c{CHARDONNAY} There is not as much information attached to the concept as you might expect, because rules are only used in Classic to obtain information about individuals. We can use this fact to find out what Classic knows about the concept, by creating a temporary "generic individual". What makes this individual a generic Chardonnay is the fact that we will only attach information to it that is already included in the CHARDONNAY concept. Let's create the individual Generic-Chardonnay, and see what happens. (You can enter the following command line if you like, to see that Classic in fact behaves as reported here. Or you can simply read the following few lines.) >>> (cl-create-ind 'Generic-Chardonnay 'CHARDONNAY) @i{GENERIC-CHARDONNAY} >>> (cl-print-object @i{GENERIC-CHARDONNAY}) @i{GENERIC-CHARDONNAY} -> Derived Information: Primitive ancestors: (@c{POTABLE-LIQUID} @c{CONSUMABLE-THING} @c{CLASSIC-THING}) Parents: (@c{WHITE-WINE} @c{CHARDONNAY}) Ancestors: (@c{THING} @c{CLASSIC-THING} @c{CONSUMABLE-THING} @c{POTABLE-LIQUID} @c{WINE}) Role Fillers and Restrictions: Region![1 ; 1] => @c{WINE-REGION} Maker![1 ; 1] => @c{WINERY} Grape![1 ; 1] -> (@i{CHARDONNAY}) => @c{GRAPE} Flavor![1 ; 1] => Primitive ancestors: (@c{WINE-PROPERTY} @c{CLASSIC-THING}) One-of Restr: (@i{MODERATE} @i{STRONG}) Body![1 ; 1] => Primitive ancestors: (@c{WINE-PROPERTY} @c{CLASSIC-THING}) One-of Restr: (@i{MEDIUM} @i{FULL}) Color![1 ; 1] -> (@i{WHITE}) => @c{WINE-COLOR} Sugar![1 ; 1] => @c{WINE-SUGAR} @i{GENERIC-CHARDONNAY} There are several points to be made here: There is some fairly sophisticated classificational reasoning going on here. The role color has been filled with White by a rule. Thus, because Generic-Chardonnay has color White, the Classic classifier can determine that Generic-Chardonnay is also a WHITE-WINE. We can also see that the body and flavor roles have not been filled, since the restriction to one of two fillers for body and flavor does not allow Classic to infer a single filler: >>> (cl-fillers @i{Generic-Chardonnay} @r{flavor}) NIL >>> (cl-fillers @i{Generic-Chardonnay} @r{body}) NIL Instead, restrictions have been added to Generic-Chardonnay by the rules attached to the CHARDONNAY and the WINE concept: >>> (cl-print-ind @i{Generic-Chardonnay}) @I{GENERIC-CHARDONNAY} -> ... Role Fillers and Restrictions: Region![1 ; 1] => @c{WINE-REGION} Maker![1 ; 1] => @c{WINERY} Grape![1 ; 1] -> (@i{CHARDONNAY}) => @c{GRAPE} Flavor![1 ; 1] => Primitive ancestors: (@c{WINE-PROPERTY} @c{CLASSIC-THING}) One-of Restr: (@i{MODERATE} @i{STRONG}) Body![1 ; 1] => Primitive ancestors: (@c{WINE-PROPERTY} @c{CLASSIC-THING}) One-of Restr: (@i{MEDIUM} @i{FULL}) Color![1 ; 1] -> (@i{WHITE}) => @c{WINE-COLOR} Sugar![1 ; 1] => @c{WINE-SUGAR} @i{GENERIC-CHARDONNAY} Be sure that you understand the sources of the information that are reported in the above printout; what definitions and rules are used? To illustrate the incremental addition of information to individuals, let's create another individual, My-Chardonnay. My-Chardonnay will begin life as a generic CHARDONNAY, but we will add information to it using "IND-ADD", which acts somewhat like a rule, but is restricted to a particular individual. At this point, you should create My-Chardonnay and print information about it. Classic should report that My-Chardonnay looks just like Generic-Chardonnay. With My-Chardonnay in the KB, first try to add information to Generic-Chardonnay that conflicts with the rules associated with CHARDONNAY. Try the following: the attempt should create an error. Add the fact that My-Chardonnay's flavor is Delicate. Now, try the following. (Use one Classic command to do this, rather than two.) This time, the attempt should work. Add the fact that My-Chardonnay's flavor is Strong, and its body is Medium. Here is what you should get at this point if you ask about My-Chardonnay. >>> (cl-print-ind @My-Chardonnay) @i{MY-CHARDONNAY} -> Derived Information: Primitive ancestors: (@c{POTABLE-LIQUID} @c{CONSUMABLE-THING} @c{CLASSIC-THING}) Parents: (@c{WHITE-WINE} @c{CHARDONNAY}) Ancestors: (@c{THING} @c{CLASSIC-THING} @c{CONSUMABLE-THING} @c{POTABLE-LIQUID} @c{WINE}) Role Fillers and Restrictions: Region![1 ; 1] => @c{WINE-REGION} Maker![1 ; 1] => @c{WINERY} Grape![1 ; 1] -> (@i{CHARDONNAY}) => @c{GRAPE} Flavor![1 ; 1] -> (@i{STRONG}) => Primitive ancestors: (@c{WINE-PROPERTY} @c{CLASSIC-THING}) One-of Restr: (@i{MODERATE} @i{STRONG}) Body![1 ; 1] -> (@i{MEDIUM}) => Primitive ancestors: (@c{WINE-PROPERTY} @c{CLASSIC-THING}) One-of Restr: (@i{MEDIUM} @i{FULL}) Color![1 ; 1] -> (@i{WHITE}) => @c{WINE-COLOR} Sugar![1 ; 1] => @c{WINE-SUGAR} @i{MY-CHARDONNAY} It would be nice to have a function that takes an instance, e.g, @i{MY-CHARDONNAY} as an argument, and returns a list of the roles and their fillers, e.g., a function that has the following behavior: > (find-role-fillers @i{MY-CHARDONNAY}) ((@r{GRAPE} @i{CHARDONNAY}) (@r{REGION}) (@r{SUGAR}) (@r{COLOR} @i{WHITE}) (@r{BODY} @i{MEDIUM}) (@r{FLAVOR} @i{STRONG}) (@r{MAKER})) Try writing such a function using existing Classic functions. If you use the Common LISP macro LOOP, this function takes 3 lines of code (and that's putting the defun on a separate line!) The trick is to find the functions that Classic already provides that makes writing this function trivial. Before you go on, type: >>> (lload "Recover/after-wine-varieties.lisp") You may get an error saying that CHARDONNAY has already been defined. Ignore it. Because they add information to an individual classified under the concept that is the antecedent of the rule, rules may also cause further classification to occur. Consider the following individual. (Type it in). >>> (cl-create-ind 'Chateau-lafite-rothschild-pauillac '(AND PAUILLAC (FILLS maker Chateau-lafite-rothschild))) Then look at what its ancestors are. It was only asserted to be a PAUILLAC, but a PAUILLAC is a MEDOC and MEDOC has rules that set sugar to Dry, and color to Red. Therefore, Chateau-Lafite-Rothschild can be inferred to be a DRY-RED-WINE and a CABERNET-SAUVIGNON-WINE. WHY ARE RULES BEING USED? There are several reasons for using rules, but the reason they are being used here, in the definition of the wine varieties, is probably the most important one from a conceptual point of view. Basically, rules are used to add to an individual information that is not definitional, i.e., you do not want to force an individual to have that information associated with it before you classify it as an instance of the concept. In the case of CHARDONNAY, above, the concept definition is saying that the color, body, and flavor information is not definitional for concept CHARDONNAY, although an individual that is classified as a CHARDONNAY will have these characteristics. The definitional characteristic of CHARDONNAY is the type of grape it is made from. As another more familiar example, consider a concept PERSON. We know that PERSONs have a social security number, but it should not be necessary for a person to have a SSN in order to be classified as a PERSON. Instead we would want the system to infer that it has a SSN and that, even if you didn't know what it was, it would have to have 9 digits. So you might add a rule to that effect. INFORMATION THAT CAN BE ADDED WITH RULES Rules, we said, are commonly used to add non-definitional information to instances of a concept. This information can be restrictions, fillers, or parents. 1. ADDING RESTRICTIONS. We have already seen, with CHARDONNAY and My-Chardonnay, an example of adding restrictions. Recall that body and flavor got their restrictions from rules. 2. ADDING FILLERS. Here is an example of adding fillers explicitly (grape is filled by inheritance). The file /Helper/wine-varieties defined CHENIN-BLANC as follows: (cl-define-concept 'CHENIN-BLANC '(AND WINE (fills grape CHENIN-BLANC))) (cl-add-rule 'chenin-blanc-color @c{CHENIN-BLANC} '(fills color White)) (cl-add-rule 'chenin-blanc-body @c{CHENIN-BLANC} '(all body (one-of Full Medium))) (cl-add-rule 'chenin-blanc-flavor @c{CHENIN-BLANC} '(fills flavor Moderate)) (cl-add-rule 'chenin-blanc-sugar @c{CHENIN-BLANC} '(all sugar (one-of Dry Off-dry))) Create an individual called Ventana-Chenin-Blanc that is a CHENIN-BLANC and has maker Ventana. Then print the object and verify that the roles color and flavor now each have a filler. 3. ADDING PARENTS. Here is an example of explicitly classifying an individual under a different concept. Type the following definitions. (cl-define-concept 'SPECIAL-RED-BORDEAUX '(AND BORDEAUX-WINE RED-WINE)) (cl-add-rule 'special-red-bordeaux-type @c{SPECIAL-RED-BORDEAUX} 'CABERNET-SAUVIGNON-WINE) Any instance of SPECIAL-RED-BORDEAUX will become a CABERNET-SAUVIGNON-WINE as well. Create an individual called My-Red-Bordeaux and define it to be a BORDEAUX-WINE and a RED-WINE (these concepts were already defined). Verify that its ancestors are: 1. A RED-BORDEAUX (because of the definition of RED-BORDEAUX) 2. A CABERNET-SAUVIGNON-WINE (because of the rule above) 3. A DRY-RED-WINE (because CABERNET-SAUVIGNON-WINEs are restricted to be dry) ADDING AND REMOVING RULES Rules do not need to be specified when a concept is defined. They can be added later as well as removed. Let's modify the information associated with the instances of RED-BORDEAUX (see above) by removing the special-red-bordeaux-type rule, and then let's add it back in. To remove the rule, type: >>> (cl-remove-rule (cl-named-rule 'special-red-bordeaux-type)) This will take a little time because it has to remove the rule as well as retract any inferences made when the rule fired on individuals. Check that the wine we created, My-Red-Bordeaux, is now no longer classified as either a CABERNET-SAUVIGNON or a DRY-RED-WINE. If we add the rule back in: >>> (cl-add-rule 'special-red-bordeaux-type @c{SPECIAL-RED-BORDEAUX} 'CABERNET-SAUVIGNON-WINE) the rule-derived ancestry for My-Red-Bordeaux is reestablished. FILTERS ON RULES: A rule may optionally contain a filter which is a concept description that must be satisfied before the rule can fire. By using a filter, we can avoid creating an unnecessary named concept whose only purpose is to be the antecedent of a rule. (QUESTION: Why is it a good idea not to create named concepts that are unnecessary? Type your answer into the lisp session in lines that begin with the comment symbol ";" so that your answer will appear in your dribble file.) First define a primitive concept called RICH-FAVORITE-WINE that is a WINE. Now define a rule called RICH-FAV that infers that a WINE is Rich's favorite wine if its color is RED and the wine is made only of the grape Cabernet-sauvignon. Create an individual, call it Good-wine, that will cause the rule RICH-FAV to fire and classify Good-wine under RICH-FAVORITE-WINE. Show that this classification happens. There are other types of rules in CLASSIC. Make sure you read the manual and understand these. Type: (dribble) to close your log file now. --------------------------------------------------------------------------- END OF asg3.txt If you are going on open the file "/asg4.txt" This file is part of: AT&T Bell Laboratories and University of Pittsburgh CLASSIC Knowledge Representation System Tutorial Copyright AT&T and University of Pittsburgh 1994 ASG4.TXT PRELIMINARIES Open a new log file: >>> (dribble "your-file4.log") If you are continuing from asg3.txt in the same session type >>> (lload "Helper/just-wines.lisp") or type >>> (lload "Recover/after-just-wines.lisp") to recover state. Otherwise, if this is a new session, type: >>> (load "/Customize.lisp") >>> (lload "Recover/after-just-wines.lisp") These loading operations may take a bit of time because they are adding many wine individuals to the KB. REVIEW OF asg1.txt through asg3.txt In the first module of this assignment we covered: 1. How to create "disjoint-primitive" concepts. Using this construct we created the concepts WINE-PROPERTY, CONSUMABLE-THING, WINERY, and WINE-REGION. We also constructed the concepts EDIBLE-THING, POTABLE-LIQUID, WINE-COLOR, WINE-BODY, WINE-SUGAR, WINE-FLAVOR, WINE and MEAL-FOOD. 2. How to get verbose or laconic debugging information from Classic when concepts and individuals are defined. 3. Commands for inspecting and navigating the KB. 4. Definition of Roles and Attributes. 5. Creation of individuals and the effect of role restrictions on individuals. In the second module of this assignment we covered: 6. Adding concepts to the KB in such a way that existing concepts and instances get reclassified under them (we illustrated this with REGIONAL-WINERY and its children). 7. Use of the inverse of a role. In the third module of this assignment we covered: 8. Using rules in Classic: enhancing concepts via rules, adding and removing rules. The main use of rules, i.e. for adding non-definitional information to instances that get classified under a concept. You may want to review some of these. MORE USES OF RULES ------------------ Definitions can help to organize knowledge, but most useful domain information does not follow from concept definitions alone. Classic provides rules as a way to extend our knowledge of individuals, by adding information that can't be inferred from the definitions of the concepts under which the individual is classified, but that will nonetheless be expected or known. In the last module we saw how rules can be used for this purpose. In this module we will look at some other uses for rules. You might want to briefly review the end of asg3.txt before proceeding. RULES FOR CREATING PURELY DISJUNCTIVE CONCEPTS We have seen that the "ONE-OF" restriction construct can be used to define a concept as a disjunction of individual instances. The definition of WINE-FLAVOR in asg1.txt is an example. > (cl-define-concept 'WINE-FLAVOR '(AND WINE-PROPERTY (ONE-OF Delicate Moderate Strong))) However, there is no general way in Classic to define a concept as a disjunction of several other concepts. For instance, there is no direct way to define a concept of DELICATE-OR-WHITE-WINE. Disjunction is intentionally limited in Classic. Despite these limitations, we can often use rules to achieve some of the effects of disjunctive concepts. "Dirty tricks" of this sort are of course risky, but they can be useful. We will use an example to illustrate the use of rules to imitate disjunctive concepts. We know that in many cases, a concept is (implicitly) a disjunction of its children concepts. Suppose you want to define a primitive concept MY-FAVORITE-WINE whose only restrictions are that it must be either a CHARDONNAY or an ITALIAN-WINE. There is no straightforward way in Classic of expressing this restriction using the constructs for defining primitive concepts. But we can use rules to approximate the disjunctive concept that we want in the definition, as follows. 1. Create a primitive concept MY-FAVORITE-WINE under WINE. (The concept has to be primitive because there is nothing definitional distinguishing it from its parent concept WINE.) 2. Add rules to CHARDONNAY and ITALIAN-WINE asserting that any instance of each of these concepts should also be an instance of MY-FAVORITE-WINE. (Note that this information is certainly not definitional for either CHARDONNAY or ITALIAN-WINE.) This is only an approximation of true disjunction for several reasons. For instance, if we create an individual My-Wine and tell Classic that it is a MY-FAVORITE-WINE with its region filled by Sonoma, Classic will not infer that it is a CHARDONNAY. Moreover, if we create another individual, My-wine2, and tell Classic that it is MY-FAVORITE-WINE and a BORDEAUX-WINE, Classic will not detect the inconsistency. You can think of it this way: this trick will in general provide sufficient conditions for classifying something under MY-FAVORITE-WINE, but it won't provide necessary conditions. Try to implement the idea, in the following steps. 1. Create the concept MY-FAVORITE-WINE. 2. Show that there are no instances under the new concept. 3. Add the appropriate rules to CHARDONNAY and ITALIAN-WINE and show that the concepts now have them. You can use "cl-concept-rules" for this. 4. Show that MY-FAVORITE-WINE now has the appropriate instances. (To recover state here, use (lload "Recover/after-just-wines.lisp") ) USING RULES TO CREATE "QUERY TEMPLATES" This section introduces a use for rules that extends the type of reasoning you might think Classic is capable of doing. The definitions and rules are in file: "/Helper/food-wines.lisp". Look at the file, if you wish, then type: >> (lload "Helper/food-wines.lisp") The "food-wines.lisp" knowledge base contains examples like the following ones, which provide information about wines appropriate for spicy-red-meat food. Do NOT enter these commands; they were included in the file you just loaded. (cl-add-rule 'spicy-red-meat-wine-color @c{spicy-red-meat} '(all appropriate-drink (fills color red))) (cl-add-rule 'spicy-red-meat-wine-body @c{spicy-red-meat} '(all appropriate-drink (fills body full))) (cl-add-rule 'spicy-red-meat-wine-flavor @c{spicy-red-meat} '(all appropriate-drink (fills flavor moderate))) (cl-add-rule 'spicy-red-meat-wine-sugar @c{spicy-red-meat} '(all appropriate-drink (fills sugar dry))) Note that the rules associated with a food concept impose a number of restrictions on any wine that fills the appropriate-drink role of an instance of the concept. The rules concentrate on the appropriate-drink role because we are assuming that the knowledge base we are building would be used to give advice in selecting drinks to go with certain foods. If we were interested in other kinds of advice (suitability for certain sorts of diets, for instance), we would have to modify the food concept by adding appropriate roles, and would need to add rules constraining these roles. You'll see below how these rules are used. Suppose we want to find out what wines go with a SPICY-RED-MEAT food. We first create a meal course that is a SPICY-RED-MEAT. >>> (cl-create-ind 'my-meal-food '(AND SPICY-RED-MEAT (FILLS appropriate-drink Some-Wine))) Create my-meal-food using this definition, and use "cl-print-object" to inspect it. You will notice that the role "appropriate-drink" has restrictions associated with it, that were created by the rules for SPICY-RED-MEAT. These restrictions represent what we know about a wine, when we are told that it is appropriate with any instance of SPICY-RED-MEAT. Manually browse through the knowledge base for an individual wine that meets all these restrictions, and an individual instance of SPICY-RED-MEAT. Do you expect Classic to know that the wine is appropriate for the meat? Make your prediction, and then query Classic for the answer. Explain why Classic gives the result it does, and test your prediction, before reading the following paragraph. ************************************************** BLANK SPACE BLANK SPACE ************************************************** You should have discovered that Classic doesn't know that any wine at all is appropriate with my-meal-food, or Beef-Curry (which is also an instance of spicy-red-meat). In particular, it doesn't know that Mazocco-Zinfandel is appropriate with Beef-Curry, even though you can verify that Mazocco-Zinfandel in fact meets all of the restrictions we have placed on the color, body, flavor, and sugar of any filler of the appropriate-wine role of an instance of SPICY-RED-MEAT. And in fact, Classic is right to remain ignorant here. There are several reasons why the system shouldn't reach this conclusion, all of them connected with the design philosophy of Classic, which is intended to facilitate the representation of partial information about the objects that populate "open domains". (1) The role restrictions give necessary, not sufficient conditions. The fact that we have put these restrictions on what wines are appropriate with spicy red meats doesn't exclude the possibility of other restrictions that we haven't entered or aren't aware of. (2) The fact that Beef-Curry is a SPICY-RED-MEAT does not prevent it from being classified under some other concept, which might impose additional restrictions on the fillers of the appropriate-drink role. But even the most open domains can have parts that are closed; and it is often very useful in special cases to simulate closed-world reasoning. The case of SPICY-RED-MEAT is a good example. It is reasonable to expect here that we have listed all the conditions that make a wine appropriate for a spicy red meat, so that a wine that satisfies them will in fact be a good recommendation for a meal featuring SPICY-RED-MEAT. In fact, it is hard to see how we can use the knowledge we have put into the system to make useful meal-planning suggestions without making some assumption of this sort. To explore how to do this, let's return to the individual my-meal-food that we created above. Remember that the role "appropriate-drink" has only the restrictions that follow from assuming that a wine goes with SPICY-RED-MEAT. What we need to know now is, which individual wines in our knowledge base satisfy these restrictions. For this we can use the function "cl-object-subsumes" in the following way. (An explanation of this function is in the Classic Manual in the section entitled "Subsumption Retrieval Functions". It can be found in section D.5.1 in version 2.2 of the manual). >> (cl-object-subsumes @my-meal-food @appropriate-drink) The function "cl-object-subsumes" takes the ALL restriction on the appropriate-drink role of the individual and retrieves the wines that match this description. Enter the above command; Classic should return the following answer to your query: (@i{MAZOCCO-ZINFANDEL}) Mazocco-Zinfandel is in fact the only wine in our KB that we can recommend with a SPICY-RED-MEAT. You can see that techniques like this have to be used with care. We have to recognize the closed-world constraints that went into our recommendation: all we really know is that Mazocco-Zinfandel is not incompatible with SPICY-RED-MEAT. We are hoping that our constraints are complete enough so that any wine that is not incompatible with the constraints will in fact be appropriate. In the previous example the relationships between meal-foods and appropriate wines have been expressed through rules. And in fact we recommended a wine as appropriate for SPICY-RED-MEAT without ever actually filling the appropriate-drink role. (You might want to check at this point to verify that Mazocco-Zinfandel still does not fill the appropriate-drink role of Beef-Curry.) USE of TEST-C ============== The next concept we need to define is MEAL-COURSE. Intuitively, a meal-course is a part of a meal that may consist of one or more foods that one served at the same time. Usually a meal-course consists of foods that go together, such as beef curry, rice, and chutney in an entree, or strawberries and cream in a dessert course. We assume that a MEAL-COURSE will have exactly one associated drink that is served with it. Next you will try to define the Classic concept for MEAL-COURSE so that: 1) It is a CONSUMABLE-THING. 2) It consists of at-least 1 food MEAL-FOOD 3) It has exactly one course-drink, which is a WINE. In order to define this new concept, you need to create its two roles first. We can imagine a course being accompanied by more than one wine, but in our domain, where meals are supposed to be well coordinated, we can assume that this will never happen. Therefore it is worthwhile to treat the course-drink role as an attribute. Thus, you should create roles as follows. Do it now. 1. course-drink: an attribute (role with single filler) 2. food: a role (with possibly more than one filler) With the roles in place, you can now enter the definition of MEAL-COURSE. Note that in CLASSIC, you cannot put a restriction on only one of a set of unknown fillers of a role without putting the restriction on all of them. Be careful! Since concepts cannot be modified, you cannot undo an incorrect concept without clearing and reloading the whole KB. We said that a MEAL-COURSE can have more than one associated MEAL-FOOD, and we know that each MEAL-FOOD imposes restrictions over the kind of WINE that you can serve with it. Continuing, let's define two new concepts: 1) SINGLE-FOOD-MEAL-COURSE, which is a MEAL-COURSE that has AT-MOST 1 food. 2) APPROPRIATE-SINGLE-FOOD-MEAL-COURSE, a SINGLE-FOOD-MEAL-COURSE whose course-drink is an appropriate-drink for its food. (You will need to use a TEST-C description to express this condition. Its use is discussed in the section called "Procedural tests", in the Classic Manual which is section 2.1.4.1 in version 2.2). In writing the condition, assume that each MEAL-FOOD has its appropriate-drink role filled by all the wines that are appropriate with the food. Define the above concepts now. If you have trouble, you can find the above definitions in the file "Helper/single-food-meal-course.lisp". If you need to recover the knowledge base up to this point, load "Recover/after-single-meal-course.lisp". To test your definition, type the following: >>> (cl-create-ind 'My-Meal-Course1 '(and SINGLE-FOOD-MEAL-COURSE (fills food Lobster) (fills course-drink Forman-Chardonnay))) >>> (cl-create-ind 'My-Meal-Course2 '(and SINGLE-FOOD-MEAL-COURSE (fills food Lobster) (fills course-drink COTTURI-ZINFANDEL))) Since Forman-Chardonnay meets the specifications for an appropriate drink with lobster, My-Meal-Course1 should satisfy the concept APPROPRIATE-SINGLE-FOOD-MEAL-COURSE. However, Cottturi-Zinfandel is not a white wine and thus, is not appropriate with lobster. So, My-Meal-Course2 is not an APPROPRIATE-SINGLE-FOOD-MEAL-COURSE. Make sure that you get this result. Now define a LISP function, CHECK-MY-MEAL-COURSE, that accepts as input an individual MEAL-FOOD and another individual WINE and tells you whether or not the resulting individual SINGLE-FOOD-MEAL-COURSE is appropriate, and, if it is not, tells you what wines would make it appropriate. Show how your function works. THE SAME-AS RESTRICTION ====================== Now, let's define three subconcepts of MEAL-COURSE: APPETIZER-COURSE, ENTREE-COURSE, AND DESSERT-COURSE. An APPETIZER-COURSE is a course all of whose foods are APPETIZERs; the other sorts of courses are defined similarly. (Recall that APPETIZER, ENTREE and DESSERT were previously defined as primitive subconcepts of MEAL-FOOD. You can verify this by consulting the file "/Helper/meal-foods.lisp>" and the figure "/edible-thing.ps>".) Enter the definitions of these three concepts now. We can now define the concept of a MEAL. We will think of a MEAL as a CONSUMABLE-THING with attributes 1) main-course, which is restricted to ENTREE-COURSE; 2) appetizer-course, which is restricted to APPETIZER-COURSE; 3) dessert-course, which is restricted to DESSERT-COURSE. Define MEAL now. At this stage, we have created some highly structured concepts, involving multiple role paths. Roles can be used to restrict individuals or concepts. Here, we are using roles main-course, course-food, appropriate-drink and color to restrict the concepts MEAL, ENTREE-COURSE, MEAL-FOOD and WINE as follows. A MEAL's main-course is restricted to ENTREE-COURSE. An ENTREE-COURSE's course-food is restricted to MEAL-FOOD. A MEAL-FOOD's appropriate-drink is restricted to WINE. A WINE's color can be filled by any one of White, Rose, and Red. Thus, given an individual that satisfies MEAL, Classic should be capable of reasoning about its main-course's course-food's appropriate-drinks' colors. It should provide an error message, for instance, if you provide information that would require the filler along this role path to be anything but one of the three individuals White, Rose, or Red. It might be helpful for you at this point to diagram the concept MEAL and the concepts that restrict its roles. The next concepts that you have to add are 1) CHEAP-MEAL: a MEAL in which all three courses are SINGLE-FOOD-MEAL-COURSE; 2) ONE-WINE-MEAL: a MEAL in which the wine is the same for every course served (Use the SAME-AS function to add this concept. The SAME-AS function is discussed in two sections of the Classic Manual called "Equality Restrictions (SAME-AS); sections 2.1.3.4 section 2.2.1 in version 2.2; 3) REALLY-CHEAP-MEAL: a CHEAP-MEAL that is also a ONE-WINE-MEAL. To test what you have done, create a new individual Cheapo that is a REALLY-CHEAP-MEAL. Print Cheapo and verify that Classic returns the expected information. The above definitions can be found in "Helper/meals.lisp". Now, create a new individual Cheapo-Appetizer. Cheapo-Appetizer is an APPETIZER-COURSE whose course-drink is Forman-Chardonnay. Add Cheapo-Appetizer as the appetizer-course of Cheapo. Now reprint Cheapo-appetizer. What new information has Classic inferred? Go on to create a new individual Cheapo-Entree, which is an ENTREE-COURSE whose course-drink is a RED-WINE. What result do you expect if you assign Cheapo-Entree as the filler of the main-course role of Cheapo? Compare this with the result that Classic returns, and explain any discrepancy. We are nearly at the end of this part of the assignment, and will turn to a more open-ended task. The last experiments that you were doing with Classic should have suggested ways in which the knowledge base we have developed could be used to make suggestions and critique certain meal plans. You should now carry this a bit further by identifying several reasoning tasks that Classic could perform using the concepts we have defined up to now and others that you might want to add. (For example, you could explore how to have Classic give suggestions to someone who is planning a REALLY-CHEAP-MEAL and wants its courses to all be appropriate.) Implement a little demonstration of your reasoning tasks using appropriate LISP functions. ========================================================== USING RULES TO BREAK CIRCULAR DEFINITIONS The wines KB/domain doesn't really have much circularity. But suppose you were asked to define the following concepts: PERSON: a primitive CHILD: a PERSON with parents who are PARENTs PARENT: a PERSON with at least 1 children who are CHILDs CHILD would have to be defined before PARENT and viceversa. To break the loop, you could: 1. define PARENT as a person with at least one children and all of whose children are PERSONs; 2. define CHILD as a PERSON with a parents role all of whose fillers are PARENTs; 3. add a rule to PERSON that says that every instance of PERSON should also be classified as a CHILD. Try this. ===================================================================== Type: (dribble) to close your log file now. --------------------------------------------------------------------------- END OF asg4.txt YOU ARE DONE WITH THIS ASSIGNMENT This file is part of: AT&T Bell Laboratories and University of Pittsburgh CLASSIC Knowledge Representation System Tutorial Copyright AT&T and University of Pittsburgh 1994 ASG5.TXT PRELIMINARIES Open a new log file: >>> (dribble "your-file5.log") The knowledge base that we will work with is essentially the one at the start of assignment 4. In order to make it easier to peruse what was loaded in, this has all been merged into one file. This new file is basically just "Recover/after-just-wines.lisp", expanded to include all the files it loaded. We also added the rules in "foods-wines.lisp". The entire file is now in "expanded-wines-kb.lisp". (There are some slight modifications in this file, so be sure to use the file "expanded-wines-kb.lisp" for this exercise, rather than "after-just-wines.lisp".) Load this file: >>> (load "/Customize.lisp") >>> (lload "Recover/expanded-wines-kb.lisp") REVIEW OF asg1.txt through asg4.txt In the first module of this assignment we covered: 1. How to create "disjoint-primitive" concepts. Using this construct we created the concepts WINE-PROPERTY, CONSUMABLE-THING, WINERY, and WINE-REGION. We also constructed the concepts EDIBLE-THING, POTABLE-LIQUID, WINE-COLOR, WINE-BODY, WINE-SUGAR, WINE-FLAVOR, WINE and MEAL-FOOD. 2. How to get verbose or laconic debugging information from Classic when concepts and individuals are defined. 3. Commands for inspecting and navigating the KB. 4. Definition of roles and attributes. 5. Creation of individuals and the effect of role restrictions on individuals. In the second module of this assignment we covered: 6. Adding concepts to the KB in such a way that existing concepts and instances get reclassified under them (we illustrated this with REGIONAL-WINERY and its children). 7. Use of the inverse of a role. In the third module of this assignment we covered: 8. Using rules in Classic: adding and removing rules. The main use of rules, i.e. for adding non-definitional info to instances that get classified under a concept. In the fourth module of this assignment we covered: 9. More use of rules: using rules to create disjunctive concepts, query templates, and circular definitions. 10. Using tests. 11. "Same-as" restrictions. You may want to review some of these topics. The purpose of this assignment is to investigate some of the issues involved with debugging and maintaining knowledge bases. While we are primarily interested in your learning the material, we are also interested in how easy or hard it is for you to learn. There are 5 times where you will be asked to time yourself while doing a task. You will not be graded on your times. Please be accurate on times. Please do make sure to include times. If by some chance you forget to time something, make an estimate and note that it was an estimate. You will also be asked to write notes in your dribble files at places. You can either precede each line with a ; so that LISP does not try to evaluate your statements, or you can surround a block of text with #| lots of text |# There is a 3 part question on one step explanations, a 4 part question on complete explanations of error situations, a 4 part question on pruning settings, and an extra credit question. USING, DEBUGGING and MAINTAINING KNOWLEDGE BASES ------------------------------------------------ In order to effectively develop, use, and extend knowledge bases, we need to be able predict the results of additions and queries. Thus, we should understand the inferences that the system makes. We will first explore the use of explanation functions to aid in this process. The last assignment (asg4) suggested that you create My-Meal-Food and explored what was true of the associated wine. We will now go into a bit more detail about some of the inferences CLASSIC makes. Let's investigate how some of the foods in the knowledge base got their restrictions on their appropriate-drink role. In asg4, you looked at the restrictions on spicy-red-meat foods. There are two ways to do this: you could just pick one of the SPICY-RED-MEAT foods in the knowledge base like Beef-curry and examine that or you could create a new SPICY-RED-MEAT food and look at it. Let's define the same SPICY-RED-MEAT food again, and examine it through the explanation functions. Define @My-meal-food again as: >>> (cl-create-ind 'My-Meal-Food '(AND SPICY-RED-MEAT (FILLS appropriate-drink Some-Wine))) Let's investigate Some-Wine again. First print it: >>>(cl-print-ind @some-wine) If we are interested in recommending wines with foods, we would want to figure out why some wine has certain fillers and restrictions for the sugar, flavor, body, and color roles. We could ask for a general explanation of the food as follows: >>>(cl-exp @some-wine) However, since the four roles, which we are interested in, have specific fillers, we can ask specifically how the fillers got there by typing: >>>(cl-exp @some-wine :aspect 'fills) We see that almost everything of interest on Some-Wine came from a propagation on My-Meal-Food because of restrictions on its appropriate-drink role. The restrictions on My-Meal-Food's appropriate-drink role influence Some-Wine because Some-Wine is known to fill My-Meal-Food's appropriate-drink role, and thus it must satisfy all the accompanying restrictions. The next question is how those restrictions got there at all. To use explanation to determine that, ask >>> (cl-exp @my-meal-food :role-path @appropriate-drink) Now we see that rule firings account for all the fills restrictions on color, body, flavor, and sugar. So, any spicy red meat food, such as Beef-Curry, should have a Red-Wine as its appropriate-drink because of the red-meat-wine-color rule, a Full-Wine because of the spicy-red-meat-wine-body rule, a Moderate-Wine because of the spicy-red-meat-wine-flavor rule, and a Dry-Wine because of the meat-wine-flavor rule. Above, we went through a two step explanation, first explaining Some-Wine and then explaining a particular role on My-Meal-Food. In this case, we could have actually simplified this process by just choosing a food, like Beef-Curry, and explaining the restrictions on its appropriate-drink role. >>> (cl-exp @beef-curry :role-path @appropriate-drink) Now, let's look at another class of food in the knowledge base. We will consider things that fall under Non-Oyster-Shellfish. Consider Lobster, and suppose that we are interested in the appropriate-drink's color, body, flavor, and sugar roles. Don't bother to create a new food and associate a wine with it, just use Lobster. Now we will time a task. Explanation 1. ***START TIMING HERE. Put a ; in your dribble file and note the time. Now use cl-exp on Lobster to answer why its appropriate-drink role has each restriction on the following roles: color, body, flavor, and sugar. ***STOP TIMING HERE. Note the time that it took you to do this task in your dribble file (preceded by a ;) We are going to time another task. This time please DO NOT use the explanation commands. On another food, Fettuccine-Alfredo, please explain the restrictions on its appropriate-drink's color, body, flavor, and sugar roles. Make sure you time this task. You can use whatever CLASSIC commands you like. (You might consider just printing the food and then looking at the file you loaded to discover what rules, propagations, etc. could have applied.) Explanation 2. **** PLEASE START TIMING NOW Put a ; and the time in your dribble file. Put your answer in the dribble file (starting each line with a ; or surrounding the whole answer by #| and |# ) *** STOP TIMING HERE. Please note your time in the dribble file. >>> Explanation 3. Make a note in your dribble file about if and when you would rather use the explanation commands and if and when you would rather use some other technique to discover why things happened. ==========================ERROR HANDLING============================ Now we will turn to working with errors. CLASSIC needs to maintain a consistent state at all times. Thus, when someone enters something that is inconsistent with the deductive closure of what CLASSIC knows, CLASSIC notes the inconsistency, provides an error message, and retracts the new information that was inconsistent. That means that if you try to add something that is not legal to a knowledge base, the new object will not be part of the updated knowledge base. However, CLASSIC does maintain error objects. Thus, if you try to add an object A that will cause an inconsistency somewhere, A will be retracted, but CLASSIC will keep the error object for A around. You can access the error object for A after A caused an error by typing (cl-error-object 'A). So, for instance, you can print the error object. Let's create a food and state that a wine is appropriate with it. We can see if CLASSIC agrees that this wine is appropriate. Suppose that we make a meal food that is SPICY-RED-MEAT and say that we want to drink Forman-Chardonnay with it. >>> (cl-create-ind 'meal-food-1 '(and spicy-red-meat (fills appropriate-drink forman-chardonnay))) We see that CLASSIC will not add Meal-food-1 to the knowledge base, since this creates a contradiction. We can examine the problem more closely by printing the error object that is referred to in the error message. >>> (cl-print-ind (cl-error-object 'forman-chardonnay)) We look at the color role since the error said that there were problems on that role. We see two fillers for color: white and red. (And we also see that the color role can have at most 1 filler.) So, we might want to find out how it got each of those fillers. Use cl-exp to find out why the error object has both those fillers for its color role by typing: >>> (cl-exp (cl-error-object 'forman-chardonnay) :role-path @color :aspect 'fills) At this point, we may want to ask followup questions: 1) Why did the chardonnay-color rule fire? 2) Why did Meal-Food-1 get its restriction on its appropriate-drink role? Fortunately, there is an explanation function, cl-complete-exp, that will ask ALL outstanding questions for you until the final answer is either that a rule fired, or that some information was told. (NOTE: you only want to do a cl-complete-exp when you have a very specific question in mind. Otherwise, too many followup questions will be asked automatically.) Now ask the cl-complete-exp question >>> (cl-complete-exp (cl-error-object 'forman-chardonnay) :role-path @color :aspect 'fills) So, Forman-Chardonnay is incoherent because it should have at most 1 filler for its color role. It has two fillers: White and Red. White is a filler because of the chardonnay-color rule. (This rule fired because Forman-Chardonnay is an instance of Chardonnay). Its other filler, Red, is there since Forman-Chardonnay fills the appropriate-drink role on Meal-Food-1. Meal-Food-1 has a restriction that requires anything that fills its color role to be Red because of the red-meat-wine-color rule. (This rule fired because Meal-Food-1 is an instance of RED-MEAT.) Now you will do this for another individual. This will be timed again. Create another meal-food (This time make the food NON-OYSTER-SHELLFISH.) and fill the appropriate-drink role with Mt-Adam-Riesling. >>> (cl-create-ind 'meal-food-2 '(and non-oyster-shellfish (fills appropriate-drink mt-adam-riesling))) This creates another error. Error handling 1. Note the time in your dribble file (preceded by a ;) Now use the explanation functions to figure out why CLASSIC reported an error. Note the time you finished. Create another meal-food: (cl-create-ind 'meal-food-3 '(and dark-meat-fowl (fills appropriate-drink taylor-port))) We will time this again, and now PLEASE DO NOT use the explanation functions to discover why CLASSIC complains about this addition. You can use any functions other than the explanation functions and you can look through the knowledge base. You might consider printing the error object, looking for incoherencies, and then looking through the Knowledge base to figure out how the incoherencies occurred. Error handling 2. Please make sure to note the time in the dribble file along with your answer. Error handling 3. Also, please comment on when you would rather use the explanation functions and when you would rather track things down without them. Put your answer in the dribble file. Error handling 4. You should now be able to extend this exercise to the scenario in assignment 4 where you created an error when you said that Beef-Curry was an instance of FOOD-GOOD-WITH-ANY-RED-WINE. Set up that scenario again. Load the following lines: >>> (cl-define-primitive-concept 'food-good-with-any-red-wine 'meal-food) >>> (defun find-red-wines () (cl-concept-instances @red-wine)) >>> (cl-add-filler-rule 'add-red-wines @food-good-with-any-red-wine @appropriate-drink 'find-red-wines) Now, state that Beef-Curry is an instance of a Food-Good-With-Any-Red-Wine. >>> (cl-ind-add @beef-curry 'food-good-with-any-red-wine) Note the error condition on a previously existing wine in the knowledge base. This is another timed task. Begin timing after you tried to say that Beef-Curry is a FOOD-GOOD-WITH-ANY-RED-WINE. Use the explanation functions to explain why the error situation occurred. Note how long this took you to do in the dribble file. We will move on to pruning but it would be wise to read the section called "Explanation Functions" in the Classic Manual (section 7.1 in version 2.2). Two particularly useful functions are cl-exp-rule-firing, which explains why a rule fired, and cl-exp-not-subsumes-[concept or ind], which explains why an object is not subsumed by a concept. =======PRUNING=============== Using the explanation commands wisely usually means asking specific questions when using a powerful command like cl-complete-exp. It also means using pruning settings. CLASSIC has a set of pruning variables. You should read about these in the section entitled "Pruning Function and Variables" in the Classic Manual (section D.10.3 in version 2.2). You can see their default settings (along with other defaults) by typing: >>> (cl-print-global-settings) (Look for the explanation pruning variable settings.) Now we will investigate pruning settings that are appropriate for you. Sometimes, for example, you will not want to see the explanation for the at-least restrictions. In our previous example with Meal-Food-1, if you printed the error object, you would see that it had an at-least 2 restriction (and an at-most 1 restriction) on the role that turned out to be incoherent. The at-most 1 restriction comes from the fact that the role was declared to be an attribute, and attributes have at most one filler. The at-least 2 restriction comes from the fact that the role had two known fillers; the number of known fillers has been set to the at-least restriction on the role. (These inferences, attribute-implies-at-most-1 and fillers-implies-at-least, are documented in the section entitled "Regular Inferences" in the Classic manual (section 7.4.1 in version 2.2) We didn't really need to know all this information for debugging. We really wanted to find out how the 2 fillers got there. Thus, it was good to have the default values of the pruning variables cause Classic to ignore the at-least and at-most restrictions. You can get a feeling of how the default pruning settings cut down the output in explanation by trying the following: >>> (cl-exp-set-pruning-variables nil) >>> (cl-exp @lobster) >>> (cl-exp-set-pruning-variables t) >>> (cl-exp @lobster) Pruning 1. Please use a situation that is natural to you where you want to use an explanation function. This could be one that we have set up in this homework or one that you define. Show a pruning selection that is best for that setting and the explanation tasks. Either defend why the default selection is the best or change one or more of the pruning variable settings and justify your selection. You can set the individual pruning variables using setq as follows: (setq *cl-exp-ignore-at-least* nil) Your dribble file should show: 1) What was loaded to create the situation, 2) What the pruning variables are set to - ie. do a cl-print-global-settings to show all the settings 3) The explanation question (or questions) that you want to ask. Show the output of the explanation with a) the default pruning settings (cl-exp-set-pruning-variables) b) your settings (if they are different) c) pruning setting to nil (cl-exp-set-pruning-variables nil) 4) A justification of why your settings are better in your chosen situation. Would your settings work for other "typical" questions in the same domain? (I.e., could you set the pruning settings once and basically forget about them?) Pruning extra credit Finally, for extra credit, suggest any new pruning variables that could be added that would be useful. Also, if you come up with additional pruning suggestions because of later work on your project, please send them to dlm@research.att.com. We are in the process of adding extra pruning functionality. Also, version 2.3 uses meta-information to provide additional pruning capabilities. Type: (dribble) to close your log file now. --------------------------------------------------------------------------- END OF asg5.txt YOU ARE DONE WITH THIS ASSIGNMENT