X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=unscrambler.py;h=1b242309b649eaa036277fdb22fc6f9c7705f0c8;hb=e8fbbb7306430478dec55d2c963eed116d8330cc;hp=c5bc9b5f15200c0f909af2bd5f849be6fa60b809;hpb=0d63d44ac89aab38fe95f36497adaf95110ab949;p=python_utils.git diff --git a/unscrambler.py b/unscrambler.py index c5bc9b5..1b24230 100644 --- a/unscrambler.py +++ b/unscrambler.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +"""A fast word unscrambler library.""" + import logging from typing import Dict, Mapping, Optional @@ -21,10 +23,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 +108,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 +118,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 +196,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: