projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add powerset to list_utils; improve chord parser.
[python_utils.git]
/
unscrambler.py
diff --git
a/unscrambler.py
b/unscrambler.py
index c5bc9b5f15200c0f909af2bd5f849be6fa60b809..a40213e2a7fcdb7663b7479ac3979c1ccb485938 100644
(file)
--- a/
unscrambler.py
+++ b/
unscrambler.py
@@
-1,5
+1,9
@@
#!/usr/bin/env python3
#!/usr/bin/env python3
+# © Copyright 2021-2022, Scott Gasch
+
+"""A fast word unscrambler library."""
+
import logging
from typing import Dict, Mapping, Optional
import logging
from typing import Dict, Mapping, Optional
@@
-21,10
+25,10
@@
cfg.add_argument(
logger = logging.getLogger(__name__)
letters_bits = 32
logger = logging.getLogger(__name__)
letters_bits = 32
-letters_mask = 2
**
letters_bits - 1
+letters_mask = 2
**
letters_bits - 1
fprint_bits = 52
fprint_bits = 52
-fprint_mask = (2
**
fprint_bits - 1) << letters_bits
+fprint_mask = (2
**
fprint_bits - 1) << letters_bits
fprint_feature_bit = {
'e': 0,
fprint_feature_bit = {
'e': 0,
@@
-106,7
+110,7
@@
class Unscrambler(object):
self.sigs = []
self.words = []
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:
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)
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']
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(
@staticmethod
def repopulate(
- lsigs: Dict[str, int],
dictfile: str = '/usr/share/dict/words',
indexfile: str = '/usr/share/dict/sparse_index',
) -> None:
dictfile: str = '/usr/share/dict/words',
indexfile: str = '/usr/share/dict/sparse_index',
) -> None: