delphin.mrs.eds

Elementary Dependency Structures (EDS).

class delphin.mrs.eds.Eds(top=None, nodes=None, edges=None)[source]

An Elementary Dependency Structure (EDS) instance.

EDS are semantic structures deriving from MRS, but they are not interconvertible with MRS and therefore do not share a common superclass (viz, Xmrs) in PyDelphin, although this may change in a future version. EDS shares some common features with DMRS, so this class borrows some DMRS elements, such as Nodes.

Parameters:
  • top – nodeid of the top node in the graph
  • nodes – iterable of Nodes
  • edges – iterable of (start, role, end) triples
edges(nodeid)[source]

Return the edges starting at nodeid.

classmethod from_dict(d)[source]

Decode a dictionary, as from to_dict(), into an Eds object.

classmethod from_triples(triples)[source]

Decode triples, as from to_triples(), into an Eds object.

classmethod from_xmrs(xmrs, predicate_modifiers=False, **kwargs)[source]

Instantiate an Eds from an Xmrs (lossy conversion).

Parameters:
  • xmrs (Xmrs) – Xmrs instance to convert from
  • predicate_modifiers (function, bool) – function that is called as func(xmrs, deps) after finding the basic dependencies (deps), returning a mapping of predicate-modifier dependencies; the form of deps and the returned mapping are {head: [(role, dependent)]}; if predicate_modifiers is True, the function is created using non_argument_modifiers() as: non_argument_modifiers(role=”ARG1”, connecting=True); if *predicate_modifiers* is `False, only the basic dependencies are returned
node(nodeid)[source]

Return the node whose nodeid is nodeid.

nodeids()[source]

Return the list of nodeids.

nodes()[source]

Return the list of nodes.

to_dict(properties=True)[source]

Encode the Eds as a dictionary suitable for JSON serialization.

to_triples(short_pred=True, properties=True)[source]

Encode the Eds as triples suitable for PENMAN serialization.

delphin.mrs.eds.dump(destination, ms, single=False, properties=False, pretty_print=True, show_status=False, predicate_modifiers=False, **kwargs)[source]

Serialize Xmrs objects to Eds and write to a file

Parameters:
  • destination – filename or file object where data will be written
  • ms – an iterator of Xmrs objects to serialize (unless the single option is True)
  • single (bool) – if True, treat ms as a single Xmrs object instead of as an iterator
  • properties (bool) – if False, suppress variable properties
  • pretty_print (bool) – if True, add newlines and indentation
  • show_status (bool) – if True, annotate disconnected graphs and nodes
delphin.mrs.eds.dumps(ms, single=False, properties=False, pretty_print=True, show_status=False, predicate_modifiers=False, **kwargs)[source]

Serialize an Xmrs object to a Eds representation

Parameters:
  • ms – an iterator of Xmrs objects to serialize (unless the single option is True)
  • single (bool) – if True, treat ms as a single Xmrs object instead of as an iterator
  • properties (bool) – if False, suppress variable properties
  • pretty_print (bool) – if True, add newlines and indentation
  • show_status (bool) – if True, annotate disconnected graphs and nodes
Returns:

an Eds string representation of a corpus of Xmrs

delphin.mrs.eds.load(fh, single=False)[source]

Deserialize Eds from a file (handle or filename)

Parameters:
  • fh (str, file) – input filename or file object
  • single (bool) – if True, only return the first Xmrs object
Returns:

a generator of Eds objects (unless the single option is True)

delphin.mrs.eds.loads(s, single=False)[source]

Deserialize Eds string representations

Parameters:
  • s (str) – Eds string
  • single (bool) – if True, only return the first Xmrs object
Returns:

a generator of Eds objects (unless the single option is True)

delphin.mrs.eds.non_argument_modifiers(role='ARG1', only_connecting=True)[source]

Return a function that finds non-argument modifier dependencies.

Parameters:
  • role (str) – the role that is assigned to the dependency
  • only_connecting (bool) – if True, only return dependencies that connect separate components in the basic dependencies; if False, all non-argument modifier dependencies are included
Returns:

a function with signature func(xmrs, deps) that returns a mapping of non-argument modifier dependencies

Examples

The default function behaves like the LKB:

>>> func = non_argument_modifiers()

A variation is similar to DMRS’s MOD/EQ links:

>>> func = non_argument_modifiers(role="MOD", only_connecting=False)