1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
// Spellchecker
// Wrapper for the IBDAWG class.
// Useful to check several dictionaries at once.
// To avoid iterating over a pile of dictionaries, it is assumed that 3 are enough:
// - the main dictionary, bundled with the package
// - the extended dictionary
// - the community dictionary, added by an organization
// - the personal dictionary, created by the user for its own convenience
"use strict";
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"],
["en", "en.json"]
|
>
>
>
|
>
>
|
<
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
// Spellchecker
// Wrapper for the IBDAWG class.
// Useful to check several dictionaries at once.
// To avoid iterating over a pile of dictionaries, it is assumed that 3 are enough:
// - the main dictionary, bundled with the package
// - the extended dictionary
// - the community dictionary, added by an organization
// - the personal dictionary, created by the user for its own convenience
/* 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"],
["en", "en.json"]
|
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
}
}
catch (e) {
let sfDictionary = (typeof(dictionary) == "string") ? dictionary : dictionary.sLangName + "/" + dictionary.sFileName;
if (bNecessary) {
throw "Error: <" + sfDictionary + "> not loaded. " + e.message;
}
console.log("Error: <" + sfDictionary + "> not loaded.")
console.log(e.message);
return null;
}
}
loadTokenizer () {
if (typeof(tokenizer) !== 'undefined') {
|
|
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
}
}
catch (e) {
let sfDictionary = (typeof(dictionary) == "string") ? dictionary : dictionary.sLangName + "/" + dictionary.sFileName;
if (bNecessary) {
throw "Error: <" + sfDictionary + "> not loaded. " + e.message;
}
console.log("Error: <" + sfDictionary + "> not loaded.");
console.log(e.message);
return null;
}
}
loadTokenizer () {
if (typeof(tokenizer) !== 'undefined') {
|
193
194
195
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
|
// checks if sWord is valid (different casing tested if the first letter is a capital)
if (this.oMainDic.isValid(sWord)) {
return true;
}
if (this.bExtendedDic && this.oExtendedDic.isValid(sWord)) {
return true;
}
if (this.bCommunityDic && this.oCommunityDic.isValid(sToken)) {
return true;
}
if (this.bPersonalDic && this.oPersonalDic.isValid(sWord)) {
return true;
}
return false;
}
lookup (sWord) {
// checks if sWord is in dictionary as is (strict verification)
if (this.oMainDic.lookup(sWord)) {
return true;
}
if (this.bExtendedDic && this.oExtendedDic.lookup(sWord)) {
return true;
}
if (this.bCommunityDic && this.oCommunityDic.lookup(sToken)) {
return true;
}
if (this.bPersonalDic && this.oPersonalDic.lookup(sWord)) {
return true;
}
return false;
}
|
|
|
|
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
|
// checks if sWord is valid (different casing tested if the first letter is a capital)
if (this.oMainDic.isValid(sWord)) {
return true;
}
if (this.bExtendedDic && this.oExtendedDic.isValid(sWord)) {
return true;
}
if (this.bCommunityDic && this.oCommunityDic.isValid(sWord)) {
return true;
}
if (this.bPersonalDic && this.oPersonalDic.isValid(sWord)) {
return true;
}
return false;
}
lookup (sWord) {
// checks if sWord is in dictionary as is (strict verification)
if (this.oMainDic.lookup(sWord)) {
return true;
}
if (this.bExtendedDic && this.oExtendedDic.lookup(sWord)) {
return true;
}
if (this.bCommunityDic && this.oCommunityDic.lookup(sWord)) {
return true;
}
if (this.bPersonalDic && this.oPersonalDic.lookup(sWord)) {
return true;
}
return false;
}
|
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
if (this.bPersonalDic) {
yield this.oPersonalDic.suggest(sWord, nSuggLimit);
}
}
* select (sFlexPattern="", sTagsPattern="") {
// generator: returns all entries which flexion fits <sFlexPattern> and morphology fits <sTagsPattern>
yield* this.oMainDic.select(sFlexPattern, sTagsPattern)
if (this.bExtendedDic) {
yield* this.oExtendedDic.select(sFlexPattern, sTagsPattern);
}
if (this.bCommunityDic) {
yield* this.oCommunityDic.select(sFlexPattern, sTagsPattern);
}
if (this.bPersonalDic) {
|
|
|
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
if (this.bPersonalDic) {
yield this.oPersonalDic.suggest(sWord, nSuggLimit);
}
}
* select (sFlexPattern="", sTagsPattern="") {
// generator: returns all entries which flexion fits <sFlexPattern> and morphology fits <sTagsPattern>
yield* this.oMainDic.select(sFlexPattern, sTagsPattern);
if (this.bExtendedDic) {
yield* this.oExtendedDic.select(sFlexPattern, sTagsPattern);
}
if (this.bCommunityDic) {
yield* this.oCommunityDic.select(sFlexPattern, sTagsPattern);
}
if (this.bPersonalDic) {
|