【发布时间】:2021-04-30 16:04:56
【问题描述】:
在 prolog 中编译此代码时,我不断收到语法错误。我是编程新手,所以不太明白。有人可以帮我调试我出错的地方吗?专家系统旨在将动物与脊椎动物和无脊椎动物进行分类。这是我目前拥有的代码:
:-dynamic known/3
top_goal(X):-animal(X).
%Animals and their classifications
animal(lion):-
type(vertebrate),
color(brown).
animal(bee):-
type(invertebrate),
color(yellow).
animal(crickets):-
type(invertebrate),
color(green).
%background information about vertebrates and invertebrates.
animal(vertebrate):-
vertebral_column(present),
nerve_cord(dorsal_and_hollow),
skeleton(internal),
heart(located_on_right_side),
haemoglobin(present_in_red_blood_cells).
animal(invertebrate):-
vertebral_column(absent),
skeleton(external),
heart(located_on_dorsal_side),
haemoglobin(dissolved_in_plasma).
%Ask rules
animal(X):-ask(type,X).
animal(X):-ask(color,X).
animal(X):-ask(sound,X).
ask(A,V):-
write(A:V),%ask user
write('?:'),
read(Y),%get the answer
asserta(known(Y,A,V),%remember it
Y==yes.%succeed or fail
solve:-
retractall(known(_,_,)),
top_goal(X),
write('The animal is '),write(X),nl.
solve:-
write('This animal is unknown '),nl.
【问题讨论】:
标签: prolog expert-system