我想檢查用戶輸入的句子中的單詞是否與列表中的至少一個字符串匹配。這是我的。當我輸入例如'香蕉車'(它應該)時,我的謂詞測試返回false。如何檢查用戶推測字符串是否與列表中的字符串匹配?
在swish prolog中,我編寫了enterQuery。當提示我寫'香蕉車'時。我回來[香蕉,車] [香蕉,蘋果]假
enterQuery:-
read(X),
processQuery(X).
processQuery(X):-
split_string(X," ", " ", L),
write(L),
test(L).
test(L):-
write([banana, apple]),
common_member(L,[banana,apple]),
write('successs').
common_member(Xs,Ys) :-
member(E,Xs),
member(E,Ys).
當我查詢:
?- enterQuery.
|: 'banana car'.
[banana,car][banana,apple]
false.
相反,我想到:
?- enterQuery.
|: 'banana car'.
[banana,car][banana,apple]successs
看起來好像沒什麼問題。你需要展示你的實際互動,僅僅說「返回假」是不夠的。 – 2016-11-04 12:13:16
@Boris行。在解釋器(swish prolog)中我寫道:enterQuery。當提示我輸入「香蕉車」時。我得到的輸出是[香蕉,汽車] [香蕉,蘋果]虛假謝謝! – JCR
不,不夠好,你應該把實際的交互式提示內容複製粘貼到問題中。 – 2016-11-04 12:28:24