X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=unscrambler.py;h=a40213e2a7fcdb7663b7479ac3979c1ccb485938;hb=001b734eb651c819d880df1017829bd54d7c16f7;hp=c5bc9b5f15200c0f909af2bd5f849be6fa60b809;hpb=5c212d7639f62fcb936f9d7a0bbe704a9f7b213d;p=python_utils.git diff --git a/unscrambler.py b/unscrambler.py index c5bc9b5..a40213e 100644 --- a/unscrambler.py +++ b/unscrambler.py @@ -1,5 +1,9 @@ #!/usr/bin/env python3 +# © Copyright 2021-2022, Scott Gasch + +"""A fast word unscrambler library.""" + import logging from typing import Dict, Mapping, Optional @@ -21,10 +25,10 @@ cfg.add_argument( logger = logging.getLogger(__name__) letters_bits = 32 -letters_mask = 2 ** letters_bits - 1 +letters_mask = 2**letters_bits - 1 fprint_bits = 52 -fprint_mask = (2 ** fprint_bits - 1) << letters_bits +fprint_mask = (2**fprint_bits - 1) << letters_bits fprint_feature_bit = { 'e': 0, @@ -106,7 +110,7 @@ class Unscrambler(object): self.sigs = [] self.words = [] - filename = self.get_indexfile(indexfile) + filename = Unscrambler.get_indexfile(indexfile) with open(filename, 'r') as rf: lines = rf.readlines() for line in lines: @@ -116,7 +120,8 @@ class Unscrambler(object): self.sigs.append(isig) self.words.append(word) - def get_indexfile(self, indexfile: Optional[str]) -> str: + @staticmethod + def get_indexfile(indexfile: Optional[str]) -> str: if indexfile is None: if 'unscrambler_default_indexfile' in config.config: indexfile = config.config['unscramble_indexfile'] @@ -193,7 +198,6 @@ class Unscrambler(object): @staticmethod def repopulate( - lsigs: Dict[str, int], dictfile: str = '/usr/share/dict/words', indexfile: str = '/usr/share/dict/sparse_index', ) -> None: