Skip to content

Commit 17fdaf7

Browse files
committed
feat: upgrade to grammalecte v2.1.1 and start to hava a functionnal run command
1 parent 2b300a2 commit 17fdaf7

38 files changed

+29499
-19430
lines changed

demo/input-file/output.txt

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,67 @@
1+
Python v3.9.5 (default, May 4 2021, 03:33:11)
2+
[Clang 12.0.0 (clang-1200.0.32.29)]
3+
Grammalecte v2.1.1
14
Quoi ? Racontes ! Racontes-moi ! Bon sangg, parles ! Oui. Il y a des menteur partout.
25
^^ ^^^^^^^^ ^^^^^^^^^^^^ °°°°° ^^^^^^ ^^^^^^^
3-
* 1 [4:6] # #1047p / nbsp_avant_double_ponctuation:
6+
* 1 [4:6] # #1089p / nbsp_avant_double_ponctuation:
47
Il manque un espace insécable.
58
> Suggestions :  ?
6-
* 2 [7:15] # #22492 / imp_verbe_groupe1__b2_a0_0:
9+
* 2 [7:15] # #32229 / gv1__imp_verbe_groupe1__b2_a1_1:
710
S’il s’agit d’un impératif, pas de “s”.
811
> Suggestions : Raconte
9-
* 3 [18:30] # #2411 / imp_verbes_composés_impératifs__b5_a0_0:
12+
* 3 [18:30] # #2540 / g0__imp_verbes_composés_impératifs__b6_a1_1:
1013
Ceci n’est pas une forme impérative correcte.
11-
> Suggestions : Raconte-moi | Racontez-moi | Racontons-moi
14+
> Suggestions : Raconte-moi | Racontons-moi | Racontez-moi
1215
> URL: http://fr.wikipedia.org/wiki/Imp%C3%A9ratif_%28grammaire%29
13-
* 5 [44:50] # #5890 / conj_xxxas_xxxes__sans_sujet__b4_a0_0:
16+
* 5 [44:50] # #7943 / g2__conj_2s_sans_sujet_xxxas_xxxes__b4_a1_1:
1417
Incohérence. Ceci est un verbe à la 2ᵉ personne du singulier. Sujet (“tu” ou “toi qui”)
1518
introuvable.
1619
> Suggestions : parle
17-
* 6 [69:76] # #15600 / gn_det_pluriel_1m__b1_a0_0:
18-
Accord de nombre erroné : « menteur » devrait être au pluriel.
20+
* 6 [69:76] # #25212 / g3__gn_det_epi_plur_1m__b1_a1_1:
21+
Accord de nombre erroné : « menteur » devrait être au pluriel.
1922
> Suggestions : menteurs
2023

21-
Je suit sidéré par la brutales arrogance de cette homme-là. Quelle salopard ! Un escrocs de la pire
24+
Je suit sidéré par la brutales arrogance de cette homme-là. Quelle salopard ! Un escrocs de la pire
2225
^^^^ ^^^^^^^^ ^^^^^ ^^^^^^ ^^^^^^^
23-
* 1 [3:7] # #5382 / conj_je__b2_a0_0:
26+
* 1 [3:7] # #7285 / g2__conj_je__b2_a1_1:
2427
Conjugaison erronée. Accord avec “Je”. Le verbe devrait être à la 1ʳᵉ personne du singulier.
2528
> Suggestions : suis
26-
* 2 [22:30] # #15039 / gn_la_1m__b2_a3_0:
27-
Accord de nombre erroné : « brutales » devrait être au singulier.
29+
* 2 [22:30] # #24254 / g3__gn_la_1m__b2_a4_1:
30+
Accord de nombre erroné : « brutales » devrait être au singulier.
2831
> Suggestions : brutale
29-
* 3 [44:49] # #15359 / gn_cette_1m__b1_a0_0:
30-
Accord de genre erroné : « homme » est masculin.
32+
* 3 [44:49] # #24723 / g3__gn_cette_1m__b1_a1_1:
33+
Accord de genre erroné : « homme » est masculin.
3134
> Suggestions : ce | cet
32-
* 4 [60:66] # #15796 / gn_quelle_1m__b1_a4_0:
33-
Accord de genre erroné : « salopard » est masculin.
35+
* 4 [60:66] # #25719 / g3__gn_quelle_1m__b1_a5_1:
36+
Accord de genre erroné : « salopard » est masculin.
3437
> Suggestions : Quel
35-
* 5 [81:88] # #15224 / gn_un_1m__b1_a2_0:
36-
Accord de nombre erroné : « escrocs » devrait être au singulier.
38+
* 5 [81:88] # #24552 / g3__gn_un_1m__b2_a3_1:
39+
Accord de nombre erroné : « escrocs » devrait être au singulier.
3740
> Suggestions : escroc
3841

