user1306283
user1306283

Reputation:

DCG(Definite clause grammar) in Prolog

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

Upvotes: 0

Views: 965

Answers (2)

whd
whd

Reputation: 1861

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.

Upvotes: 0

Alexander Serebrenik
Alexander Serebrenik

Reputation: 3577

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

Upvotes: 1

Related Questions