This file is part of: AT&T Research NeoClassic Knowledge Representation System Tutorial Copyright AT&T 1996 ASG1.TXT INTRODUCTION ------------ This file contains your first NeoClassic 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 NeoClassic knowledge representation system, and to provide an idea of the types of reasoning and knowledge representation that can be done using NeoClassic. NeoClassic is a fairly complex system that provides logical completions which are sometimes non-obvious. This first assignment is intended to be a hands-on tutorial introduction to NeoClassic. 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 NeoClassic. To better understand this first module of the tutorial, you should read the "Concepts" section under "NeoClassic Conceptual Building Blocks" in the NeoClassic Reference Manual. All the functions mentioned in this file are documented in the Reference 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, except for the built-in NeoClassic concepts, 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 NeoClassic system: NeoClassic function names are in mixed case as they should be written, e.g., createConcept C++: C++ built-in functions and primitives are in lower case, e.g., while C++ 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 NeoClassic 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 NeoClassic code that are prefixed by >>>. You should also follow directions with respect to the "session logs" 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 session log. 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 a shell in EMACS. You can get this by typing meta-X shell. When you are done, or while you are still using it, you can write the session log to a file by simply saving it. Be sure to save your session log before you exit EMACS. CAREFUL!! Use different shell filenames for different 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 NeoClassic 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. You will be using the function "readFile" to load files. You will need to put in the full path of the file that you are loading. That file might be in the Helper or Recover sub-directories relative to "topdir", 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. Change directories, to the NeoClassic directory, if necessary. If you put the directory in your path, you can type the command, "neoclassic" from any directory. This command will start up the NeoClassic interpreter. Make sure your work is being recorded in a file starting now. >>> meta-x shell Start the NeoClassic interpreter. >>> neoclassic INITIALIZING NeoClassic ----------------------- The function reinitCollection initializes the KB. If you have just loaded NeoClassic, you don't need to call it, but if you have been working in NeoClassic 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 reinitCollection removes all concepts, individuals, roles and rules except for Thing, ClassicThing, HostThing, 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. Note that the syntax of NeoClassic allows you to put the parentheses around the arguments to the function only (as in C or C++) or you can include the function name inside of the parentheses (as in Lisp). However, once you start typing an expression into the interpreter, the syntax must remain in the same mode (C or Lisp). Throughout this tutorial we will use the Lisp mode. >>> (reinitCollection) 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 ClassicThing. 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 NeoClassic application will usually have primitives in the highest tiers of the hierarchy. NOTE: 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 "Primitives" under the section called "Concepts" which is in the "NeoClassic Interface Functionality" section in the NeoClassic Reference Manual. 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, HostThing or ClassicThing. A non-primitive concept definition specifies both the necessary and sufficient conditions that an individual must satisfy in order to be an instance of that 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 will 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, NeoClassic 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 be 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. 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. 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 or implicitly told to do so. An example of implicitly telling the system to do this is: Concept R has parent P and Concept C has parent R. Now, using the functions "createDisjointGroup" and "createConcept", create the disjoint primitive concepts WINE-PROPERTY, CONSUMABLE-THING, WINERY and WINE-REGION as children of ClassicThing within a disjoint grouping called classic-thing-type. ---------------- The four disjoint concepts that you have just defined create a partition or disjoint grouping called "classic-thing-type" in the space of concepts under ClassicThing. 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 NeoClassic User's Guide for other examples and more explanation of disjoint primitives and disjoint groupings.) The following statements attempt 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 >>> (createConcept C (and WINE-PROPERTY WINE-REGION)) ; an inconsistent individual >>> (createIndividual Ind (and WINERY WINE-REGION)) INSPECTING AND NAVIGATING THE KB -------------------------------- Now let's practice using some of the commands NeoClassic provides for inspecting the knowledge base. This will let you browse the information that has already been created for purposes of this exercise. The NeoClassic functions that use concepts, individuals, and roles as arguments do not expect you to use a particular format for indicating these arguments, except in cases where the function can take more than one type of argument in a particular place and the argument given can be more than one of those types. In that case, the argument is prefaced with the type of argument it is, as a function name. For instance, if you want to get the comment associated with the role "color" and there is also a concept called "color" you would need to say "(getComment (role color))". If you have not used the same name for a concept, individual, or role you will not need to be concerned with this. (Note: NeoClassic does distinguish between upper and lower case.) The functions used to specify particular arguments are role, symbolToRole, concept, symbolToConcept, symbolToClassicConcept, classic-concept, symbolToHostConcept, host-concept, symbolToRule, rule, classic-individual and symbolToClassicIndividual. Try typing: >>> (concept WINERY) To print the concept WINE-REGION, type the following: >>> (printInfo WINE-REGION) Here is the output you should see: ======================== ClassicConcept ======================== || Name: WINE-REGION || Primitive: {classic-thing-type} || Primitives: {WINE-REGION} || Rules: {} || Ingredients: || Told Parents: {ClassicThing} || Taxonomy: || Parents: {ClassicThing} || Children: {} || DirectInstances {} || Soup: || Primitive Ancestors: {} || One of: {} || RoleRestrictions: {} || Tests: {} || Incoherent? false ================================================================ The output is easy to interpret. ClassicThing is the only parent (WINE-REGION was declared as a primitive under it). ClassicThing is the most general concept in the domain of non-host objects: every individual created in the NeoClassic knowledge base will be a ClassicThing. Thus, ClassicThing will be an ancestor of every CLASSIC individual and concept. Note that the information also includes that it is in the disjoint grouping labeled classic-thing-type. You can use almost anything as a name for a disjoint grouping. The names you choose are in most cases not particularly important, but it is important to choose unique names for disjoint groupings. If the concept is not disjoint, but it is primitive the "Primitive:" value shown would be true. If it is not a primitive the value in that slot would be false. If you want to see only a specific detail about an object, use the specific function for that detail. Try typing: >>> (getPrimitive WINE-REGION) Remember how we defined WINE-REGION: (createConcept WINE-REGION ClassicThing classic-thing-type) Here the response includes information that this is a disjoint primitive on parent ClassicThing. 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 NeoClassic functions, which are documented in the NeoClassic Reference Manual under the section on "Taxonomy Retrievals" which is under the section on Concepts which is in the "NeoClassic Interface Functionality" section. getParents getChildren getDirectInstances getAncestors getDescendants getPrimitive To get some practice in using the above functions to browse through a Classic hierarchy, try the following: Print the children of ClassicThing: (getChildren ClassicThing) Starting from HostThing, 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 sections called "Queries" and "Told Retrievals" under the "Descriptions" section of the part of the NeoClassic Reference Manual which is called "NeoClassic Interface Functionality". 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.Neo" ---------------------------------------------------- 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 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 oneOf restriction which is explained in the section entitled "Building Classic Descriptions" in the NeoClassic User's Guide. 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: 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 getInstances command on WINE-COLOR. Use the command to see what the instances of WINE-COLOR are. You should have gotten an empty set. This happens because the individuals White, Rose, and Red did not exist prior to the definition of WINE-COLOR. NeoClassic created these individuals, but since nothing else is specified about them, they are just classified as ClassicThings. If WINE-COLOR was defined as "(oneOf White Rose Red)", and did not include the primitive concept WINE-PROPERTY in its definition, the individuals in the oneOf 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 or WINE-PROPERTY. The command "addToldInformation" can be used to do this, e.g. >>> (addToldInformation White WINE-COLOR) Note that individuals are one thing that NeoClassic will automatically create if they haven't been mentioned before, unlike concepts and roles which have to be defined before they are used. NeoClassic 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: getParents getAncestors Also, remember the function, getDirectInstances, which retrieves information about a concept. Try the following: Print the direct instances of ClassicThing. 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.Neo". 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 (in the part called "NeoClassic Conceptual Building Blocks") of the NeoClassic Reference Manual for more information about roles. For example, let's create the attribute 'color' >>> (createRole color true) 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 NeoClassic provides constructs for defining number restrictions on roles. For further information about this read the section called "Building Classic Descriptions" (section 2.1 in version 0.7 of the user's guide). For example, to specify that WINE has exactly one color, you may combine an "atLeast 1" and "atMost 1" number restriction. But if a role is defined to be an attribute, an "atMost 1" restriction is automatically established, while the default atLeast 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 atLeast number restrictions must be specified in the definition of the WINE concept. Also remember that when you state that there is at most one filler for a role and that role has a particular restriction, all (one) of those fillers have that particular restriction. Define the concept WINE now. To look at the newly defined concept, use functions to get told and derived information on that concept with different roles. 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 as: 1) an EDIBLE-THING 2) having at least 1 appropriate-drink 3) having all appropriate-drinks be WINEs. If you are in trouble, you can find the definitions of WINE and MEAL-FOOD in "/Recover/upto-meal-food.Neo". 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.Neo". 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. NeoClassic reminds you of this in the error message by creating a new individual (which you can examine) with its boolean Inconsistent value set to true. The error message also states that it occurred along the role-path "grape", pointing out that the new value for the role does not work. Since the object could not be created it was not one that you can access by its name. You can access any object that was created by the most recent command by typing "$". So, if you want to print information about this inconsistent object you can type "(printInfo $)". You can also access the object returned by the command entered just before the previous one by typing "$$", and the one before that by typing "$$$." Create W2 again, this time choosing semillon as the only filler. NeoClassic does not complain this time, and W2 is created (make sure of this by printing W2, using printInfo). 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 NeoClassic create W2 without complaining? If you have problems answering this question, watch how NeoClassic complains when you try to type: >>> (closeRole W2 color) Insert in your shell file an explanation of what happened here. (Remember to comment out your explanation.) Write your shell file out with a name now. --------------------------------------------------------------------------- END OF asg1.txt If you are going on, open the file "/asg2.txt" This file is part of: AT&T Research NeoClassic Knowledge Representation System Tutorial Copyright AT&T 1996 ASG2.TXT PRELIMINARIES ------------- Open a new shell file (meta-X shell) and name it by saving it. If you are continuing from lab-asg1.txt in the same session, type: >>> (readFile "/Helper/meal-foods.Neo") otherwise type: >>> (readFile "/Recover/after-meal-food.Neo") REVIEW OF asg1.txt In the previous module of this assignment we covered: 1. How to create disjoint-primitive concepts. 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. Commands for inspecting and navigating the KB. 3. How to define roles and attributes. 4. How to create individuals, and when role restrictions will make the description of an individual inconsistent. MORE INDIVIDUAL CREATION ------------------------ The next parts of the KB that 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: >>> (createIndividual 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 NeoClassic function "getClassicIndividuals". Do it. Remember, you can never delete an individual from the KB, unless you decide to remove all the existing individuals from all KB's using the function called reinitCollection -- 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 an individual using the function "removeToldInformation". Whenever an individual is modified through deletion or addition of information, NeoClassic will reclassify it using the new definition. For instance, print the information that NeoClassic 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 ClassicThing 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. >>> (readFile "/Helper/wineries-and-regions.Neo") >>> (readFile "/Helper/meal-food-instances.Neo") You can verify that the instances of WINERY and WINE-REGION have been created properly by using the "getDirectInstances" 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 "oneOf" 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 "isClassicIndividual" that there is no individual Charlie in your NeoClassic 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 NeoClassic does not complain about your definition! Check the KB again with "getClassicIndividuals". What has NeoClassic done? (Put a brief commented answer in your file.) Evidently, NeoClassic 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 ClassicThing that is one of Bordeaux, Bourgogne, Beaujolais, Loire, and Medoc. Examine this concept; note that NeoClassic 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 NeoClassic 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 NeoClassic 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.Neo".) 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. Don't do it yet! Read on first. Remember that you need to define roles before you can use them. See the section of the NeoClassic User's Guide entitled "Roles" 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.Neo".) Check that everything worked as it should by calling the function printInfo. The description that you get should look exactly like this. ======================== ClassicConcept ======================== || Name: REGIONAL-WINERY || Primitive: false || Primitives: {WINERY} || Rules: {} || Ingredients: || Told Parents: {WINERY} || Components: {(atLeast 1 region), (all region WINE-REGION)} || Taxonomy: || Parents: {WINERY} || Children: {} || DirectInstances {} || Soup: || Primitive Ancestors: {WINERY} || One of: {} || RoleRestrictions: {} || Tests: {} || Incoherent? false ================================================================ 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 "atMost 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 "atLeast 1" restriction in the definition; NeoClassic will automatically infer the "atMost 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 "atMost" 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 "atMost" 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. In our KB, we are, in fact, very sure that all the wineries will have at most one associated region. Therefore, we can define region as an attribute in order to avoid including the "atMost 1" restriction in the definition of WINERY. You can check whether you made region an attribute typing >>> (isAttribute 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 >>> (readFile "/Recover/after-regional-winery.Neo") You might want to look at the file "/Recover/until-wineries.Neo" to see what you would have needed to do if region had not been an attribute. NeoClassic 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 NeoClassic classifies My-Winery as a regional winery. Second, try to create an individual Impossible-Winery that is a REGIONAL-WINERY and yet cannot have any regions. Note the response that you get from NeoClassic 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.Neo".) Once the concepts are defined, print one of them to make sure that NeoClassic 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 Knowedge Representation (KR) systems, including NeoClassic, 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 NeoClassic returns the information that it does; in particular, why doesn't NeoClassic 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. NeoClassic 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 NeoClassic place C3 under REGIONAL-WINERY? Verify this using NeoClassic. You shouldn't be surprised that it doesn't; explain why NeoClassic 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 NeoClassic User's Guide shows these in the "Addition" section under the section called "Updates". We will need to add both a role and its filler. The function to use is called "addToldInformation." 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 addToldInformation and try that now. (Hint: use fills.) If you absolutely can't do it by yourself, look at the file "/Helper/winery-region-info.Neo". 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 NeoClassic KB. ---------------------------------------------------------------- We won't make you go through all the wineries. But you might look at the file "/Helper/winery-region-info.Neo" to see what's in it. Then type: >>> (readFile "/Helper/winery-region-info.Neo") Use NeoClassic functions to determine the instances of FRENCH-WINERY and of OTHER-EUROPEAN-WINERY. Save and close your shell file which is logging your input now. --------------------------------------------------------------------------- END OF asg2.txt If you are going on, open the file "/asg3.txt" This file is part of: AT&T Research NeoClassic Knowledge Representation System Tutorial Copyright AT&T 1996 ASG3.TXT PRELIMINARIES ------------- Open a new shell file (meta-X shell) and name it by saving it. Whether you are continuing from asg2.txt or starting this while starting up a fresh interpreter for NeoClassic, you should recover the state of the system by typing this command. >>> (readFile "/Recover/after-wineries.Neo") This will guarantee that there are no errors in the system. You may want to skip down to the end of the review section if you are continuing from asg2.txt in the same session. 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. Commands for inspecting and navigating the KB. 3. Definition of Roles and Attributes. 4. Creation of individuals and the effect of role restrictions on individuals. In the second module of this assignment we covered: 5. Adding concepts to the KB in such a way that existing concepts and individuals get reclassified under the new concepts (we illustrated this with REGIONAL-WINERY and its children). You may want to review some of these topics. 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 NeoClassic and its error messages to realize when an error message or unexpected response is being used to make a point. If NeoClassic 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.Neo". Make sure these concepts are defined before going on. In the above definitions, you could have used "fills" or "oneOf". For instance, the alternative definitions are equivalent. >>> (createConcept DELICATE-WINE1 (and WINE (fills flavor Delicate))) and >>> (createConcept DELICATE-WINE2 (and WINE (all flavor (oneOf Delicate)) )) Enter the two definitions, and test for their equivalence. How can you tell that NeoClassic identifies these two concepts? 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. (createConcept MEAL-FOOD (and EDIBLE-THING (atLeast 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 oneOf Forman-Chardonnay. (Enter the definition.) Would you expect either of these concepts to be classified under the other? Does NeoClassic give the answer that you expect? Comment out your response. If NeoClassic 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 NeoClassic 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 NeoClassic ------------------------- In this section we will learn to use rules in NeoClassic 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: >>> (createConcept 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 of CHARDONNAY wines. To specify such properties, we use rules like the following: >>> (createRule chardonnay-color CHARDONNAY (fills color White)) >>> (createRule chardonnay-body CHARDONNAY (all body (oneOf Full Medium))) >>> (createRule chardonnay-flavor CHARDONNAY (all flavor (oneOf 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. 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 NeoClassic 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. 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 rules on the concept CHARDONNAY. >>> (getRules CHARDONNAY) {chardonnay-flavor, chardonnay-body, chardonnay-color} >>> (printInfo chardonnay-flavor) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Rule @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ Name: chardonnay-flavor @ Antecedent: CHARDONNAY @ Consequent: (all flavor (oneOf Moderate Strong)) @ Inconsistent? false @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ >>> (printInfo chardonnay-body) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Rule @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ Name: chardonnay-body @ Antecedent: CHARDONNAY @ Consequent: (all body (oneOf Medium Full)) @ Inconsistent? false @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ >>> (printInfo chardonnay-color) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Rule @@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ Name: chardonnay-color @ Antecedent: CHARDONNAY @ Consequent: (fills color White) @ Inconsistent? false @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Notice that the only rules shown are those that are directly associated with the concept, i.e. those attached to ancestors are not shown. There is not as much information attached to the concept as you might expect, because rules are only used in NeoClassic to obtain information about individuals. We can use this fact to find out what NeoClassic knows about the concept, by creating a "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 NeoClassic in fact behaves as reported here. Or you can simply read the following few lines.) >>> (createIndividual Generic-Chardonnay CHARDONNAY) Generic-Chardonnay >>> (printInfo Generic-Chardonnay) ********************* ClassicIndividual ******************** * Name: Generic-Chardonnay * Ingredients: * Told Parents: {CHARDONNAY} * Components: {} * Closed Roles: {} * Rules: { (fills color White)>, (all body (oneOf Medium Full))>, (all flavor (oneOf Moderate Strong))>, (all grape GRAPE)>, (and (all maker WINERY) (atLeast 1 maker))>, (and (all region WINE-REGION) (atLeast 1 region))>} * In Propagations: {} * Parents: {CHARDONNAY, WHITE-WINE} * Inconsistent: false * Out Propagations: { Propagation(Generic-Chardonnay Chardonnay (and EDIBLE-THING GRAPE (oneOf Chardonnay))), Propagation(Generic-Chardonnay White (and WINE-COLOR (oneOf White)))} * Soup: * Primitive Ancestors: {POTABLE-LIQUID, CONSUMABLE-THING} * One of: {} * RoleRestrictions: { , , , , , , } * Tests: {} * Comment: ************************************************************ 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 NeoClassic 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 NeoClassic to infer a single filler: >>> (derivedFillers Generic-Chardonnay flavor) {} >>> (derivedFillers Generic-Chardonnay body) {} Instead, restrictions have been added to Generic-Chardonnay by the rules attached to the CHARDONNAY and the WINE concept: >>> (printInfo Generic-Chardonnay) ********************* ClassicIndividual ******************** * Name: Generic-Chardonnay ... * RoleRestrictions: { , , , , , , } ************************************************************ 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 "addToldInformation" (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. The printInfo command should show it just like Generic-Chardonnay. With My-Chardonnay in the KB, first try to add information to it 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 NeoClassic 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. >>> (printInfo My-Chardonnay) ********************* ClassicIndividual ******************** * Name: My-Chardonnay * Ingredients: * Told Parents: {CHARDONNAY} * Components: {(fills flavor Strong), (fills body Medium)} * Closed Roles: {} * Rules: { (fills color White)>, (all body (oneOf Medium Full))>, (all flavor (oneOf Moderate Strong))>, (all grape GRAPE)>, (and (all maker WINERY) (atLeast 1 maker))>, (and (all region WINE-REGION) (atLeast 1 region))>} * In Propagations: {} * Parents: {CHARDONNAY, WHITE-WINE} * Inconsistent: false * Out Propagations: { Propagation(My-Chardonnay Strong (and WINE-FLAVOR (oneOf Moderate Strong) (oneOf Strong))), Propagation(My-Chardonnay Medium (and WINE-BODY (oneOf Medium Full) (oneOf Medium))), Propagation(My-Chardonnay Chardonnay (and EDIBLE-THING GRAPE (oneOf Chardonnay))), Propagation(My-Chardonnay White (and WINE-COLOR (oneOf White)))} * Soup: * Primitive Ancestors: {POTABLE-LIQUID, CONSUMABLE-THING} * One of: {} * RoleRestrictions: { , , , , , , } * Tests: {} * Comment: ************************************************************ Before you go on, type: >>> (readFile "/Recover/after-wine-varieties.Neo") 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). >>> (createIndividual 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 social security number in order to be classified as a PERSON. Instead we would want the system to infer that an instance of PERSON has a social security number 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. Notice that rules do not need to be specified when a concept is defined. They can be added later. 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.Neo defines CHENIN-BLANC as follows: (createConcept CHENIN-BLANC (and WINE (fills grape Chenin-Blanc))) (createRule chenin-blanc-color CHENIN-BLANC (fills color White)) (createRule chenin-blanc-body CHENIN-BLANC (all body (oneOf Full Medium))) (createRule chenin-blanc-flavor CHENIN-BLANC (fills flavor Moderate)) (createRule chenin-blanc-sugar CHENIN-BLANC (all sugar (oneOf 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. (createConcept SPECIAL-RED-BORDEAUX (and BORDEAUX-WINE RED-WINE)) (createRule special-red-bordeaux-type 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) FILTERS ON RULES: A rule must contain a concept as the antecedent. This means that sometimes the user must create a 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 shell session in lines that begin with the comment symbol ";" so that your answer will appear in your log file.) Make sure you read the manual to understand all about rules in NeoClassic. Get into your shell buffer and type meta-X save file. 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 Research NeoClassic Knowledge Representation System Tutorial Copyright AT&T 1996 ASG4.TXT PRELIMINARIES ------------- Open a new shell file (meta-X shell) and name it by saving it. If you are continuing from asg3.txt in the same session, type >>> (readFile "/Helper/just-wines.Neo") or type >>> (readFile "/Recover/after-just-wines.Neo") to recover state. Otherwise, if this is a new session, type: >>> (readFile "/Recover/after-just-wines.Neo") 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. Commands for inspecting and navigating the KB. 3. Definition of Roles and Attributes. 4. Creation of individuals and the effect of role restrictions on individuals. In the second module of this assignment we covered: 5. Adding concepts to the KB in such a way that existing concepts and individuals get reclassified under the new concept (we illustrated this with REGIONAL-WINERY and its children). In the third module of this assignment we covered: 6. Using rules in NeoClassic: enhancing concepts via rules, adding 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 topics. MORE USES OF RULES ------------------ Definitions can help to organize knowledge, but most useful domain information does not follow from concept definitions alone. NeoClassic 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 individuals are 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 "oneOf" 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. > (createConcept WINE-FLAVOR (and WINE-PROPERTY (oneOf Delicate Moderate Strong))) However, there is no general way in NeoClassic 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 NeoClassic. 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 NeoClassic 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 NeoClassic that it is a MY-FAVORITE-WINE with its region filled by Sonoma, NeoClassic will not infer that it is a CHARDONNAY. Moreover, if we create another individual, My-wine2, and tell NeoClassic that it is MY-FAVORITE-WINE and a BORDEAUX-WINE, NeoClassic 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 "getRules" on the concept for this. 4. Show that MY-FAVORITE-WINE now has the appropriate instances. To recover state here, use: (readFile "/Recover/after-just-wines.Neo") USING RULES TO CREATE "QUERY TEMPLATES" --------------------------------------- This section introduces a use for rules that extends the type of reasoning you might think NeoClassic is capable of doing. The definitions and rules are in file: "/Helper/food-wines.Neo". Look at the file, if you wish, then type: >> (readFile "/Helper/food-wines.Neo") The "food-wines.Neo" 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. (createRule spicy-red-meat-wine-color SPICY-RED-MEAT (all appropriate-drink (fills color Red))) (createRule spicy-red-meat-wine-body SPICY-RED-MEAT (all appropriate-drink (fills body Full))) (createRule spicy-red-meat-wine-flavor SPICY-RED-MEAT (all appropriate-drink (fills flavor Moderate))) (createRule spicy-red-meat-wine-sugar 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. >>> (createIndividual My-Meal-Food (and SPICY-RED-MEAT (fills appropriate-drink Some-Wine))) Create My-Meal-Food using this definition, and use "printInfo" 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 NeoClassic to know that the wine is appropriate for the meat? Make your prediction now, and then query NeoClassic for the answer. Explain why NeoClassic gives the result it does, and test your prediction, before reading the following paragraph. ************************************************** BLANK SPACE BLANK SPACE ************************************************** You should have discovered that NeoClassic 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, NeoClassic 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 NeoClassic, 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 "getInstances" in the following way. (An explanation of this function is in the NeoClassic Reference Manual in the section entitled "Taxonomy Retrievals". It can be found under the top level section called "NeoClassic Interface Functionality" and in the section called "Concepts" in there.) First we create a concept that contains the description. >> (createConcept MY-WINE1 (derivedValueRestriction MY-MEAL-FOOD appropriate-drink)) Then we can find the instances that satisfy this concept. >> (getInstances MY-WINE1) The function "getInstances" takes a concept. The concept that we need is found in the derivedValueRestriction for the individual, My-Meal-Food, on its appropriate-drink role. The "getInstances" function retrieves the wines that match this concept. Enter the above command; NeoClassic should return the following answer to your query: {Mazocco-Zinfandel, Some-Wine} Mazocco-Zinfandel is in fact the only wine in our KB that we can recommend with a SPICY-RED-MEAT. Some-Wine was just a variable for that wine. 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.) ========================================================== 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: XS to save your shell to a file. --------------------------------------------------------------------------- END OF asg4.txt YOU ARE DONE WITH THIS ASSIGNMENT  This file is part of: AT&T Research NeoClassic Knowledge Representation System Tutorial Copyright AT&T 1996 ASG5.TXT PRELIMINARIES ------------- Open a new shell file (meta-X shell) and name it by saving it. 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.Neo", expanded to include all the files it loaded. We also added the rules in "food-wines.Neo". The entire file is now in "expanded-wines-kb.Neo". (There are some slight modifications in this file, so be sure to use the file "expanded-wines-kb.Neo" for this exercise, rather than "after-just-wines.Neo".) Enter this: >>> (readFile "/Recover/expanded-wines-kb.Neo") 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. Commands for inspecting and navigating the KB. 3. Definition of roles and attributes. 4. Creation of individuals and the effect of role restrictions on individuals. In the second module of this assignment we covered: 5. Adding concepts to the KB in such a way that existing concepts and individuals get reclassified under the new concept (we illustrated this with REGIONAL-WINERY and its children). In the third module of this assignment we covered: 6. Using rules in NeoClassic: 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: 7. More use of rules: using rules to create disjunctive concepts, query templates, and circular definitions. 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 shell files at places. You can precede each line with a ; so that the interpreter does not try to evaluate your statements. 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. In the last assignment (asg4), you created 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 NeoClassic 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: >>> (createIndividual My-Meal-Food (and SPICY-RED-MEAT (fills appropriate-drink Some-Wine))) Let's investigate Some-Wine again. First print it: >>>(printInfo 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: >>>(explain Some-Wine) However, since the four roles, which we are interested in, have specific fillers, we can ask specifically how each of the fillers got there by typing: >>>(explain Some-Wine (fills color Red)) >>>(explain Some-Wine (fills sugar Dry)) >>>(explain Some-Wine (fills body Full)) >>>(explain Some-Wine (fills flavor Moderate)) 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, do the following. First get the Inferences from the explanation. Note that '$' translates to the previous answer and '$$' translates to the one before that. There is also a translation for '$$$'. >>> (getInferences $) Get the first of those inferences >>> (select $ 0) Get the Antecedents on that inference >>> (getAntecedents $) Get the second of those antecedents >>> (select $ 1) Explain that antecedent >>> (explain $) You can repeat this process for each of the four roles. 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 six step explanation, first explaining a role filler for 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 each of the restrictions on its appropriate-drink role, like this: >>> (explain Beef-Curry (all appropriate-drink (fills color Red))) 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 shell file and note the time. Now use explain 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 shell 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 NeoClassic 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 shell file. Put your answer in the shell file (starting each line with a ; ) *** STOP TIMING HERE. Please note your time in the shell file. >>> Explanation 3. Make a note in your shell 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. NeoClassic needs to maintain a consistent state at all times. Thus, when someone enters something that is inconsistent with the deductive closure of what NeoClassic knows, NeoClassic 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, NeoClassic does maintain error objects. Thus, if you try to add an object A that will cause an inconsistency somewhere, A will be retracted, but NeoClassic will keep the error object for A around as long as you have a variable set to it. You can set a variable called "myErr" to the error object in the following way: >>>(set myErr $) You can now access this error object by using its variable. For instance, you may print the information about this error object by typing: >>>(printInfo $myErr) Let's create a food and state that a wine is appropriate with it. We can see if NeoClassic 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. >>> (createIndividual Meal-Food-1 (and SPICY-RED-MEAT (fills appropriate-drink Forman-Chardonnay))) We see that NeoClassic 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. Remember that variables are automatically created for the three most recent results but they are only temporary. >>> (printInfo $) 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 explain to find out why the error object has both those fillers for its color role by typing: >>> (explain $$ (and (fills color White) (fills color Red))) 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 a way to get that information, though you have to go through many steps to get it. The steps you will go through are similar to those shown prevously (i.e. explain, getInferences, select and getAntecedents). In the future there will be an explainComplete function 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 will only want to do an explainComplete when you have a very specific question in mind. Otherwise, too many followup questions will be asked automatically.) 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. >>> (createIndividual 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 shell file (preceded by a ;) Now use the explanation functions to figure out why NeoClassic reported an error. Note the time you finished. Create another meal-food: (createIndividual 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 NeoClassic 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 shell 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 shell 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: >>> (createConcept FOOD-GOOD-WITH-ANY-RED-WINE MEAL-FOOD true) >>> (createRule add-red-wines food-good-with-any-red-wine (all appropriate-drink (oneOf (getInstances RED-WINE)))) Now, state that Beef-Curry is an instance of a FOOD-GOOD-WITH-ANY-RED-WINE. >>> (createIndividual 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 shell file. It would be wise to read the section called "Explanation" in the "NeoClassic Interface Functionality" section of the NeoClassic Reference Manual. There is one main function called explain which we talked about earlier. It can go through steps explaining how each thing happened, including rule firings. There is also another explanation function called explainSubsumed which takes two arguments, the subsumee and the subsumer. It explains why a concept or an individual is subsumed by a description or concept. Type: XS to save your shell to a file. --------------------------------------------------------------------------- END OF asg5.txt YOU ARE DONE WITH THIS ASSIGNMENT