私はデータ構造が初めてで、編集距離を使用して名前のデータベースを明確にする試みを実装しています。私はトライの次の実装を使用しています:
http://stevehanov.ca/blog/index.php?id=114
これは基本的に次のとおりです。
class TrieNode:
def __init__(self):
self.word = None
self.children = {}
global NodeCount
NodeCount += 1
def insert( self, word ):
node = self
for letter in word:
if letter not in node.children:
node.children[letter] = TrieNode()
node = node.children[letter]
node.word = word
# read dictionary file into a trie
trie = TrieNode()
for name in names:
WordCount += 1
trie.insert( name )
これは、すべての名前をトライに挿入するので、うまく機能します。ここで、持っている名前のリストを 1 つずつ調べ、トライを使用して、渡された名前から特定の編集距離にあるすべての名前のリストを返します。次に、リストに返されたトライからすべての名前を削除したいと思います。
それを行うための速い方法はありますか?
ありがとう!