16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
-
-
+
+
-
+
+
+
-
-
+
+
-
-
-
+
+
+
-
-
+
-
+
+
+
-
-
+
+
+
+
+
+
-
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
|
}
${map}
const dDefaultDictionaries = new Map([
["fr", "fr.bdic"],
["en", "en.bdic"]
["fr", "fr.json"],
["en", "en.json"]
]);
class Spellchecker {
constructor (sLangCode, sfMainDic="", sfExtendedDic="", sfPersonalDic="") {
constructor (sLangCode, mainDic=null, extentedDic=null, personalDic=null, sPath="") {
// returns true if the main dictionary is loaded
this.sLangCode = sLangCode;
console.log(sLangCode);
console.log(mainDic);
if (sfMainDic === "") {
sfMainDic = dDefaultDictionaries.gl_get(sLangCode, "");
if (mainDic === null) {
mainDic = dDefaultDictionaries.gl_get(sLangCode, "");
}
this.oMainDic = this._loadDictionary(sfMainDic);
this.oExtendedDic = this._loadDictionary(sfExtendedDic);
this.oPersonalDic = this._loadDictionary(sfPersonalDic);
this.oMainDic = this._loadDictionary(mainDic, sPath, true);
this.oExtendedDic = this._loadDictionary(extentedDic, sPath);
this.oPersonalDic = this._loadDictionary(personalDic, sPath);
return bool(this.oMainDic);
}
_loadDictionary (sfDictionary) {
_loadDictionary (dictionary, sPath, bNecessary=false) {
// returns an IBDAWG object
if (sfDictionary === "") {
if (dictionary === null) {
return null;
}
try {
if (typeof(require) !== 'undefined') {
console.log(">>>> <resource:>");
return ibdawg.IBDAWG(sfDictionary);
}
return new ibdawg.IBDAWG(dictionary); // dictionary can be a filename or a JSON object
} else {
console.log(">>>> no <resource:>");
return new IBDAWG(dictionary, sPath); // dictionary can be a filename or a JSON object
}
}
catch (e) {
console.log("Error: <" + sDicName + "> not loaded.");
if (bNecessary) {
throw e.message;
}
console.log(e.message);
return null;
}
}
setMainDictionary (sfDictionary) {
setMainDictionary (dictionary) {
// returns true if the dictionary is loaded
this.oMainDic = this._loadDictionary(sfDictionary);
this.oMainDic = this._loadDictionary(dictionary);
return bool(this.oMainDic);
}
setExtendedDictionary (sfDictionary) {
setExtendedDictionary (dictionary) {
// returns true if the dictionary is loaded
this.oExtendedDic = this._loadDictionary(sfDictionary);
this.oExtendedDic = this._loadDictionary(dictionary);
return bool(this.oExtendedDic);
}
setPersonalDictionary (sfDictionary) {
setPersonalDictionary (dictionary) {
// returns true if the dictionary is loaded
this.oPersonalDic = this._loadDictionary(sfDictionary);
this.oPersonalDic = this._loadDictionary(dictionary);
return bool(this.oPersonalDic);
}
// IBDAWG functions
isValidToken (sToken) {
// checks if sToken is valid (if there is hyphens in sToken, sToken is split, each part is checked)
|
146
147
148
149
150
151
152
|
155
156
157
158
159
160
161
162
163
164
165
|
+
+
+
+
|
yield* this.oExtendedDic.select(sPattern);
}
if (this.oPersonalDic) {
yield* this.oPersonalDic.select(sPattern);
}
}
}
if (typeof(exports) !== 'undefined') {
exports.Spellchecker = Spellchecker;
}
|