DCG 输出单个变量,而不是列表中的整个子句



我在创建问答Prolog文件时遇到问题。我有一个包含位置的数据库,我已经可以得到问题并写出答案。但是有不同类型的对象,需要不同的前缀。所以我为前缀定义了 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] 

这适用于正确验证输入,但似乎对输出毫无用处。我怎么能只取变量而不取子句?

好的,我试图将整个程序翻译成一个或多或少有用且有效的示例。

location(kentuckys, road66, 121).
location(soliver, trafalgarsquare, 15).
location(marcopolo, trafalgarsquare, 15).
location(internist, jumpstreet, 21).
questionsentence(P,G) --> [where],[is], article(G), noun(G,P).
answer(P,A,G) :- location(P, Str, Nr), prep(W,Str), article(G,Art,[]), flatten([there, is, Art, P, W, Str,Nr], A).
question(A) --> questionsentence(P,G),{answer(P,A,G)}.
article(m) --> [a].
article(f) --> [an].
noun(m, P) --> [P], {member(P, [kentuckys, soliver, marcopolo])}.
noun(f, P) --> [P], {member(P, [internist])}.
prep([at],Str)  :- member(Str, [trafalgarsquare, road66]).
prep([in],Str)  :- member(Str, [jumpstreet]).

结果:

?- question(A, [where,is,a,kentuckys],[]).
A = [there, is, a, kentuckys, at, road66, 121] .

我想,我寻找的是一个结构,如:文章(G,Art,[])来确定依赖的DCG变量...实际上我还不知道最后两个论点是如何工作的......

最新更新