我正在开发一个简单的序言程序。这是我的问题。
说我已经有一个事实fruit(apple).
我希望程序接受这样的输入?- input([what,is,apple]).
和输出apple is a fruit
对于输入,?-input([is,apple,a,fruit])
而不是默认的 print true
or false
,我希望程序打印一些更好的短语,例如yes
andno
有人可以帮我弄这个吗?
我的代码部分如下:
input(Text) :-
phrase(sentence(S), Text),
perform(S).
%...
sentence(query(Q)) --> query(Q).
query(Query) -->
['is', Thing, 'a', Category],
{ Query =.. [Category, Thing]}.
% here it will print true/false, is there a way in prolog to have it print yes/no,
%like in other language: if(q){write("yes")}else{write("no")}
perform(query(Q)) :- Q.