Commit c1c3d4ed by Jeroen F.J. Laros

Prepared support for different types of leaf nodes.

parent 53880f20
 ... @@ -73,8 +73,9 @@ def _iterate(path, node): ... @@ -73,8 +73,9 @@ def _iterate(path, node): yield path yield path for char in node: for char in node: for result in _iterate(path + char, node[char]): if char: yield result for result in _iterate(path + char, node[char]): yield result def _fill(node, alphabet, length): def _fill(node, alphabet, length): ... @@ -117,16 +118,17 @@ def _hamming(path, node, word, distance, cigar): ... @@ -117,16 +118,17 @@ def _hamming(path, node, word, distance, cigar): car, cdr = word[0], word[1:] car, cdr = word[0], word[1:] for char in node: for char in node: if char == car: if char: penalty = 0 if char == car: operation = '=' penalty = 0 else: operation = '=' penalty = 1 else: operation = 'X' penalty = 1 for result in _hamming( operation = 'X' path + char, node[char], cdr, distance - penalty, for result in _hamming( cigar + operation): path + char, node[char], cdr, distance - penalty, yield result cigar + operation): yield result def _levenshtein(path, node, word, distance, cigar): def _levenshtein(path, node, word, distance, cigar): ... @@ -155,22 +157,23 @@ def _levenshtein(path, node, word, distance, cigar): ... @@ -155,22 +157,23 @@ def _levenshtein(path, node, word, distance, cigar): yield result yield result for char in node: for char in node: # Substitution. if char: if car: # Substitution. if char == car: if car: penalty = 0 if char == car: operation = '=' penalty = 0 else: operation = '=' penalty = 1 else: operation = 'X' penalty = 1 operation = 'X' for result in _levenshtein( path + char, node[char], cdr, distance - penalty, cigar + operation): yield result # Insertion. for result in _levenshtein( for result in _levenshtein( path + char, node[char], cdr, distance - penalty, path + char, node[char], word, distance - 1, cigar + 'I'): cigar + operation): yield result yield result # Insertion. for result in _levenshtein( path + char, node[char], word, distance - 1, cigar + 'I'): yield result class Trie(object): class Trie(object): ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!