I have defined my grammar in prolog as DCG (Definite Clause Grammar).
Now I want to generate some phrases according with the facts present in my knowledge base.
For example, if I have likes(mark, julia). I want to generate the sentence
Mark likes Julia.
How can I do this?
We must take into account that
likes/2is a normal Prolog predicate, not a DCG.Hence, we use
{}//1to refer to regular Prolog predicates within DCGs.For example:
sentence --> [X, likes, Y], { likes(X, Y) }.Sample usage: