Fast determination of subtype relationship in a single inheritance type hierarchy

Abstract: In a rule-based programming language which supports type inheritence, a method of subtype determination uses Huffman coding. Each object to be evaluated for subtype determinating in the type hierarchy is provided with a corresponding unique binary number, a pattern and a mask; each binary number contains information identifying ancestors in the hierarchy; the mask contains information as to the significant number of bits in the binary. A bit wise AND operation of the binary of the first object is performed with the mask of the second object to obtain a result which is compared with the binary of the Second object to determine the type/subtype of the second object.

Description: FIELD OF THE INVENTION The present invention relates to artificial intelligence and more specifically, to a method for fast determination of the subtype relationship in a single inheritance type hierarchy for a rule-based language. BACKGROUND OF THE INVENTION Rule-based languages, used in artificial intelligence applications such as expert systems, are advantageous when there is a large amount of data to be searched and actions are taken based on the results of the search. In order to minimize the searching through this large amount of data, rule-based languages take the information that is available about what is the best approach to a problem and attempt a solution. A single instruction in a rule-based language takes the form of "when these conditions are met, then do these actions". In other words, the instruction checks to see if certain conditions are met, and if they are, then a number of actions are performed. In a rule-based language, there is no organized flow of control, rather the computer will look for situations and patterns. In other words, a rule-based language is a pattern matching language. For example, one of the instructions may be "when there is object of type A, an object of type B and an object of type C in the data base, then do X, do Y and do Z". In all rule-based languages, there is a distinction made between the types of data and instances of those types. This distinction is exactly analogous to the distinction made in data bases between a record format and actual records. For example, a particular application could declare a type, BOOK. All instances of the type BOOK contain the same kinds of information: a title, an author, a catalog number, and a page count. This application could then create an instance of type BOOK for each book in the town library. One such example might contain the following information. title: "Artificial Intelligence and You" author: Smith, John catalog number: 0-670-81442-3 page count: 285 This instance of type BOOK (also referred to as data of type BOOK, an object of type BOOK, or a BOOK object) could potentially satisfy any condition in any rule which is searching for an object of type BOOK. When the notation of "type inheritance" is introduced, which is a powerful extension to the capabilities of a rule-based language, the situation becomes more complicated. Type inheritance involves the concept of one object type being a subtype of another object type. For example, in a particular application, the type CAT could be declared to be a subtype of the type MAMMAL, and MAMMAL a subtype of VERTEBRATE, and VERTEBRATE a subtype of ANIMAL. The type CAT inherits certain features of the type MAMMAL , since it is a subtype. Examples of features that the subtype CAT inherits from the parent type MAMMAL (i.e. the supertype) could include the characteristics of nursing its young, warm-blooded, etc. The other thing which a type inherits from its parent type is membership. Although any object is an instance of one and only one type, it can usually be used as if it were an instance of any of its supertypes. Thus, a CAT object could satisfy a requirement for an instance of type MAMMAL, or a requirement for an ANIMAL. The document US-A-4 675 829 defines a mechanism to perform efficiently the inhentance in a hierarchical knowledge-based system. Type inheritance is a powerful concept because it maps directly to the way the real world is described by human beings. The English language already has categories like ANIMAL, sub-categories like MAMMAL, and sub-sub-categories like CAT, and instances like someone's 3 year old siamese cat. If a school teacher says, "Bring in an animal for show and tell," then every child in the class would know that someone's 3 year old siamese cat would satisfy the teacher's request, but so also would a frog or a hamster. Using a rule-based programming language, a computer will attempt to match every piece of data against every type or subtype that appears as a pattern being matched. For example, if the pattern being matched is MAMMAL, the computer will compare the type of every piece of data in the data base against the type MAMMAL and every subtype of MAMMAL. If a MAMMAL is being searched for among the data to satisfy a rule, then any data of type CAT should satisfy the requirement for a MAMMAL, since CAT is a subtype of MAMMAL. To do this method of searching and matching, however, the type/subtype relationships between the types (a "type hierarchy") must be known. The determination of the subtype relationship (i.e. whether a specified type is equal to or is a subtype of some other specified type), and more specifically the membership relationship (i.e. whether a specific object can be treated as if it were an instance of a specified type, which is true if and only if the type of the object is equal to or is a subtype of the specified type), is a critical operation in the overall performance of a pattern matching language, such as a rule-based language. Therefore, the determination should be done as quickly as possible, but without greatly increasing the memory space. The term "single inheritance" means that a subtype can have only one immediate parent type in the type hierarchy. One method of determining membership involves checking the type of the data to see whether that type is the same type as the type that is being matched, and if that fails,checking the supertype of the data against the match type. This checking is done against subsequently higher and higher supertypes until either the supertype and the match type are equivalent (i.e. the object is a member of the match type), or there are no more supertypes to compare (i.e. not a member of the match type). With such an approach, a large number of levels may have to be searched before a match or a mismatch is found. For example, it takes two checks to determine that a CAT object can satisfy a match type of MAMMAL; first CAT is compared to MAMMAL, then the supertype of CAT, MAMMAL is compared to MAMMAL and found to be equivalent. However, to determine that the same CAT object will not satisfy a match type of VEGETABLE takes four checks: CAT compared to VEGETABLE, MAMMAL compared to VEGETABLE, VERTEBRATE compared to VEGETABLE, and ANIMAL compared to VEGETABLE. Such an approach, because of these multi-level searches, especially on mismatches (which are almost always far more common than matches), would degrade the performance of a rule-based language to a totally unacceptable level. Another approach to determining the subtype relationship is to link a set of comparisons together with logical OR's. For example, if a condition in a rule will match if it finds an instance of a MAMMAL, then this is equivalent to matching if it finds a MAMMAL object, or a CAT object, or a DOG, or a HORSE, or a COW, et cetera, for all the subtypes of MAMMAL, and for all sub-subtypes and sub-sub-subtypes, et cetera. This approach becomes very slow and cumbersome whenever the type hierarchy is of any appreciable size. Another approach for providing knowledge of the subtype relationship would be to provide N 2 space in memory when N is the total number of types. Each axis would list each of the separate types in a grid format. Every point in the grid corresponds to an intersection of one type with another type and will contain a bit. If the bit is a 1, then the type (such as CAT) on one axis is a subtype of the type on the other axis of the grid, for example, MAMMAL. If the bit is a 0, then the type (CAT) on one axis of the grid is not a subtype of the type on the other axis of the grid (for example, AMPHIBIAN). The obvious drawback to this approach is the extremely large amount of memory space that would be needed when the total number of types in an application is large; for example, when N is equal to 10 4 , (an entirely reasonable number of types for an application - e.g. the number of parts in a modern aircraft) the amount of memory space needed would be 10 8 . There is therefore a need for a method of quickly determining the subtype relationship in a single inheritance type hierarchy, which finds usefulness in computer programmed with a rule-based language, without increasing greatly the amount of memory space or instructions needed for implementation. SUMMARY OF THE INVENTION This and other needs are provided by the present invention which quickly determines the subtype relationship in a single inheritance type hierarchy. Using Huffman coding, a well-known technique, each specific type in a type hierarchy is provided with a specific binary value. Furthermore, each specific type is also provided with a mask that represents the number of bits of the specific binary value that will be significant for matching purposes. By using the mask and the specific binary value that represents a specific type, the relationship between any two types in the type hierarchy can be found in a two-step process. This process involves masking off those bits which are not necessary for comparison, and then performing a match of the pattern of one type to the other type. Each pattern contains within it encoded information from which it can be determined in a simple manner each of the parent types of that subtype. The invention in its broad form resides in a method of determining a subtype relationship of first and second objects in a single inheritance type hierarchy, the hierarchy having a plurality of levels, characterized by the steps of: providing each object in the type hierarchy with corresponding unique binary numbers, a pattern and a mask, each binary pattern containing information which identifies ancestors of the corresponding object in the type hierarchy, and the mask containing information as to how many bits in said binary pattern are significant; performing a bit-wise AND of the binary pattern of a first object with the mask of a second object to produce a result; and comparing said result with the binary pattern of the second object, a match indicating that the first object is an instance of a type or subtype of the second object, and a nonmatch indicating the first object is not an instance of a type or subtype of the second object. BRIEF DESCRIPTION OF THE DRAWINGS A more detailed understanding of the invention may be had from the following description of a preferred embodiment, given by way of example and to be understood in conjunction with the accompanying drawing wherein: Figure 1 illustrates an example of a type hierarchy for an application which processes orders for computer equipment. Figure 2 is a flow chart of an embodiment of the compilation process according to an embodiment of the present invention. Figure 3 is a tale of the objects of the type hierarchy of Figure 1 and the bit patters for these objects created using the compilation process of Figure 2. Figure 4 is a flow chart of an embodiment of the execution process according to a preferred embodiment of the present invention. DETAILED DESCRIPTION In certain artificial intelligence applications such as expert systems the capability of organizing all the types of data into a hierarchy is very important. A type hierarchy shows the relationships between all the types in a system. An example of a type hierarchy is shown in Figure 1. Each circle in the figure represents a different type in the hierarchy, and each has been numbered for convenient reference. Each line connecting the types in the figure represents a connection between a supertype (a.k.a. a parent type) and its subtypes (a.k.a. children types). As exemplified in the figure, a type can have at most one supertype, but it can have many subtypes. Level 1 of the type hierarchy of Figure 1 includes LINE-ITEM 10 and DEVICE 12. These two types, the LINE-ITEM 10 and the DEVICE 12 of level 1, are considered to be "siblings" since they are the only objects in level 1. The LINE-ITEM 10 has two children, ORDERED-ITEM 14 and IMPLIED-ITEM 16. The ORDERED-ITEM 14 and the IMPLIED-ITEM 16 are considered to be siblings, and are subtypes of the LINE-ITEM 10. Similarly, the DEVICE 12 in level 1 has a number of children types, a central processing unit (CPU) 18, a MEMORY 20 and a STORAGE 22. Each of these children types represents a different subtype of the type represented by the DEVICE 12. It should be understood that Figure 1 represents the relationships between types and subtypes, and that the hierarchy does not represent the actual physical connection of the elements of a computer system. The CPU 18 has three children 24-28, each of which represents a different subtype of CPU. In other words, the type CPU-1 numbered 24 is one specific subtype of CPU, while the type CPU-2 numbered 26 is a different subtype of CPU and could, for example, be manufactured by different companies. The different CPU subtypes 24, 26, 28 are all found in level 3 of the type hierarchy. The type STORAGE 22 has two children, DISK 30 and TAPE 32. The DISK 30 and the TAPE 32 are not siblings of the CPU subtypes 24, 26, 28 although they are siblings of each other. Finally, there are five different subtypes of DISK 30 shown in the example of Figure 1, these different subtypes of DISKS being designated as 34, 36, 38, 40 and 42. Each of these different types represents a different subtype of DISK 30. The TAPE 32 has two different subtypes, 44 and 46. The different subtypes of disks and tapes make up level 4. As seen in Figure 1, a subtype can only have one parent type (or "supertype"). This is referred to as "single inheritance" type hierarchy. Inheritance means the characteristics of a type are inherited by a subtype, unless specifically noted otherwise. These characteristics can include default values, membership and basic structure of information. For example, type 44, TAPE-1, is a subtype of TAPE 32. Therefore, the type 44 will inherit the same default values or characteristics that characterize TAPE 32. As another example, type 42, DISK-5, will inherit features from its supertype (DISK 30) and the supertypes of the DISK 30 (i.e. the STORAGE 22 and the DEVICE 12). Thus, type 42 (representing a specific subtype of DISK) can be considered to be a subtype of any of the supertypes DISK 30, STORAGE 22, or DEVICE 12. In a rule-based programming language, it is often the case that problems are described in general terms. However, in solving the problem, it is specific objects that are considered when searching the data base. For example, if the solution to a problem requires a DISK and an object of type 42, DISK-5, is considered, the question becomes whether that object satisfies the need for a disk. In other words, it must be determined whether type 42, DISK-5, is a subtype of DISK 30. Similarly, if some type of storage 22 is needed, and object of type 42, DISK-5, is considered, it must be determined whether that object will satisfy this higher level type. The present invention provides for most of the work in determining whether a specified type is equal to or is a subtype of another specified type to be done at compilation. In other words, the determining of the subtype relationship is performed, as much as possible, as part of the compilation process. The present invention uses a coding technique, known as Huffman coding, in order to encode non-redundant objects as a set of binary values. The following explanation of the encoding and compilation process will be made with reference to Figures 2 and 3. Figure 2 describes the compiling process itself, while Figure 3 shows the results of the compiling process. Figure 3 is a table that lists for each type of Figure 1 the level that the type is found on, a first binary number A N , a second binary number X N and a third binary number P N for each type in the type hierarchy. How this table is generated is described below with reference to Figure 2, while how the numbers are used will be described with reference to Figure 4. Figure 2 is a flow chart of the compilation process that generates a value for each type as shown in Figure 3. At the start of the compilation process, a maximum number of siblings is determined for each of the levels in the type hierarchy in execution step 60. Siblings are those types on a level in the type hierarchy which share the same parent. There can be many groups of siblings on the same level. All types on the first level are considered siblings. Once the number of siblings in the largest group of siblings on a level is determined, the number of bits (M L ) needed to uniquely number that many siblings is determined in execution step 62. For example, the number of siblings in the largest group on level 4 are 5. Therefore, in order to uniquely identify any one of those five siblings (types 34-42) a three-bit binary number is needed. This is the number (M 4 = 3) that is determined in execution step 62. The same number of bits is used for the rest of the groups of siblings on that level also. Once the number of bits needed to identify the maximum number of siblings in a level is determined in execution step 62, it is determined in decision step 64 whether execution steps 60 and 62 have been performed for each of the levels in the type hierarchy. Once these steps 60, 62 have been performed for each level, the total number of bits necessary to uniquely identify an object in the hierarchy is determined in execution step 66. The total number of bits necessary, B, is determined by adding the values of M L for all of the levels in the type hierarchy. Every object in the top level (level 1) is assigned a binary number A N which is M 1 bits long. In this example, M 1 is equal to one bit. Each of the types are assigned a number starting at 0. This is performed in execution step 68. In execution step 70, for every type in the hierarchy which has already been assigned an A N value but whose children have not been assigned values, an M L bit binary number A N is assigned to each of its children starting at 0. Thus each group of siblings starts a numbering series with "A N = O, A N = 1 ..." This is performed until all of the types in the type hierarchy have been assigned a value A N , as determined in decision step 72. Once each of the types in the type hierarchy has been assigned a value A N , a mask X N is created for each type in execution step 74. Each mask X N is B bits long. The mask X N is formed by starting at the left-most bit with a number C of 1's, and is then right-filled with 0's. This is done according to the equation: where Q is the level of type N. Finally, in execution step 76, a pattern P N is created for every type N in the type hierarchy. This pattern P N is B bits long and is formed by starting at the left-most bit and concatenating the A N values for all of the type's ancestors. This is done by beginning with the bits A 1 for the top level ancestor and concatenating the bits through each successive ancestor (A 2 , A 3 etc.) until its own A N value is concatenated. The remaining bits in the pattern P N are right-filled with 0's. Referring to Figure 3, it can be seen that the A N created for every type uniquely identifies that type from among its siblings using a minimum number of bits. For example, type 36 is one of five siblings. Each of the five siblings 34-42 are assigned a unique (to that sibling group) three-bit number A N . Similarly, the two other siblings 44 and 46 belonging to the other group of level 4 are each assigned separate values A N . From the values of A N , each of the patterns P N that identify a single type in the type hierarchy is created. For example, for type 28, the top level ancestor is device 12 which has an A N of 1. Thus the left-most bit of P N for object 28 is a 1. The next lower level ancestor for type 28 is CPU 18. The value of A N for CPU 18 is 00. This value of A N for CPU 18 is concatenated with 1, the A N for type 12. The value of A N of type 28, (i.e. 10), is then concatenated with the values of A N of types 12 and 18. This forms the binary number 10010. Finally, three zeros are right-filled to complete the pattern P N . In this manner, a pattern P N is created that identifies the object 28 in the type hierarchy. The mask X N is a mask that reflects how many bits of a pattern P N will be significant for matching purposes. Because the M L value for the first level is 1, a single binary digit (one) 1 is put into the left-most bits of the value X N for each of the types in the hierarchy. For each of the types on level 2, since the number of bits needed to encode each of the types is equal to 2, two one bits are concatenated to the left-most bit for the mask X N . Similarly, for level 3, two more bits are used in the values of A N for each of the types on level 3. Therefore, two more 1's are placed into the mask X N for each of the types on level 3. Finally, for the lowest-most level, level 4, three bits are needed for A N . Therefore, three 1's are placed into the remaining bits of X N for each of the types in the fourth level. The mask X N is used in the matching process in order to determine how many left-most bits of two patterns P N need to be compared to determine whether an object is a type or subtype of another object in the type hierarchy. The determination of whether an object can be used as if it were an instance of a specific type is shown in Figure 4, which is a flow chart of the execution or matching process. For the following example, assume that there is an object of type R for which it is to be determined whether that object can be treated as if it were an instance of the of the type T (i.e. whether R is equal to T or is a subtype of T). In execution step 80, a bit-wise AND of the pattern P N of type R is performed with the mask X N of type T to produce a result. In the second execution step 82, the result generated above is compared with the pattern P N of type T. If the patterns match, then the object of type R can be considered to be of type T. If the result does not match the pattern P N of type T, then the object is not of type T or of any of the subtypes of type T. As an example, assume that we are attempting to find objects which match type 22, STORAGE; thus for this example, type STORAGE is used as T in the process of figure 3. Now assume that the first object to be compared is an instance of type 36 (DISK-2). By the process of figure 3, the pattern P 36 , is bit-wise AND'ed with mask X 22 . P 36 is 11000001, X 22 is 11100000, and the result of the bit-wise AND is 11000000. This result is then compared to P 22 , 11000000, and because they are exactly the same, then the object of type 36 (DISK-2) can indeed satisfy the requirement for an object of type 22 (STORAGE). Now assume that the next object to be compared is of type 24 (CPU-1). Again, by the process of figure 3, the pattern P 24 , 10000000, is bit-wise AND'ed with the mask X 22 , 11100000, and the result, 10000000, is then compared to the pattern P 22 , 11000000. In this case, because they are not equivalent, the object cannot be used to satisfy the requirement for an object of type 22 (STORAGE). When there is no match, using this same two-step execution process will indicate that an object of type R is not of type T or a subtype of type T. This avoids the problem of having to check intermediate types all the way up the type hierarchy when the type T is on a high level in the hierarchy. With the present invention, the object of type R can be directly compared with type T to determine if it is a type or subtype of T, even though there may be intermediate levels of subtype relationships between type R and type T. Thus, once the initial compilation has been performed, the determination of whether or not an object of one type is to be considered to be an object of type T or any subtype of type T, can always be performed in two steps. The number of steps remains constant no matter which type of object is matched to a specific type. Further, the amount of memory space needed for this system is approximately per type, where N is the total number of types defined. The invention described above can be implemented on a conventional computer usable for artificial intelligence applications, and as such, the computer itself is not shown in detail. However, one example of a commercial computer which can be used with the present invention is a DEC Station 3100, manufactured by Digital Equipment Corporation. The foregoing description has been directed to a particular exemplary embodiment of the invention for the purpose of illustration and explanation only. However, it will be apparent to one skilled in the art that many modifications and changes in the device of the present invention will be possible without departing from the scope of this invention. It is intended that the following claims be interpreted to embrace all such modifications and changes.

