user7045171
user7045171

Reputation: 49

Prolog: uncaught exception: error(existence_error(procedure,s/3),top_level/0)

I know there have been questioned asked about this before but I still haven't been able to figure out whats wrong. I'm trying to create a DCG that can handle subject/object distinction, singular/plural distinction, capable of producing parse trees and make use of a separate lexicon.

I have this code:

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)}.

when I test it with s(X,[he,eats,the,apple],[]). I want to get the output X = s(np(pronoun(he, singular, subject)), vp(v(eats, singular), np(det(the, singular), n(apple, singular, object)))).

But I get the error, uncaught exception: error(existence_error(procedure,s/3),top_level/0). and ERROR: Undefined procedure: s/3 However, there are definitions for: s/5

ERROR: Stream user_input:6:1 Syntax error: Unexpected end of file

I tried changing it to

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

but then I get the output: X = s(np(pronoun(he)),vp(v(eats),np(det(the),n(apple)))) I can't figure out where I'm going wrong. Any advice is appreciated.

Upvotes: 3

Views: 1080

Answers (1)

mat
mat

Reputation: 40768

Use the phrase/2 interface predicate to invoke a 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.

Upvotes: 2

Related Questions