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
10000which 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
RSTRrole used in links to select the restriction of a quantifier.
- delphin.dmrs.EQ_POST¶
The
EQpost-slash label on links that indicates the endpoints of a link share a scope.
- delphin.dmrs.NEQ_POST¶
The
NEQpost-slash label on links that indicates the endpoints of a link do not share a scope.
- delphin.dmrs.HEQ_POST¶
The
HEQpost-slash label on links that indicates thestartnode of a link immediately outscopes theendnode.
- delphin.dmrs.H_POST¶
The
Hpost-slash label on links that indicates thestartnode of a link is qeq to theendnode (i.e.,startscopes overend, but not necessarily immediately).
- delphin.dmrs.CVARSORT¶
The
cvarsortdictionary key inNode.sortinfothat accesses the node’stype.
Classes¶
- class delphin.dmrs.DMRS(top: int | None = None, index: int | None = None, nodes: Iterable[Node] | None = None, links: Iterable[Link] | None = None, lnk: Lnk | None = None, surface=None, identifier=None)[source]¶
Bases:
ScopingSemanticStructure[int,Node]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
/HLink 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.
- Type:
delphin.sembase.ID | None
- index¶
The non-scopal top node.
- nodes¶
The list of Nodes (alias of
predications).
- links¶
The list of Links.
- Type:
- lnk¶
The surface alignment for the whole MRS.
- Type:
- 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, heavy], [arg1_link])
- arguments(types: Iterable[str] | None = None, expressed: bool | None = None) dict[int, list[tuple[str, int]]][source]¶
Return a mapping of the argument structure.
When types is used, any DMRS Links with
Link.attrset toH_POSTorHEQ_POSTare 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.typeof 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() list[tuple[Node | None, Node | 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[Node]] | None = None) dict[int, list[tuple[str, ScopeRelation, str]]][source]¶
Return a mapping of the scopal argument structure.
The return value maps node ids to lists of scopal arguments as (role, scope_relation, scope_label) triples. If scopes is given, it is used as the source of scope labels. Otherwise,
scopes()is first called to generate those labels. Note thatMOD/EQlinks 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() tuple[str | None, dict[str, list[Node]]][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. Iftopdoes not select a top node, theNoneis returned for the top label.The scope map is a dictionary mapping scope labels to the lists of nodes sharing a scope.
- class delphin.dmrs.Node(id: int, predicate: str, type: str | None = None, properties: dict[str, str] | None = None, carg: str | None = None, lnk: Lnk | None = None, surface=None, base=None)[source]¶
Bases:
Predication[int]A DMRS node.
Nodes are very simple predications for DMRSs. Nodes don’t have arguments or labels like
delphin.mrs.EPobjects, 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)
- carg¶
constant value (e.g., for named entities)
- lnk¶
surface alignment
- Type:
- cfrom¶
surface alignment starting position
- cto¶
surface alignment ending position
- base¶
base form
- class delphin.dmrs.Link(start: int, end: int, role: str, post: str)[source]¶
Bases:
objectDMRS-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: MRS, representative_priority: Callable[[P], Any] | None = None) DMRS[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:
PyDelphinSyntaxErrorRaised when an invalid DMRS serialization is encountered.
- exception delphin.dmrs.DMRSWarning(*args, **kwargs)[source]¶
Bases:
PyDelphinWarningIssued when a DMRS may be incorrect or incomplete.