delphin.mrs.components

Classes and functions for working with the components of *MRS objects.

Variables and Predicates

delphin.mrs.components.sort_vid_split(vs)[source]

Split a valid variable string into its variable sort and id.

Examples

>>> sort_vid_split('h3')
('h', '3')
>>> sort_vid_split('ref-ind12')
('ref-ind', '12')
delphin.mrs.components.var_sort(v)[source]

Return the sort of a valid variable string.

Examples

>>> var_sort('h3')
'h'
>>> var_sort('ref-ind12')
'ref-ind'
delphin.mrs.components.var_id(v)[source]

Return the integer id of a valid variable string.

Examples

>>> var_id('h3')
3
>>> var_id('ref-ind12')
12
class delphin.mrs.components.Pred[source]

A semantic predicate.

Abstract predicates don’t begin with an underscore, and they generally are defined as types in a grammar. Surface predicates always begin with an underscore (ignoring possible quotes), and are often defined as strings in a lexicon.

In PyDelphin, Preds are equivalent if they have the same lemma, pos, and sense, and are both abstract or both surface preds. Other factors are ignored for comparison, such as their being surface-, abstract-, or real-preds, whether they are quoted or not, whether they end with _rel or not, or differences in capitalization. Hashed Pred objects (e.g., in a dict or set) also use the normalized form. However, unlike with equality comparisons, Pred-formatted strings are not treated as equivalent in a hash.

Parameters:
  • type – the type of predicate; valid values are Pred.ABSTRACT, Pred.REALPRED, and Pred.SURFACE, although in practice Preds are instantiated via classmethods that select the type
  • lemma – the lemma of the predicate
  • pos – the part-of-speech; a single, lowercase character
  • sense – the (often omitted) sense of the predicate
Returns:

a Pred object

type

predicate type (Pred.ABSTRACT, Pred.REALPRED, and Pred.SURFACE)

lemma

lemma component of the predicate

pos

part-of-speech component of the predicate

sense

sense component of the predicate

Example

Preds are compared using their string representations. Surrounding quotes (double or single) are ignored, and capitalization doesn’t matter. In addition, preds may be compared directly to their string representations:

>>> p1 = Pred.surface('_dog_n_1_rel')
>>> p2 = Pred.realpred(lemma='dog', pos='n', sense='1')
>>> p3 = Pred.abstract('dog_n_1_rel')
>>> p1 == p2
True
>>> p1 == '_dog_n_1_rel'
True
>>> p1 == p3
False
classmethod abstract(predstr)[source]

Instantiate a Pred from its symbol string.

classmethod grammarpred(predstr)[source]

Instantiate a Pred from its symbol string.

is_quantifier()[source]

Return True if the predicate has a quantifier part-of-speech.

Deprecated since v0.6.0

classmethod realpred(lemma, pos, sense=None)[source]

Instantiate a Pred from its components.

short_form()[source]

Return the pred string without quotes or a _rel suffix.

The short form is the same as the normalized form from normalize_pred_string().

Example

>>> p = Pred.surface('"_cat_n_1_rel"')
>>> p.short_form()
'_cat_n_1'
classmethod string_or_grammar_pred(predstr)[source]

Instantiate a Pred from either its surface or abstract symbol.

classmethod stringpred(predstr)[source]

Instantiate a Pred from its quoted string representation.

classmethod surface(predstr)[source]

Instantiate a Pred from its quoted string representation.

classmethod surface_or_abstract(predstr)[source]

Instantiate a Pred from either its surface or abstract symbol.

delphin.mrs.components.is_valid_pred_string(predstr)[source]

Return True if predstr is a valid predicate string.

Examples

>>> is_valid_pred_string('"_dog_n_1_rel"')
True
>>> is_valid_pred_string('_dog_n_1')
True
>>> is_valid_pred_string('_dog_noun_1')
False
>>> is_valid_pred_string('dog_noun_1')
True
delphin.mrs.components.normalize_pred_string(predstr)[source]

Normalize the predicate string predstr to a conventional form.

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

Examples

>>> normalize_pred_string('"_dog_n_1_rel"')
'_dog_n_1'
>>> normalize_pred_string('_dog_n_1')
'_dog_n_1'
delphin.mrs.components.split_pred_string(predstr)[source]

Split predstr and return the (lemma, pos, sense, suffix) components.

Examples

>>> Pred.split_pred_string('_dog_n_1_rel')
('dog', 'n', '1', 'rel')
>>> Pred.split_pred_string('quant_rel')
('quant', None, None, 'rel')

MRS and RMRS Components

class delphin.mrs.components.ElementaryPredication[source]

An MRS elementary predication (EP).

EPs combine a predicate with various structural semantic properties. They must have a nodeid, pred, and label. Arguments and other properties are optional. Note nodeids are not a formal property of MRS (unlike DMRS, or the “anchors” of RMRS), but they are required for Pydelphin to uniquely identify EPs in an Xmrs. Intrinsic arguments (ARG0) are not required, but they are important for many semantic operations, and therefore it is a good idea to include them.

Parameters:
  • nodeid – a nodeid
  • pred (Pred) – semantic predicate
  • label (str) – scope handle
  • args (dict, optional) – mapping of roles to values
  • lnk (Lnk, optional) – surface alignment
  • surface (str, optional) – surface string
  • base (str, optional) – base form
nodeid

a nodeid

pred

semantic predicate

Type:Pred
label

scope handle

Type:str
args

mapping of roles to values

Type:dict
lnk

surface alignment

Type:Lnk
surface

surface string

Type:str
base

base form

Type:str
cfrom

surface alignment starting position

Type:int
cto

surface alignment ending position

Type:int
carg

The value of the constant argument.

intrinsic_variable

The value of the intrinsic argument (likely ARG0).

is_quantifier()[source]

Return True if this is a quantifier predication.

iv

A synonym for ElementaryPredication.intrinsic_variable

delphin.mrs.components.elementarypredication(xmrs, nodeid)[source]

Retrieve the elementary predication with the given nodeid.

Parameters:nodeid – nodeid of the EP to return
Returns:ElementaryPredication
Raises:KeyError – if no EP matches
delphin.mrs.components.elementarypredications(xmrs)[source]

Return the list of ElementaryPredication objects in xmrs.

class delphin.mrs.components.HandleConstraint[source]

A relation between two handles.

Parameters:
  • hi (str) – hi handle (hole) of the constraint
  • relation (str) – relation of the constraint (nearly always “qeq”, but “lheq” and “outscopes” are also valid)
  • lo (str) – lo handle (label) of the constraint
hi

hi handle (hole) of the constraint

Type:str
relation

relation of the constraint

Type:str
lo

lo handle (label) of the constraint

Type:str
delphin.mrs.components.hcons(xmrs)[source]

Return the list of all HandleConstraints in xmrs.

class delphin.mrs.components.IndividualConstraint[source]

A relation between two variables.

Parameters:
  • left (str) – left variable of the constraint
  • relation (str) – relation of the constraint
  • right (str) – right variable of the constraint
left

left variable of the constraint

Type:str
relation

relation of the constraint

Type:str
right

right variable of the constraint

Type:str
delphin.mrs.components.icons(xmrs)[source]

Return the list of all IndividualConstraints in xmrs.

DMRS and EDS Components

class delphin.mrs.components.Node[source]

A DMRS node.

Nodes are very simple predications for DMRSs. Nodes don’t have arguments or labels like ElementaryPredication objects, but they do have a property for CARGs and contain their variable sort and properties in sortinfo.

Parameters:
  • nodeid – node identifier
  • pred (Pred) – semantic predicate
  • sortinfo (dict, optional) – mapping of morphosyntactic properties and values; the cvarsort property is specified in this mapping
  • lnk (Lnk, optional) – surface alignment
  • surface (str, optional) – surface string
  • base (str, optional) – base form
  • carg (str, optional) – constant argument string
Attributes
pred

semantic predicate

Type:Pred
sortinfo

mapping of morphosyntactic properties and values; the cvarsort property is specified in this mapping

Type:dict
lnk

surface alignment

Type:Lnk
surface

surface string

Type:str
base

base form

Type:str
carg

constant argument string

Type:str
cfrom

surface alignment starting position

Type:int
cto

surface alignment ending position

Type:int
cvarsort

The “variable” type of the predicate.

Note

DMRS does not use variables, but it is useful to indicate whether a node is an individual, eventuality, etc., so this property encodes that information.

is_quantifier()[source]

Return True if the Node’s predicate appears to be a quantifier.

Deprecated since v0.6.0

properties

Morphosemantic property mapping.

Unlike sortinfo, this does not include cvarsort.

delphin.mrs.components.nodes(xmrs)[source]

Return the list of Nodes for xmrs.

DMRS-style dependency link.

Links are a way of representing arguments without variables. A Link encodes a start and end node, the role name, and the scopal relationship between the start and end (e.g. label equality, qeq, etc).

Parameters:
  • start – nodeid of the start of the Link
  • end – nodeid of the end of the Link
  • rargname (str) – role of the argument
  • post (str) – “post-slash label” indicating the scopal relationship between the start and end of the Link; possible values are NEQ, EQ, HEQ, and H
start

nodeid of the start of the Link

end

nodeid of the end of the Link

rargname

role of the argument

Type:str
post

“post-slash label” indicating the scopal relationship between the start and end of the Link

Type:str

Return the list of Links for the xmrs.