Prolog DCGs Multiple Features?
Asked Answered
R

2

7

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.
Recoverable answered 30/6, 2011 at 0:17 Comment(0)
G
6

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

Goodill answered 30/6, 2011 at 6:46 Comment(2)
What are the advantages/disadvantages of representing them uniformly as a list instead of as a compound(?) term ?Recoverable
It is more uniform: So extracting features is much simpler. Putting features into arguments of some compound terms means that you have to write access code for each kind of compound term.Goodill
S
5

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

Sturgill answered 30/6, 2011 at 10:30 Comment(1)
Just to point out that lookup by the word form (e.g. 'written') will be slow unless the facts (e.g. tv/6) are indexed by all the arguments. A faster lexicon representation would be tv(written, past_participle, X^Y^writes(X,Y)).Hipbone

© 2022 - 2024 — McMap. All rights reserved.