|
Home Contents: |
7.3.4 GarfieldExample of exploiting transitivityConsider the following Prolog+CG program: // Type-hierarchy // // Example of exploiting transitivity of type-hierarchy // Available in the AAU directory as "GarfieldOdieJon.plgCG" // Type-hierarchy Entity > Animate, Act. Animate > Animal, Human. Animal > Cat, Dog. // Catalog of instances Cat = Garfield. Dog = Odie. Human = Jon. Act = Kick, Like, Love. // Graphs // Garfield kicks Odie graph(gr1, [Cat: Garfield]<-AGNT-[Act: Kick]-PTNT->[Dog: Odie]). // Jon likes Garfield graph(gr2, [Human: Jon]<-AGNT-[Act: Like]-THME->[Cat: Garfield]). // Odie likes Garfield graph(gr3, [Dog: Odie]<-AGNT-[Act: Like]-THME->[Cat: Garfield]). // Garfield loves Garfield graph(gr4, [Cat: Garfield]<-AGNT-[Act: Love]-THME->[Cat: Garfield]). // Rules AnimalDoes(L,G) :- graph(L, G), subsume([Animal]<-AGNT-[Act], G). AnimateDoes(L,G) :- graph(L, G), subsume([Animate]<-AGNT-[Act], G). If we now ask the query: ?- AnimalDoes(L,G). We get the following answer: {L = gr1, G = [Act : Kick] -
-PTNT->[Dog : Odie],
-AGNT->[Cat : Garfield]}
{L = gr3, G = [Act : Like] -
-THME->[Cat : Garfield],
-AGNT->[Dog : Odie]}
{L = gr4, G = [Act : Love] -
-THME->[Cat : Garfield],
-AGNT->[Cat : Garfield]}
This reflects the fact that both "Dog" and "Cat" are subtypes of "Animal". Since the "subsume" goal looks for graphs which are more general than other graphs, all of these three graphs match the graph which has "Animal" in it. Likewise, if we ask the query: ?- AnimateDoes(L,G). We get the following answer: {L = gr1, G = [Act : Kick] -
-PTNT->[Dog : Odie],
-AGNT->[Cat : Garfield]}
{L = gr2, G = [Act : Like] -
-THME->[Cat : Garfield],
-AGNT->[Human : Jon]}
{L = gr3, G = [Act : Like] -
-THME->[Cat : Garfield],
-AGNT->[Dog : Odie]}
{L = gr4, G = [Act : Love] -
-THME->[Cat : Garfield],
-AGNT->[Cat : Garfield]}
This is the same answer as before, except that graph 2, "Jon likes Garfield" is also in the results. This is because "Human" is a subtype of "Animate", just like "Dog" and "Cat" are. PrevLite: 7.3.3 Macbeth 2 NextLite: 7.3.5 branchOfCG Prev: 7.3.3 Macbeth 2 Up: 7.3 Examples Next: 7.3.5 branchOfCG |