Beispiel #1
0
def is_loop(g: Graph, v: Vertex, e: Edge):
    """ Check if a vertex can reach itself again using the provided edge (check if the edge creates a loop)"""
    if not has_path_not_using_any_loop_edges(e.target_vertex, v):
        return False

    # Simulate deletion of edge and check if still loops
    e_orig_source = e.source
    e_orig_target = e.target
    e_orig_attr = e.attributes()
    g.delete_edges(e)

    has_any_loops = False
    for e in v.out_edges():
        if has_path_not_using_any_loop_edges(e.target_vertex, v):
            has_any_loops = True
            break

    g.add_edge(e_orig_source, e_orig_target, **e_orig_attr)

    return not has_any_loops
Beispiel #2
0
 def match(self, vertex: Vertex):
     if not vertex['morph_inf_list']:
         return False
     if self.grammemes and self.grammemes not in vertex['morph_info_list'][
             0].tag:
         return False
     if self.white_list and vertex['morph_info_list'].normal_form.lower(
     ) not in self.white_list:
         return False
     if self.black_list and vertex['morph_info_list'].normal_form.lower(
     ) in self.black_list:
         return False
     if not self._children:
         return True
     children = {e.graph.vs[e.target] for e in vertex.out_edges()}
     for child_pattern in self._children:
         for child in filter(child_pattern.match, children):
             children.discard(child)
             break
         else:
             return False
     return True
Beispiel #3
0
def count_bags(vertex: ig.Vertex):
    return 1 + sum(edge['contains'] * count_bags(edge.target_vertex)
                   for edge in list(vertex.out_edges()))
Beispiel #4
0
def iterate_switch_edges(
        v: Vertex) -> Tuple[Edge, List[SwitchCaseOperation], bool]:
    """See iterate_switch_edges_using_edges_and_op."""
    return iterate_switch_edges_using_edges_and_op(v.out_edges(), v['op'])