dnolen
dnolen

Reputation: 18556

Prolog DCGs Multiple Features?

From what I understand, in Prolog you capture features while parsing like so:

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

Is this common when designing DCGs ?

 foo(featureA(X), featureB(Y)) --> [X], [Y], bar.

Upvotes: 7

Views: 255

Answers (2)

false
false

Reputation: 10102

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,...].

Upvotes: 6

Fred Foo
Fred Foo

Reputation: 363547

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

Upvotes: 5

Related Questions