1
votes

i'm new to prolog and I try to program a answering machine. At first I like to figure out for what was asked, and to check correct syntax.

question(P) --> [where],[is], article(G,K,N), location(P,G,K,N).
location(P,G,K,N) --> [P], {member(P, [bakery, mcdonalds, kfc, embassy]),noun(G,K,N)}.

article(m, akk, sg) --> [a].
article(f, akk, sg) --> [an].

noun(m, akk, sg) --> [bakery]|[mcdonalds]|[kfc].
noun(f, akk, sg) --> [embassy].

but i got this error:

question(What, [where,is,a,bakery],[]).
ERROR: location/6: Undefined procedure: noun/3
ERROR:   However, there are definitions for:
ERROR:         noun/5

however, i found that the last two arguments of dcg variables are some kind of lists, but i really found nothing for that topic... do you have any tipps or solution for me? PS: I tried to translate the example from german grammar, so don't be confused ;)

2
Are you sure that your Prolog syntax is right? Shouldn't you use :- as the separator of rule's header and the body, instead of -->? - Sergey Kalinichenko
@dasblinkenlight: --> introduces a definite clause grammar rule. - Fred Foo
@larsmans Thanks! I've been out of the Prolog world for more than a decade and a half, so I have forgotten a great deal of it. I'm pretty sure that I've never used DCG's, though, so the syntax looks new to me. - Sergey Kalinichenko

2 Answers

2
votes

In the location rule, you put noun inside {} so it's treated like an ordinary Prolog rule. Take it outside the {} and your grammar "works" (well, the parse fails, but it doesn't throw an error).

location(P,G,K,N) --> [P], {member(P, [bakery, mcdonalds, kfc, embassy])},
                      noun(G,K,N).
0
votes

a 'DCG predicate' has two 'hidden' arguments; noun(G,K,N) would be noun(G,K,N,L,R) where L would be the input list and R what is left after a noun has be recognised.

swi-prolog related man page

note that it's better to use the predicates phrase/[2,3] instead of using the equivalent predicate (the implementation could change).

as larsmans said, in this code noun should be outside {}