Grammalecte  Check-in [8959d8c2be]

Overview
Comment:[njs] core add Set Dictionary for main and personal
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | nodejs
Files: files | file ages | folders
SHA3-256: 8959d8c2beb0cdba291c52be10a34c82a45af3fce370ddca211bd28c21419028
User & Date: IllusionPerdu on 2018-10-21 21:45:37
Other Links: branch diff | manifest | tags
Context
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
17:31
[njs] Cli update doc with new command check-in: c4df2bb8f2 user: IllusionPerdu tags: nodejs
Changes

Modified gc_lang/fr/nodejs/core/api.js from [83bcbb9eeb] to [df78933803].

     6      6   /* jshint esversion:6, -W097 */
     7      7   /* jslint esversion:6 */
     8      8   /* global require, exports, console */
     9      9   
    10     10   "use strict";
    11     11   
    12     12   class GrammarChecker {
    13         -
    14     13       constructor(aInit, sLangCode = "fr", sContext = "Javascript") {
    15     14           this.sLangCode = sLangCode;
    16     15           this.sContext = sContext;
    17     16   
    18     17           //Importation des fichiers nécessaire
    19     18           this.sPathRoot = __dirname + "/grammalecte";
    20     19           this._helpers = require(this.sPathRoot + "/graphspell/helpers.js");
................................................................................
    23     22               Grammalecte: false,
    24     23               Graphspell: false,
    25     24               Tokenizer: false,
    26     25               TextFormatter: false,
    27     26               Lexicographer: false
    28     27           };
    29     28   
    30         -        if (aInit){
           29  +        if (aInit) {
    31     30               this.load(aInit);
    32     31           }
    33     32       }
    34     33   
    35     34       //Auto-chargement avec dépendence
    36         -    load(aInit = ["Grammalecte", "Graphspell", "TextFormatter", "Lexicographer", "Tokenizer"]){
           35  +    load(aInit = ["Grammalecte", "Graphspell", "TextFormatter", "Lexicographer", "Tokenizer"]) {
    37     36           //aInit permet de charger que certain composant
    38     37           // => évite de charger toutes données si par exemple on a besoin que du lexigraphe
    39     38           // => sorte de gestionnaire de dépendence (peut être amélioré)
    40     39           this.isInit = {};
    41         -        if ( aInit.indexOf("Grammalecte") !== false ){
           40  +        if (aInit.indexOf("Grammalecte") !== false) {
    42     41               //console.log('init Grammalecte');
    43     42               this._oGce = require(this.sPathRoot + "/fr/gc_engine.js");
    44     43               this._oGce.load(this.sContext);
    45     44               this.isInit.Grammalecte = true;
    46     45               this.oSpellChecker = this._oGce.getSpellChecker();
    47     46               this.isInit.Graphspell = true;
    48     47               this.oTokenizer = this.oSpellChecker.getTokenizer();
    49     48               this.isInit.Tokenizer = true;
    50     49           }
    51     50   
    52         -        if ( !this.isInit.Graphspell && (aInit.indexOf("Graphspell") !== false || aInit.indexOf("Lexicographer") !== false)){
           51  +        if (!this.isInit.Graphspell && (aInit.indexOf("Graphspell") !== false || aInit.indexOf("Lexicographer") !== false)) {
    53     52               //console.log('init Graphspell');
    54     53               this._SpellChecker = require(this.sPathRoot + "/graphspell/spellchecker.js");
    55     54               this.oSpellChecker = new this._SpellChecker.SpellChecker(this.sLangCode, this.sPathRoot + "/graphspell/_dictionaries");
    56     55               this.isInit.Graphspell = true;
    57     56               this.oTokenizer = this.oSpellChecker.getTokenizer();
    58     57               this.isInit.Tokenizer = true;
    59     58           }
    60     59   
    61         -        if ( !this.isInit.Tokenizer && aInit.indexOf("Tokenizer") !== false ){
           60  +        if (!this.isInit.Tokenizer && aInit.indexOf("Tokenizer") !== false) {
    62     61               //console.log('init Tokenizer');
    63     62               this._Tokenizer = require(this.sPathRoot + "/graphspell/tokenizer.js");
    64     63               this.oTokenizer = new this._Tokenizer.Tokenizer(this.sLangCode);
    65     64               this.isInit.Tokenizer = true;
    66     65           }
    67     66   
    68         -        if ( aInit.indexOf("TextFormatter") !== false ){
           67  +        if (aInit.indexOf("TextFormatter") !== false) {
    69     68               //console.log('init TextFormatter');
    70     69               this._oText = require(this.sPathRoot + "/fr/textformatter.js");
    71     70               this.oTextFormatter = new this._oText.TextFormatter();
    72     71               this.isInit.TextFormatter = true;
    73     72           }
    74     73   
    75         -        if ( aInit.indexOf("Lexicographer") !== false ){
           74  +        if (aInit.indexOf("Lexicographer") !== false) {
    76     75               //console.log('init Lexicographer');
    77     76               this._oLex = require(this.sPathRoot + "/fr/lexicographe.js");
    78     77               this.oLexicographer = new this._oLex.Lexicographe(
    79     78                   this.oSpellChecker,
    80     79                   this.oTokenizer,
    81     80                   this._helpers.loadFile(this.sPathRoot + "/fr/locutions_data.json")
    82     81               );
    83     82               this.isInit.Lexicographer = true;
    84     83           }
    85     84       }
    86     85   
    87     86       //Fonctions concernant: Grammalecte
    88         -    getGrammalecte(){
           87  +    getGrammalecte() {
    89     88           if (!this.isInit.Grammalecte) {
    90     89               this.load(["Grammalecte"]);
    91     90           }
    92     91           return this._oGce;
    93     92       }
    94     93   
    95         -    gramma(sText){
           94  +    gramma(sText) {
    96     95           if (!this.isInit.Grammalecte) {
    97     96               this.load(["Grammalecte"]);
    98     97           }
    99     98           return Array.from(this._oGce.parse(sText, this.sLangCode));
   100     99       }
   101    100   
   102         -    getGceOptions () {
          101  +    getGceOptions() {
   103    102           if (!this.isInit.Grammalecte) {
   104    103               this.load(["Grammalecte"]);
   105    104           }
   106    105           return this._helpers.mapToObject(this._oGce.getOptions());
   107    106       }
   108    107   
   109         -    getGceDefaultOptions () {
          108  +    getGceDefaultOptions() {
   110    109           if (!this.isInit.Grammalecte) {
   111    110               this.load(["Grammalecte"]);
   112    111           }
   113    112           return this._helpers.mapToObject(this._oGce.getDefaultOptions());
   114    113       }
   115    114   
   116         -    setGceOptions (dOptions) {
          115  +    setGceOptions(dOptions) {
   117    116           if (!this.isInit.Grammalecte) {
   118    117               this.load(["Grammalecte"]);
   119    118           }
   120    119           if (!(dOptions instanceof Map)) {
   121    120               dOptions = this._helpers.objectToMap(dOptions);
   122    121           }
   123    122           this._oGce.setOptions(dOptions);
   124    123           return this._helpers.mapToObject(this._oGce.getOptions());
   125    124       }
   126    125   
   127         -    setGceOption (sOptName, bValue) {
          126  +    setGceOption(sOptName, bValue) {
   128    127           if (!this.isInit.Grammalecte) {
   129    128               this.load(["Grammalecte"]);
   130    129           }
   131    130           if (sOptName) {
   132    131               this._oGce.setOption(sOptName, bValue);
   133    132               return this._helpers.mapToObject(this._oGce.getOptions());
   134    133           }
   135    134           return false;
   136    135       }
   137    136   
   138         -    resetGceOptions () {
          137  +    resetGceOptions() {
   139    138           if (!this.isInit.Grammalecte) {
   140    139               this.load(["Grammalecte"]);
   141    140           }
   142    141           this._oGce.resetOptions();
   143    142           return this._helpers.mapToObject(this._oGce.getOptions());
   144    143       }
   145    144   
   146         -    getGceRules (bParagraph) {
          145  +    getGceRules(bParagraph) {
   147    146           if (!this.isInit.Grammalecte) {
   148    147               this.load(["Grammalecte"]);
   149    148           }
   150    149           return this._oGce.getRules(bParagraph);
   151    150       }
   152    151   
   153         -    getGceIgnoreRules () {
          152  +    getGceIgnoreRules() {
   154    153           if (!this.isInit.Grammalecte) {
   155    154               this.load(["Grammalecte"]);
   156    155           }
   157    156           return Array.from(this._oGce.getIgnoreRules());
   158    157       }
   159    158   
   160         -    setGceIgnoreRules (dRules) {
          159  +    setGceIgnoreRules(dRules) {
   161    160           if (!this.isInit.Grammalecte) {
   162    161               this.load(["Grammalecte"]);
   163    162           }
   164    163           if (!(dRules instanceof Set)) {
   165    164               dRules = new Set(dRules);
   166    165           }
   167    166           this._oGce._aIgnoredRules = dRules;
   168    167           return Array.from(this._oGce.getIgnoreRules());
   169    168       }
   170    169   
   171         -    setGceIgnoreRule (sRuleId, bValue) {
          170  +    setGceIgnoreRule(sRuleId, bValue) {
   172    171           if (!this.isInit.Grammalecte) {
   173    172               this.load(["Grammalecte"]);
   174    173           }
   175         -        if (bValue){ //Add
          174  +        if (bValue) {
          175  +            //Add
   176    176               this._oGce.ignoreRule(sRuleId);
   177         -        } else {     //Delete
          177  +        } else {
          178  +            //Delete
   178    179               this._oGce.reactivateRule(sRuleId);
   179    180           }
   180    181           return Array.from(this._oGce.getIgnoreRules());
   181    182       }
   182    183   
   183         -    resetGceIgnoreRules () {
          184  +    resetGceIgnoreRules() {
   184    185           if (!this.isInit.Grammalecte) {
   185    186               this.load(["Grammalecte"]);
   186    187           }
   187    188           this._oGce.resetIgnoreRules();
   188    189           return Array.from(this._oGce.getIgnoreRules());
   189    190       }
   190    191   
   191    192       //Fonctions concernant: Graphspell
   192         -    getGraphspell(){
          193  +    getGraphspell() {
   193    194           if (!this.isInit.Graphspell) {
   194    195               this.load(["Graphspell"]);
   195    196           }
   196    197           return this.oSpellChecker;
   197    198       }
   198    199   
   199         -    spellParagraph(sText, bSuggest = true){
          200  +    setMainDictionary(dictionary, sPath = "") {
          201  +        return this.oSpellChecker.setMainDictionary(dictionary, sPath);
          202  +    }
          203  +
          204  +    setPersonalDictionary(dictionary, sPath = "", bActivate = true) {
          205  +        return this.oSpellChecker.setPersonalDictionary(dictionary, sPath, bActivate);
          206  +    }
          207  +
          208  +    spellParagraph(sText, bSuggest = true) {
   200    209           if (!this.isInit.Graphspell) {
   201    210               this.load(["Graphspell"]);
   202    211           }
   203         -        if (bSuggest){
          212  +        if (bSuggest) {
   204    213               let lError = this.oSpellChecker.parseParagraph(sText);
   205    214               for (let token of lError) {
   206    215                   token.aSuggestions = this.suggest(token.sValue);
   207    216               }
   208    217               return lError;
   209    218           } else {
   210    219               return this.oSpellChecker.parseParagraph(sText);
   211    220           }
   212    221       }
   213    222   
   214         -    spell(sWord){
          223  +    spell(sWord) {
   215    224           if (!this.isInit.Graphspell) {
   216    225               this.load(["Graphspell"]);
   217    226           }
   218    227           return this.oSpellChecker.isValid(sWord);
   219    228       }
   220    229   
   221         -    suggest(sWord, nbLimit = 10, bMerge = true){
          230  +    suggest(sWord, nbLimit = 10, bMerge = true) {
   222    231           if (!this.isInit.Graphspell) {
   223    232               this.load(["Graphspell"]);
   224    233           }
   225    234           let lSuggest = this.oSpellChecker.suggest(sWord, nbLimit);
   226         -        if (bMerge){
          235  +        if (bMerge) {
   227    236               let lSuggestRep = [];
   228    237               for (let lSuggestTmp of lSuggest) {
   229    238                   for (let word of lSuggestTmp) {
   230    239                       lSuggestRep.push(word);
   231    240                   }
   232    241               }
   233    242               return lSuggestRep;
   234    243           } else {
   235    244               return Array.from(lSuggest);
   236    245           }
   237         -
   238    246       }
   239    247   
   240         -    lemma(sWord){
          248  +    lemma(sWord) {
   241    249           if (!this.isInit.Graphspell) {
   242    250               this.load(["Graphspell"]);
   243    251           }
   244    252           return this.oSpellChecker.getLemma(sWord);
   245    253       }
   246    254   
   247         -    morph(sWord){
          255  +    morph(sWord) {
   248    256           if (!this.isInit.Graphspell) {
   249    257               this.load(["Graphspell"]);
   250    258           }
   251    259           return this.oSpellChecker.getMorph(sWord);
   252    260       }
   253    261   
   254    262       //Fonctions concernant: Lexicographer
   255         -    getLexicographer(){
          263  +    getLexicographer() {
   256    264           if (!this.isInit.Lexicographer) {
   257    265               this.load(["Lexicographer"]);
   258    266           }
   259    267           return this.oLexicographer;
   260    268       }
   261    269   
   262         -    lexique(sText){
          270  +    lexique(sText) {
   263    271           if (!this.isInit.Lexicographer) {
   264    272               this.load(["Lexicographer"]);
   265    273           }
   266    274           return this.oLexicographer.getListOfTokensReduc(sText);
   267    275       }
   268    276   
   269    277       //Fonctions concernant: TextFormatter
   270         -    getTextFormatter(){
          278  +    getTextFormatter() {
   271    279           if (!this.isInit.TextFormatter) {
   272    280               this.load(["TextFormatter"]);
   273    281           }
   274    282           return this.oTextFormatter;
   275    283       }
   276    284   
   277         -    formatText(sText){
          285  +    formatText(sText) {
   278    286           if (!this.isInit.TextFormatter) {
   279    287               this.load(["TextFormatter"]);
   280    288           }
   281    289           return this.oTextFormatter.formatText(sText);
   282    290       }
   283    291   
   284    292       setTfOptions(dOptions) {
................................................................................
   307    315           }
   308    316           let optionsTF = this.oTextFormatter.getDefaultOptions();
   309    317           this.oTextFormatter.setOptions(optionsTF);
   310    318           return this._helpers.mapToObject(this.oTextFormatter.getOptions());
   311    319       }
   312    320   
   313    321       //fonctions concernant plussieurs parties
   314         -    verifParagraph(sText, bSuggest = true){
          322  +    verifParagraph(sText, bSuggest = true) {
   315    323           if (!this.isInit.Grammalecte || !this.isInit.Graphspell) {
   316    324               this.load(["Grammalecte"]);
   317    325           }
   318    326           return {
   319    327               lGrammarErrors: Array.from(this._oGce.parse(sText, this.sLangCode)),
   320    328               lSpellingErrors: this.spellParagraph(sText, bSuggest)
   321    329           };
   322    330       }
   323         -
   324    331   }
   325    332   
   326    333   if (typeof exports !== "undefined") {
   327    334       exports.GrammarChecker = GrammarChecker;
   328    335   }