Grammalecte  Diff

Differences From Artifact [c328932d14]:

To Artifact [82063d3e76]:


19
20
21
22
23
24
25

26
27

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
87
88
89
90

91
92
93
94
95

96
97












98
99
100
101
102
103
104

//Initialisation des messages
const msgStart = "\x1b[31mBienvenu sur Grammalecte pour NodeJS!!!\x1b[0m\n";
const msgPrompt = "\x1b[36mGrammaJS\x1b[33m>\x1b[0m ";
const msgSuite = "\x1b[33m…\x1b[0m ";
const msgEnd = "\x1b[31m\x1b[5m\x1b[5mBye bye!\x1b[0m";


var repJson = false;
var repPerf = false;


var sBufferConsole = "";
var sCmdToExec = "";
var sText = "";

var cmdAction = {
    help: {
        short: "",

        description: "Affiche les informations que vous lisez ;)",
        execute: ""
    },
    perf: {
        short: "",

        description: "(on/off) Permet d'afficher le temps d'exécution des commandes.",
        execute: ""
    },
    json: {
        short: "",

        description: "(on/off) Réponse en format format json.",
        execute: ""
    },
    exit: {
        short: "",

        description: "Client intéractif: Permet de le quitter.",
        execute: ""
    },
    text: {
        short: "",

        description: "Client / Server: Définir un texte pour plusieurs actions.",
        execute: ""
    },
    gceoption: {
        short: "",
        description: "Défini une option a utilisé par le correcteur de grammaire.",
        execute: ""
    },
    format: {
        short: "",

        description: "Permet de mettre en forme le texte.",
        execute: "formatText"
    },
    check: {
        short: "",

        description: "Vérifie la grammaire et l'orthographe d'un texte.",
        execute: "verifParagraph"
    },
    lexique: {
        short: "",

        description: "Affiche le lexique du texte.",
        execute: "lexique"
    },
    spell: {
        short: "",

        description: "Vérifie l'existence d'un mot.",
        execute: "spell"
    },
    suggest: {
        short: "",

        description: "Suggestion des orthographes possible d'un mot.",
        execute: "suggest"
    },
    morph: {
        short: "",

        description: "Affiche les informations pour un mot.",
        execute: "morph"
    },
    lemma: {
        short: "",

        description: "Donne le lemme d'un mot.",
        execute: "lemma"












    }
};

var cmdOne = ["json", "perf", "help", "exit"];
var cmdMulti = ["text", "format", "check", "lexique", "spell", "suggest", "morph", "lemma"];

var cmdAll = [...cmdOne, ...cmdMulti];







>
|
|
>








>





>
|




>
|




>
|




>



<
<
<
<
<


>





>





>





>





>





>





>


>
>
>
>
>
>
>
>
>
>
>
>







19
20
21
22
23
24
25
26
27
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

//Initialisation des messages
const msgStart = "\x1b[31mBienvenu sur Grammalecte pour NodeJS!!!\x1b[0m\n";
const msgPrompt = "\x1b[36mGrammaJS\x1b[33m>\x1b[0m ";
const msgSuite = "\x1b[33m…\x1b[0m ";
const msgEnd = "\x1b[31m\x1b[5m\x1b[5mBye bye!\x1b[0m";

var repPreference = {
    json: false,
    perf: false
};

var sBufferConsole = "";
var sCmdToExec = "";
var sText = "";

var cmdAction = {
    help: {
        short: "",
        arg: "",
        description: "Affiche les informations que vous lisez ;)",
        execute: ""
    },
    perf: {
        short: "",
        arg: "on/off",
        description: "Permet d'afficher le temps d'exécution des commandes.",
        execute: ""
    },
    json: {
        short: "",
        arg: "on/off",
        description: "Réponse en format format json.",
        execute: ""
    },
    exit: {
        short: "",
        arg: "",
        description: "Client interactif: Permet de le quitter.",
        execute: ""
    },
    text: {
        short: "",
        arg: "texte",
        description: "Client / Server: Définir un texte pour plusieurs actions.",
        execute: ""
    },





    format: {
        short: "",
        arg: "texte",
        description: "Permet de mettre en forme le texte.",
        execute: "formatText"
    },
    check: {
        short: "",
        arg: "texte",
        description: "Vérifie la grammaire et l'orthographe d'un texte.",
        execute: "verifParagraph"
    },
    lexique: {
        short: "",
        arg: "texte",
        description: "Affiche le lexique du texte.",
        execute: "lexique"
    },
    spell: {
        short: "",
        arg: "mot",
        description: "Vérifie l'existence d'un mot.",
        execute: "spell"
    },
    suggest: {
        short: "",
        arg: "mot",
        description: "Suggestion des orthographes possible d'un mot.",
        execute: "suggest"
    },
    morph: {
        short: "",
        arg: "mot",
        description: "Affiche les informations pour un mot.",
        execute: "morph"
    },
    lemma: {
        short: "",
        arg: "mot",
        description: "Donne le lemme d'un mot.",
        execute: "lemma"
    },
    gceoption: {
        short: "",
        arg: "+/-name",
        description: "Défini les options à utiliser par le correcteur de grammaire.",
        execute: ""
    },
    tfoption: {
        short: "",
        arg: "+/-name",
        description: "Défini les options à utiliser par le formateur de texte.",
        execute: ""
    }
};

var cmdOne = ["json", "perf", "help", "exit"];
var cmdMulti = ["text", "format", "check", "lexique", "spell", "suggest", "morph", "lemma"];

var cmdAll = [...cmdOne, ...cmdMulti];
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
function toTitle(aStr) {
    return aStr.charAt(0).toUpperCase() + aStr.slice(1);
}

function repToText(oRep) {
    //console.log(oRep);
    let repText = "";
    for (const action of ["Json", "Perf", "GceOption"]) {
        if (action in oRep) {
            repText += toTitle(action) + " " + oRep[action];
        }
    }

    for (const action of ["morph", "lemma"]) {
        if (action in oRep) {







|







157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
function toTitle(aStr) {
    return aStr.charAt(0).toUpperCase() + aStr.slice(1);
}

function repToText(oRep) {
    //console.log(oRep);
    let repText = "";
    for (const action of ["json", "perf", "gceoption", "tfoption"]) {
        if (action in oRep) {
            repText += toTitle(action) + " " + oRep[action];
        }
    }

    for (const action of ["morph", "lemma"]) {
        if (action in oRep) {
314
315
316
317
318
319
320

321
322
323
324
325
326
327
328
329
330
331
332
333
334

335

336
337
338
339
340

341

342
343


344
345
346
347
348
349
350

    if (!isBool(aArg.text)) {
        sText = aArg.text;
    }

    repAction["text"] = sText;


    if (getArg(aArg, ["json"])) {
        repJson = getArgVal(aArg, ["json"]);
        repAction["Json"] = repJson ? "ON" : "OFF";
    }

    if (getArg(aArg, ["perf"])) {
        repPerf = getArgVal(aArg, ["perf"]);
        repAction["Perf"] = repPerf ? "ON" : "OFF";
    }

    if (repPerf) {
        tStart = performance.now();
    }


    if (getArg(aArg, ["gceoption"])) {

        let sOpt = sText.split(" ");
        if (sOpt[0] == "reset") {
            oGrammarChecker.resetGceOptions();
            repAction["GceOption"] = "reset";
        } else {

            let bOptVal = toBool(sOpt[1]);

            oGrammarChecker.setGceOption(sOpt[0], bOptVal);
            repAction["GceOption"] = sOpt[0] + " " + (bOptVal ? "ON" : "OFF");


        }
    }

    for (const action in aArg) {
        if (cmdAction[action] && cmdAction[action].execute !== "") {
            if (!isBool(aArg[action]) && aArg[action] !== "") {
                repAction.text = aArg[action];







>
|
|
|
|
|
<
<
<
|
<
|



>
|
>
|
|
|
|
|
>
|
>
|
|
>
>







335
336
337
338
339
340
341
342
343
344
345
346
347



348

349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374

    if (!isBool(aArg.text)) {
        sText = aArg.text;
    }

    repAction["text"] = sText;

    for (const action of ["json", "perf"]) {
        if (getArg(aArg, [action])) {
            repPreference[action] = getArgVal(aArg, [action]);
            repAction[action] = repPreference[action] ? "ON" : "OFF";
        }
    }





    if (repPreference.perf) {
        tStart = performance.now();
    }

    for (const action of ["gceoption", "tfoption"]) {
        if (getArg(aArg, [action])) {
            let sFonction = action == "gceoption" ? "GceOption" : "TfOption";
            let sOpt = sText.split(" ");
            if (sOpt[0] == "reset") {
                oGrammarChecker["reset"+sFonction+"s"]();
                repAction[action] = "reset";
            } else {
                for (const optAction of sOpt) {
                    let bOptVal = optAction[0] == '+' ? true : false;
                    let sOptName = optAction.slice(1, optAction.length);
                    oGrammarChecker["set"+sFonction](sOptName, bOptVal);
                    repAction[action] = sText;
                }
            }
        }
    }

    for (const action in aArg) {
        if (cmdAction[action] && cmdAction[action].execute !== "") {
            if (!isBool(aArg[action]) && aArg[action] !== "") {
                repAction.text = aArg[action];
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
        repAction["help"].push(" * pour le client exemple: «gramma-cli --command \"mot/texte\"».");
        repAction["help"].push(" * le serveur se lance avec la commande «gramma-cli --server --port 8085».");

        repAction["help"].push("");
        repAction["help"].push("========================= Les commandes/arguments: ========================");
        repAction["help"].push("");
        for (const action in cmdAction) {
            repAction["help"].push(action.padEnd(15, ' ') + ': ' + cmdAction[action].description);
        }
        repAction["help"].push("");
        repAction["help"].push("================================== Note: ==================================");
        repAction["help"].push("");
        repAction["help"].push("En mode client: les arguments sont de la forme «--argument» !");
        repAction["help"].push("En mode client intéractif: pour les commandes concernant un texte, vous");
        repAction["help"].push("  pouvez taper la commande puis entrer (pour saisir le texte) pour ");
        repAction["help"].push("  terminer la saisie du texte et exécuter la commande taper /\"commande\"");
    }

    if (repPerf) {
        tEnd = performance.now();
        //On ajoute l"information au résultat
        repAction["time"] = (Math.round((tEnd - tStart) * 1000) / 1000).toString();
    }

    if (repJson) {
        return JSON.stringify(repAction);
    } else {
        return repToText(repAction);
    }
}

function argToExec(aCommand, aText, rl, resetCmd = true){







|










|





|







393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
        repAction["help"].push(" * pour le client exemple: «gramma-cli --command \"mot/texte\"».");
        repAction["help"].push(" * le serveur se lance avec la commande «gramma-cli --server --port 8085».");

        repAction["help"].push("");
        repAction["help"].push("========================= Les commandes/arguments: ========================");
        repAction["help"].push("");
        for (const action in cmdAction) {
            repAction["help"].push(action.padEnd(10, ' ') + ': ' + cmdAction[action].arg.padEnd(8, ' ') + ': ' + cmdAction[action].description);
        }
        repAction["help"].push("");
        repAction["help"].push("================================== Note: ==================================");
        repAction["help"].push("");
        repAction["help"].push("En mode client: les arguments sont de la forme «--argument» !");
        repAction["help"].push("En mode client intéractif: pour les commandes concernant un texte, vous");
        repAction["help"].push("  pouvez taper la commande puis entrer (pour saisir le texte) pour ");
        repAction["help"].push("  terminer la saisie du texte et exécuter la commande taper /\"commande\"");
    }

    if (repPreference.perf) {
        tEnd = performance.now();
        //On ajoute l"information au résultat
        repAction["time"] = (Math.round((tEnd - tStart) * 1000) / 1000).toString();
    }

    if (repPreference.json) {
        return JSON.stringify(repAction);
    } else {
        return repToText(repAction);
    }
}

function argToExec(aCommand, aText, rl, resetCmd = true){