Grammalecte  Check-in [a9c5ccc29c]

Overview
Comment:[graphspell] suggestions for French language: add words with apostrophes when it seems relevant
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fr
Files: files | file ages | folders
SHA3-256: a9c5ccc29c46c178b65df8152ee4e98912414b2a7183995eebca05e19070c576
User & Date: olr on 2019-05-14 12:23:33
Other Links: manifest | tags
Context
2019-05-14
12:58
[graphspell][fx][js] add default suggestions module check-in: c3cdee9c76 user: olr tags: trunk, fx, graphspell
12:23
[graphspell] suggestions for French language: add words with apostrophes when it seems relevant check-in: a9c5ccc29c user: olr tags: trunk, fr
10:02
[fr] nr: conf verbe/ppas, +ajustements check-in: 7424c98a5b user: olr tags: trunk, fr
Changes

Modified graphspell-js/ibdawg.js from [9db187764b] to [04aaec821c].

75
76
77
78
79
80
81

82
83
84

85
86
87
88
89
90
91
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93







+



+







            if (lRes.length > nSuggLimit) {
                break;
            }
        }
        lRes = char_player.filterSugg(lRes);
        if (this.sWord.gl_isUpperCase()) {
            lRes = lRes.map((sSugg) => { return sSugg.toUpperCase(); });
            lRes = [...new Set(lRes)];
        }
        else if (this.sWord.slice(0,1).gl_isUpperCase()) {
            lRes = lRes.map((sSugg) => { return sSugg.slice(0,1).toUpperCase() + sSugg.slice(1); });
            lRes = [...new Set(lRes)];
        }
        return lRes.slice(0, nSuggLimit);
    }

    reset () {
        this.aSugg.clear();
        this.dSugg.clear();
268
269
270
271
272
273
274
275
276
277

278
279
280
281
282
283
284
270
271
272
273
274
275
276


277
278
279
280
281
282
283
284
285







-
-

+







                if (sWord.gl_isUpperCase()) {
                    if (this.bAcronymValid) {
                        return true;
                    }
                    return !!(this.lookup(sWord.toLowerCase()) || this.lookup(sWord.gl_toCapitalize()));
                }
                return !!this.lookup(sWord.slice(0, 1).toLowerCase() + sWord.slice(1));
            } else {
                return !!this.lookup(sWord.toLowerCase());
            }
            return !!this.lookup(sWord.toLowerCase());
        }
        if (sWord.slice(0,1).gl_isDigit()) {
            return true;
        }
        return false;
    }

374
375
376
377
378
379
380




381
382
383
384
385
386
387
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392







+
+
+
+







                oSuggResult.addSugg(sNewWord);
                for (let sTail of this._getTails(iAddr)) {
                    oSuggResult.addSugg(sNewWord+sTail);
                }
                return;
            }
            else if ( (sNewWord.length + sRemain.length == oSuggResult.sWord.length) && oSuggResult.sWord.toLowerCase().startsWith(sNewWord.toLowerCase()) && this.isValid(sRemain) ) {
                if (this.sLangCode == "fr"
                    && ["l", "d", "n", "m", "t", "s", "c", "j", "qu", "lorsqu", "puisqu", "quoiqu", "jusqu", "quelqu"].includes(sNewWord.toLowerCase()) && char_player.aVowel.has(sRemain.slice(0,1))) {
                    oSuggResult.addSugg(sNewWord+"’"+sRemain);
                }
                oSuggResult.addSugg(sNewWord+" "+sRemain);
            }
        }
        if (nDist > oSuggResult.nDistLimit) {
            return;
        }

Modified graphspell/ibdawg.py from [35ba56f9ba] to [2ca6102d5a].

9
10
11
12
13
14
15

16
17
18
19
20
21
22
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23







+







import traceback
import pkgutil
import re
from functools import wraps
import time
import json
import binascii
from collections import OrderedDict

#import logging
#logging.basicConfig(filename="suggestions.log", level=logging.DEBUG)

from . import str_transform as st
from . import char_player as cp
from .echo import echo
73
74
75
76
77
78
79
80

81

82

83
84
85
86
87
88
89
74
75
76
77
78
79
80

81
82
83

84
85
86
87
88
89
90
91







-
+

+
-
+







        for nDist, lSugg in self.dSugg.items():
            if nDist <= self.nDistLimit:
                lRes.extend(lSugg)
                if len(lRes) > nSuggLimit:
                    break
        lRes = list(cp.filterSugg(lRes))
        if self.sWord.isupper():
            lRes = list(map(lambda sSugg: sSugg.upper(), lRes))
            lRes = list(OrderedDict.fromkeys(map(lambda sSugg: sSugg.upper(), lRes))) # use dict, when Python 3.6+
        elif self.sWord[0:1].isupper():
            # dont’ use <.istitle>
            lRes = list(map(lambda sSugg: sSugg[0:1].upper()+sSugg[1:], lRes))  # dont’ use <.istitle>
            lRes = list(OrderedDict.fromkeys(map(lambda sSugg: sSugg[0:1].upper()+sSugg[1:], lRes))) # use dict, when Python 3.6+
        return lRes[:nSuggLimit]

    def reset (self):
        "clear data"
        self.aSugg.clear()
        self.dSugg.clear()

333
334
335
336
337
338
339


340
341
342
343
344
345
346
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350







+
+







        if int.from_bytes(self.byDic[iAddr:iAddr+self.nBytesArc], byteorder='big') & self._finalNodeMask:
            if not sRemain:
                oSuggResult.addSugg(sNewWord, nDeep)
                for sTail in self._getTails(iAddr):
                    oSuggResult.addSugg(sNewWord+sTail, nDeep)
                return
            if (len(sNewWord) + len(sRemain) == len(oSuggResult.sWord)) and oSuggResult.sWord.lower().startswith(sNewWord.lower()) and self.isValid(sRemain):
                if self.sLangCode == "fr" and sNewWord.lower() in ("l", "d", "n", "m", "t", "s", "c", "j", "qu", "lorsqu", "puisqu", "quoiqu", "jusqu", "quelqu") and sRemain[0:1] in cp.aVowel:
                    oSuggResult.addSugg(sNewWord+"’"+sRemain)
                oSuggResult.addSugg(sNewWord+" "+sRemain)
        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)