essaie de representer tes connaissances sous forme de frame ou script ou/et classes (representation hybride), et de là, cas des frames ressemblent à des procédures qui se déclenchent une fois les faits trouvés, on peut même leurs appliquer des démons (appelation en anglais) appelé encore reflexe ' tels que si-ajout, si-besoin, ...).
tout ceci est programmable en prolog, ou smalltak,...
voila un exemple que j'ai tiré de Internet
/*---------------------------------------------------------------*/
/* PARISTECH - Ecole Nationale Superieure des Telecommunications */
/*---------------------------------------------------------------*/
/* J-L. Dessalles 2009 Dep. INFRES */
/* */
/* >>>>> Logic programming and Knowledge representation <<<<<< */
/* www.telecom-paristech.fr/~icc/PLC */
/* */
/*---------------------------------------------------------------*/
% ========================
% Knowledge Representation
% ========================
%-------------------------------
% findall reconsidered
%-------------------------------
:- consult('geo.pl'). % just to get a database to read
:- dynamic(found/1).
findany(Var, Pred, _) :-
assert(found([])),
Pred, % the execution of Pred instantiates Var
retract(found(R)), % always only one instance of `found'
% in memory, no alternative to backtrack onto
assert(found([Var|R])),
fail.
findany(_,_,L) :-
retract(found(L)).
go(L) :-
findany(D, neighbour(D,_), L).
% Atlernative solution
findany1(Var, Pred, _) :-
retractall(found(_)), % resets memory
Pred, % the execution of Pred instantiates Var
asserta(found(Var)), % alternative solution: store Var without retracting
fail.
findany1(_,_,L) :-
collect_found(L).
collect_found([V|L]) :-
retract(found(V)),
!,
collect_found(L).
collect_found([]).
%--------------------------------
% semantic networks
%--------------------------------
isa(bird, animal).
isa(albert, albatross).
isa(albatross, bird).
isa(kiwi, bird).
isa(willy, kiwi).
isa(crow, bird).
locomotion(bird, fly).
locomotion(kiwi, walk).
locomotion(X, Loc) :-
isa(X, SuperX),
locomotion(SuperX, Loc).
food(albatross,fish).
food(bird,grain).
/* drawback : n particular inheritance rules */
/* solution: one general predicate : "known" */
known(Fact) :-
Fact,
!.
known(Fact) :-
Fact =.. [Rel, Arg1, Arg2],
isa(Arg1, SuperArg1),
SuperFact =.. [Rel, SuperArg1, Arg2],
known(SuperFact).
habitat(X, island) :-
known(locomotion(X, M)),
M = fly,
!.
habitat(_X, unknown).
%-----------------
% Frames
%-----------------
bird(kind_of, animal).
bird(locomotion, flight).
bird(active_period, day).
bird(food, grain).
albatross(kind_of, bird).
albatross(colour, black_and_white).
albatross(size, 115).
albatross(food, fish).
kiwi(kind_of, bird).
kiwi(colour, marron).
kiwi(active_period, night).
kiwi(locomotion, walk).
kiwi(size, 40).
albert(instance_of, albatross).
albert(size, 120).
willy(instance_of, kiwi).
fish(kind_of, animal).
carnivorous_plant(kind_of, being).
carnivorous_plant(food, insect).
insect(kind_of, animal).
animal(relative_size, method(relative_size)).
animal(kind_of, being).
being(diet, method(diet)).
relative_size(Object, TR) :-
value(Object, size, Size_of_Object),
value(Object, instance_of, ClasseObject),
value(ClasseObject, size, Size_of_Classe),
TR is Size_of_Object / Size_of_Classe * 100.
diet(Object, carnivorous) :-
value(Object, food, Meal),
value(Meal, kind_of, animal),
!.
diet(_, herbivorous).
%---------------
% First solution with no processing of methods
%---------------
value( Frame, Slot, Val) :-
Request =.. [Frame, Slot, Val],
Request,
!.
value( Frame, Slot, Val) :-
parent(Frame, SurFrame), % using inheritance
value(SurFrame, Slot, Val).
parent(Frame, SurFrame) :-
Request =.. [Frame, kind_of, SurFrame],
Request.
parent(Frame, SurFrame) :-
Request =.. [Frame, instance_of, SurFrame],
Request.
%---------------
% Another solution which includes the processing of methods
%---------------
value1(Frame, Slot, Val) :-
value2(Slot, Frame, Frame, Val). % keeping memory of the initial frame
value2(Slot, Frame, HFrame, Val) :-
Request =.. [HFrame,Slot,Info],
Request, % instantiates Info
!,
execute(Info, Frame, Val). % executes Info if it contains a method
value2(Slot, Frame, HFrame, Val) :-
parent(HFrame, SurHFrame), % using inheritance
value2(Slot,Frame,SurHFrame,Val).
execute(method(Meth), Frame, Val) :-
!,
Goal =.. [Meth, Frame, Val], % the method is given its arguments
Goal. % the method is executed
execute(Val, _, Val).
7 mars 2020 à 06:38