序言:未捕获的异常:错误(existence_error(procedure,s / 3),top_level / 0)

时间:2018-10-03 18:14:58

标签: prolog dcg

我知道之前有人对此有疑问,但我仍然无法弄清楚出什么问题了。我正在尝试创建一个DCG,该DCG可以处理主题/对象的区分,单数/复数的区分,能够生成分析树并使用单独的词典。

我有此代码:

lex(the,det,_).
lex(a,det,singular).

lex(man,n,singular).
lex(men,n,plural).
lex(apple,n,singular).
lex(apples,n,plural).

lex(eat,v,plural).
lex(eats,v,singular).

lex(i,pronoun,singular,subject).
lex(we,pronoun,plural,subject).
lex(me,pronoun,singular,object).
lex(us,pronoun,plural,object).
lex(you,pronoun,_,_).
lex(he,pronoun,singular,subject).
lex(she,pronoun,singular,subject).
lex(him,pronoun,singular,object).
lex(her,pronoun,singular,object).
lex(they,pronoun,plural,subject).
lex(them,pronoun,plural,object).
lex(it,pronoun,singular,_).

s(s(NP, VP), Q, P) --> np(NP, Q, P), vp(VP, Q).
np(np(DET, N), Q, _) --> det(DET, Q), n(N, Q).
np(np(PRONOUN), Q, P) --> pronoun(PRONOUN, Q, P).

vp(vp(V, NP), Q) --> v(V, Q), np(NP, _, object).
vp(vp(V), Q) --> v(V, Q).

det(det(W), Q) --> [W], {lex(W, det, Q)}.
pronoun(pronoun(W), Q, P) --> [W], {lex(W, pronoun, Q, P)}.
n(n(W), Q) --> [W], {lex(W, n, Q)}.
v(v(W), Q) --> [W], {lex(W, v, Q)}.

当我用s(X,[he,eats,the,apple],[])测试它时。我想得到输出 X = s(np(代词(他,单数,主题)),vp(v(吃,单数),np(det(the,单数),n(苹果,单数,对象)))))。

但是我得到了错误,未捕获的异常:error(existence_error(procedure,s / 3),top_level / 0)。和 错误:未定义的过程:s / 3但是,有以下定义:s / 5

错误:流user_input:6:1语法错误:文件意外结束

我尝试将其更改为

    s(s(NP, VP)) --> np(NP, Q, P), vp(VP, Q).

但是我得到输出:X = s(np(代词(he)),vp(v(吃),np(det(the),n(apple)))) 我不知道我要去哪里。任何建议表示赞赏。

1 个答案:

答案 0 :(得分:2)

使用 phrase/2 接口谓词调用DCG:

?- phrase(s(A,B,C), [he,eats,the,apple]).
A = s(np(pronoun(he)), vp(v(eats), np(det(the), n(apple)))),
B = singular,
C = subject ;
false.