Prolog DCGs Multiple Features?

From what I understand, in Prolog, you grab functions during parsing as follows:

foo(feature(X)) --> [X], bar. 

Is this a common occurrence when developing DCG?

  foo(featureA(X), featureB(Y)) --> [X], [Y], bar. 
+6
source share
2 answers

DCGs describe the relationship between lists and non-terminal arguments. However, these arguments are simply terms. They can be used to represent functions, but they do not represent them directly. To see the difference, imagine that you want to associate a Numus function with each node. In DCG, you need to decide in each case how to present this function. In one node it is feature(X, singular) , and in another node it may look different. Or you can consistently represent all objects with a list in this way [nodename=idx,..., numerus=singular,...] .

+5
source

This is perfectly true and very useful. As an example, consider this rule, taken from the classic (and now free!) PNLA book , which uses two arguments to capture inflection and the โ€œsenseโ€ (logical form, LF ) of the transitive verb tv :

 tv(nonfinite, LF) --> [TV], {tv(TV, _, _, _, _, LF)}. tv(finite, LF) --> [TV], {tv(_, TV, _, _, _, LF)}. tv(finite, LF) --> [TV], {tv(_, _, TV, _, _, LF)}. tv(past_participle, LF) --> [TV], {tv(_, _, _, TV, _, LF)}. tv(pres_participle, LF) --> [TV], {tv(_, _, _, _, TV, LF)}. 

Then the verb can be defined as

 tv( write, writes, wrote, written, writing, X^Y^ `writes(X,Y) ). 

( See full example. )

+4
source

Source: https://habr.com/ru/post/891687/


All Articles