delphin.mrs.prolog

Serialization functions for the Prolog format.

Example

>>> from delphin.interfaces import rest
>>> from delphin.mrs import prolog
>>> response = rest.parse('The dog sleeps soundly.', params={'mrs':'json'})
>>> print(prolog.dumps([response.result(0).mrs()], pretty_print=True))
psoa(h1,e3,
[rel('_the_q',h4,
    [attrval('ARG0',x6),
        attrval('RSTR',h7),
        attrval('BODY',h5)]),
rel('_dog_n_1',h8,
    [attrval('ARG0',x6)]),
rel('_sleep_v_1',h2,
    [attrval('ARG0',e3),
        attrval('ARG1',x6)]),
rel('_sound_a_1',h2,
    [attrval('ARG0',e9),
        attrval('ARG1',e3)])],
hcons([qeq(h1,h2),qeq(h7,h8)]))
delphin.mrs.prolog.dump(destination, ms, single=False, pretty_print=False, **kwargs)[source]

Serialize Xmrs objects to the Prolog representation 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 – if True, treat ms as a single Xmrs object instead of as an iterator
  • pretty_print – if True, add newlines and indentation
delphin.mrs.prolog.dumps(ms, single=False, pretty_print=False, **kwargs)[source]

Serialize an Xmrs object to the Prolog representation

Parameters:
  • ms – an iterator of Xmrs objects to serialize (unless the single option is True)
  • single – if True, treat ms as a single Xmrs object instead of as an iterator
  • pretty_print – if True, add newlines and indentation
Returns:

the Prolog string representation of a corpus of Xmrs