예제 #1
0
def _reify_xmrs(path, top_axis=None):
    nodes = {}
    links = []
    agenda = [(0, top_axis or ':/H>', path)]
    while agenda:
        srcnid, axis, tgt = agenda.pop()
        if tgt is None:
            continue
        # add link to tgt
        rargname, post = axis.strip(':<>').split('/')
        if axis.startswith('<'):
            links.append(Link(tgt.nodeid, srcnid, rargname or None, post))
        elif axis.endswith('>'):
            links.append(Link(srcnid, tgt.nodeid, rargname or None, post))
        elif axis == ':/EQ:':
            links.append(Link(srcnid, tgt.nodeid, None, 'EQ'))
        else:
            raise XmrsPathError('Invalid axis: {}'.format(axis))
        # add node if necessary (note, currently does not update pred
        # or sortinfo if encountered twice)
        if tgt.nodeid not in nodes:
            sortinfo = dict([('cvarsort', tgt.context.get('varsort') or 'u')] +
                            [(k.lstrip('@'), v)
                             for k, v in tgt.context.items()
                             if k.startswith('@')])
            nodes[tgt.nodeid] = Node(tgt.nodeid, tgt.pred, sortinfo=sortinfo)
        # add new agenda for tgt
        for axis, next_tgt in tgt.links.items():
            agenda.append((tgt.nodeid, axis, next_tgt))
    return Dmrs(list(nodes.values()), links)
예제 #2
0
파일: dmrx.py 프로젝트: moreymat/pydelphin
def _decode_link(elem):
    # <!ELEMENT link (rargname, post)>
    # <!ATTLIST link
    #           from CDATA #REQUIRED
    #           to   CDATA #REQUIRED >
    # <!ELEMENT rargname (#PCDATA)>
    # <!ELEMENT post (#PCDATA)>
    return Link(start=elem.get('from'),
                end=elem.get('to'),
                rargname=getattr(elem.find('rargname'), 'text', None),
                post=getattr(elem.find('post'), 'text', None))
예제 #3
0
def decode_link(elem):
    return Link(start=elem.get('from'),
                end=elem.get('to'),
                rargname=elem.find('rargname').text,
                post=elem.find('post').text)