delphin.predicate

Semantic predicates.

Semantic predicates are atomic symbols representing semantic entities or constructions. For example, in the English Resource Grammar, _mouse_n_1 is the predicate for the word mouse, but it is underspecified for lexical semantics—it could be an animal, a computer’s pointing device, or something else. Another example from the ERG is compound, which is used to link two compounded nouns, such as for mouse pad.

There are two main categories of predicates: abstract and surface. In form, abstract predicates do not begin with an underscore and in usage they often correspond to semantic constructions that are not represented by a token in the input, such as the compound example above. Surface predicates, in contrast, are the semantic representation of surface (i.e., lexical) tokens, such as the _mouse_n_1 example above. In form, they must always begin with a single underscore, and have two or three components: lemma, part-of-speech, and (optionally) sense.

See also

In DELPH-IN there is the concept of “real predicates” which are surface predicates decomposed into their lemma, part-of-speech, and sense, but in PyDelphin (as of v1.0.0) predicates are always simple strings. However, this module has functions for composing and decomposing predicates from/to their components (the create() and split() functions, respectively). In addition, there are functions to normalize (normalize()) and validate (is_valid(), is_surface(), is_abstract()) predicate symbols.

Module Functions

delphin.predicate.split(s)[source]

Split predicate string s and return the lemma, pos, and sense.

This function uses more robust pattern matching than used by the validation functions is_valid(), is_surface(), and is_abstract(). This robustness is to accommodate inputs that are not entirely well-formed, such as surface predicates with underscores in the lemma or a missing part-of-speech. Additionally it can be used, with some discretion, to inspect abstract predicates, which technically do not have individual components but in practice follow the same convention as surface predicates.

Examples

>>> split('_dog_n_1_rel')
('dog', 'n', '1')
>>> split('udef_q')
('udef', 'q', None)
delphin.predicate.create(lemma, pos, sense=None)[source]

Create a surface predicate string from its lemma, pos, and sense.

The components are validated in order to guarantee that the resulting predicate symbol is well-formed.

This function cannot be used to create abstract predicate symbols.

Examples

>>> create('dog', 'n', '1')
'_dog_n_1'
>>> create('some', 'q')
'_some_q'
delphin.predicate.normalize(s)[source]

Normalize the predicate string s to a conventional form.

This makes predicate strings more consistent by removing quotes and the _rel suffix, and by lowercasing them.

Examples

>>> normalize('"_DOG_n_1_rel"')
'_dog_n_1'
>>> normalize('_dog_n_1')
'_dog_n_1'
delphin.predicate.is_valid(s)[source]

Return True if s is a valid predicate string.

Examples

>>> is_valid('"_dog_n_1_rel"')
True
>>> is_valid('_dog_n_1')
True
>>> is_valid('_dog_noun_1')
False
>>> is_valid('dog_noun_1')
True
delphin.predicate.is_surface(s)[source]

Return True if s is a valid surface predicate string.

Examples

>>> is_surface('"_dog_n_1_rel"')
True
>>> is_surface('_dog_n_1')
True
>>> is_surface('_dog_noun_1')
False
>>> is_surface('dog_noun_1')
False
delphin.predicate.is_abstract(s)[source]

Return True if s is a valid abstract predicate string.

Examples

>>> is_abstract('udef_q_rel')
True
>>> is_abstract('"coord"')
True
>>> is_abstract('"_dog_n_1_rel"')
False
>>> is_abstract('_dog_n_1')
False

Exceptions

exception delphin.predicate.PredicateError(*args, **kwargs)[source]

Bases: delphin.exceptions.PyDelphinException

Raised on invalid predicate or predicate operations.