def get_partial_suffix_array(text, k): tree = SuffixTree( len( text ) ) for char in text: tree.add_char( char ) suffix_array = get_suffix_array( tree ) partial_suffix_array = [] for i in range( len(suffix_array) ): if suffix_array[i] % k == 0: partial_suffix_array.append( (i, suffix_array[i]) ) return partial_suffix_array
def get_suffix_array_from_text(text): tree = SuffixTree(len(text)) for char in text: tree.add_char(char) return get_suffix_array(tree)
edges.sort() for e in edges: n = tree.nodes[e[1]] child_depth = depth + n.end - n.start if len(n.edges) == 0: suffix_array.append(n.start - depth) build_suffix_array(n, child_depth) build_suffix_array(tree.nodes[tree.root], 0) return suffix_array def get_suffix_array_from_text(text): tree = SuffixTree(len(text)) for char in text: tree.add_char(char) return get_suffix_array(tree) if __name__ == "__main__": with open(sys.argv[1]) as fh: text = next(fh).strip() tree = SuffixTree(len(text)) for char in text: tree.add_char(char) print ", ".join([str(x) for x in get_suffix_array(tree)])