0
global facts
  xpositive(symbol,symbol)
  xnegative(symbol,symbol)

predicates
  animal_is(symbol) - nondeterm (o)
  it_is(symbol) - nondeterm (i)
  ask(symbol,symbol,symbol) - determ (i,i,i)
  remember(symbol,symbol,symbol) - determ (i,i,i)
  positive(symbol,symbol) - determ (i,i)
  negative(symbol,symbol) - determ (i,i)
  clear_facts - determ ()
  run - determ ()

clauses
  animal_is(cheetah):-
it_is(mammal),
    it_is(carnivore),
positive(has,tawny_color),
positive(has,dark_spots).

  animal_is(tiger):-
it_is(mammal),
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),
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),
positive(does,lay_eggs).

  it_is(carnivore):-
positive(does,eat_meat).

  it_is(carnivore):-
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).

  positive(X,Y):-
xpositive(X,Y),!.
  positive(X,Y):-
not(xnegative(X,Y)),
ask(X,Y,yes).

  negative(X,Y):-
xnegative(X,Y),!.
  negative(X,Y):-
not(xpositive(X,Y)),
ask(X,Y,no).

  ask(X,Y,yes):-
!,
write(X," it ",Y,'\n'),
readln(Reply),nl,
frontchar(Reply,'y',_),
remember(X,Y,yes).
  ask(X,Y,no):-
!,
write(X," it ",Y,'\n'),
readln(Reply),nl,
frontchar(Reply,'n',_),
remember(X,Y,no).

  remember(X,Y,yes):-
assertz(xpositive(X,Y)).
  remember(X,Y,no):-
assertz(xnegative(X,Y)).

  clear_facts:-
write("\n\nPlease press the space bar to exit\n"),
retractall(_,dbasedom),
readchar(_).

  run:-
animal_is(X),!,
write("\nYour animal may be a (an) ",X),
nl,
clear_facts.
  run:-
write("\nUnable to determine what"),
write("your animal is.\n\n"),
clear_facts.

goal
  run.

我正在尝试运行这个专家系统程序,但是当我编译时出现以下错误。

compiling C:/Users/daemon/Desktop/ch16E01.PRO for byte code...
C:/Users/daemon/Desktop/ch16E01.PRO:1:8: syntax error: . or operator expected after     expression
C:/Users/daemon/Desktop/ch16E01.PRO:127:3: syntax error: . or operator expected after     expression
 2 error(s)
compilation failed
4

3 回答 3

1

然后您需要将代码转换为 Prolog。尽管它们的名字,TurboProlog/VisualProlog,虽然是有趣的逻辑编程语言,但根据 Prolog 的官方和事实上的标准定义,它们并不是 Prolog 系统。

使用标准 Prolog 系统(例如 GNU Prolog)编译代码所需的一些更改包括:删除带有“子句”和“目标”文本的行;还删除“全局事实”和“ predicates" 块;将 write/1 的参数中的双引号替换为单引号;将对 readchar/1 的调用替换为对 get_char/1 的调用。但是还有其他不那么微不足道的更改。最后,最好寻找首先为 Prolog 编写的教程代码。

于 2012-03-06T11:37:21.810 回答
0

您发布的代码似乎是为 TurboProlog/VisualProlog 编写的。但是,查看编译错误消息,您似乎正在使用(另一个)Prolog 编译器。你确定吗?

于 2012-03-06T02:11:53.467 回答
0

请将可读代码粘贴到您的编译器中并发布您的错误..

DATABASE - dbasedom
  xpositive(symbol,symbol)
  xnegative(symbol,symbol)

PREDICATES
  animal_is(symbol) - nondeterm (o)
  it_is(symbol) - nondeterm (i)
  ask(symbol,symbol,symbol) - determ (i,i,i)
  remember(symbol,symbol,symbol) - determ (i,i,i)
  positive(symbol,symbol) - determ (i,i)
  negative(symbol,symbol) - determ (i,i)
  clear_facts - determ ()
  run - determ ()


Goal
run.


CLAUSES


run:-
animal_is(X),!,
write("\nYour animal may be a (an) ",X),
nl,
clear_facts.

run:-
write("\nUnable to determine what"),
write("your animal is.\n\n"),
clear_facts.



animal_is(cheetah):-
it_is(mammal),
it_is(carnivore),
positive(has,tawny_color),
positive(has,dark_spots).

animal_is(tiger):-
it_is(mammal),
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),
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),



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),
positive(does,lay_eggs).

it_is(carnivore):-
positive(does,eat_meat).
it_is(carnivore):-
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).


positive(X,Y):-
xpositive(X,Y),!.
positive(X,Y):-
not(xnegative(X,Y)),
ask(X,Y,yes).

negative(X,Y):-
xnegative(X,Y),!.
negative(X,Y):-
not(xpositive(X,Y)),
ask(X,Y,no).


ask(X,Y,yes):-
!,
write(X," it ",Y,'\n'),
readln(Reply),nl,
frontchar(Reply,'y',_),
remember(X,Y,yes).

ask(X,Y,no):-
!,
write(X," it ",Y,'\n'),
readln(Reply),nl,
frontchar(Reply,'n',_),
remember(X,Y,no).

remember(X,Y,yes):-
assertz(xpositive(X,Y)).
remember(X,Y,no):-
assertz(xnegative(X,Y)).


negative(does,fly),
positive(does,swim),
positive(has,black_and_white_color).


clear_facts:-
write("\n\nPlease press the space bar to exit\n"),
retractall(_,dbasedom),
readchar(_).
于 2012-03-09T07:25:38.247 回答