delphin.mrs¶
Minimal Recursion Semantics ([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.
Serialization Formats¶
Module Constants¶
- delphin.mrs.RESTRICTION_ROLE¶
The
RSTRrole used to select the restriction of a quantifier.
- delphin.mrs.BODY_ROLE¶
The
BODYrole used to select the body of a quantifier.
Classes¶
- class delphin.mrs.MRS(top: str | None = None, index: str | None = None, rels: Iterable[EP] | None = None, hcons: Iterable[HCons] | None = None, icons: Iterable[ICons] | None = None, variables: Mapping[str, Sequence[tuple[str, str]] | Mapping[str, str]] | None = None, lnk: Lnk | None = None, surface=None, identifier=None)[source]¶
Bases:
ScopingSemanticStructure[str,EP]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
- rels¶
The list of EPs (alias of
predications).
- hcons¶
The list of handle constraints.
- Type:
- icons¶
The list of individual constraints.
- Type:
- lnk¶
The surface alignment for the whole MRS.
- Type:
- identifier¶
A discourse-utterance identifier.
- arguments(types: Iterable[str] | None = None, expressed: bool | None = None) dict[str, list[tuple[str, str]]][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; ifFalse, only include those unexpressed; ifNone, include both
- Returns:
A mapping of predication ids to lists of (role, target) pairs for outgoing arguments for the predication.
- is_quantifier(id: str | None) bool[source]¶
Return
Trueif var is the bound variable of a quantifier.
- properties(id: str | None) dict[str, str][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() list[tuple[EP | None, EP | None]][source]¶
Return a list of (Quantifiee, Quantifier) pairs.
Both the Quantifier and Quantifiee are
Predicationobjects, unless they do not quantify or are not quantified by anything, in which case they areNone. In well-formed and complete structures, the quantifiee will never beNone.Example
>>> [(p.predicate, q.predicate) for p, q in m.quantification_pairs()] [('_dog_n_1', '_the_q'), ('_bark_v_1', None)]
- scopal_arguments(scopes: Mapping[str, Sequence[EP]] | None = None) dict[str, list[tuple[str, ScopeRelation, str]]][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).The scopes argument is kept for backward compatibility but it is ignored.
- Parameters:
scopes – mapping of scope labels to lists of predications
- scopes() tuple[str | None, dict[str, list[EP]]][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. Iftopdoes not select a top scope, theNoneis 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: str, label: str, args: dict[str, str] | None = None, lnk: Lnk | None = None, surface=None, base=None)[source]¶
Bases:
Predication[str]An MRS elementary predication (EP).
EPs combine a predicate with various structural semantic properties. They must have a
predicate, andlabel. 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
ivexcept for quantifiers which replace theiv’s variable type withq)- Type:
- predicate¶
semantic predicate
- iv¶
intrinsic variable (shortcut for
args['ARG0'])
- carg¶
constant argument (shortcut for
args['CARG'])
- lnk¶
surface alignment
- Type:
- base¶
base form
- class delphin.mrs.HCons(hi: str, relation: str, lo: str)[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 relation: ScopeRelation¶
The constraint relation.
- class delphin.mrs.ICons(left: str, relation: str, right: str)[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: MRS) bool[source]¶
Return
Trueif 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: MRS) bool[source]¶
Return
Trueif m satisfies the intrinsic variable property.An MRS has the intrinsic variable property when it passes the following:
Note that for quantifier EPs,
ARG0is overloaded to mean “bound variable”. Each quantifier should have anARG0that 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: MRS) bool[source]¶
Return
Trueif all non-quantifier EPs have intrinsic variables.
- delphin.mrs.has_unique_intrinsic_variables(m: MRS) bool[source]¶
Return
Trueif all intrinsic variables are unique to their EPs.
- delphin.mrs.is_well_formed(m: MRS) bool[source]¶
Return
Trueif 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: MRS) bool[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: MRS, m2: MRS, properties: bool = True) bool[source]¶
Return
Trueif 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: Iterable[MRS], goldbag: Iterable[MRS], properties: bool = True, count_only: bool = 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 predicationscount_only – If
True, the returned triple will only have the counts of each; ifFalse, 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.
Exceptions¶
- exception delphin.mrs.MRSError(*args, **kwargs)[source]¶
Bases:
PyDelphinExceptionRaises on invalid MRS operations.
- exception delphin.mrs.MRSSyntaxError(message=None, filename=None, lineno=None, offset=None, text=None)[source]¶
Bases:
PyDelphinSyntaxErrorRaised when an invalid MRS serialization is encountered.