Grammalecte  Check-in [e22e75159b]

Overview
Comment:[njs] cli possibility to change main and personal dictionary
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | nodejs
Files: files | file ages | folders
SHA3-256: e22e75159b3eb2f38e873dc40a5c096d8f6380e51bd3100e352cf16d9b442ba5
User & Date: IllusionPerdu on 2018-10-21 22:10:35
Other Links: branch diff | manifest | tags
Context
2018-10-22
11:15
[njs] Move check for loading dictionary in api check-in: c03dede353 user: IllusionPerdu tags: nodejs
2018-10-21
22:10
[njs] cli possibility to change main and personal dictionary check-in: e22e75159b user: IllusionPerdu tags: nodejs
21:45
[njs] core add Set Dictionary for main and personal check-in: 8959d8c2be user: IllusionPerdu tags: nodejs
Changes

Modified gc_lang/fr/nodejs/cli/bin/gramma-cli.js from [7a17b93c22] to [facfd09481].

    12     12   Doc :
    13     13   https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
    14     14   https://stackoverflow.com/questions/41058569/what-is-the-difference-between-const-and-const-in-javascript
    15     15   */
    16     16   
    17     17   const argCmd = require("../lib/minimist.js")(process.argv.slice(2));
    18     18   const { performance } = require("perf_hooks");
           19  +const path = require("path");
           20  +const fs = require("fs");
    19     21   
    20     22   //Initialisation des messages
    21     23   const msgStart = "\x1b[31mBienvenue sur Grammalecte pour NodeJS!!!\x1b[0m\n";
    22     24   const msgPrompt = "\x1b[36mGrammaJS\x1b[33m>\x1b[0m ";
    23     25   const msgSuite = "\x1b[33m…\x1b[0m ";
    24     26   const msgEnd = "\x1b[31m\x1b[5m\x1b[5mBye bye!\x1b[0m";
    25     27   
................................................................................
   163    165   function toTitle(aStr) {
   164    166       return aStr.charAt(0).toUpperCase() + aStr.slice(1);
   165    167   }
   166    168   
   167    169   function repToText(oRep) {
   168    170       //console.log(oRep);
   169    171       let repText = "";
   170         -    for (const action of ["json", "perf", "gceoption", "tfoption", "gcerule"]) {
          172  +    for (const action of ["json", "perf", "gceoption", "tfoption", "gcerule", "dicomain", "dicoperso"]) {
   171    173           if (action in oRep) {
   172    174               repText += toTitle(action) + " " + oRep[action];
   173    175           }
   174    176       }
   175    177   
   176    178       for (const action of ["morph", "lemma"]) {
   177    179           if (action in oRep) {
................................................................................
   411    413   
   412    414       for (const action of ["json", "perf"]) {
   413    415           if (getArg(aArg, [action])) {
   414    416               repPreference[action] = getArgVal(aArg, [action]);
   415    417               repAction[action] = repPreference[action] ? "ON" : "OFF";
   416    418           }
   417    419       }
          420  +
          421  +    if (getArg(aArg, ["dicomain"])) {
          422  +        let filename = sText.endsWith(".json") ? sText : sText + ".json";
          423  +        repAction["dicomain"] = "Chargement du dictionnaire principal " + (oGrammarChecker.setMainDictionary(filename) ? "OK" : "Pas OK");
          424  +    }
          425  +
          426  +    if (getArg(aArg, ["dicoperso"])) {
          427  +        let pathnormalized = path.normalize(sText);
          428  +        if (fs.existsSync(pathnormalized)) {
          429  +            let filename = path.basename(pathnormalized);
          430  +            let dirname = path.dirname(pathnormalized);
          431  +            repAction["dicoperso"] = "Chargement du dictionnaire personnel " + (oGrammarChecker.setPersonalDictionary(filename, dirname) ? "OK" : "Pas OK");
          432  +        } else {
          433  +            repAction["dicoperso"] = "Le fichier de dictionnaire n'existe pas.";
          434  +        }
          435  +    }
   418    436   
   419    437       for (const action of ["gceoption", "tfoption", "gcerule"]) {
   420    438           if (getArg(aArg, [action])) {
   421         -            let sFonction = (action == "gceoption") ? "GceOption" : (action == "tfoption") ? "TfOption" : "GceIgnoreRule";
          439  +            let sFonction = action == "gceoption" ? "GceOption" : action == "tfoption" ? "TfOption" : "GceIgnoreRule";
   422    440               let sOpt = sText.split(" ");
   423    441               if (sOpt[0] == "reset") {
   424    442                   oGrammarChecker["reset" + sFonction + "s"]();
   425    443                   repAction[action] = "reset";
   426    444               } else {
   427    445                   for (const optAction of sOpt) {
   428    446                       let bOptVal = optAction[0] == "+" ? true : false;