Intro
  • Inheritance is about gaining a property or feature by being related directly or indirectly to an other item that has that property.
  • Recursion is involved because the indirect link is described by a series of the same relationship defined in terms of itself. Often it features in subclasses and classes (groups and super groups) as found in frames, but also in other situations such as family trees (ancestral lines).

Subgroup, group or supergroup?
  • These terms are to a certain extent the same as they are relative to the group (or class) that you are focussing on, for example a group or supergroup could also be a subgroup to another group on a higher level. The point is that there is a hierarchy of groups or classes.

inheritance

  • How can an individual (instance) posess a property?
    • the property can be possesed personally by the individual (explicit, not dependent on inheritance) or by inheritance from a related item (implicit)
  • inheritance can be
    • direct (single step belonging to a supergroup), or
    • indirect (multi-step belonging to a hierarchy of supergroups)

  • The above options can be written more formally:
  • individual has a property
    • has(individual, property)
    • has(fred, brown_eyes)
  • individual belongs to a group, group has property so individual has property
    • has(Individual, Property) if belongs(Individual, Group), has(Group, Property)
    • belongs(fred, 6a).
    • has_form_teacher(6a, mr_bruce).
    • has_form_teacher(Pupil, Teacher) if belongs(Pupil, Reg_class), has_form_teacher(Reg_class, Teacher).
    • QUERY: has_form_teacher(fred, mr_bruce)?
    • yes because fred belongs to 6a, 6a has mr bruce as a form teacher
  • individual belongs to group, group belongs to super group, super group has property so group has property so individual has property
    • has(Individual, Property) if belongs(Individual, Group), belongs(Group, Supergroup), has(Supergroup, Property)
    • has_head_of_year(sixth_year, mr_campbell).
    • belongs(6a, sixth_year).
    • belongs(fred, 6a).
    • QUERY: has_head_of_year(fred, mr_campbell)?
    • this last statement contains a recursive part (in red), since a group can belong to another group which in turn can belong to yet another group, and so on
    • this chain or hierarchy of classes belonging to another class can be several links long, this gives a problem; how can inheritance of properties be passed?
    • rather than write out each belongs(GroupA, GroupB), belongs(GroupB, GroupC), belongs(GroupC, GroupD) .. and so on, a recursive version does away with this as shown in the recursive section below.
  • sub-groups can inherit properties from another sub-group the same way as individuals can inherit from a sub-group
    • has(Group, Property) if belongs(Group, Supergroup), has(Supergroup, Property)
    • QUERY: has_head_of_year(6a, mr_campbell)?

  • benefit

  • inheritance (and recursive rules) allow an individual or subclass to posses the attributes of related classes
    • without needing to explicitly represent the knowledge in extra facts.
    • this saves memory in the knowledge base,
    • makes it easier to read for humans,
    • keeps semantic nets and frames more compact

  • frames

  • frames describe belonging to in a particular way, inheritance of properties is passed by
  • instance and
  • subclass (also super_class)
    • this is similar to semantic nets: is_a(X, Y) or belongs(X, Y), (X can be an instance or a class, Y is always a class)

  • recursion

  • remember recursion means a relationship defined in terms of itself, it provides for repetition ie a loop.
  • recursion is involved with inheritance since a sub-class can inherit from another sub-class which can inherit from another sub-class

  • instance(X,Y) is cannotbe used recursively since Y cannot be an instance, Y must be a class
    • instance(fred, human).
    • you could not also have instance(human, Z). since human is a class, it cannot be an instance
  • subclass(X, Y) canbe used recursively since X and Y can both be subclasses, though subclass Y is a superclass of subclass X
    • subclass(human, primate).
    • subclass(primate, mammal).
    • subclass(mammal, vertebrate).

  • Here are the recursive inheritance clauses, one for instance inheritance and one subclass inheritance
  • clause 1: has(Individual, Property) :- instance(Individual, Class), has(Class, Property).
    • an individual has a property if the individual is an instance of some class and that class has the property
  • clause 2: has(Class, Property) :- subclass(Class, Superclass), has(Superclass, Property).
    • an class has a property if the class is an subclass of some other class and that other class has the property

  • Take the example of fred who is a human, humans are primates, primates are mammals, mammals are vertebrates and vertebrates have a backbone.
  • How does PROLOG determine the query: has(fred, backbone)?
    • match clause 1, bind fred to Individual, backbone to Property: subgoals - instance(fred, Class), has(Class, backbone)
    • match instance(fred, human), bind human to Class, subgoal - has(human, backbone)
    • match clause 2, bind human to Class and backbone to Property, subgoals - subclass(human, Superclass), has(Superclass, backbone)
    • match subclass(human, primate), bind primate to Superclass, try subgoal has(primate, backbone)
    • match clause 2, bind primate to Class and backbone to Property, subgoals - subclass(primate, Superclass), has(Superclass, backbone)
    • match subclass(primate, mammal), bind mammal to Superclass, try subgoal has(mammal, backbone)
    • match clause 2, bind mammal to Class and backbone to Property, subgoals - subclass(mammal, Superclass), has(Superclass, backbone)
    • match subclass(mammal, vertebrate), bind vertebrate to Superclass, try subgoal has(vertebrate, backbone) which SUCCEEDS so
    • each preceding subgoal succeeds and so does the goal succeeded



  • recursion is also involved in other rules such as family tress
  • ancestor(X, Y) :- child(X, Y)
  • ancestor(X, Y) :- child(X, Z), ancestor(Z, Y).


SQA examples


  • SQA question A

    is_at_distance(astronomical_object, millions_of_miles).
 
    sub_class(planet, astronomical_object).
    sub_class(star, astronomical_object).
 
    temperature(star, very_hot).
    made_of(star, plasma).
    made_of(planet, gas).
 
    instance(the_sun, star).
    instance(alpha_centauri, star).
    instance(betelgeuse, star).
    instance(jupiter, planet).
    instance(earth, planet).
 
    made_of(earth, rock).


  • (iii) Write two rules that will ensure that the sun will inherit the properties of all stars.

  • HELP: the sun is an instance of the subclass star so it should inherit the properties of stars; made_of and temperature, this is inheritance without recursion

  • SQA question B

    has_legs(mammal, 4).
    has_legs(bouncer, 3).
    reproduces_by(mammal, live_young).
    reproduces_by(platypus, lays_eggs).
    subclass(dog, mammal).
    subclass(platypus, mammal).
    subclass(poodle, dog).
    instance(bouncer, poodle).
    reproduces_by(X, live_young):- subclass(X,Y),
    reproduces_by(Y, live_young).
    reproduces_by(X, live_young):- instance(X,Y),
    reproduces_by(Y, live_young).

  • Write two rules which will ensure that Bouncer (or any other mammals added to the knowledge base) will inherit the property “reproduces by live young”.
  • HELP: You need the non-recursive rule for instances inheriting from the subclass they belong to and then the recursive rule that lets a subclass inherit the properties of another subclass to which the first subclass belongs.


Summary

  • >


links


return to list processing (cAH)



This page has been edited 1 times. The last modification was made by - deborahkennedy deborahkennedy on May 29, 2012 7:13 am