gpt4 book ai didi

prolog - prolog 中的小型专家系统

转载 作者:行者123 更新时间:2023-12-02 23:17:32 25 4
gpt4 key购买 nike

我正在使用 Prolog 制作这个对动物进行分类的专家系统,并且我使用的是 GNU/Prolog 和 Debian GNU/Linux。

xpositive(symbol,symbol)
xnegative(symbol,symbol)

nondeterm animal_is(symbol)
nondeterm it_is(symbol)
ask(symbol,symbol,symbol)
remember(symbol,symbol,symbol)
positive(symbol,symbol)
negative(symbol,symbol)
clear_facts
run

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,nl,clear_facts.
run:-
write("\nUnable to determine what"),
write("your animal is.\n\n"),
clear_facts.

run.

我的这个程序有问题。我编译了程序,但收到错误消息:

GNU Prolog 1.3.0
By Daniel Diaz
Copyright (C) 1999-2007 Daniel Diaz
| ?- [system].
compiling /root/Dokumenty/Lab/Expert/system.pl for byte code...
/root/Dokumenty/Lab/Expert/system.pl:2:1: syntax error: . or operator expected after > expression
1 error(s)
compilation failed

我正在尝试解决我的问题,但仍然收到错误消息:

xpositive(symbol,symbol).
xnegative(symbol,symbol).

nondeterm animal_is(symbol)
nondeterm it_is(symbol)
ask(symbol,symbol,symbol)
remember(symbol,symbol,symbol)
positive(symbol,symbol)
negative(symbol,symbol)
clear_facts
run

错误消息:

| ?- [system].
compiling /root/Dokumenty/Lab/Expert/system.pl for byte code...
/root/Dokumenty/Lab/Expert/system.pl:4:11: syntax error: . or operator expected after expression
1 error(s)
compilation failed

感谢您提前提供的帮助

最佳答案

您正在使用 WinProlog 的源代码(原为 TurboProlog)。

只需删除所有这些声明,即那些没有结束点的行(直到运行,包括)。 Prolog 中不需要。

您还需要重命名 write 调用,或者为了简单起见,在参数周围添加方括号,使它们的元数为 1。例如:

...
write([X," it ",Y,'\n']),
...

然后你就打电话

?- run.

在控制台上。

关于prolog - prolog 中的小型专家系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13976733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com