2
我有一個問題,同時創建一個問題答案Prolog文件。我有一個包含位置的數據庫,我已經可以找到問題並寫出答案。但是有不同類型的對象,需要不同的前綴。所以我定義了DCG作爲前綴。DCG輸出單個變量而不是整個子句在列表中
answer(P,A) :- location(P, Str, Nr),A = [there, is, article(G,K,N,P), noun(G,K,N,P), pre(P),Str,Nr].
question(A) --> questionsentence(P),{answer(P,A)}.
pre(P) --> [in, P], {member(P, [road66])}.
pre(P) --> [at, P], {member(P, [trafalgarsquare])}.
但我得到的是這樣的:
?-question(A, [where,is,a,kentuckys],[]).
A = [there, is, article(_G2791, _G2792, _G2793, kentuckys), noun(_G2791, _G2792, _G2793, kentuckys), prep(kentuckys), road66, 123]
這適用於正確驗證輸入,但它似乎是無用的輸出。我怎樣才能把變量而不是條款?
你的例子似乎是不完整的:'questionsentence'和'pre'之間沒有關係,'location'丟失,並且' A'只是一個術語,而不是呼叫謂詞... –
對不起,我只是粘貼一小段代碼,因爲整個程序都是用德語寫的,我懶得翻譯所有的東西......但是,我重構了一下,解決了我的問題。 – abimelex