delphin.mrs

Minimal Recursion Semantics ([MRS]).

MRS

Copestake, Ann, Dan Flickinger, Carl Pollard, and Ivan A. Sag. “Minimal recursion semantics: An introduction.” Research on language and computation 3, no. 2-3 (2005): 281-332.

Module Constants

delphin.mrs.INTRINSIC_ROLE

The ARG0 role that is associated with the intrinsic variable (EP.iv).

delphin.mrs.RESTRICTION_ROLE

The RSTR role used to select the restriction of a quantifier.

delphin.mrs.BODY_ROLE

The BODY role used to select the body of a quantifier.

delphin.mrs.CONSTANT_ROLE

The CARG role used to encode the constant value (EP.carg) associated with certain kinds of predications, such as named entities, numbers, etc.

Classes

class delphin.mrs.MRS(top=None, index=None, rels=None, hcons=None, icons=None, variables=None, lnk=None, surface=None, identifier=None)[source]

Bases: delphin.scope.ScopingSemanticStructure

A semantic representation in Minimal Recursion Semantics.

Parameters
  • top – the top scope handle

  • index – the top variable

  • rels – iterable of EP relations

  • hcons – iterable of handle constraints

  • icons – iterable of individual constraints

  • variables – mapping of variables to property maps

  • lnk – surface alignment

  • surface – surface string

  • identifier – a discourse-utterance identifier

top

The top scope handle.

index

The top variable.

rels

The list of EPs (alias of predications).

hcons

The list of handle constraints.

icons

The list of individual constraints.

variables

A mapping of variables to property maps.

lnk

The surface alignment for the whole MRS.

surface

The surface string represented by the MRS.

identifier

A discourse-utterance identifier.

arguments(types=None, expressed=None)[source]

Return a mapping of the argument structure.

Parameters
  • types – an iterable of predication types to include

  • expressed – if True, only include arguments to expressed predications; if False, only include those unexpressed; if None, include both

Returns

A mapping of predication ids to lists of (role, target) pairs for outgoing arguments for the predication.

is_quantifier(id)[source]

Return True if var is the bound variable of a quantifier.

properties(id)[source]

Return the properties associated with EP id.

Note that this function returns properties associated with the intrinsic variable of the EP whose id is id. To get the properties of a variable directly, use variables.

quantification_pairs()[source]

Return a list of (Quantifiee, Quantifier) pairs.

Both the Quantifier and Quantifiee are Predication objects, unless they do not quantify or are not quantified by anything, in which case they are None. In well-formed and complete structures, the quantifiee will never be None.

Example

>>> [(p.predicate, q.predicate)
...  for p, q in m.quantification_pairs()]
[('_dog_n_1', '_the_q'), ('_bark_v_1', None)]
scopal_arguments(scopes=None)[source]

Return a mapping of the scopal argument structure.

Unlike SemanticStructure.arguments(), the list of arguments is a 3-tuple including the scopal relation: (role, scope_relation, scope_label).

Parameters

scopes – mapping of scope labels to lists of predications

scopes()[source]

Return a tuple containing the top label and the scope map.

Note that the top label is different from top, which is the handle that is qeq to the top scope’s label. If top does not select a top scope, the None is returned for the top label.

The scope map is a dictionary mapping scope labels to the lists of predications sharing a scope.

class delphin.mrs.EP(predicate, label, args=None, lnk=None, surface=None, base=None)[source]

Bases: delphin.sembase.Predication

An MRS elementary predication (EP).

EPs combine a predicate with various structural semantic properties. They must have a predicate, and label. Arguments are optional. Intrinsic arguments (ARG0) are not strictly required, but they are important for many semantic operations, and therefore it is a good idea to include them.

Parameters
  • predicate – semantic predicate

  • label – scope handle

  • args – mapping of roles to values

  • lnk – surface alignment

  • surface – surface string

  • base – base form

id

an identifier (same as iv except for quantifiers which replace the iv’s variable type with q)

predicate

semantic predicate

label

scope handle

args

mapping of roles to values

iv

intrinsic variable (shortcut for args[‘ARG0’])

carg

constant argument (shortcut for args[‘CARG’])

lnk

surface alignment

cfrom

surface alignment starting position

Type

int

cto

