50 likes | 456 Views
predicates nondeterm isa(symbol,symbol) nondeterm hasprop(symbol,symbol,symbol). nondeterm hasproperty(symbol,symbol,symbol). clauses isa(canary,bird). isa(robin,bird). isa(ostrich,bird). isa(bird,animal). isa(opus,penguin). isa(penguin,bird). isa(fish,animal). isa(tweety,canary).
E N D
predicates nondeterm isa(symbol,symbol) nondeterm hasprop(symbol,symbol,symbol). nondeterm hasproperty(symbol,symbol,symbol). clauses isa(canary,bird). isa(robin,bird). isa(ostrich,bird). isa(bird,animal). isa(opus,penguin). isa(penguin,bird). isa(fish,animal). isa(tweety,canary). hasprop(tweety,color,white). hasprop(robin,color,red). hasprop(canary,color,yellow). hasprop(penguin,color,brown). hasprop(bird,travel,fly). Implementing inference using inheretance hasprop(fish,travel,swim). hasprop(ostrich,travel,walk). hasprop(penguin,travel,walk). hasprop(robin,sound,sing). hasprop(canary,sound,sing). hasprop(bird,cover,feather). hasprop(animal,cover,skin). hasproperty(Obj,Pr,Val):-hasprop(Obj,Pr,Val). hasproperty(Obj,Pr,Val):-isa(Obj,Parent),hasproperty(Parent,Pr,Val). goal hasproperty(Obj,Pr,fly).
Name:bird Name:animal Isa: animal Isa: animate Prop:flies,feather Prop:eats,skin Default: Default: Name:tweety Name:canary Isa: canary Isa: bird Prop: color(yellow),sound(sing) Prop: color(yellow),sound(sing) Default:color(white) Default:size(small) Frames from a knowledge base of birds
domains obj=symbol prop=travel(symbol);color(symbol);call(symbol);size(symbol);cover(symbol);action(symbol) listp=prop* name=name(obj) isa=isa(obj) predicates nondeterm frame(name,isa,listp,listp) nondeterm get(prop,obj) nondeterm member(prop,listp) nondeterm memberf(prop,listp) nondeterm uget(obj,listp) nondeterm equal(prop,prop) print(listp) clauses frame(name(bird),isa(animal),[travel(flies),cover(feathers)],[]). frame(name(penguin),isa(bird),[color(brown)],[travel(walks)]). frame(name(canary),isa(bird),[color(yellow),call(sing)],[size(small)]). frame(name(tweety),isa(canary),[],[color(white)]). equal(travel(_),travel(_)). equal(color(_),color(_)). equal(call(_),call(_)). equal(size(_),size(_)).equal(cover(_),cover(_)). equal(action(_),action(_)).
memberf(P,[H|_]):-equal(P,H). memberf(Pro,[_|T]):-memberf(Pro,T). member(P,[H|_]):-P=H. member(Pro,[_|T]):-member(Pro,T). get(Pro,Obj):-frame(name(Obj),_,LP,_),member(Pro,LP). get(Pro,Obj):-frame(name(Obj),_,_,LD),member(Pro,LD). get(Pro,Obj):-frame(name(Obj),isa(Parent),_,_),get(Pro,Parent). uget(Obj,L):-get(H,Obj),NOT(memberf(H,L)),uget(Obj,[H|L]). uget(Obj,L):-write(Obj),write(":"),print(L). print([]). print([H|T]):-write(H),print(T). goal uget(tweety,[]). tweety:cover("feathers")travel("flies")size("small")call("sing")color("white")yes