3942
espece.
4043
°°°°°°
4144
Quant sera t’il châtiés pour ses mensonge ? Merde ! J’en aie marre.
4245
^^^^^ ^^^ ^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^^^ ^^ ^^^
43-
* 1 [0:5] # #9595 / conf_quand_quant_qu_en__b1_a0_0:
46+
* 1 [0:5] # #13076 / g2__conf_quand_quant_qu_en__b1_a1_1:
4447
Confusion. Quand = à quel moment. Quant à = à propos de.
4548
> Suggestions : Quand
46-
* 2 [10:13] # #1664s / tu_t_euphonique_incorrect:
49+
* 2 [10:13] # #1667s / tu_t_euphonique_incorrect:
4750
Pour le “t” euphonique, il faut deux traits d’union. Pas d’apostrophe. Pas d’espace.
4851
> Suggestions : -t-
49-
* 3 [16:23] # #21642 / ppas_inversion_être_il__b1_a0_0:
50-
Accord avec le sujet “il” : “châtiés” devrait être au masculin singulier.
52+
* 3 [16:23] # #30079 / gv1__ppas_3sg_mas_verbe_état__b5_a1_1:
53+
Accord avec le sujet “il” : “châtiés” devrait être au masculin singulier.
5154
> Suggestions : châtié
52-
* 4 [33:41] # #15600 / gn_det_pluriel_1m__b1_a0_0:
53-
Accord de nombre erroné : « mensonge » devrait être au pluriel.
55+
* 4 [33:41] # #25212 / g3__gn_det_epi_plur_1m__b1_a1_1:
56+
Accord de nombre erroné : « mensonge » devrait être au pluriel.
5457
> Suggestions : mensonges
55-
* 5 [43:56] # #376p / esp_milieu_ligne:
56-
Espace(s) surnuméraire(s) à supprimer.
58+
* 5 [43:56] # #368p / esp_milieu_ligne:
59+
Espace·s surnuméraire·s à supprimer.
5760
> Suggestions :
58-
* 6 [61:63] # #1047p / nbsp_avant_double_ponctuation:
61+
* 6 [61:63] # #1089p / nbsp_avant_double_ponctuation:
5962
Il manque un espace insécable.
6063
> Suggestions :  !
61-
* 7 [69:72] # #25110 / vmode_sujet_indicatif__b2_a0_0:
64+
* 7 [69:72] # #35024 / gv2__vmode_sujet_indicatif__b1_a1_1:
6265
Ce verbe ne devrait pas être au subjonctif.
63-
> Suggestions : ai | aurai | avais | eus
66+
> Suggestions : ai | avais | eus | aurai
67+

extension.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const vscode = require("vscode");
22
const { spawn } = require("child_process");
3+
const path = require("path");
34

