380 likes | 711 Views
Изкуствен интелект Упражнение № 6. спец. Информатика, ФМИ 2004/2005. Семантични мрежи и фрейми. Семантични мрежи Фрейми. Семантични мрежи. Семантичните мрежи се състоят от обекти и релации между обектите
E N D
Изкуствен интелектУпражнение № 6 спец. Информатика, ФМИ 2004/2005
Семантични мрежи и фрейми • Семантични мрежи • Фрейми
Семантични мрежи • Семантичните мрежи се състоят от обекти и релации между обектите • Обикновено се представят чрез граф, като възлите на графа съответстват на обектите, а релациите между обектите се представят чрез именувани дъги свързващи възлите на графа
Семантична мрежа animal isa active_at moving_method daylight bird fly isa isa colour albatross kiwi brown colour isa moving_method isa isa active_at Ross walk black_&_white Kim night Albert
isa(bird,animal). isa(albatross,bird). isa(kiwi,bird). isa(ross,albatross). isa(albert,albatross). isa(kim,kiwi). moving_method(bird,fly). moving_method(kiwi,walk). active_at(bird,daylight). active_at(kiwi,night). colour(albatross,black_&_white). colour(kiwi,brown). moving_method(X,Method):- isa(X,SuperX), moving_method(SuperX,Method).
(де)композиция на терм +Term =.. ?List ?Term =.. +List List е списък, чийто първи елемент е функтор на Term, а останалите елементи на List са аргументите на този терм Term, т.е. | ?- product(0, n, n-1) =.. L. L = [product,0,n,n-1] | ?- n-1 =.. L. L = [-,n,1] | ?- product =.. L. L = [product] | ?- X=..[functor,arg1,arg2,arg3,arg4]. X = functor(arg1,arg2,arg3,arg4) ? Вместо този предикат може да се използват arg/3 и functor/3.
fact(Fact):- Fact,!. fact(Fact):- Fact=..[Rel,Arg1,Arg2], isa(Arg1,SuperArg), SuperFact=..[Rel,SuperArg,Arg2], fact(SuperFact).
| ?- fact(moving_method(kim,Method)). Method = walk ? | ?- fact(moving_method(albert,Method)). Method = fly ?
Съпоставяне на семантични мрежи figure oval polygon 4-side triangle circle ellipse rectangle trapezoid square
Съпоставяне на семантични мрежи % is_a hierarchy isa(square,rectangle). isa(rectangle,4-side). isa(trapezoid,4-side). isa(parallelogram,4-side). isa(circle,oval). isa(ellipse,oval). isa(triangle,polygon). isa(4-side,polygon). isa(polygon,figure). isa(oval,figure).
Съпоставяне на семантични мрежи c c a b a b Арка support(a,c). touch(a,b). c a b a b c
Съпоставяне на семантични мрежи % Objects represented as facts in the format: % object(Name,Parts,IsaRelations, MustRelations,MustNotRelations object(arch,[a,b,c], [isa(a,4-side),isa(b,4-side), isa(c,polygon)], [support(a,c),support(b,c)], [touch(a,b)]).
Съпоставяне на семантични мрежи % Test patterns test1([X,Y,Z], [isa(X,rectangle),isa(Y,rectangle),isa(Z,triangle)], [support(X,Z),support(Y,Z)]). test2([X,Y,Z], [isa(X,rectangle),isa(Y,rectangle),isa(Z,triangle)], [support(X,Z),support(Y,Z),touch(X,Y)]).
Съпоставяне на семантични мрежи % Sample runs ?- match([X,Y,Z], [isa(X,rectangle),isa(Y,rectangle),isa(Z,triangle)], [support(X,Z),support(Y,Z)], Name). Name=arch ?- test1(Parts,Isa,Rels),match(Parts,Isa,Rels,Name). Name=arch
Съпоставяне на семантични мрежи match(Parts,Isa1,Rels,Name) :- object(Name,Parts,Isa2,Must,MustNot), match_isa(Isa1,Isa2), subset(Must,Rels), \+ intersect(Rels,MustNot).
Съпоставяне на семантични мрежи match_isa([],[]). match_isa([isa(X,P)|T],[isa(X,Q)|V]) :- parent(P,Q), match_isa(T,V).
Съпоставяне на семантични мрежи subset([],_). subset([X|T],Y) :- member(X,Y), subset(T,Y). intersect(L1,L2) :- member(X,L1), member(X,L2).
Съпоставяне на семантични мрежи parent(X,X). parent(X,Z) :- isa(X,Y), parent(Y,Z).
Opus Bill Pat Bats Cats Penguins Animals Mammals Birds Legs:2 Flies:T Legs: 2 Flies:T Name:Pat Name:Bill Friend: Name:Opus Friend: Legs:4 Flies:F Alive:T Flies:F rel(alive,animals,t). rel(flies,animals,f). subset(birds,animals). subset(mammals,animals). rel(flies,birds,t). rel(legs,birds,2). rel(legs,mammals,4). Фрейми Subset Subset Subset Subset Subset Member Member Member
Opus Birds Bill Mammals Penguins Animals Cats Bats Pat Legs: 2 Flies:T Name:Opus Friend: Legs:2 Flies:T Legs:4 Flies:F Name:Pat Alive:T Flies:F Name:Bill Friend: rel(legs,mammals,4). subset(penguins,birds). subset(cats,mammals). subset(bats,mammals). rel(flies,penguins,f). rel(legs,bats,2). rel(flies,bats,t). Subset Subset Subset Subset Subset Member Member Member
Opus Birds Bill Mammals Penguins Animals Cats Bats Pat Legs: 2 Flies:T Name:Opus Friend: Legs:2 Flies:T Legs:4 Flies:F Name:Pat Alive:T Flies:F Name:Bill Friend: is_a(opus,penguins). is_a(bill,cats). is_a(pat,bats). name(opus,'Opus'). friend(opus,bill). name(bill,'Bill'). friend(bill,opus). name(Pat,'Pat'). Subset Subset Subset Subset Subset Member Member Member
Пример FRAME:bird a_kind_of: animal moving_method: fly active_at: daylight
Пример FRAME:albatross a_kind_of: bird colour: black_and_white size: 115 % 115 cm long FRAME:kiwi a_kind_of: bird moving_method: walk active_at: night colour: brown size: 40
Пример FRAME:Albert instance_of: albatross size: 120
% A frame is represented as a set of % Prolog facts: % frame_name(Slot,Value) % where Value is either a simple value or % a procedure % Frame bird: the prototypical bird bird(a_kind_of,animal). bird(movin_method,fly). bird(active_at,daylight). % Frame albatross: albatross is a typical bird % with some extra facts: it is black and white, % and it is 115 cm long albatross(a_kind_of, bird). albatross(colour,black_and_white). albatross(size,115).
% Frame kiwi: kiwi is a rather untypical % bird in that it walks instead of flies, % and it is active at night kiwi(a_kind_of,bird). kiwi(moving_method,walk). kiwi(active_at,night). kiwi(colour,brown). kiwi(size,40). % Frame albert: an instance of big albatross albert(instance_of,albatross). albert(size,120). % Frame ross: an instance of baby albatross ross(instance_ot,albatross). ross(size,40).
% Frame animal: slot relative_size % obtains its value by executing % procedure relative_size animal(relative_size, execute( relative_size(Object,Value), Object, Value ) ).
value(Frame,Slot,Value):- Query=..[Frame,Slot,Value], call(Query),!. value(Frame,Slot,Value):- parent(Frame,ParentFrame), value(ParentFrame,Slot,Value). parent(Frame,ParentFrame):- (Query=..[Frame,a_kind_of,ParentFrame] ; Query=..[Frame,instance_of,ParentFrame]), call(Query).
?-value(albert,active_at,AlbertTime). AlbertTime=daylight ?-value(kiwi,active_at,KiwiTime). KiwiTime=night
% 40/115*100%=34.78% ?-value(ross,relative_size,R). R=34.78 relative_size(Object,RelativeSize):- value(Object,size,ObjSize), value(Object,instance_of,ObjClass), value(ObjClass,size,ClassSize), RelativeSize is ObjSize/ClassSize*100. animal(relative_size, execute( relative_size(Obj,Val), Obj, Val ) ).
value(Frame,Slot,Value):- value(Frame,Frame,Slot,Value). value(Frame,SuperFrame,Slot,Value):- Query=..[SuperFrame,Slot,Information], call(Query), process(Information,Frame,Value). value(Frame,SuperFrame,Slot,Value):- parent(SuperFrame,ParentSuperFrame), value(Frame,ParentSuperFrame,Slot,Value). process(execute(Goal,Frame,Value),Frame,Value):-!, call(Goal). process(Value,_,Value).