Index: gc_core/py/lang_core/tests_core.py ================================================================== --- gc_core/py/lang_core/tests_core.py +++ gc_core/py/lang_core/tests_core.py @@ -60,10 +60,11 @@ @classmethod def setUpClass (cls): gc_engine.load() cls._zError = re.compile(r"\{\{.*?\}\}") + cls._zRuleEnd = re.compile(r"_a\d+_\d+$") cls._aTestedRules = set() def test_parse (self): zOption = re.compile("^__([a-zA-Z0-9]+)__ ") spHere, _ = os.path.split(__file__) @@ -143,13 +144,14 @@ self._aTestedRules.add(dErr["sRuleId"].rstrip("0123456789")) # test messages if False: aMsgErrs = gc_engine.parse(purgeMessage(dErr["sMessage"])) if aMsgErrs or "" in dErr["sMessage"] or "" in dErr["sMessage"]: - print("\n# Incorrect message: <" + dErr["sMessage"] + ">\n " + dErr["sLineId"] + " / " + dErr["sRuleId"]) - if aMsgErrs: - for dMsgErr in sorted(aMsgErrs, key=lambda d: d["nStart"]): + aSelectedErrs = [ dMsgErr for dMsgErr in sorted(aMsgErrs, key=lambda d: d["nStart"]) if self._zRuleEnd.sub("", dMsgErr["sRuleId"]) != self._zRuleEnd.sub("", dErr["sRuleId"]) ] + if aSelectedErrs: + print("\n# Error in: <" + dErr["sMessage"] + ">\n " + dErr["sLineId"] + " / " + dErr["sRuleId"]) + for dMsgErr in aSelectedErrs: print(" error: {sLineId} / {sRuleId} at {nStart}:{nEnd}".format(**dMsgErr)) return sRes, sListErr, "|||".join(lAllSugg) def _getExpectedErrors (self, sLine): sRes = " " * len(sLine) Index: gc_lang/fr/modules/tests_modules.py ================================================================== --- gc_lang/fr/modules/tests_modules.py +++ gc_lang/fr/modules/tests_modules.py @@ -6,11 +6,11 @@ import unittest import time from contextlib import contextmanager -from ..graphspell.ibdawg import IBDAWG +from ..graphspell.spellchecker import SpellChecker from . import conj from . import phonet from . import mfsp @@ -30,43 +30,55 @@ class TestDictionary (unittest.TestCase): "Test du correcteur orthographique" @classmethod def setUpClass (cls): - cls.oDic = IBDAWG("${dic_main_filename_py}") + cls.oSpellChecker = SpellChecker("fr") def test_lookup (self): for sWord in ["branche", "Émilie"]: - self.assertTrue(self.oDic.lookup(sWord), sWord) + self.assertTrue(self.oSpellChecker.lookup(sWord), sWord) def test_lookup_failed (self): for sWord in ["Branche", "BRANCHE", "BranchE", "BRanche", "BRAnCHE", "émilie"]: - self.assertFalse(self.oDic.lookup(sWord), sWord) + self.assertFalse(self.oSpellChecker.lookup(sWord), sWord) def test_isvalidtoken (self): for sWord in ["Branche", "branche", "BRANCHE", "Émilie", "ÉMILIE", "aujourd'hui", "aujourd’hui", "Aujourd'hui", "Aujourd’hui", "je-suis-vraiment-fatigué", ""]: - self.assertTrue(self.oDic.isValidToken(sWord), sWord) + self.assertTrue(self.oSpellChecker.isValidToken(sWord), sWord) def test_isvalid (self): for sWord in ["Branche", "branche", "BRANCHE", "Émilie", "ÉMILIE", "aujourd’hui", "Aujourd’hui"]: - self.assertTrue(self.oDic.isValid(sWord), sWord) + self.assertTrue(self.oSpellChecker.isValid(sWord), sWord) def test_isvalid_failed (self): for sWord in ["BranchE", "BRanche", "BRAnCHE", "émilie", "éMILIE", "émiLie", "aujourd'hui", "Aujourd'hui", ]: - self.assertFalse(self.oDic.isValid(sWord), sWord) + self.assertFalse(self.oSpellChecker.isValid(sWord), sWord) def test_suggest (self): for sWord in [ "déelirranttesss", "vallidasion", "Emilie", "exibission", "ditirembique", "jai", "email", "fatiqué", "coeur", "trèèèèèèèèès", "vraaaaiiiimeeeeennnt", "apele", "email", "Co2", "emmppâiiiller", "testt", "apelaion", "exsepttion", "sintaxik", "ebriete", "ennormmement" ]: - aSugg = self.oDic.suggest(sWord) + aSugg = self.oSpellChecker.suggest(sWord) #with timeblock(sWord): - # aSugg = self.oDic.suggest(sWord) + # aSugg = self.oSpellChecker.suggest(sWord) # print(sWord, "->", " ".join(aSugg)) + def test_lemmas (self): + for sWord, sInfi in [ + ("jetez", "jeter"), + ("finit", "finir"), + ("mangé", "manger"), + ("oubliait", "oublier"), + ("arrivais", "arriver"), + ("venait", "venir"), + ("prendre", "prendre") + ]: + self.assertIn(sInfi, self.oSpellChecker.getLemma(sWord)) + class TestConjugation (unittest.TestCase): "Tests des conjugaisons" @classmethod