Generalize dictionary management. Disable Canadian and Australian variants.
--- a/py/gadict_spellcheck.py Thu Nov 10 16:28:25 2016 +0200
+++ b/py/gadict_spellcheck.py Thu Nov 10 16:42:43 2016 +0200
@@ -9,34 +9,27 @@
class EofReached (Exception):
pass
-class EmptyChecker:
- def __init__(self):
- pass
- def check(self, word):
- pass
-
class GadictSpellChecker:
SEPARATOR_RE = regex.compile(u"^__$")
EMPTY_RE = regex.compile( u"^$" )
HEADWORD_ATTR_RE = regex.compile( u"^ " )
- def _get_checker(self, lang):
+ def _add_checker(self, lang):
try:
- dic = enchant.Dict(lang)
+ self.dicts.append(enchant.Dict(lang))
except enchant.errors.DictNotFoundError:
print("Dictionary '{:s}' is not found...".format(lang))
- dic = EmptyChecker()
- return dic
def __init__(self, stream, fname):
self.stream = stream
self.fname = fname
self.lineno = 0
- self.dict_us = self._get_checker('en_US')
- self.dict_gb = self._get_checker('en_GB')
- self.dict_au = self._get_checker('en_AU')
- self.dict_ca = self._get_checker('en_CA')
+ self.dicts = []
+ self._add_checker('en_US')
+ self._add_checker('en_GB')
+ # self._add_checker('en_AU')
+ # self._add_checker('en_CA')
def _readline(self):
line = self.stream.readline()
@@ -67,7 +60,7 @@
continue
line = line.strip()
for word in regex.split("[ ,]+", line):
- if self.dict_us.check(word) or self.dict_gb.check(word) or self.dict_au.check(word) or self.dict_ca.check(word):
+ if any([dic.check(word) for dic in self.dicts]):
continue
print("""{:s}:{:d}: "{:s}" is misspelled""".format(self.fname, self.lineno, word))