gpt4 book ai didi

Prolog: 未捕获异常: error(existence_error(procedure,s/3),top_level/0)

转载 作者:行者123 更新时间:2023-12-01 15:08:51 29 4
gpt4 key购买 nike

我知道之前有人问过这个问题,但我仍然无法弄清楚哪里出了问题。我正在尝试创建一个 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(代词(he, singular, subject)), vp(v(eats, singular), np(det(the, singular), n(apple, singular, object)))).

但我收到错误,未捕获的异常: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(eats),np(det(the),n(apple))))我不知道我哪里出错了。任何建议表示赞赏。

最佳答案

使用phrase/2接口(interface)谓词调用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.

关于Prolog: 未捕获异常: error(existence_error(procedure,s/3),top_level/0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52633334/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com