︙ | | | ︙ | |
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
/* jshint esversion:6, -W097 */
/* jslint esversion:6 */
/* 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"],
|
|
<
>
|
<
|
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
/* jshint esversion:6, -W097 */
/* jslint esversion:6 */
/* global require, exports, console, IBDAWG, Tokenizer */
"use strict";
if (typeof(process) !== 'undefined') {
var ibdawg = require("./ibdawg.js");
var tokenizer = require("./tokenizer.js");
}
else if (typeof(require) !== 'undefined') {
var ibdawg = require("resource://grammalecte/graphspell/ibdawg.js");
var tokenizer = require("resource://grammalecte/graphspell/tokenizer.js");
}
${map}
const dDefaultDictionaries = new Map([
["fr", "fr-allvars.json"],
|
︙ | | | ︙ | |
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.dDefaultSugg = 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) {
|
|
|
|
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
}
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;
// Lexicographer
this.lexicographer = null;
this.loadLexicographer(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) {
|
︙ | | | ︙ | |
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
}
deactivatePersonalDictionary () {
this.bPersonalDic = false;
}
// Default suggestions
loadSuggestions (sLangCode) {
// load default suggestion module for <sLangCode>
// When “import” works everywhere, do like with Python
try {
if (typeof(suggest) !== 'undefined') {
this.dDefaultSugg = suggest[sLangCode];
}
}
catch (e) {
console.error(e);
}
}
// Storage
activateStorage () {
|
|
|
<
<
|
|
|
>
>
|
|
>
|
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
}
deactivatePersonalDictionary () {
this.bPersonalDic = false;
}
// Lexicographer
loadLexicographer (sLangCode) {
// load default suggestion module for <sLangCode>
if (typeof(process) !== 'undefined') {
this.lexicographer = require(`./lexgraph_${sLangCode}.js`);
}
else if (typeof(require) !== 'undefined') {
this.lexicographer = require(`resource://grammalecte/graphspell/lexgraph_${sLangCode}.js`);
}
else if (self.hasOwnProperty("lexgraph_"+sLangCode)) {
console.log(self);
this.lexicographer = self["lexgraph_"+sLangCode];
}
}
// Storage
activateStorage () {
|
︙ | | | ︙ | |
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
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.dDefaultSugg) {
if (this.dDefaultSugg.has(sWord)) {
yield this.dDefaultSugg.get(sWord).split("|");
} else if (sWord.gl_isTitle() && this.dDefaultSugg.has(sWord.toLowerCase())) {
let lRes = this.dDefaultSugg.get(sWord.toLowerCase()).split("|");
yield lRes.map((sSugg) => { return sSugg.slice(0,1).toUpperCase() + sSugg.slice(1); });
} else {
yield this.oMainDic.suggest(sWord, nSuggLimit, true);
}
} else {
yield this.oMainDic.suggest(sWord, nSuggLimit, true);
}
|
|
|
|
|
|
|
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
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.lexicographer) {
if (this.lexicographer.dSugg.has(sWord)) {
yield this.lexicographer.dSugg.get(sWord).split("|");
} else if (sWord.gl_isTitle() && this.lexicographer.dSugg.has(sWord.toLowerCase())) {
let lRes = this.lexicographer.dSugg.get(sWord.toLowerCase()).split("|");
yield lRes.map((sSugg) => { return sSugg.slice(0,1).toUpperCase() + sSugg.slice(1); });
} else {
yield this.oMainDic.suggest(sWord, nSuggLimit, true);
}
} else {
yield this.oMainDic.suggest(sWord, nSuggLimit, true);
}
|
︙ | | | ︙ | |