def longestSharedSubstring(text):
	suffixTree = ColoredSuffixTree(text)
	suffixTree.modifiedSuffixTreeConstruction()
	suffixTree.treeColoring()
	bfpath = BreadthFirstPaths(suffixTree,text)
	bfpath.bfs(0)
	longestSubstring = ''
	for i in suffixTree.nodes.keys():
		node = suffixTree.nodes[i]
		if node.color == 2 and len(node.child) > 0:
			currentPath =  bfpath.pathTo[i]
			if len(currentPath) > len(longestSubstring):
				longestSubstring = currentPath
	print longestSubstring
示例#2
0
def shortestUnsharedSubstring(text):
	suffixTree = ColoredSuffixTree(text)
	suffixTree.modifiedSuffixTreeConstruction()
	suffixTree.treeColoring()
	
	bfpath = BreadthFirstPaths(suffixTree,text)
	bfpath.bfs(0)
	
	shortestLen = float("inf")
	shortestNode = None

	for i in suffixTree.nodes.keys():
		node = suffixTree.nodes[i]
		if node.color != 2 and len(node.child) > 0:
			currentPath =  bfpath.pathTo[i]
			if len(currentPath) < shortestLen:
				shortestNode = i
				shortestLen = len(currentPath)
	print bfpath.pathTo[shortestNode]