Overview
Comment: | [graphspell] better quicker spelling suggestions: check 2grams existence |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk | graphspell |
Files: | files | file ages | folders |
SHA3-256: |
f3f1cc9e3090ebc5b7e59c28517cb6cc |
User & Date: | olr on 2018-10-06 13:46:58 |
Other Links: | manifest | tags |
Context
2018-10-09
| ||
08:54 | [graphspell][js] performance tests check-in: 14ed269c7c user: olr tags: trunk, graphspell | |
2018-10-06
| ||
13:46 | [graphspell] better quicker spelling suggestions: check 2grams existence check-in: f3f1cc9e30 user: olr tags: trunk, graphspell | |
13:46 | [fr] passation de pouvoir check-in: 4292f525f4 user: olr tags: trunk, fr | |
Changes
Modified graphspell-js/dawg.js from [711ba29b0e] to [d94e6b7163].
1 2 3 4 5 6 7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | - + | // JavaScript // FSA DICTIONARY BUILDER // // by Olivier R. // License: MPL 2 // |
︙ | |||
37 38 39 40 41 42 43 | 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 | - + - + + + + + + | case "S": funcStemmingGen = str_transform.defineSuffixCode; break; case "N": funcStemmingGen = str_transform.noStemming; break; default: throw "Error. Unknown stemming code: " + cStemming; } |
︙ | |||
80 81 82 83 84 85 86 | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | - + - + | if (lEntry.length == 0) { throw "Error. Empty lexicon"; } lEntry = [...new Set(lEntry.map(e => JSON.stringify(e)))].map(s => JSON.parse(s)); // Set can’t distinguish similar lists, so we transform list item in string given to the Set // then we transform items in list a new. |
︙ | |||
129 130 131 132 133 134 135 | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | - + | if (cStemming == "A") { this.funcStemming = str_transform.changeWordWithAffixCode; } else if (cStemming == "S") { this.funcStemming = str_transform.changeWordWithSuffixCode; } else { this.funcStemming = str_transform.noStemming; } |
︙ | |||
218 219 220 221 222 223 224 | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | - + | countArcs () { this.nArc = 0; for (let oNode of this.dMinimizedNodes.values()) { this.nArc += oNode.arcs.size; } } |
︙ | |||
271 272 273 274 275 276 277 278 279 280 281 282 283 284 | 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | + | console.log("Entries: " + this.nEntry); console.log("Characters: " + this.nChar); console.log("Affixes: " + this.nAff); console.log("Tags: " + this.nTag); console.log("Arc values: " + this.nArcVal); console.log("Nodes: " + this.nNode); console.log("Arcs: " + this.nArc); console.log("2grams: " + this.a2grams.size); console.log("Stemming: " + this.cStemming + "FX"); } getArcStats () { let d = new Map(); for (let oNode of this.dMinimizedNodes.values()) { let n = oNode.arcs.size; |
︙ | |||
392 393 394 395 396 397 398 | 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | - + + | "nArc": this.nArc, "lArcVal": this.lArcVal, "nArcVal": this.nArcVal, "nCompressionMethod": nCompressionMethod, "nBytesArc": this.nBytesArc, "nBytesNodeAddress": this.nBytesNodeAddress, "nBytesOffset": this.nBytesOffset, |
︙ | |||
484 485 486 487 488 489 490 | 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | - + | // VERSION 1 ===================================================================================================== convToBytes1 (nBytesArc, nBytesNodeAddress) { /* Node scheme: - Arc length is defined by nBytesArc - Address length is defined by nBytesNodeAddress |
︙ |
Modified graphspell-js/ibdawg.js from [b8f88a2609] to [c786a97f15].
︙ | |||
44 45 46 47 48 49 50 | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | - + | this.dSugg.set(nDist, []); } this.dSugg.get(nDist).push(sSugg); this.aSugg.add(sSugg); if (nDist < this.nMinDist) { this.nMinDist = nDist; } |
︙ | |||
135 136 137 138 139 140 141 142 143 144 145 146 147 148 | 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | + | } if (!(this.nCompressionMethod == 1 || this.nCompressionMethod == 2 || this.nCompressionMethod == 3)) { throw RangeError("# Error. Unknown dictionary compression method: " + this.nCompressionMethod); } // <dChar> to get the value of an arc, <dCharVal> to get the char of an arc with its value this.dChar = helpers.objectToMap(this.dChar); this.dCharVal = this.dChar.gl_reverse(); this.a2grams = new Set(this.l2grams); if (this.cStemming == "S") { this.funcStemming = str_transform.changeWordWithSuffixCode; } else if (this.cStemming == "A") { this.funcStemming = str_transform.changeWordWithAffixCode; } else { this.funcStemming = str_transform.noStemming; |
︙ | |||
210 211 212 213 214 215 216 | 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | - + + | "nArc": this.nArc, "lArcVal": this.lArcVal, "nArcVal": this.nArcVal, "nCompressionMethod": this.nCompressionMethod, "nBytesArc": this.nBytesArc, "nBytesNodeAddress": this.nBytesNodeAddress, "nBytesOffset": this.nBytesOffset, |
︙ | |||
347 348 349 350 351 352 353 | 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | - + - + - + | let cCurrent = sRemain.slice(0, 1); for (let [cChar, jAddr] of this._getCharArcs(iAddr)) { if (char_player.d1to1.gl_get(cCurrent, cCurrent).indexOf(cChar) != -1) { this._suggest(oSuggResult, sRemain.slice(1), nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump, nDist, nDeep+1, jAddr, sNewWord+cChar); } else if (!bAvoidLoop) { |
︙ | |||
393 394 395 396 397 398 399 400 401 402 403 404 405 406 | 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | + + + + + + + | this._suggest(oSuggResult, "", nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump, nDist, nDeep+1, iAddr, sNewWord, true); // remove last char and go on for (let sRepl of char_player.dFinal1.gl_get(sRemain, [])) { this._suggest(oSuggResult, sRepl, nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump, nDist, nDeep+1, iAddr, sNewWord, true); } } } } isNgramsOK (sChars) { if (sChars.length != 2) { return true; } return this.a2grams.has(sChars); } * _getCharArcs (iAddr) { // generator: yield all chars and addresses from node at address <iAddr> for (let [nVal, jAddr] of this._getArcs(iAddr)) { if (nVal <= this.nChar) { yield [this.dCharVal.get(nVal), jAddr]; } |
︙ |
Modified graphspell/dawg.py from [257e064164] to [ade3c3ba0a].
︙ | |||
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 | 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 88 89 | + + + | aEntry = set() lChar = ['']; dChar = {}; nChar = 1; dCharOccur = {} lAff = []; dAff = {}; nAff = 0; dAffOccur = {} lTag = []; dTag = {}; nTag = 0; dTagOccur = {} nErr = 0 self.a2grams = set() try: zFilter = re.compile(sSelectFilterRegex) if sSelectFilterRegex else None except: print(" # Error. Wrong filter regex. Filter ignored.") traceback.print_exc() zFilter = None # read lexicon if type(src) is str: iterable = readFile(src) else: iterable = src for sFlex, sStem, sTag in iterable: if not zFilter or zFilter.search(sTag): self.a2grams.update(st.getNgrams(sFlex)) addWordToCharDict(sFlex) # chars for c in sFlex: if c not in dChar: dChar[c] = nChar lChar.append(c) nChar += 1 |
︙ | |||
281 282 283 284 285 286 287 288 289 290 291 292 293 294 | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | + | print(" * {:<12} {:>16,}".format("Entries:", self.nEntry)) print(" * {:<12} {:>16,}".format("Characters:", self.nChar)) print(" * {:<12} {:>16,}".format("Affixes:", self.nAff)) print(" * {:<12} {:>16,}".format("Tags:", self.nTag)) print(" * {:<12} {:>16,}".format("Arc values:", self.nArcVal)) print(" * {:<12} {:>16,}".format("Nodes:", self.nNode)) print(" * {:<12} {:>16,}".format("Arcs:", self.nArc)) print(" * {:<12} {:>16,}".format("2grams:", len(self.a2grams))) print(" * {:<12} {:>16}".format("Stemming:", self.cStemming + "FX")) def getArcStats (self): "return a string with statistics about nodes and arcs" d = {} for oNode in self.lMinimizedNodes: n = len(oNode.arcs) |
︙ | |||
444 445 446 447 448 449 450 | 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | - + + | "nCompressionMethod": nCompressionMethod, "nBytesArc": self.nBytesArc, "nBytesNodeAddress": self.nBytesNodeAddress, "nBytesOffset": self.nBytesOffset, # Mozilla’s JS parser don’t like file bigger than 4 Mb! # So, if necessary, we use an hexadecimal string, that we will convert later in Firefox’s extension. # https://github.com/mozilla/addons-linter/issues/1361 |
︙ | |||
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | + + + + + + | - Section Values: * a list of strings encoded in binary from utf-8, each value separated with a tabulation - Section Word Graph (nodes / arcs) * A list of nodes which are a list of arcs with an address of the next node. See DawgNode.convToBytes() for details. - Section 2grams: * A list of 2grams (as strings: 2 chars) encoded in binary from utf-8, each value separated with a tabulation """ self._calculateBinary(nCompressionMethod) if not sPathFile.endswith(".bdic"): sPathFile += "."+str(nCompressionMethod)+".bdic" with open(sPathFile, 'wb') as hDst: # header hDst.write("/grammalecte-fsa/{}/".format(nCompressionMethod).encode("utf-8")) hDst.write(b"\0\0\0\0") # infos sInfo = "{}//{}//{}//{}//{}//{}//{}//{}//{}//{}//{}//{}//".format(self.sLangCode, self.sLangName, self.sDicName, self._getDate(), \ self.nChar, self.nBytesArc, self.nBytesNodeAddress, \ self.nEntry, self.nNode, self.nArc, self.nAff, self.cStemming) hDst.write(sInfo.encode("utf-8")) hDst.write(b"\0\0\0\0") # lArcVal hDst.write("\t".join(self.lArcVal).encode("utf-8")) hDst.write(b"\0\0\0\0") # 2grams hDst.write("\t".join(self.a2grams).encode("utf-8")) hDst.write(b"\0\0\0\0") # DAWG: nodes / arcs if nCompressionMethod == 1: hDst.write(self.oRoot.convToBytes1(self.nBytesArc, self.nBytesNodeAddress)) for oNode in self.lMinimizedNodes: hDst.write(oNode.convToBytes1(self.nBytesArc, self.nBytesNodeAddress)) elif nCompressionMethod == 2: hDst.write(self.oRoot.convToBytes2(self.nBytesArc, self.nBytesNodeAddress)) |
︙ |
Modified graphspell/ibdawg.py from [fc0e14c33c] to [eceb83c9e7].
︙ | |||
58 59 60 61 62 63 64 | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | - + | if nDist <= self.nDistLimit: if nDist not in self.dSugg: self.dSugg[nDist] = [] self.dSugg[nDist].append(sSugg) self.aSugg.add(sSugg) if nDist < self.nMinDist: self.nMinDist = nDist |
︙ | |||
149 150 151 152 153 154 155 | 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 | - + - - + + - + + - + | def _initBinary (self): "initialize with binary structure file" if self.by[0:17] != b"/grammalecte-fsa/": raise TypeError("# Error. Not a grammalecte-fsa binary dictionary. Header: {}".format(self.by[0:9])) if not(self.by[17:18] == b"1" or self.by[17:18] == b"2" or self.by[17:18] == b"3"): raise ValueError("# Error. Unknown dictionary version: {}".format(self.by[17:18])) try: |
︙ | |||
185 186 187 188 189 190 191 192 193 194 195 196 197 198 | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | + | self.nBytesOffset = 1 # version 3 def _initJSON (self, oJSON): "initialize with a JSON text file" self.__dict__.update(oJSON) self.byDic = binascii.unhexlify(self.sByDic) self.dCharVal = { v: k for k, v in self.dChar.items() } self.a2grams = set(self.l2grams) def getInfo (self): "return string about the IBDAWG" return " Language: {0.sLangName} Lang code: {0.sLangCode} Dictionary name: {0.sDicName}" \ " Compression method: {0.nCompressionMethod:>2} Date: {0.sDate} Stemming: {0.cStemming}FX\n" \ " Arcs values: {0.nArcVal:>10,} = {0.nChar:>5,} characters, {0.nAff:>6,} affixes, {0.nTag:>6,} tags\n" \ " Dictionary: {0.nEntry:>12,} entries, {0.nNode:>11,} nodes, {0.nArc:>11,} arcs\n" \ |
︙ | |||
223 224 225 226 227 228 229 | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | - + + | "nCompressionMethod": self.nCompressionMethod, "nBytesArc": self.nBytesArc, "nBytesNodeAddress": self.nBytesNodeAddress, "nBytesOffset": self.nBytesOffset, # JavaScript is a pile of shit, so Mozilla’s JS parser don’t like file bigger than 4 Mb! # So, if necessary, we use an hexadecimal string, that we will convert later in Firefox’s extension. # https://github.com/mozilla/addons-linter/issues/1361 |
︙ | |||
319 320 321 322 323 324 325 | 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | - + - + - + + + + + + | if nDist > oSuggResult.nDistLimit: return cCurrent = sRemain[0:1] for cChar, jAddr in self._getCharArcs(iAddr): if cChar in cp.d1to1.get(cCurrent, cCurrent): self._suggest(oSuggResult, sRemain[1:], nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump, nDist, nDeep+1, jAddr, sNewWord+cChar) elif not bAvoidLoop: |
︙ |