Beispiel #1
0
def _canonicalize_node(node: Node, model: Model) -> Node:
    var, edges = node
    canonical_edges = []
    for i, edge in enumerate(edges):
        role, tgt = edge
        # alignments aren't parsed off yet, so handle them superficially
        role, tilde, alignment = role.partition('~')
        if not is_atomic(tgt):
            tgt = _canonicalize_node(tgt, model)
        canonical_role = model.canonicalize_role(role) + tilde + alignment
        canonical_edges.append((canonical_role, tgt))
    return (var, canonical_edges)
Beispiel #2
0
    def test_canonicalize_role(self, mini_amr):
        m = Model()
        assert m.canonicalize_role(':ARG0') == ':ARG0'
        assert m.canonicalize_role(':ARG0-of') == ':ARG0-of'
        assert m.canonicalize_role(':ARG0-of-of') == ':ARG0'
        assert m.canonicalize_role(':consist') == ':consist'
        assert m.canonicalize_role(':consist-of') == ':consist-of'
        assert m.canonicalize_role(':consist-of-of') == ':consist'
        assert m.canonicalize_role(':mod') == ':mod'
        assert m.canonicalize_role(':mod-of') == ':mod-of'
        assert m.canonicalize_role(':domain') == ':domain'
        assert m.canonicalize_role(':domain-of') == ':domain-of'
        # without :
        assert m.canonicalize_role('ARG0') == ':ARG0'
        assert m.canonicalize_role('ARG0-of') == ':ARG0-of'
        assert m.canonicalize_role('ARG0-of-of') == ':ARG0'

        m = Model.from_dict(mini_amr)
        assert m.canonicalize_role(':ARG0') == ':ARG0'
        assert m.canonicalize_role(':ARG0-of') == ':ARG0-of'
        assert m.canonicalize_role(':ARG0-of-of') == ':ARG0'
        assert m.canonicalize_role(':consist') == ':consist-of-of'
        assert m.canonicalize_role(':consist-of') == ':consist-of'
        assert m.canonicalize_role(':consist-of-of') == ':consist-of-of'
        assert m.canonicalize_role(':mod') == ':mod'
        assert m.canonicalize_role(':mod-of') == ':domain'
        assert m.canonicalize_role(':domain') == ':domain'
        assert m.canonicalize_role(':domain-of') == ':mod'
        # without :
        assert m.canonicalize_role('consist') == ':consist-of-of'
        assert m.canonicalize_role('consist-of') == ':consist-of'
        assert m.canonicalize_role('consist-of-of') == ':consist-of-of'