+ """A class that unscrambles words quickly by computing a signature
+ (sig) for the word based on its position independent letter
+ population and then using a pregenerated index to look up known
+ words the same set of letters.
+
+ Note that each instance of Unscrambler caches its index to speed
+ up lookups number 2..N; careless reinstantiation will by slower.
+
+ Sigs are designed to cluster similar words near each other so both
+ lookup methods support a "fuzzy match" argument that can be set to
+ request similar words that do not match exactly in addition to any
+ exact matches.
+
+ """
+
+ def __init__(self, indexfile: Optional[str] = None):
+ # Cached index per instance.
+ self.sigs = []
+ self.words = []
+
+ filename = Unscrambler.get_indexfile(indexfile)
+ with open(filename, 'r') as rf:
+ lines = rf.readlines()
+ for line in lines:
+ line = line[:-1]
+ (fsig, word) = line.split('+')
+ isig = int(fsig, 16)
+ self.sigs.append(isig)
+ self.words.append(word)