1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
+
+
+
|
/*
! Grammalecte, grammar checker !
API pour faciliter l'utilisation de Grammalecte.
*/
/* jshint esversion:6, -W097 */
/* jslint esversion:6 */
/* global require, exports, console */
"use strict";
const path = require("path");
const fs = require("fs");
class GrammarChecker {
constructor(aInit, sLangCode = "fr", sContext = "Javascript") {
this.sLangCode = sLangCode;
this.sContext = sContext;
//Importation des fichiers nécessaire
this.sPathRoot = __dirname + "/grammalecte";
|
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
196
197
198
199
200
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
getGraphspell() {
if (!this.isInit.Graphspell) {
this.load(["Graphspell"]);
}
return this.oSpellChecker;
}
setMainDictionary(dictionary, sPath = "") {
return this.oSpellChecker.setMainDictionary(dictionary, sPath);
}
setPersonalDictionary(dictionary, sPath = "", bActivate = true) {
return this.oSpellChecker.setPersonalDictionary(dictionary, sPath, bActivate);
setMainDictionary(dictionary) {
if (typeof dictionary == "string") {
let pathnormalized = path.normalize(dictionary);
if (pathnormalized == "fr-allvars" || pathnormalized == "fr-classic" || pathnormalized == "fr-reform") {
pathnormalized = path.normalize(this.sPathRoot + "/graphspell/_dictionaries/" + pathnormalized);
}
pathnormalized = !pathnormalized.endsWith(".json") ? pathnormalized + ".json" : pathnormalized;
if (fs.existsSync(pathnormalized)) {
let filename = path.basename(pathnormalized);
let dirname = path.dirname(pathnormalized);
return this.oSpellChecker.setMainDictionary(filename, dirname);
}
return false;
}
//It's a valid json?
if (typeof dictionary !== "undefined" && dictionary.sHeader && dictionary.sHeader.startsWith("/grammalecte-fsa/")) {
return this.oSpellChecker.setMainDictionary(dictionary);
}
return false;
}
setPersonalDictionary(dictionary, bActivate = true) {
if (typeof dictionary == "string") {
let pathnormalized = path.normalize(dictionary);
pathnormalized = !pathnormalized.endsWith(".json") ? pathnormalized + ".json" : pathnormalized;
if (fs.existsSync(pathnormalized)) {
let filename = path.basename(pathnormalized);
let dirname = path.dirname(pathnormalized);
return this.oSpellChecker.setPersonalDictionary(filename, dirname, bActivate);
}
return false;
}
//It's a valid json?
if (typeof dictionary !== "undefined" && dictionary.sHeader && dictionary.sHeader.startsWith("/grammalecte-fsa/")) {
return this.oSpellChecker.setPersonalDictionary(dictionary, bActivate);
}
return false;
}
spellParagraph(sText, bSuggest = true) {
if (!this.isInit.Graphspell) {
this.load(["Graphspell"]);
}
if (bSuggest) {
|