130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
// Lexicographer
loadLexicographer (sLangCode) {
// load default suggestion module for <sLangCode>
if (typeof(process) !== 'undefined') {
this.lexicographer = require(`./lexgraph_${sLangCode}.js`);
}
else if (self && self.hasOwnProperty("lexgraph_"+sLangCode)) { // self is the Worker
this.lexicographer = self["lexgraph_"+sLangCode];
}
}
else if (typeof(require) !== 'undefined') {
this.lexicographer = require(`resource://grammalecte/graphspell/lexgraph_${sLangCode}.js`);
analyze (sWord) {
// returns a list of words and their morphologies
if (!this.lexicographer) {
return [];
}
let lWordAndMorph = [];
for (let sElem of this.lexicographer.split(sWord)) {
if (sElem) {
let lMorph = this.getMorph(sElem);
let sLex = this.lexicographer.analyze(sElem)
let aRes = [];
if (sLex) {
aRes = [ [lMorph.join(" | "), sLex] ];
} else {
for (let sMorph of lMorph) {
aRes.push([sMorph, this.lexicographer.formatTags(sMorph)]);
}
}
if (aRes.length > 0) {
lWordAndMorph.push([sElem, aRes]);
}
}
}
return lWordAndMorph;
}
readableMorph (sMorph) {
if (!this.lexicographer) {
return [];
}
return this.lexicographer.formatTags(sMorph);
}
setLabelsOnToken (oToken) {
if (!this.lexicographer) {
return;
}
if (!oToken.hasOwnProperty("lMorph")) {
oToken["lMorph"] = this.getMorph(oToken["sValue"]);
}
if (oToken["sType"] == "WORD") {
oToken["bValidToken"] = this.isValidToken(oToken["sValue"]);
let [sPrefix, sStem, sSuffix] = this.lexicographer.split(oToken["sValue"]);
if (sStem != oToken["sValue"]) {
oToken["lSubTokens"] = [
{ "sType": "WORD", "sValue": sPrefix, "lMorph": this.getMorph(sPrefix) },
{ "sType": "WORD", "sValue": sStem, "lMorph": this.getMorph(sStem) },
{ "sType": "WORD", "sValue": sSuffix, "lMorph": this.getMorph(sSuffix) }
];
}
}
this.lexicographer.setLabelsOnToken(oToken);
}
// Storage
activateStorage () {
this.bStorage = true;
|