8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
-
+
|
import os
import re
import time
from contextlib import contextmanager
from ..graphspell.ibdawg import IBDAWG
from ..graphspell.echo import echo
from . import gc_engine as gce
from . import gc_engine
from . import conj
from . import phonet
from . import mfsp
@contextmanager
def timeblock (label, hDst):
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
-
-
+
+
-
+
|
if hDst:
hDst.write("{:<12.6}".format(end-start))
def perf (sVersion, hDst=None):
"performance tests"
print("\nPerformance tests")
gce.load()
gce.parse("Texte sans importance… utile pour la compilation des règles avant le calcul des perfs.")
gc_engine.load()
gc_engine.parse("Texte sans importance… utile pour la compilation des règles avant le calcul des perfs.")
spHere, _ = os.path.split(__file__)
with open(os.path.join(spHere, "perf.txt"), "r", encoding="utf-8") as hSrc:
if hDst:
hDst.write("{:<12}{:<20}".format(sVersion, time.strftime("%Y.%m.%d %H:%M")))
for sText in ( s.strip() for s in hSrc if not s.startswith("#") and s.strip() ):
with timeblock(sText[:sText.find(".")], hDst):
gce.parse(sText)
gc_engine.parse(sText)
if hDst:
hDst.write("\n")
def _fuckBackslashUTF8 (s):
"fuck that shit"
return s.replace("\u2019", "'").replace("\u2013", "–").replace("\u2014", "—")
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
-
+
|
class TestGrammarChecking (unittest.TestCase):
"Tests du correcteur grammatical"
@classmethod
def setUpClass (cls):
gce.load()
gc_engine.load()
cls._zError = re.compile(r"\{\{.*?\}\}")
cls._aTestedRules = set()
def test_parse (self):
zOption = re.compile("^__([a-zA-Z0-9]+)__ ")
spHere, _ = os.path.split(__file__)
with open(os.path.join(spHere, "gc_test.txt"), "r", encoding="utf-8") as hSrc:
|
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
-
+
-
-
-
+
+
+
-
+
|
"\n found: " + sFoundSuggs + \
"\n errors: \n" + sListErr)
nError += 1
if nError:
print("Unexpected errors:", nError)
# untested rules
i = 0
for _, sOpt, sLineId, sRuleId in gce.listRules():
for _, sOpt, sLineId, sRuleId in gc_engine.listRules():
if sOpt != "@@@@" and sRuleId not in self._aTestedRules and not re.search("^[0-9]+[sp]$|^[pd]_", sRuleId):
echo(f"# untested rule: {sLineId}/{sRuleId}")
i += 1
if i:
echo(" [{} untested rules]".format(i))
def _splitTestLine (self, sLine):
sText, sSugg = sLine.split("->>")
return (sText.strip(), sSugg.strip())
def _getFoundErrors (self, sLine, sOption):
if sOption:
gce.setOption(sOption, True)
aErrs = gce.parse(sLine)
gce.setOption(sOption, False)
gc_engine.gc_options.setOption(sOption, True)
aErrs = gc_engine.parse(sLine)
gc_engine.gc_options.setOption(sOption, False)
else:
aErrs = gce.parse(sLine)
aErrs = gc_engine.parse(sLine)
sRes = " " * len(sLine)
sListErr = ""
lAllSugg = []
for dErr in aErrs:
sRes = sRes[:dErr["nStart"]] + "~" * (dErr["nEnd"] - dErr["nStart"]) + sRes[dErr["nEnd"]:]
sListErr += " * {sLineId} / {sRuleId} at {nStart}:{nEnd}\n".format(**dErr)
lAllSugg.append("|".join(dErr["aSuggestions"]))
|