Ответ в теме: DCG в SWI-Prolog

      Комментарии к записи Ответ в теме: DCG в SWI-Prolog отключены
#2542

aleator
Участник

% top([is, it, true, that, william, shatner, is, an, actor]).

top(Sentence):-
	yesno4(ListQuery, Sentence, []),
	(findall( Query, (member(Query, ListQuery), Query), Goals ),
		ListQuery = Goals,
      write("Yes, thats true")
		; write("Sorry, no")
    ).

yesno4(Sem) -->  [is, it, true, that], statementN(_^_^[Sem]).

% ------------------------------------------------------------------

% вопросы произвольного уровня вложенности

top(Sentence):-
    yesno5(ListQuery, Sentence, []),
	(findall( Query, (member(Query, ListQuery), Query), Goals ),
		ListQuery = Goals,
      write("Yes, thats true")
		; write("Sorry, no")
    ).

yesno5(Sem) -->  statementN(_^_^Sem),[right].

statementN(Subj1^Obj1^Sem1) -->
   noun_phrase(Subj1),
   verb_phrase(Subj1^Obj1^Sem1),[and],
   statement(_^_^Sem2),
   {append(Sem1,Sem2,_)}.
statementN(Subj1^Obj1^Sem1) -->
   noun_phrase(Subj1),
   verb_phrase(Subj1^Obj1^Sem1),
   statementN(_^_^Sem2),
   {append(Sem1,Sem2,_)}.

Тему можно закрывать.