remember(X, Y, Reply).
remember(X, Y, y):-asserta(xpositive(X, Y)). remember(X, Y, n):-asserta(xnegative(X, Y)),fail. clear_facts:-retract(xpositive(_, _)),fail. clear_facts:-retract(xnegative(_, _)),fail.
clear_facts:-write(\
readchar(_).
/* Knowledge Base*/ animal_is(cheetah):- %猎豹
it_is(carnivore),
positive(has,tawny_color), positive(has,black_spots).
%老虎
animal_is(tiger):-
it_is(carnivore),
positive(has, tawny_color), positive(has, black_stripes).
%长颈鹿
animal_is(giraffe):-
it_is(ungulate),
positive(has, long_neck), positive(has, long_legs), positive(has, dark_spots).
%斑马
animal_is(zebra):-
it_is(ungulate),
6
positive(has,black_stripes).
%鸵鸟
animal_is(ostrich):-
it_is(bird), negative(does, fly),
positive(has, long_neck), positive(has, long_legs),
positive(has, black_and_white_color).
animal_is(penguin):- %企鹅
it_is(bird), negative(does, fly), positive(does, swim),
positive(has, black_and_white_color).
%信天翁
animal_is(albatross):-
it_is(bird),
positive(does,fly_well).
it_is(mammal):- %哺乳动物
positive(has,hair).
it_is(mammal):-
positive(does,give_milk).
%鸟类
it_is(bird):-
positive(has,feathers).
it_is(bird):-
positive(does,fly),
7
positive(does,lay_eggs).
it_is(carnivore):- %肉食动物
positive(does,eat_meat).
it_is(carnivore):-
it_is(mammal),
positive(has,pointed_teeth), positive(has,claws), positive(has,forward_eyes).
it_is(ungulate):- %有蹄类动物
it_is(mammal), positive(has,hooves).
it_is(ungulate):-
it_is(mammal),
positive(does,chew_cud).
4.2调试步骤
1.在TXT文本中编写规则代码,添加到状态图通用搜索程序中,修改程序。 2.打开Turbo prolog2.0文件,启动prolog.exe应用程序,并按空格键(SPACE)进入集成开发环境。
3.选择Setup项,打开下拉菜单,选择Directories项,进行工作目录修改,按Esc键退出,选择Save Configuration项,保存修改。
4.在相应的路径所在文件件夹中会生成work.Pro文件将其用文本打开,将要运行的程序写入,保存。
5.选择Files项,选择Load项,选择要打开的示例程序
8