Overview
Comment: | [core][py] gc: use spellchecker storage |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | core | rg |
Files: | files | file ages | folders |
SHA3-256: |
445405d36276c84274e0c91ac6231913 |
User & Date: | olr on 2018-05-23 08:46:45 |
Other Links: | branch diff | manifest | tags |
Context
2018-05-23
| ||
08:47 | [core][py] gc: use spellchecker storage check-in: bc740f8402 user: olr tags: core, rg | |
08:46 | [core][py] gc: use spellchecker storage check-in: 445405d362 user: olr tags: core, rg | |
08:37 | [graphspell][py] data memorization check-in: 3f84923104 user: olr tags: graphspell, rg | |
Changes
Modified gc_lang/fr/modules/gce_analyseur.py from [39975de0ac] to [50ac148025].
︙ | ︙ | |||
13 14 15 16 17 18 19 | return "vous" if s2 == "nous": return "nous" if s2 == "vous": return "vous" if s2 == "eux": return "ils" | | < | < | | < | | < | | < | | < | | | 13 14 15 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 88 89 90 91 92 | return "vous" if s2 == "nous": return "nous" if s2 == "vous": return "vous" if s2 == "eux": return "ils" if s2 == "elle" or s2 == "elles": if cr.mbNprMasNotFem(_oSpellChecker.getMorph(s1)): return "ils" # si épicène, indéterminable, mais OSEF, le féminin l’emporte return "elles" return s1 + " et " + s2 def apposition (sWord1, sWord2): "returns True if nom + nom (no agreement required)" return cr.mbNomNotAdj(_oSpellChecker.getMorph(sWord2)) and cr.mbPpasNomNotAdj(_oSpellChecker.getMorph(sWord1)) def isAmbiguousNAV (sWord): "words which are nom|adj and verb are ambiguous (except être and avoir)" lMorph = _oSpellChecker.getMorph(sWord) if not cr.mbNomAdj(lMorph) or sWord == "est": return False if cr.mbVconj(lMorph) and not cr.mbMG(lMorph): return True return False def isAmbiguousAndWrong (sWord1, sWord2, sReqMorphNA, sReqMorphConj): "use it if sWord1 won’t be a verb; word2 is assumed to be True via isAmbiguousNAV" a2 = _oSpellChecker.getMorph(sWord2) if not a2: return False if cr.checkConjVerb(a2, sReqMorphConj): # verb word2 is ok return False a1 = _oSpellChecker.getMorph(sWord1) if not a1: return False if cr.checkAgreement(a1, a2) and (cr.mbAdj(a2) or cr.mbAdj(a1)): return False return True def isVeryAmbiguousAndWrong (sWord1, sWord2, sReqMorphNA, sReqMorphConj, bLastHopeCond): "use it if sWord1 can be also a verb; word2 is assumed to be True via isAmbiguousNAV" a2 = _oSpellChecker.getMorph(sWord2) if not a2: return False if cr.checkConjVerb(a2, sReqMorphConj): # verb word2 is ok return False a1 = _oSpellChecker.getMorph(sWord1) if not a1: return False if cr.checkAgreement(a1, a2) and (cr.mbAdj(a2) or cr.mbAdjNb(a1)): return False # now, we know there no agreement, and conjugation is also wrong if cr.isNomAdj(a1): return True #if cr.isNomAdjVerb(a1): # considered True if bLastHopeCond: return True return False def checkAgreement (sWord1, sWord2): a2 = _oSpellChecker.getMorph(sWord2) if not a2: return True a1 = _oSpellChecker.getMorph(sWord1) if not a1: return True return cr.checkAgreement(a1, a2) _zUnitSpecial = re.compile("[µ/⁰¹²³⁴⁵⁶⁷⁸⁹Ωℓ·]") _zUnitNumbers = re.compile("[0-9]") |
︙ | ︙ |
Modified gc_lang/fr/modules/gce_suggestions.py from [79835965e4] to [818aeb6977].
1 2 3 4 5 6 7 8 9 10 11 | #### GRAMMAR CHECKING ENGINE PLUGIN: Suggestion mechanisms from . import conj from . import mfsp from . import phonet ## Verbs def suggVerb (sFlex, sWho, funcSugg2=None): aSugg = set() | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #### GRAMMAR CHECKING ENGINE PLUGIN: Suggestion mechanisms from . import conj from . import mfsp from . import phonet ## Verbs def suggVerb (sFlex, sWho, funcSugg2=None): aSugg = set() for sStem in _oSpellChecker.getLemma(sFlex): tTags = conj._getTags(sStem) if tTags: # we get the tense aTense = set() for sMorph in _oSpellChecker.getMorph(sFlex): for m in re.finditer(">"+sStem+" .*?(:(?:Y|I[pqsf]|S[pq]|K|P))", sMorph): # stem must be used in regex to prevent confusion between different verbs (e.g. sauras has 2 stems: savoir and saurer) if m: if m.group(1) == ":Y": aTense.add(":Ip") aTense.add(":Iq") aTense.add(":Is") |
︙ | ︙ | |||
38 39 40 41 42 43 44 | if aSugg: return "|".join(aSugg) return "" def suggVerbPpas (sFlex, sWhat=None): aSugg = set() | | | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | if aSugg: return "|".join(aSugg) return "" def suggVerbPpas (sFlex, sWhat=None): aSugg = set() for sStem in _oSpellChecker.getLemma(sFlex): tTags = conj._getTags(sStem) if tTags: if not sWhat: aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1")) aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2")) aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3")) aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4")) |
︙ | ︙ | |||
81 82 83 84 85 86 87 | if aSugg: return "|".join(aSugg) return "" def suggVerbTense (sFlex, sTense, sWho): aSugg = set() | | | | | 81 82 83 84 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 115 116 117 118 119 120 | if aSugg: return "|".join(aSugg) return "" def suggVerbTense (sFlex, sTense, sWho): aSugg = set() for sStem in _oSpellChecker.getLemma(sFlex): if conj.hasConj(sStem, sTense, sWho): aSugg.add(conj.getConj(sStem, sTense, sWho)) if aSugg: return "|".join(aSugg) return "" def suggVerbImpe (sFlex): aSugg = set() for sStem in _oSpellChecker.getLemma(sFlex): tTags = conj._getTags(sStem) if tTags: if conj._hasConjWithTags(tTags, ":E", ":2s"): aSugg.add(conj._getConjWithTags(sStem, tTags, ":E", ":2s")) if conj._hasConjWithTags(tTags, ":E", ":1p"): aSugg.add(conj._getConjWithTags(sStem, tTags, ":E", ":1p")) if conj._hasConjWithTags(tTags, ":E", ":2p"): aSugg.add(conj._getConjWithTags(sStem, tTags, ":E", ":2p")) if aSugg: return "|".join(aSugg) return "" def suggVerbInfi (sFlex): return "|".join([ sStem for sStem in _oSpellChecker.getLemma(sFlex) if conj.isVerb(sStem) ]) _dQuiEst = { "je": ":1s", "j’": ":1s", "j’en": ":1s", "j’y": ":1s", \ "tu": ":2s", "il": ":3s", "on": ":3s", "elle": ":3s", "nous": ":1p", "vous": ":2p", "ils": ":3p", "elles": ":3p" } _lIndicatif = [":Ip", ":Iq", ":Is", ":If"] _lSubjonctif = [":Sp", ":Sq"] |
︙ | ︙ | |||
129 130 131 132 133 134 135 | return "" sWho = _dQuiEst.get(sSuj.lower(), None) if not sWho: if sSuj[0:1].islower(): # pas un pronom, ni un nom propre return "" sWho = ":3s" aSugg = set() | | > | | | 129 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 | return "" sWho = _dQuiEst.get(sSuj.lower(), None) if not sWho: if sSuj[0:1].islower(): # pas un pronom, ni un nom propre return "" sWho = ":3s" aSugg = set() for sStem in _oSpellChecker.getLemma(sFlex): tTags = conj._getTags(sStem) if tTags: for sTense in lMode: if conj._hasConjWithTags(tTags, sTense, sWho): aSugg.add(conj._getConjWithTags(sStem, tTags, sTense, sWho)) if aSugg: return "|".join(aSugg) return "" ## Nouns and adjectives def suggPlur (sFlex, sWordToAgree=None): "returns plural forms assuming sFlex is singular" if sWordToAgree: lMorph = _oSpellChecker.getMorph(sFlex) if not lMorph: return "" sGender = cr.getGender(lMorph) if sGender == ":m": return suggMasPlur(sFlex) elif sGender == ":f": return suggFemPlur(sFlex) aSugg = set() if "-" not in sFlex: if sFlex.endswith("l"): |
︙ | ︙ | |||
189 190 191 192 193 194 195 | if aSugg: return "|".join(aSugg) return "" def suggMasSing (sFlex, bSuggSimil=False): "returns masculine singular forms" | < | | 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | if aSugg: return "|".join(aSugg) return "" def suggMasSing (sFlex, bSuggSimil=False): "returns masculine singular forms" aSugg = set() for sMorph in _oSpellChecker.getMorph(sFlex): if not ":V" in sMorph: # not a verb if ":m" in sMorph or ":e" in sMorph: aSugg.add(suggSing(sFlex)) else: sStem = cr.getLemmaOfMorph(sMorph) if mfsp.isFemForm(sStem): |
︙ | ︙ | |||
217 218 219 220 221 222 223 | if aSugg: return "|".join(aSugg) return "" def suggMasPlur (sFlex, bSuggSimil=False): "returns masculine plural forms" | < | | 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | if aSugg: return "|".join(aSugg) return "" def suggMasPlur (sFlex, bSuggSimil=False): "returns masculine plural forms" aSugg = set() for sMorph in _oSpellChecker.getMorph(sFlex): if not ":V" in sMorph: # not a verb if ":m" in sMorph or ":e" in sMorph: aSugg.add(suggPlur(sFlex)) else: sStem = cr.getLemmaOfMorph(sMorph) if mfsp.isFemForm(sStem): |
︙ | ︙ | |||
248 249 250 251 252 253 254 | if aSugg: return "|".join(aSugg) return "" def suggFemSing (sFlex, bSuggSimil=False): "returns feminine singular forms" | < | | 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | if aSugg: return "|".join(aSugg) return "" def suggFemSing (sFlex, bSuggSimil=False): "returns feminine singular forms" aSugg = set() for sMorph in _oSpellChecker.getMorph(sFlex): if not ":V" in sMorph: # not a verb if ":f" in sMorph or ":e" in sMorph: aSugg.add(suggSing(sFlex)) else: sStem = cr.getLemmaOfMorph(sMorph) if mfsp.isFemForm(sStem): |
︙ | ︙ | |||
274 275 276 277 278 279 280 | if aSugg: return "|".join(aSugg) return "" def suggFemPlur (sFlex, bSuggSimil=False): "returns feminine plural forms" | < | | 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | if aSugg: return "|".join(aSugg) return "" def suggFemPlur (sFlex, bSuggSimil=False): "returns feminine plural forms" aSugg = set() for sMorph in _oSpellChecker.getMorph(sFlex): if not ":V" in sMorph: # not a verb if ":f" in sMorph or ":e" in sMorph: aSugg.add(suggPlur(sFlex)) else: sStem = cr.getLemmaOfMorph(sMorph) if mfsp.isFemForm(sStem): |
︙ | ︙ | |||
299 300 301 302 303 304 305 | aSugg.add(e) if aSugg: return "|".join(aSugg) return "" def hasFemForm (sFlex): | | | < | | | < | < | < | | 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 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 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | aSugg.add(e) if aSugg: return "|".join(aSugg) return "" def hasFemForm (sFlex): for sStem in _oSpellChecker.getLemma(sFlex): if mfsp.isFemForm(sStem) or conj.hasConj(sStem, ":PQ", ":Q3"): return True if phonet.hasSimil(sFlex, ":f"): return True return False def hasMasForm (sFlex): for sStem in _oSpellChecker.getLemma(sFlex): if mfsp.isFemForm(sStem) or conj.hasConj(sStem, ":PQ", ":Q1"): # what has a feminine form also has a masculine form return True if phonet.hasSimil(sFlex, ":m"): return True return False def switchGender (sFlex, bPlur=None): aSugg = set() if bPlur == None: for sMorph in _oSpellChecker.getMorph(sFlex): if ":f" in sMorph: if ":s" in sMorph: aSugg.add(suggMasSing(sFlex)) elif ":p" in sMorph: aSugg.add(suggMasPlur(sFlex)) elif ":m" in sMorph: if ":s" in sMorph: aSugg.add(suggFemSing(sFlex)) elif ":p" in sMorph: aSugg.add(suggFemPlur(sFlex)) else: aSugg.add(suggFemSing(sFlex)) aSugg.add(suggFemPlur(sFlex)) elif bPlur: for sMorph in _oSpellChecker.getMorph(sFlex): if ":f" in sMorph: aSugg.add(suggMasPlur(sFlex)) elif ":m" in sMorph: aSugg.add(suggFemPlur(sFlex)) else: for sMorph in _oSpellChecker.getMorph(sFlex): if ":f" in sMorph: aSugg.add(suggMasSing(sFlex)) elif ":m" in sMorph: aSugg.add(suggFemSing(sFlex)) if aSugg: return "|".join(aSugg) return "" def switchPlural (sFlex): aSugg = set() for sMorph in _oSpellChecker.getMorph(sFlex): if ":s" in sMorph: aSugg.add(suggPlur(sFlex)) elif ":p" in sMorph: aSugg.add(suggSing(sFlex)) if aSugg: return "|".join(aSugg) return "" def hasSimil (sWord, sPattern=None): return phonet.hasSimil(sWord, sPattern) def suggSimil (sWord, sPattern=None, bSubst=False): "return list of words phonetically similar to sWord and whom POS is matching sPattern" aSugg = phonet.selectSimil(sWord, sPattern) for sMorph in _oSpellChecker.getMorph(sWord): aSugg.update(conj.getSimil(sWord, sMorph, bSubst)) break if aSugg: return "|".join(aSugg) return "" def suggCeOrCet (sWord): if re.match("(?i)[aeéèêiouyâîï]", sWord): return "cet" if sWord[0:1] == "h" or sWord[0:1] == "H": return "ce|cet" return "ce" def suggLesLa (sWord): if any( ":p" in sMorph for sMorph in _oSpellChecker.getMorph(sWord) ): return "les|la" return "la" _zBinary = re.compile("^[01]+$") def formatNumber (s): |
︙ | ︙ |