Question

Just a little confused about this prolog script..

  /*frame representation */

   frame(name(bird), isa(animal), hasproperty([fly, feathers, sing])).
   frame(name(canary),isa(bird), hasproperty([yellow, nervous, easily_frightened])).
   frame(name(tweety), isa(canary), hasproperty([baby, my_pet])).
   frame(name(barn_owl), isa(bird), hasproperty([nocturnal,large_eyes])).
   frame(name(barny), isa(barn_owl), hasproperty([sick,forward_facing])).

   /* inheritance -using recursion*/

   inherit(Concept, Prop):- frame(name(Concept), _, hasproperty(Prop)).

   inherit(Concept, Prop):-
       frame(name(Concept), isa(Parent), _),
       write(Parent), nl,
       frame(name(Parent), _, hasproperty(PP)),
       write(PP), nl, 
       inherit(Parent, NewProp).

I understand the first rule where it checks to see if the concept has a certain property, however I don't quite get the second rule.. I know It's supposed to work out if the frame it inherits from has a certain property but I am not sure how it is checking this, especially when the attribute names vary from PP to NewProp.. Also how does prolog know which rule to execute in this script if there are two rules with the same name? Cheers for any help!

Was it helpful?

Solution

I think what you want to do, in the second clause for inherit, is find the parent of your concept and then call inherit right away. Right now, you're doing half of that work again.

inherit(Concept, Prop):- frame(name(Concept), _, hasproperty(Prop)).

inherit(Concept, Prop):-
   frame(name(Concept), isa(Parent), _),
   write(Parent), nl,
   inherit(Parent, Prop).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top