Grammalecte  Diff

Differences From Artifact [88e56a7f78]:

To Artifact [f7e92c1ab0]:


1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18










-
+







#! python3

"""
Grammar checker tests for French language
"""

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


@contextmanager
def timeblock (label, hDst=None):
28
29
30
31
32
33
34
35

36
37
38
39

40
41
42
43

44
45
46
47

48
49
50
51

52
53
54
55

56
57
58
59
60
61
62
63

64
65

66
67












68
69
70
71
72
73
74
28
29
30
31
32
33
34

35
36
37
38

39
40
41
42

43
44
45
46

47
48
49
50

51
52
53
54

55
56
57
58
59
60
61
62

63
64

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86







-
+



-
+



-
+



-
+



-
+



-
+







-
+

-
+


+
+
+
+
+
+
+
+
+
+
+
+









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
    def setUpClass (cls):
        pass