surface alignment ending position

Type

int

surface

surface string

base

base form

is_quantifier()[source]

Return True if this is a quantifier predication.

class delphin.mrs.HCons[source]

A relation between two handles.

Parameters
  • hi – the higher-scoped handle

  • relation – the relation of the constraint (nearly always “qeq”, but “lheq” and “outscopes” are also valid)

  • lo – the lower-scoped handle

property hi

The higher-scoped handle.

property lo

The lower-scoped handle.

property relation

The constraint relation.

class delphin.mrs.ICons[source]

Individual Constraint: A relation between two variables.

Parameters
  • left – intrinsic variable of the constraining EP

  • relation – relation of the constraint

  • right – intrinsic variable of the constrained EP

property left

The intrinsic variable of the constraining EP.

property relation

The constraint relation.

property right

The intrinsic variable of the constrained EP.

Module Functions

delphin.mrs.is_connected(m)[source]

Return True if m is a fully-connected MRS.

A connected MRS is one where, when viewed as a graph, all EPs are connected to each other via regular (non-scopal) arguments, scopal arguments (including qeqs), or label equalities.

delphin.mrs.has_intrinsic_variable_property(m)[source]

Return True if m satisfies the intrinsic variable property.

An MRS has the intrinsic variable property when it passes the following:

Note that for quantifier EPs, ARG0 is overloaded to mean “bound variable”. Each quantifier should have an ARG0 that is the intrinsic variable of exactly one non-quantifier EP, but this function does not check for that.

delphin.mrs.has_complete_intrinsic_variables(m)[source]

Return True if all non-quantifier EPs have intrinsic variables.

delphin.mrs.has_unique_intrinsic_variables(m)[source]

Return True if all intrinsic variables are unique to their EPs.

delphin.mrs.is_well_formed(m)[source]

Return True if MRS m is well-formed.

A well-formed MRS meets the following criteria:

The final criterion is a heuristic for determining if the MRS scopes by checking if handle constraints and scopal arguments have any immediate violations (e.g., a scopal argument selecting the label of its EP).

delphin.mrs.plausibly_scopes(m)[source]

Quickly test if MRS m can plausibly resolve a scopal reading.

This tests a number of things:

  • Is the MRS’s top qeq to a label

  • Do any EPs scope over themselves

  • Do multiple EPs use the handle constraint

  • Is the lo handle of a qeq not actually a label

  • Are any qeqs not selected by an EP

It does not test for transitive scopal plausibility.

delphin.mrs.is_isomorphic(m1, m2, properties=True)[source]

Return True if m1 and m2 are isomorphic MRSs.

Isomorphicity compares the predicates of a semantic structure, the morphosemantic properties of their predications (if properties=True), constant arguments, and the argument structure between predications. Non-semantic properties like identifiers and surface alignments are ignored.

Parameters
  • m1 – the left MRS to compare

  • m2 – the right MRS to compare

  • properties – if True, ensure variable properties are equal for mapped predications

delphin.mrs.compare_bags(testbag, goldbag, properties=True, count_only=True)[source]

Compare two bags of MRS objects, returning a triple of (unique-in-test, shared, unique-in-gold).

Parameters
  • testbag – An iterable of MRS objects to test

  • goldbag – An iterable of MRS objects to compare against

  • properties – if True, ensure variable properties are equal for mapped predications

  • count_only – If True, the returned triple will only have the counts of each; if False, a list of MRS objects will be returned for each (using the ones from testbag for the shared set)

Returns

A triple of (unique-in-test, shared, unique-in-gold), where each of the three items is an integer count if the count_only parameter is True, or a list of MRS objects otherwise.

delphin.mrs.from_dmrs(d)[source]

Create an MRS by converting from DMRS d.

Parameters

d – the input DMRS

Returns

MRS

Raises

MRSError when conversion fails.

Exceptions

exception delphin.mrs.MRSError(*args, **kwargs)[source]

Bases: delphin.exceptions.PyDelphinException

Raises on invalid MRS operations.

exception delphin.mrs.MRSSyntaxError(message=None, filename=None, lineno=None, offset=None, text=None)[source]

Bases: delphin.exceptions.PyDelphinSyntaxError

Raised when an invalid MRS serialization is encountered.