Pretty Print PyDelphin?

Is there a way to take an MRS string and pretty print it using PyDelphin? I see in the documentation a way to do so using command line tools, but how can I do it in a python file?

I use:

simplemrs.encode(...)

Where mrs is the object you get from, for example the ACE Parser, like this:

with ace.ACEParser(self.erg_file(), cmdargs=cmd_args, stderr=f) as parser:
    ace_response = parser.interact(phrase)
    for parse_index in range(0, len(ace_response.results())):
        mrs = ace_response.result(parse_index).mrs()
        print(simplemrs.encode(mrs, indent=True))

[Just realizing now that you are starting with an MRS string so this isn’t quite what you were asking for but maybe will help somehow…]

Right, I am starting with the string, but to be more clear I should say, I get a string like this:

[ TOP: h71 INDEX: e68 RELS: < [ unknown LBL: h70 ARG: x48 ARG0: e68 ] [ _the_q LBL: h67 ARG0: x48 RSTR: h65 BODY: h66 ] [ loc_nonsp LBL: h49 ARG0: i60 ARG1: x48 ARG2: x53 ] [ _lake_n_1 LBL: h49 ARG0: x48 ] [ def_implicit_q LBL: h59 ARG0: x53 RSTR: h57 BODY: h58 ] [ _east_a_1 LBL: h55 ARG0: i52 ARG1: x53 ARG2: x46 ] [ _the_q LBL: h45 ARG0: x46 RSTR: h43 BODY: h44 ] [ _mountain_n_1 LBL: h47 ARG0: x46 ] [ place_n LBL: h55 ARG0: x53 ] > HCONS: < h43 qeq h47 h57 qeq h55 h65 qeq h49 h71 qeq h70 > ]

When I would really want it to look like this:

[ 
	TOP: h71 INDEX: e68
	RELS: < 
		[ unknown LBL: h70 ARG: x48 ARG0: e68 ] 
		[ _the_q LBL: h67 ARG0: x48 RSTR: h65 BODY: h66 ]
		[ loc_nonsp LBL: h49 ARG0: i60 ARG1: x48 ARG2: x53 ]		
        [ _lake_n_1 LBL: h49 ARG0: x48 ]
		[ def_implicit_q LBL: h59 ARG0: x53 RSTR: h57 BODY: h58 ] 		
        [ _east_a_1 LBL: h55 ARG0: i52 ARG1: x53 ARG2: x46 ]
		[ _the_q LBL: h45 ARG0: x46 RSTR: h43 BODY: h44 ] 		
        [ _mountain_n_1 LBL: h47 ARG0: x46 ]
		[ place_n LBL: h55 ARG0: x53 ] > 
	HCONS: < h43 qeq h47 h57 qeq h55 h65 qeq h49 h71 qeq h70 >
]

It’s really hard to debug issues with MRSs that won’t generate when it’s all one line, so for now I’m just “prettifying” it by hand each time, but I hope there’s some code out there that already does this.

that is the form that

simplemrs.encode(mrs, indent=True)

generates. If you can get your string parsed into an MRS object, then you could use the simplemrs.encode() approach to pretty print it.

2 Likes

Ohhhh, it was the indent=True that I was missing all along :slight_smile: thanks!