print customized result in prolog
- by Allan Jiang
I am working on a simple prolog program. Here is my problem.
Say I already have a fact fruit(apple).
I want the program take a input like this ?- input([what,is,apple]).
and output apple is a fruit
and for input like ?-input([is,apple,a,fruit])
instead of default print true or false, I want the program print some better phrase like yes and no
Can someone help me with this?
My code part is below:
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.