please ask a specific, short question. Include relevant code without excessive comments.
Here's how.
Given the DCG rules
sentence2(VP) --> noun_phrase2(Actor),verb_phrase2(Actor, VP).
noun_phrase2(Name) --> properName(Name).
verb_phrase2(Actor, VP) --> intrans_verb(Actor, VP).
verb_phrase2(Somebody, VP) --> trans_verb(Somebody, Something, VP),
noun_phrase2(Something).
properName(john) --> [john].
properName(mary) --> [mary].
intrans_verb(Actor, paints(Actor)) --> [paints].
trans_verb(Somebody, Something, likes(Somebody, Something)) --> [likes].
how does the following achieve its result?
?- sentence2(Meaning, [john, paints], []).
Meaning = paints(john)
Answer:
The above rules are equivalent to
sentence2(VP, L, Z):- noun_phrase2(Actor, L, L2),
verb_phrase2(Actor, VP, L2, Z).
noun_phrase2(Name, L, Z):- properName(Name, L, Z).
verb_phrase2(Actor, VP, L, Z):- intrans_verb(Actor, VP, L, Z).
verb_phrase2(Somebody, VP, L, Z):- trans_verb(Somebody, Something, VP, L, L2),
noun_phrase2(Something, L2, Z).
properName(john, L, Z):-
L = [john | Z]. %// 'john' is present in the input stream
properName(mary, L, Z):-
L = [mary | Z]. %// 'mary' is present in the input stream
/* an alternative definition
properName(X) --> [X], { member(X, [john, mary]) }.
%% would be translated as
properName(X, L, Z):- L = [X | Z], member(X, [john, mary]).
*/
intrans_verb(Actor, paints(Actor), L, Z):-
L = [paints | Z]. %// 'paints' is present in the input stream
trans_verb(Somebody, Something, likes(Somebody, Something), L, Z):-
L = [likes | Z]. %// 'likes' is present in the input stream
In particular,
?- sentence2(Meaning, [john, paints], []).
?- noun_phrase2(Actor, [john, paints], L2),
verb_phrase2(Actor, Meaning, L2, []).
?- noun_phrase2(Actor, [john, paints], L2).
?- properName(Actor, [john, paints], L2).
?- properName(john, [john, paints], L2). { Actor=john }
!- [john, paints] = [john | [paints]] { L2=[paints] }
?- verb_phrase2(john, Meaning, [paints], []).
?- intrans_verb(john, Meaning, [paints], []).
?- intrans_verb(john, paints(john), [paints], []). { Meaning=paints(john) }
!- [paints] = [paints | []]
!-