class BrokenPhone: def __init__(self): self._tree = BKTree() def load(self, path): file = open(path, 'r') for word in file: self._tree.insert(word.rstrip())
import sys from Astar import Astar from BKTree import BKTree from BrokenPhone import BrokenPhone bk_tree = BKTree() file = open(sys.argv[1], 'r') print("Start loading file!") for word in file: bk_tree.insert(word.rstrip()) print("End loading file!") astar = Astar() astar.search(bk_tree, "life", "death") for item in astar.getChain(): print(item)
def _check_insert(node, tree_depth): BKTree.insert(tree, root[0], node, get_distance) self.assertEqual(BKTree.get_depth(tree, root[0]), tree_depth)
from BKTree import BKTree tree = BKTree() tree.insert("food") tree.insert("good") tree.insert("cook") tree.insert("fowl") tree.insert("spoon") tree.insert("fork") print(tree._tree) print(tree.search("aork", 1))