Converting MRS string to pydelphin MRS object

Is there a quick way to convert an MRS string into a PyDelphin MRS object? It seems that the MRS object has to be instantiated by specifying the value of LTOP, INDEX, RELS, etc explicitly. I’m wondering if there is some documentation I missed telling me how to take an MRS string as it is produced from delphin.ace.ACEParser.interact and convert it into a delphin.mrs.MRS object that I can mess with.

>>> s = "[ LTOP: h0 INDEX: e2 [ e SF: prop TENSE: pres MOOD: indicative PROG: - PERF: - ] RELS: < [ _the_q<0:3> LBL: h4 ARG0: x3 [ x PERS: 3 NUM: sg IND: + ] RSTR: h5 BODY: h6 ]  [ _cat_n_1<4:7> LBL: h7 ARG0: x3 ]  [ _white_a_1<11:16> LBL: h1 ARG0: e2 ARG1: x3 ] > HCONS: < h0 qeq h1 h5 qeq h7 > ICONS: < > ]"
>>> from delphin.codecs import simplemrs
>>> m = simplemrs.decode(s)
>>> m
<MRS object (_the_q _cat_n_1 _white_a_1) at 4360980400>

See first example at Working with Semantic Structures — PyDelphin 1.6.0 documentation


If you’re working with the Response objects from ACEParser.interact(), note that those objects are not just dictionaries but have some helpful methods. Since each response can have multiple results, you can either iterate over the results with response.results() or get a specific one with response.result(i), where i is the 0-based index of the result you want (most likely 0). A result object has a method mrs() that calls delphin.codecs.simplemrs.decode() for you…