Claims: A method of determining a subtype relationship of first and second objects in a single inheritance type hierarchy, the hierarchy having a plurality of levels, characterized by the steps of: providing each object in the type hierarchy with corresponding unique binary numbers, a pattern and a mask, each binary pattern containing information which identifies ancestors of the corresponding object in the type hierarchy, and the mask containing information as to how many bits in said binary pattern are significant; performing a bit-wise AND of the binary pattern of a first object with the mask of a second object to produce a result; and comparing said result with the binary pattern of the second object, a match indicating that the first object is an instance of a type or subtype of the second object, and a nonmatch indicating the first object is not an instance of a type or subtype of the second object. The method of claim 1, wherein the step of providing includes the step of performing Huffman coding on each object in the type hierarchy. The method of claim 1, wherein the step of providing includes the steps of: determining a maximum number of siblings for each level of the hierarchy; determining for each level of the hierarchy a minimum number of bits M L needed to uniquely number the maximum number of siblings for each level; adding together the minimum number of bits M L for each level in the hierarchy to determine the total number of bits B necessary to identify an object in the hierarchy; assigning each object in the hierarchy a value A N which has M L bits, the value of A N beginning at 0 for each group of siblings; concatenating the values A N for each object, with the left-most bits being the value A N of a top level object, and successively next left-most bits that are concatenated being the values A N of each of an object's ancestors; and right-filling with 0's the concatenated values of A N until the concatenated values of A N with right-filled 0's has the total number of bits B to form the binary pattern for each object. The method of claim 3, wherein the step of providing further includes the step of forming said mask by filling left-most bits of a binary number B bits long with a number C of 1's and right-filling with 0's, where Q being the level L of the object having the mask that is being formed. A computer programmed to determine a subtype relationship of first and second objects in a single inheritance type hierarchy (10-46), the type hierarchy having a plurality of levels, characterized by: means for providing each object in the type hierarchy with a corresponding unique pair of binary numbers, a pattern (P N ) and a mask (X N ), each binary pattern containing information which identifies ancestors of the corresponding object in the type hierarchy, and the mask containing information as to how many bits in said binary pattern are significant; means for performing a bit-wise AND of the binary pattern of a first object with the mask of a second object to produce a resut (80); and means for comparing said result (82) with the binary pattern of the second object, a match indicating that the first object is a type or subtype of the second object, and a nonmatch indicating the first object is not a type or subtype of the second object. The computer of claim 5, where the program is written in a rule-based language. The computer of claim 6, wherein the means for providing includes means for performing Huffman coding on each object in the type hierarchy. The computer of claim 6, wherein the means for providing includes: means for determining a maximum number of siblings for each level of the hierarchy; means for determining for each level of the hierarchy a minimum number of bits M L needed to uniquely number the maximum number of siblings for each level; means for adding together the minimum number of bits M L for each level in the hierarchy to determine the total number of bits B necessary to uniquely identify an object in the hierarchy; means for assigning each object in the hierarchy a value A N which has M L bits, the value of A N beginning at 0 for each group of siblings; means for concatenating the values A N for each object, with the left-most bits being the value A N of a top level object, and successively next left-most bits that are concatenated being the values A N of each of an object's ancestors; and means for right-filling with 0's the concatenated values of A N until the concatenated values of A N with right-filled 0's has the total number of bits B to form the binary pattern for each object. The computer of claim 8, wherein the means for providing further includes means for forming said mask by filling left-most bits of a binary number B bits long with a number C of 1's and right-filling with 0's, where Q being the level L of the object having the mask that is being formed.

Inventors: BARABASH WILLIAM, KIRK STEVEN ALAN, YERAZUNIS WILLIAM STEPHEN, BARABASH, WILLIAM, KIRK, STEVEN ALAN, YERAZUNIS, WILLIAM STEPHEN
Applicants: DIGITAL EQUIPMENT CORP, DIGITAL EQUIPMENT CORPORATION
Application year: 1991
Main classification: G06F9
IPC codes: G06F9