Exemple #1
0
def test_has_get():
    g = _read_graph()
    assert semgraph.has_out_edge(g, 'T0', {"punct"})
    assert not semgraph.has_out_edge(g, 'T2', {"punct"})
    assert not semgraph.has_out_edge(g, 'T0', {""})

    assert semgraph.has_in_edge(g, 'T1', {"punct"})
    assert not semgraph.has_in_edge(g, 'T2', {"punct"})
    assert not semgraph.has_in_edge(g, 'T1', {""})

    assert semgraph.has_out_node(g, 'T0', {":"})
    assert not semgraph.has_out_node(g, 'T1', {":"})
    assert not semgraph.has_out_node(g, 'T0', {""})

    assert semgraph.has_in_node(g, 'T1', {"finding"})
    assert not semgraph.has_in_node(g, 'T4', {"finding"})
    assert not semgraph.has_in_node(g, 'T1', {""})

    assert semgraph.get_in(g, 'T1', {"finding"}, {"punct"})
    assert semgraph.get_in(g, 'T1', {""}, {"punct"}) is None

    assert semgraph.has_in(g, 'T1', {"finding"}, {"punct"})
    assert not semgraph.has_in(g, 'T1', {""}, {"punct"})

    assert semgraph.has_out(g, 'T0', {":"}, {"punct"})
    assert not semgraph.has_out(g, 'T0', {""}, {"punct"})
Exemple #2
0
 def match_neg(self, graph, node):
     """
     Returns a matcher
     """
     for pattern in self.neg_patterns:
         for m in pattern.finditer(graph):
             n0 = m.group(0)
             if n0 == node:
                 try:
                     key = m.get('key')
                     if semgraph.has_out_edge(graph, key, ['neg']):
                         continue
                 except:
                     pass
                 if semgraph.has_out(graph, n0, ['new'], ['amod']):
                     continue
                 return m
     return None
Exemple #3
0
    def match_uncertainty(self, graph, node):
        for pattern in self.uncertain_patterns:
            for m in pattern.finditer(graph):
                n0 = m.group(0)
                if n0 == node:
                    return m

        # parsing error
        # suggestive of XXX
        p = ngrex.compile('{} <{dependency:/nmod:of/} {lemma:/suggestive/}')
        for m in p.finditer(graph):
            n0 = m.group(0)
            if n0 == node:
                if semgraph.has_out_node(graph, m.group(1), ['most']):
                    return None
                elif semgraph.has_out(graph, n0, ['new', 'develop'], ['amod']):
                    continue
                else:
                    return m
        return None