0

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 ;)

false
  • 10,264
  • 13
  • 101
  • 209
Karl Adler
  • 15,780
  • 10
  • 70
  • 88
  • 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 May 29 '12 at 17:21
  • @dasblinkenlight: `-->` introduces a definite clause grammar rule. – Fred Foo May 29 '12 at 17:26
  • @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 May 29 '12 at 17:32

2 Answers2

1

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).
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • if I do the noun outside the brackets I need to write the noun two times in the question, otherwise I got "false" -> question(What, [where,is,a,bakery, bakery],[]). – Karl Adler May 29 '12 at 17:46
  • 1
    @abimelex: it's a long time since I last did anything with DCGs, but I think you can skip the entire `location` if you add an extra argument `P` to `noun`. – Fred Foo May 29 '12 at 18:54
0

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 {}

Thanos Tintinidis
  • 5,828
  • 1
  • 20
  • 31