Index: graphspell-js/ibdawg.js ================================================================== --- graphspell-js/ibdawg.js +++ graphspell-js/ibdawg.js @@ -319,11 +319,11 @@ } } return l; } - suggest (sWord, nSuggLimit=10) { + suggest (sWord, nSuggLimit=10, bSplitTrailingNumbers=false) { // returns a array of suggestions for //console.time("Suggestions for " + sWord); sWord = char_player.spellingNormalization(sWord); let sPfx = ""; let sSfx = ""; @@ -331,10 +331,13 @@ let nMaxSwitch = Math.max(Math.floor(sWord.length / 3), 1); let nMaxDel = Math.floor(sWord.length / 5); let nMaxHardRepl = Math.max(Math.floor((sWord.length - 5) / 4), 1); let nMaxJump = Math.max(Math.floor(sWord.length / 4), 1); let oSuggResult = new SuggResult(sWord); + if (bSplitTrailingNumbers) { + this._splitTrailingNumbers(oSuggResult, sWord); + } this._splitSuggest(oSuggResult, sWord); this._suggest(oSuggResult, sWord, nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump); let aSugg = oSuggResult.getSuggestions(nSuggLimit); if (sSfx || sPfx) { // we add what we removed @@ -342,16 +345,18 @@ } //console.timeEnd("Suggestions for " + sWord); return aSugg; } - _splitSuggest (oSuggResult, sWord) { - // split trailing numbers + _splitTrailingNumbers (oSuggResult, sWord) { let m = /^([a-zA-Zà-öÀ-Ö_ø-ÿØ-ßĀ-ʯfi-st][a-zA-Zà-öÀ-Ö_ø-ÿØ-ßĀ-ʯfi-st-]+)([0-9]+)$/.exec(sWord); if (m) { oSuggResult.addSugg(m[1] + " " + char_player.numbersToExponent(m[2])); } + } + + _splitSuggest (oSuggResult, sWord) { // split at apostrophes for (let cSplitter of "'’") { if (sWord.includes(cSplitter)) { let [sWord1, sWord2] = sWord.split(cSplitter, 2); if (this.isValid(sWord1) && this.isValid(sWord2)) { Index: graphspell-js/spellchecker.js ================================================================== --- graphspell-js/spellchecker.js +++ graphspell-js/spellchecker.js @@ -231,16 +231,16 @@ 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 - yield this.oMainDic.suggest(sWord, nSuggLimit); + yield this.oMainDic.suggest(sWord, nSuggLimit, true); if (this.bCommunityDic) { - yield this.oCommunityDic.suggest(sWord, nSuggLimit); + yield this.oCommunityDic.suggest(sWord, Math.floor(nSuggLimit/2)+1); } if (this.bPersonalDic) { - yield this.oPersonalDic.suggest(sWord, nSuggLimit); + yield this.oPersonalDic.suggest(sWord, Math.floor(nSuggLimit/2)+1); } } * select (sFlexPattern="", sTagsPattern="") { // generator: returns all entries which flexion fits and morphology fits Index: graphspell/ibdawg.py ================================================================== --- graphspell/ibdawg.py +++ graphspell/ibdawg.py @@ -293,34 +293,36 @@ if sWord.isupper() and len(sWord) > 1: l.extend(self.morph(sWord.capitalize())) return l #@timethis - def suggest (self, sWord, nSuggLimit=10): + def suggest (self, sWord, nSuggLimit=10, bSplitTrailingNumbers=False): "returns a set of suggestions for " sWord = sWord.rstrip(".") # useful for LibreOffice sWord = cp.spellingNormalization(sWord) sPfx, sWord, sSfx = cp.cut(sWord) nMaxSwitch = max(len(sWord) // 3, 1) nMaxDel = len(sWord) // 5 nMaxHardRepl = max((len(sWord) - 5) // 4, 1) nMaxJump = max(len(sWord) // 4, 1) oSuggResult = SuggResult(sWord) + if bSplitTrailingNumbers: + self._splitTrailingNumbers(oSuggResult, sWord) self._splitSuggest(oSuggResult, sWord) self._suggest(oSuggResult, sWord, nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump) aSugg = oSuggResult.getSuggestions(nSuggLimit) if sSfx or sPfx: # we add what we removed return list(map(lambda sSug: sPfx + sSug + sSfx, aSugg)) return aSugg - def _splitSuggest (self, oSuggResult, sWord): - # split trailing numbers + def _splitTrailingNumbers (self, oSuggResult, sWord): m = re.match(r"(\D+)([0-9]+)$", sWord) if m: - print("ok") oSuggResult.addSugg(m.group(1) + " " + cp.numbersToExponent(m.group(2))) + + def _splitSuggest (self, oSuggResult, sWord): # split at apostrophes for cSplitter in "'’": if cSplitter in sWord: sWord1, sWord2 = sWord.split(cSplitter, 1) if self.isValid(sWord1) and self.isValid(sWord2): Index: graphspell/spellchecker.py ================================================================== --- graphspell/spellchecker.py +++ graphspell/spellchecker.py @@ -223,17 +223,17 @@ yield self.dDefaultSugg[sWord].split("|") elif sWord.istitle() and sWord.lower() in self.dDefaultSugg: lRes = self.dDefaultSugg[sWord.lower()].split("|") yield list(map(lambda sSugg: sSugg[0:1].upper()+sSugg[1:], lRes)) else: - yield self.oMainDic.suggest(sWord, nSuggLimit) + yield self.oMainDic.suggest(sWord, nSuggLimit, True) else: - yield self.oMainDic.suggest(sWord, nSuggLimit) + yield self.oMainDic.suggest(sWord, nSuggLimit, True) if self.bCommunityDic: - yield self.oCommunityDic.suggest(sWord, nSuggLimit) + yield self.oCommunityDic.suggest(sWord, (nSuggLimit//2)+1) if self.bPersonalDic: - yield self.oPersonalDic.suggest(sWord, nSuggLimit) + yield self.oPersonalDic.suggest(sWord, (nSuggLimit//2)+1) def select (self, sFlexPattern="", sTagsPattern=""): "generator: returns all entries which flexion fits and morphology fits " yield from self.oMainDic.select(sFlexPattern, sTagsPattern) if self.bCommunityDic: