12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
+
+
|
/* global require, exports, console, IBDAWG, Tokenizer */
"use strict";
if(typeof(process) !== 'undefined') {
var ibdawg = require("./ibdawg.js");
var tokenizer = require("./tokenizer.js");
var suggest = require("./suggest.js");
} else if (typeof(require) !== 'undefined') {
var ibdawg = require("resource://grammalecte/graphspell/ibdawg.js");
var tokenizer = require("resource://grammalecte/graphspell/tokenizer.js");
var suggest = require("resource://grammalecte/graphspell/suggest.js");
}
${map}
const dDefaultDictionaries = new Map([
["fr", "fr-allvars.json"],
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
+
+
+
|
}
this.oMainDic = this._loadDictionary(mainDic, sPath, true);
this.oCommunityDic = this._loadDictionary(communityDic, sPath);
this.oPersonalDic = this._loadDictionary(personalDic, sPath);
this.bCommunityDic = Boolean(this.oCommunityDic);
this.bPersonalDic = Boolean(this.oPersonalDic);
this.oTokenizer = null;
// Default suggestions
this.oDefaultSugg = null;
this.loadSuggestions(sLangCode)
// storage
this.bStorage = false;
this._dMorphologies = new Map(); // key: flexion, value: list of morphologies
this._dLemmas = new Map(); // key: flexion, value: list of lemmas
}
_loadDictionary (dictionary, sPath="", bNecessary=false) {
|
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
+
+
+
+
+
+
+
+
+
+
+
|
this.bCommunityDic = false;
}
deactivatePersonalDictionary () {
this.bPersonalDic = false;
}
// Default suggestions
loadSuggestions (sLangCode) {
// load default suggestion module for <sLangCode>
// When “import” works everywhere, do like with Python
if (suggest && suggest.hasOwnProperty(sLangCode)) {
this.oDefaultSugg = suggest[sLangCode];
}
}
// Storage
activateStorage () {
this.bStorage = true;
}
|
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
+
+
+
+
+
+
+
-
+
+
+
+
+
|
return this._dLemmas.get(sWord);
}
return Array.from(new Set(this.getMorph(sWord).map((sMorph) => { return sMorph.slice(1, sMorph.indexOf("/")); })));
}
* suggest (sWord, nSuggLimit=10) {
// generator: returns 1, 2 or 3 lists of suggestions
if (this.oDefaultSugg) {
if (this.oDefaultSugg.hasOwnProperty(sWord)) {
yield this.oDefaultSugg[sWord].split("|");
} else if (sWord.gl_isTitle() && this.oDefaultSugg.hasOwnProperty(sWord.lower())) {
let lRes = this.oDefaultSugg[sWord.toLowerCase()].split("|");
yield lRes.map((sSugg) => { return sSugg.slice(0,1).toUpperCase() + sSugg.slice(1); });
} else {
yield this.oMainDic.suggest(sWord, nSuggLimit, true);
yield this.oMainDic.suggest(sWord, nSuggLimit, true);
}
} else {
yield this.oMainDic.suggest(sWord, nSuggLimit, true);
}
if (this.bCommunityDic) {
yield this.oCommunityDic.suggest(sWord, Math.floor(nSuggLimit/2)+1);
}
if (this.bPersonalDic) {
yield this.oPersonalDic.suggest(sWord, Math.floor(nSuggLimit/2)+1);
}
}
|