Beispiel #1
0
def test_hcons():
    assert sorted(hcons(x1)) == [('h0', 'qeq', 'h1')]
    assert sorted(hcons(x2)) == [('h0', 'qeq', 'h1')]
    assert sorted(hcons(x3)) == [('h0', 'qeq', 'h1'), ('h6', 'qeq', 'h3')]
    assert sorted(hcons(x4)) == [('h0', 'qeq', 'h1'), ('h5', 'qeq', 'h9')]
    assert sorted(hcons(x5)) == [('h0', 'qeq', 'h1'), ('h10', 'qeq', 'h13'),
                                 ('h5', 'qeq', 'h7')]
Beispiel #2
0
def serialize_mrs(m, version=_default_version, pretty_print=False):
    # note that varprops is modified as a side-effect of the lower
    # functions
    varprops = {v: vd["props"] for v, vd in m._vars.items() if vd["props"]}
    toks = []
    if version >= 1.1:
        header_toks = []
        if m.lnk is not None:
            header_toks.append(serialize_lnk(m.lnk))
        if m.surface is not None:
            header_toks.append('"{}"'.format(m.surface))
        if header_toks:
            toks.append(" ".join(header_toks))
    if m.top is not None:
        toks.append(serialize_argument(_top if version >= 1.1 else _ltop, m.top, varprops))
    if m.index is not None:
        toks.append(serialize_argument(_index, m.index, varprops))
    delim = " " if not pretty_print else "\n          "
    toks.append("RELS: < {eps} >".format(eps=delim.join(serialize_ep(ep, varprops, version=version) for ep in m.eps())))
    toks += [serialize_hcons(hcons(m))]
    icons_ = icons(m)
    if icons_:  # make unconditional for "ICONS: < >"
        toks += [serialize_icons(icons_)]
    delim = " " if not pretty_print else "\n  "
    return "{} {} {}".format(_left_bracket, delim.join(toks), _right_bracket)
Beispiel #3
0
def _serialize_mrs(m, version=_default_version, pretty_print=False):
    # note that varprops is modified as a side-effect of the lower
    # functions
    varprops = {v: vd['props'] for v, vd in m._vars.items() if vd['props']}
    toks = []
    if version >= 1.1:
        header_toks = []
        if m.lnk is not None and m.lnk.data != (-1, -1):  # don't do <-1:-1>
            header_toks.append(_serialize_lnk(m.lnk))
        if m.surface is not None:
            header_toks.append('"{}"'.format(m.surface))
        if header_toks:
            toks.append(' '.join(header_toks))
    if m.top is not None:
        toks.append(
            _serialize_argument('TOP' if version >= 1.1 else 'LTOP', m.top,
                                varprops))
    if m.index is not None:
        toks.append(_serialize_argument('INDEX', m.index, varprops))
    delim = ' ' if not pretty_print else '\n          '
    toks.append('RELS: < {eps} >'.format(eps=delim.join(
        _serialize_ep(ep, varprops, version=version) for ep in m.eps())))
    toks += [_serialize_hcons(hcons(m))]
    icons_ = icons(m)
    if icons_:  # make unconditional for "ICONS: < >"
        toks += [_serialize_icons(icons_)]
    delim = ' ' if not pretty_print else '\n  '
    return '{} {} {}'.format('[', delim.join(toks), ']')
Beispiel #4
0
def serialize_mrs(m, version=_default_version, pretty_print=False):
    # note that varprops is modified as a side-effect of the lower
    # functions
    varprops = {v: vd['props'] for v, vd in m._vars.items() if vd['props']}
    toks = []
    if version >= 1.1:
        header_toks = []
        if m.lnk is not None and m.lnk.data != (-1, -1):  # don't do <-1:-1>
            header_toks.append(serialize_lnk(m.lnk))
        if m.surface is not None:
            header_toks.append('"{}"'.format(m.surface))
        if header_toks:
            toks.append(' '.join(header_toks))
    if m.top is not None:
        toks.append(serialize_argument(
            'TOP' if version >= 1.1 else 'LTOP', m.top, varprops
        ))
    if m.index is not None:
        toks.append(serialize_argument(
            'INDEX', m.index, varprops
        ))
    delim = ' ' if not pretty_print else '\n          '
    toks.append('RELS: < {eps} >'.format(
        eps=delim.join(serialize_ep(ep, varprops, version=version)
                       for ep in m.eps())
    ))
    toks += [serialize_hcons(hcons(m))]
    icons_ = icons(m)
    if icons_:  # make unconditional for "ICONS: < >"
        toks += [serialize_icons(icons_)]
    delim = ' ' if not pretty_print else '\n  '
    return '{} {} {}'.format('[', delim.join(toks), ']')
Beispiel #5
0
def serialize_mrs(m, version=_default_version, pretty_print=False):
    # note that varprops is modified as a side-effect of the lower
    # functions
    varprops = {v: vd['props'] for v, vd in m._vars.items() if vd['props']}
    toks = []
    if version >= 1.1:
        header_toks = []
        if m.lnk is not None:
            header_toks.append(serialize_lnk(m.lnk))
        if m.surface is not None:
            header_toks.append('"{}"'.format(m.surface))
        if header_toks:
            toks.append(' '.join(header_toks))
    if m.top is not None:
        toks.append(serialize_argument(
            _top if version >= 1.1 else _ltop, m.top, varprops
        ))
    if m.index is not None:
        toks.append(serialize_argument(
            _index, m.index, varprops
        ))
    delim = ' ' if not pretty_print else '\n          '
    toks.append('RELS: < {eps} >'.format(
        eps=delim.join(serialize_ep(ep, varprops, version=version)
                       for ep in m.eps())
    ))
    toks += [serialize_hcons(hcons(m))]
    icons_ = icons(m)
    if icons_:  # make unconditional for "ICONS: < >"
        toks += [serialize_icons(icons_)]
    delim = ' ' if not pretty_print else '\n  '
    return '{} {} {}'.format(_left_bracket, delim.join(toks), _right_bracket)
Beispiel #6
0
 def test_empty(self):
     x = Mrs()
     # Mrs view
     assert len(eps(x)) == 0
     assert len(hcons(x)) == 0
     assert len(icons(x)) == 0
     # Xmrs members
     check_xmrs(x, None, None, None, 0, 0, 0, 0)
Beispiel #7
0
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