Prolog DCGs Multiple Features?
From what I understand, in Prolog you capture features while parsing 开发者_JS百科like so:
foo(feature(X)) --> [X], bar.
Is this common when designing DCGs ?
foo(featureA(X), featureB(Y)) --> [X], [Y], bar.
DCGs describe relations between lists and the non-terminals' arguments. However, these arguments are just terms. They can be used to represent features but do not represent them directly. To see the difference, imagine you want to associate a feature numerus to each node. In DCGs you have now to decide, case by case, how to represent that feature. In one node it is feature(X, singular)
and in another node it might look different. Or you might decide to represent all features uniformly with a list, thus [nodename=idx,..., numerus=singular,...]
.
It's perfectly valid, and quite useful. As an example, consider this rule, taken from the classic (and now free!) book PNLA, which uses two arguments to capture the inflection and the "meaning" (the logical form, LF
) of a 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)}.
A verb can then be defined as
tv( write, writes, wrote, written, writing, X^Y^ `writes(X,Y) ).
(See full example.)
精彩评论