0

I am trying to make a DCG in prolog so that I create a sentence based on some predicates. I have two pieces of information = properties of objects ("Charles is a man.") and relations between objects ("Charles is the father of William.")

The task is to create sentences like this

[charles,is,a,man]
[camilla,is,a,woman]
[camilla,is,the,wife,of,charles]
[charles,is,the,father,of,william]
[charles,is,the,husband,of,camilla]

I can create a simple DCG which can generate sentences but how I can implement the relations so that the subject(charles, camilla, charles) correspond to the predicate part (is a man, is a woman)?

false
  • 10,264
  • 13
  • 101
  • 209
  • Do you mean to ask how do you record the information that Charles is a male name and Camilla - a female name? – Alexander Serebrenik May 28 '12 at 14:53
  • no really, more like when I have predicate man(charles) and father(charles,william) how to connect it with DCG. –  May 28 '12 at 16:47

2 Answers2

1

You can combine DCG rules with Prolog predicates as follows

rpn --> [RPN], {rpn(RPN)}.   /* relative pronoun */
rpn(that).
rpn(which).
rpn(who).

Example is taken from J.R. Fisher's tutorial

Alexander Serebrenik
  • 3,567
  • 2
  • 16
  • 32
0
zdanie --> person, " ", iss, " ", animal, ".".

 man --> "adam" or "john".
women --> "eve" or "travolta".
iss --> "is".
animal --> "dog" or "cat" or "bird".

sentence(Z) :-
   phrase(zdanie, [I|R]),
   code_type(I, to_lower(J)),
   atom_codes(Z, [0' , J|R]).

and so on.

whd
  • 1,819
  • 1
  • 21
  • 52