我是 Prolog 的新手。我想知道如何做简单的专家系统,比如
go :- hypothesize(Vehicle),
write('I guess that the Vehicle is: '),
write(Vehicle), nl, undo.
hypothesize(car) :- car, !.
hypothesize(van) :- van,!.
hypothesize(bike) :- bike, !.
hypothesize(mini) :- mini, !.
hypothesize(tank) :-tank, !.
hypothesize(sau) :- sau, !.
hypothesize(excavator) :- excavator, !.
hypothesize(bulldozer) :- bulldozer, !.
hypothesize(rocket) :- rocket, !.
hypothesize(shuttle) :- shuttle , !.
hypothesize(destroyer) :- destroyer, !.
hypothesize(civil_plane) :- civil_plane, !.
hypothesize(unknown).
/* Vehicle identification rules */
sau :- grounder,
verify(has_gun),
verify(long_fire).
tank :- grounder,
verify(has_gun),
verify(short_fire).
excavator :- grounder,
verify(no_gun),
verify(have_ladle).
bulldozer :- grounder,
verify(no_gun),
verify(no_ladle).
car :- grounder,
verify(big_body),
verify(for_passengers).
van :- grounder,
verify(big_body),
verify(for_cargo).
bike :- grounder,
verify(small_body),
verify(two_wheels).
mini :- grounder,
verify(small_body),
verify(four_wheels).
rocket :- flying,
verify(cosmos_flying),
verify(can_return).
shuttle :- flying,
verify(cosmos_flying),
verify(cant_return).
destroyer :- flying,
verify(air_flying),
verify(warmade).
civil_plane :- flying,
verify(air_flying),
verify(civil).
/* classification rules */
grounder :- verify(has_wheels), !.
grounder :- verify(have_engine).
flying :- verify(has_wings), !.
flying :- verify(has_jets).
/* how to ask questions */
ask(Question) :-
write('Does the vehicle have the following attribute: '),
write(Question), write('? '),
read(Response), nl,
( (Response == yes ; Response == y)
-> assert(yes(Question)) ;
assert(no(Question)), fail).
:- dynamic yes/1,no/1.
/* How to verify something */
verify(S) :- (yes(S) -> true ; (no(S) -> fail ; ask(S))).
/* undo all yes/no assertions */
undo :- retract(yes(_)),fail.
undo :- retract(no(_)),fail.
undo.
这很好,但问题是 - 如何进行“后退”输出,例如,我将在序言窗口中输入“坦克”,他将给出这个坦克的所有部件 - 比如枪 - 是的,短步枪 -是的,翅膀 - 不,等等
是否有可能在这样的专家系统中做,或者我必须做另一个程序?
感谢你的回复