delphin.dmrs

Dependency Minimal Recursion Semantics ([DMRS])

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.

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 the start node of a link immediately outscopes the end node.

delphin.dmrs.H_POST

The H post-slash label on links that indicates the start node of a link is qeq to the end node (i.e., start scopes over end, but not necessarily immediately).

delphin.dmrs.CVARSORT

The cvarsort dictionary key in Node.sortinfo that accesses the node’s type.

Classes

class delphin.dmrs.DMRS(top=None, index=None, nodes=None, links=None, lnk=None, surface=None, identifier=None)[source]

Bases: delphin.scope.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 id 0. 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).

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 to H_POST or HEQ_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 the Node.type of the link’s target.

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 id is the id of a quantifier node.

properties(id)[source]

Return the morphosemantic properties for id.

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.

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. Only links with a Link.role value are considered, so 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. If top does not select a top node, 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.dmrs.Node(id, predicate, type=None, properties=None, carg=None, lnk=None, surface=None, base=None)[source]

Bases: delphin.sembase.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 in sortinfo.

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.

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, and H

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: delphin.exceptions.PyDelphinSyntaxError

Raised when an invalid DMRS serialization is encountered.