我正在编写一个小 Prolog 程序,预计将执行以下操作:
?-input([allan,is,a,name]).
true.
?-input([Is,allan,a,name]).
true.
这是我的代码:
% Simple answering agent
input(Text) :-
phrase(sentence(S), Text),
perform(S).
sentence(statement(S)) --> statement(S).
sentence(query(Q)) --> query(Q).
statement(Statement) -->
[Thing, 'is', 'a', Category],
{ Statement =.. [Category, Thing]}.
query(Query) -->
['Is', Thing, 'a', Category],
{ Query =.. [Category, Thing]}.
perform(statement(S)) :- asserta(S).
perform(query(Q)) :- Q.
该input([allan,is,a,name]).
部分似乎工作正常,但查询部分有问题,如果我输入input([Is,allan,a,name]).
,它会打印
Is = 'Is'
谁能帮我看看这个问题,谢谢。