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
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.
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:
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; 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.
- 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 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=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. Iftop
does not select a top scope, theNone
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:
Predication
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
- 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
- surface
surface string
- base
base form
- class delphin.mrs.HCons(hi, relation, lo)[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(left, relation, right)[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 anARG0
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 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:
PyDelphinException
Raises on invalid MRS operations.
- exception delphin.mrs.MRSSyntaxError(message=None, filename=None, lineno=None, offset=None, text=None)[source]
Bases:
PyDelphinSyntaxError
Raised when an invalid MRS serialization is encountered.