45
/**
56
* @param {vscode.ExtensionContext} context
@@ -8,14 +9,20 @@ function activate(context) {
89
let disposable = vscode.commands.registerCommand(
910
"grammalecte.run",
1011
function () {
11-
const grammalecte = spawn("python3", [
12-
"grammalecte-cli.py",
13-
"-f",
14-
"demo/input-file/input.txt",
15-
]);
16-
grammalecte.stdout.on("data", (data) => {
17-
vscode.window.showInformationMessage(`stdout: ${data}`);
18-
});
12+
const editor = vscode.window.activeTextEditor;
13+
if (editor) {
14+
const file = editor.document.uri.path;
15+
const grammalecte = spawn("python3", [
16+
context.asAbsolutePath("grammalecte-cli.py"),
17+
"--json",
18+
"--file",
19+
file,
20+
]);
21+
grammalecte.stdout.on("data", (data) => {
22+
const json = JSON.parse(data.toString());
23+
console.log(json);
24+
});
25+
}
1926
}
2027
);
2128

grammalecte-cli.py

100644100755
Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import os.path
99
import argparse
1010
import json
11+
import itertools
1112
import re
1213
import traceback
1314

1415
import grammalecte
1516
import grammalecte.text as txt
17+
import grammalecte.graphspell.str_transform as strt
1618
from grammalecte.graphspell.echo import echo
1719

1820

@@ -27,7 +29,8 @@
2729
!word spelling suggestion
2830
>word draw path of word in the word graph
2931
=[filter1][=[filter2]] show entries which fit to filters (filter1 for word, filter2 for morphology)
30-
$some_text show sentences and tokens of text
32+
≠word|word|… show distance between words
33+
$some_text show sentences and tokens of text
3134
3235
Other commands:
3336
/help /h show this text
@@ -129,6 +132,10 @@ def getCommand ():
129132

130133
def main ():
131134
"launch the CLI (command line interface)"
135+
if sys.version_info < (3, 5):
136+
print("Python 3.5+ required")
137+
return
138+
132139
xParser = argparse.ArgumentParser()
133140
xParser.add_argument("-f", "--file", help="parse file (UTF-8 required!) [on Windows, -f is similar to -ff]", type=str)
134141
xParser.add_argument("-ff", "--file_to_file", help="parse file (UTF-8 required!) and create a result file (*.res.txt)", type=str)
@@ -153,7 +160,6 @@ def main ():
153160

154161
oGrammarChecker = grammalecte.GrammarChecker("fr")
155162
oSpellChecker = oGrammarChecker.getSpellChecker()
156-
oLexicographer = oGrammarChecker.getLexicographer()
157163
oTextFormatter = oGrammarChecker.getTextFormatter()
158164
if xArgs.personal_dict:
159165
oJSON = loadDictionary(xArgs.personal_dict)
@@ -271,8 +277,10 @@ def main ():
271277
for sWord in sText[1:].strip().split():
272278
if sWord:
273279
echo("* " + sWord)
274-
for sMorph in oSpellChecker.getMorph(sWord):
275-
echo(" {:<32} {}".format(sMorph, oLexicographer.formatTags(sMorph)))
280+
for sElem, aRes in oSpellChecker.analyze(sWord):
281+
echo(" - " + sElem)
282+
for sMorph, sMeaning in aRes:
283+
echo(" {:<40} {}".format(sMorph, sMeaning))
276284
elif sText.startswith("!"):
277285
for sWord in sText[1:].strip().split():
278286
if sWord:
@@ -291,6 +299,11 @@ def main ():
291299
sTagsPattern = ""
292300
for aRes in oSpellChecker.select(sFlexPattern, sTagsPattern):
293301
echo("{:<30} {:<30} {}".format(*aRes))
302+
elif sText.startswith("≠"):
303+
lWords = sText[1:].split("|")
304+
for s1, s2 in itertools.combinations(lWords, 2):
305+
nDist = strt.distanceDamerauLevenshtein(s1, s2)
306+
print(f"{s1}{s2}: {nDist}")
294307
elif sText.startswith("/o+ "):
295308
oGrammarChecker.gce.setOptions({ opt:True for opt in sText[3:].strip().split() if opt in oGrammarChecker.gce.getOptions() })
296309
echo("done")
@@ -329,18 +342,31 @@ def main ():
329342
if xArgs.textformatter:
330343
sParagraph = oTextFormatter.formatText(sParagraph)
331344
lParagraphErrors, lSentences = oGrammarChecker.gce.parse(sParagraph, bDebug=xArgs.debug, bFullInfo=True)
332-
echo(txt.getReadableErrors(lParagraphErrors, xArgs.width))
345+
#echo(txt.getReadableErrors(lParagraphErrors, xArgs.width))
333346
for dSentence in lSentences:
334-
echo("{nStart}:{nEnd}".format(**dSentence))
335-
echo(" <" + dSentence["sSentence"]+">")
336-
for dToken in dSentence["lToken"]:
337-
echo(" {0[nStart]:>3}:{0[nEnd]:<3} {1} {0[sType]:<14} {2} {0[sValue]:<16} {3:<10} {4}".format(dToken, \
338-
"×" if dToken.get("bToRemove", False) else " ",
339-
"!" if dToken["sType"] == "WORD" and not dToken.get("bValidToken", False) else " ",
340-
" ".join(dToken.get("lMorph", "")), \
341-
"·".join(dToken.get("aTags", "")) ) )
342-
echo(txt.getReadableErrors(dSentence["lGrammarErrors"], xArgs.width))
347+
echo("{nStart}:{nEnd} <{sSentence}>".format(**dSentence))
348+
for dToken in dSentence["lTokens"]:
349+
if dToken["sType"] == "INFO" or "bMerged" in dToken:
350+
continue
351+
echo(" {0[nStart]:>3}:{0[nEnd]:<3} {1} {0[sType]:<14} {2} {0[sValue]:<16} {3}".format(dToken, \
352+
"×" if dToken.get("bToRemove", False) else " ",
353+
"!" if dToken["sType"] == "WORD" and not dToken.get("bValidToken", False) else " ",
354+
" ".join(dToken.get("aTags", "")) ) )
355+
if "lMorph" in dToken:
356+
for sMorph, sLabel in zip(dToken["lMorph"], dToken["aLabels"]):
357+
echo(" {0:40} {1}".format(sMorph, sLabel))
358+
if "lSubTokens" in dToken:
359+
for dSubToken in dToken["lSubTokens"]:
360+
if dSubToken["sValue"]:
361+
echo(" · {0:20}".format(dSubToken["sValue"]))
362+
for sMorph, sLabel in zip(dSubToken["lMorph"], dSubToken["aLabels"]):
363+
echo(" {0:40} {1}".format(sMorph, sLabel))
364+
#echo(txt.getReadableErrors(dSentence["lGrammarErrors"], xArgs.width))
343365
else:
366+
if sText.startswith("TEST: "):
367+
sText = sText[6:]
368+
sText = sText.replace("{{", "").replace("}}", "")
369+
sText = re.sub(" ->> .*$", "", sText).rstrip()
344370
for sParagraph in txt.getParagraph(sText):
345371
if xArgs.textformatter:
346372
sParagraph = oTextFormatter.formatText(sParagraph)

0 commit comments

Comments
 (0)