def make_spanning_tree(glyphs, k=None): if k is None: k = knn.kNNInteractive() uniq_dists = k.distance_matrix(glyphs, 0) g = graph.Undirected() g.create_minimum_spanning_tree(glyphs, uniq_dists) return g
def _pregroup(self, glyphs, function): G = graph.Undirected() G.add_nodes(glyphs) progress = util.ProgressFactory("Pre-grouping glyphs...", len(glyphs)) try: for i in range(len(glyphs)): gi = glyphs[i] for j in range(i + 1, len(glyphs)): gj = glyphs[j] if function(gi, gj): G.add_edge(gi, gj) progress.step() finally: progress.kill() return G
def _pregroup(self, glyphs, function): from gamera import graph G = graph.Undirected() # assert G.add_nodes(glyphs) # TODO only for testing for glyph in glyphs: print(glyph) assert G.add_node(glyph) assert G.has_node(glyph) progress = util.ProgressFactory("Pre-grouping glyphs...", len(glyphs)) try: for i in range(len(glyphs)): gi = glyphs[i] for j in range(i + 1, len(glyphs)): gj = glyphs[j] if function(gi, gj): G.add_edge(gi, gj) progress.step() finally: progress.kill() return G