delphin.dmrs
Dependency Minimal Recursion Semantics ([DMRS])
Copestake, Ann. Slacker Semantics: Why superficiality, dependency and avoidance of commitment can be the right way to go. In Proceedings of the 12th Conference of the European Chapter of the Association for Computational Linguistics, pages 1–9. Association for Computational Linguistics, 2009.
Serialization Formats
Module Constants
- delphin.dmrs.FIRST_NODE_ID
The node identifier
10000
which is conventionally the first identifier used in a DMRS structure. This constant is mainly used for DMRS conversion or serialization.
- delphin.dmrs.RESTRICTION_ROLE
The
RSTR
role used in links to select the restriction of a quantifier.
- delphin.dmrs.EQ_POST
The
EQ
post-slash label on links that indicates the endpoints of a link share a scope.
- delphin.dmrs.NEQ_POST
The
NEQ
post-slash label on links that indicates the endpoints of a link do not share a scope.
- delphin.dmrs.HEQ_POST
The
HEQ
post-slash label on links that indicates thestart
node of a link immediately outscopes theend
node.
- delphin.dmrs.H_POST
The
H
post-slash label on links that indicates thestart
node of a link is qeq to theend
node (i.e.,start
scopes overend
, but not necessarily immediately).
- delphin.dmrs.CVARSORT
The
cvarsort
dictionary key inNode.sortinfo
that accesses the node’stype
.
Classes
- class delphin.dmrs.DMRS(top=None, index=None, nodes=None, links=None, lnk=None, surface=None, identifier=None)[source]
Bases:
ScopingSemanticStructure
Dependency Minimal Recursion Semantics (DMRS) class.
DMRS instances have a list of Node objects and a list of Link objects. The scopal top node may be set directly via a parameter or may be implicitly set via a
/H
Link from the special node id0
. If both are given, the link is ignored. The non-scopal top (index) node may only be set via the index parameter.- Parameters:
top – the id of the scopal top node
index – the id of the non-scopal top node
nodes – an iterable of DMRS nodes
links – an iterable of DMRS links
lnk – surface alignment
surface – surface string
identifier – a discourse-utterance identifier
- top
The scopal top node.
- index
The non-scopal top node.
- nodes
The list of Nodes (alias of
predications
).
- links
The list of Links.
- lnk
The surface alignment for the whole MRS.
- surface
The surface string represented by the MRS.
- identifier
A discourse-utterance identifier.
Example:
>>> rain = Node(10000, '_rain_v_1', type='e') >>> heavy = Node(10001, '_heavy_a_1', type='e') >>> arg1_link = Link(10000, 10001, role='ARG1', post='EQ') >>> d = DMRS(top=10000, index=10000, [rain], [arg1_link])
- arguments(types=None, expressed=None)[source]
Return a mapping of the argument structure.
When types is used, any DMRS Links with
Link.attr
set toH_POST
orHEQ_POST
are considered to have a type of'h'
, so one can exclude scopal arguments by omitting'h'
on types. Otherwise an argument’s type is theNode.type
of the link’s target.- 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.
- 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.
The return value maps node ids to lists of scopal arguments as (role, scope_relation, target) triples. If scopes is given, the target is the scope label, otherwise it is the target node’s id. Note that
MOD/EQ
links are not included as scopal arguments.- Parameters:
scopes – mapping of scope labels to lists of predications
Example
>>> d = DMRS(...) # for "It doesn't rain. >>> d.scopal_arguments() {10000: [('ARG1', 'qeq', 10001)]} >>> top, scopes = d.scopes() >>> d.scopal_arguments(scopes=scopes) {10000: [('ARG1', 'qeq', 'h2')]}
- scopes()[source]
Return a tuple containing the top label and the scope map.
Note that the top label is different from
top
, which the top node’s id. Iftop
does not select a top node, 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.dmrs.Node(id, predicate, type=None, properties=None, carg=None, lnk=None, surface=None, base=None)[source]
Bases:
Predication
A DMRS node.
Nodes are very simple predications for DMRSs. Nodes don’t have arguments or labels like
delphin.mrs.EP
objects, but they do have an attribute for CARGs and contain their vestigial variable type and properties insortinfo
.- Parameters:
id – node identifier
predicate – semantic predicate
type – node type (corresponds to the intrinsic variable type in MRS)
properties – morphosemantic properties
carg – constant value (e.g., for named entities)
lnk – surface alignment
surface – surface string
base – base form
- id
node identifier
- predicate
semantic predicate
- type
node type (corresponds to the intrinsic variable type in MRS)
- properties
morphosemantic properties
- sortinfo
properties with the node type at key
"cvarsort"
- carg
constant value (e.g., for named entities)
- lnk
surface alignment
- cfrom
surface alignment starting position
- cto
surface alignment ending position
- surface
surface string
- base
base form
- property sortinfo
Morphosemantic property mapping with cvarsort.
- class delphin.dmrs.Link(start, end, role, post)[source]
Bases:
object
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 – node id of the start of the Link
end – node id of the end of the Link
role – role of the argument
post – “post-slash label” indicating the scopal relationship between the start and end of the Link; possible values are
NEQ
,EQ
,HEQ
, andH
- start
node id of the start of the Link
- end
node id of the end of the Link
- role
role of the argument
- post
“post-slash label” indicating the scopal relationship between the start and end of the Link
Module Functions
- delphin.dmrs.from_mrs(m, representative_priority=None)[source]
Create a DMRS by converting from MRS m.
In order for MRS to DMRS conversion to work, the MRS must satisfy the intrinsic variable property (see
delphin.mrs.has_intrinsic_variable_property()
).- Parameters:
m – the input MRS
representative_priority – a function for ranking candidate representative nodes; see
scope.representatives()
- Returns:
DMRS
- Raises:
DMRSError when conversion fails. –
Exceptions
- exception delphin.dmrs.DMRSSyntaxError(message=None, filename=None, lineno=None, offset=None, text=None)[source]
Bases:
PyDelphinSyntaxError
Raised when an invalid DMRS serialization is encountered.
- exception delphin.dmrs.DMRSWarning(*args, **kwargs)[source]
Bases:
PyDelphinWarning
Issued when a DMRS may be incorrect or incomplete.