def encode_mrs(m): varprops = {v: vd['props'] for v, vd in m._vars.items() if vd['props']} attributes = {'cfrom': str(m.cfrom), 'cto': str(m.cto)} if m.surface is not None: attributes['surface'] = m.surface if m.identifier is not None: attributes['ident'] = m.identifier e = etree.Element('mrs', attrib=attributes) if m.top is not None: e.append(encode_label(m.top)) if m.index is not None: e.append(encode_variable(m.index, varprops)) for ep in elementarypredications(m): e.append(encode_ep(ep, varprops)) for hcon in hcons(m): e.append(encode_hcon(hcon)) for icon in icons(m): e.append(encode_icon(icon)) return e
def contiguous_semantic_constituents(x): """ Yield semantic constituents whose preds come from contiguous words in the source sentence (judged by the CFROM and CTO values). """ from delphin.mrs.components import elementarypredications import delphin.mrs.path as mp epmap = {ep.nodeid: ep for ep in elementarypredications(x)} seen = set() for p in mp.explore(x, method='headed', flags=mp.DEFAULT | mp.UND | mp.B): pnids = tuple(sorted(mp.get_nodeids(p))) if 0 in pnids or pnids in seen: continue # ignore paths with TOP or already yielded paths eps = [epmap[nid] for nid in pnids] cfrom = min(ep.cfrom for ep in eps) cto = max(ep.cto for ep in eps) span = sorted( (e for e in epmap.values() if e.cfrom >= cfrom and e.cto <= cto), key=lambda e: e.nodeid) if eps == span: seen.add(pnids) yield pnids
def contiguous_semantic_constituents(x): """ Yield semantic constituents whose preds come from contiguous words in the source sentence (judged by the CFROM and CTO values). """ from delphin.mrs.components import elementarypredications import delphin.mrs.path as mp epmap = {ep.nodeid: ep for ep in elementarypredications(x)} seen = set() for p in mp.explore(x, method='headed', flags=mp.DEFAULT|mp.UND|mp.B): pnids = tuple(sorted(mp.get_nodeids(p))) if 0 in pnids or pnids in seen: continue # ignore paths with TOP or already yielded paths eps = [epmap[nid] for nid in pnids] cfrom = min(ep.cfrom for ep in eps) cto = max(ep.cto for ep in eps) span = sorted( (e for e in epmap.values() if e.cfrom >= cfrom and e.cto <= cto), key=lambda e: e.nodeid ) if eps == span: seen.add(pnids) yield pnids