Grammalecte  Check-in [445405d362]

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: 445405d36276c84274e0c91ac623191304744262177e25bbc1fe1d496f054072
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     13           return "vous"
    14     14       if s2 == "nous":
    15     15           return "nous"
    16     16       if s2 == "vous":
    17     17           return "vous"
    18     18       if s2 == "eux":
    19     19           return "ils"
    20         -    if s2 == "elle" or s2 == "elles":
    21         -        # We don’t check if word exists in _dAnalyses, for it is assumed it has been done before
    22         -        if cr.mbNprMasNotFem(_dAnalyses.get(s1, False)):
           20  +    if s2 == "elle" or s2 == "elles":    
           21  +        if cr.mbNprMasNotFem(_oSpellChecker.getMorph(s1)):
    23     22               return "ils"
    24     23           # si épicène, indéterminable, mais OSEF, le féminin l’emporte
    25     24           return "elles"
    26     25       return s1 + " et " + s2
    27     26   
    28     27   
    29     28   def apposition (sWord1, sWord2):
    30     29       "returns True if nom + nom (no agreement required)"
    31         -    # We don’t check if word exists in _dAnalyses, for it is assumed it has been done before
    32         -    return cr.mbNomNotAdj(_dAnalyses.get(sWord2, False)) and cr.mbPpasNomNotAdj(_dAnalyses.get(sWord1, False))
           30  +    return cr.mbNomNotAdj(_oSpellChecker.getMorph(sWord2)) and cr.mbPpasNomNotAdj(_oSpellChecker.getMorph(sWord1))
    33     31   
    34     32   
    35     33   def isAmbiguousNAV (sWord):
    36     34       "words which are nom|adj and verb are ambiguous (except être and avoir)"
    37         -    if sWord not in _dAnalyses and not _storeMorphFromFSA(sWord):
           35  +    lMorph = _oSpellChecker.getMorph(sWord)
           36  +    if not cr.mbNomAdj(lMorph) or sWord == "est":
    38     37           return False
    39         -    if not cr.mbNomAdj(_dAnalyses[sWord]) or sWord == "est":
    40         -        return False
    41         -    if cr.mbVconj(_dAnalyses[sWord]) and not cr.mbMG(_dAnalyses[sWord]):
           38  +    if cr.mbVconj(lMorph) and not cr.mbMG(lMorph):
    42     39           return True
    43     40       return False
    44     41   
    45     42   
    46     43   def isAmbiguousAndWrong (sWord1, sWord2, sReqMorphNA, sReqMorphConj):
    47     44       "use it if sWord1 won’t be a verb; word2 is assumed to be True via isAmbiguousNAV"
    48         -    # We don’t check if word exists in _dAnalyses, for it is assumed it has been done before
    49         -    a2 = _dAnalyses.get(sWord2, None)
           45  +    a2 = _oSpellChecker.getMorph(sWord2)
    50     46       if not a2:
    51     47           return False
    52     48       if cr.checkConjVerb(a2, sReqMorphConj):
    53     49           # verb word2 is ok
    54     50           return False
    55         -    a1 = _dAnalyses.get(sWord1, None)
           51  +    a1 = _oSpellChecker.getMorph(sWord1)
    56     52       if not a1:
    57     53           return False
    58     54       if cr.checkAgreement(a1, a2) and (cr.mbAdj(a2) or cr.mbAdj(a1)):
    59     55           return False
    60     56       return True
    61     57   
    62     58   
    63     59   def isVeryAmbiguousAndWrong (sWord1, sWord2, sReqMorphNA, sReqMorphConj, bLastHopeCond):
    64     60       "use it if sWord1 can be also a verb; word2 is assumed to be True via isAmbiguousNAV"
    65         -    # We don’t check if word exists in _dAnalyses, for it is assumed it has been done before
    66         -    a2 = _dAnalyses.get(sWord2, None)
           61  +    a2 = _oSpellChecker.getMorph(sWord2)
    67     62       if not a2:
    68     63           return False
    69     64       if cr.checkConjVerb(a2, sReqMorphConj):
    70     65           # verb word2 is ok
    71     66           return False
    72         -    a1 = _dAnalyses.get(sWord1, None)
           67  +    a1 = _oSpellChecker.getMorph(sWord1)
    73     68       if not a1:
    74     69           return False
    75     70       if cr.checkAgreement(a1, a2) and (cr.mbAdj(a2) or cr.mbAdjNb(a1)):
    76     71           return False
    77     72       # now, we know there no agreement, and conjugation is also wrong
    78     73       if cr.isNomAdj(a1):
    79     74           return True
................................................................................
    80     75       #if cr.isNomAdjVerb(a1): # considered True
    81     76       if bLastHopeCond:
    82     77           return True
    83     78       return False
    84     79   
    85     80   
    86     81   def checkAgreement (sWord1, sWord2):
    87         -    # We don’t check if word exists in _dAnalyses, for it is assumed it has been done before
    88         -    a2 = _dAnalyses.get(sWord2, None)
           82  +    a2 = _oSpellChecker.getMorph(sWord2)
    89     83       if not a2:
    90     84           return True
    91         -    a1 = _dAnalyses.get(sWord1, None)
           85  +    a1 = _oSpellChecker.getMorph(sWord1)
    92     86       if not a1:
    93     87           return True
    94     88       return cr.checkAgreement(a1, a2)
    95     89   
    96     90   
    97     91   _zUnitSpecial = re.compile("[µ/⁰¹²³⁴⁵⁶⁷⁸⁹Ωℓ·]")
    98     92   _zUnitNumbers = re.compile("[0-9]")

Modified gc_lang/fr/modules/gce_suggestions.py from [79835965e4] to [818aeb6977].

     5      5   from . import phonet
     6      6   
     7      7   
     8      8   ## Verbs
     9      9   
    10     10   def suggVerb (sFlex, sWho, funcSugg2=None):
    11     11       aSugg = set()
    12         -    for sStem in stem(sFlex):
           12  +    for sStem in _oSpellChecker.getLemma(sFlex):
    13     13           tTags = conj._getTags(sStem)
    14     14           if tTags:
    15     15               # we get the tense
    16     16               aTense = set()
    17         -            for sMorph in _dAnalyses.get(sFlex, []): # we don’t check if word exists in _dAnalyses, for it is assumed it has been done before
           17  +            for sMorph in _oSpellChecker.getMorph(sFlex):
    18     18                   for m in re.finditer(">"+sStem+" .*?(:(?:Y|I[pqsf]|S[pq]|K|P))", sMorph):
    19     19                       # stem must be used in regex to prevent confusion between different verbs (e.g. sauras has 2 stems: savoir and saurer)
    20     20                       if m:
    21     21                           if m.group(1) == ":Y":
    22     22                               aTense.add(":Ip")
    23     23                               aTense.add(":Iq")
    24     24                               aTense.add(":Is")
................................................................................
    38     38       if aSugg:
    39     39           return "|".join(aSugg)
    40     40       return ""
    41     41   
    42     42   
    43     43   def suggVerbPpas (sFlex, sWhat=None):
    44     44       aSugg = set()
    45         -    for sStem in stem(sFlex):
           45  +    for sStem in _oSpellChecker.getLemma(sFlex):
    46     46           tTags = conj._getTags(sStem)
    47     47           if tTags:
    48     48               if not sWhat:
    49     49                   aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
    50     50                   aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2"))
    51     51                   aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3"))
    52     52                   aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4"))
................................................................................
    81     81       if aSugg:
    82     82           return "|".join(aSugg)
    83     83       return ""
    84     84   
    85     85   
    86     86   def suggVerbTense (sFlex, sTense, sWho):
    87     87       aSugg = set()
    88         -    for sStem in stem(sFlex):
           88  +    for sStem in _oSpellChecker.getLemma(sFlex):
    89     89           if conj.hasConj(sStem, sTense, sWho):
    90     90               aSugg.add(conj.getConj(sStem, sTense, sWho))
    91     91       if aSugg:
    92     92           return "|".join(aSugg)
    93     93       return ""
    94     94   
    95     95   
    96     96   def suggVerbImpe (sFlex):
    97     97       aSugg = set()
    98         -    for sStem in stem(sFlex):
           98  +    for sStem in _oSpellChecker.getLemma(sFlex):
    99     99           tTags = conj._getTags(sStem)
   100    100           if tTags:
   101    101               if conj._hasConjWithTags(tTags, ":E", ":2s"):
   102    102                   aSugg.add(conj._getConjWithTags(sStem, tTags, ":E", ":2s"))
   103    103               if conj._hasConjWithTags(tTags, ":E", ":1p"):
   104    104                   aSugg.add(conj._getConjWithTags(sStem, tTags, ":E", ":1p"))
   105    105               if conj._hasConjWithTags(tTags, ":E", ":2p"):
................................................................................
   106    106                   aSugg.add(conj._getConjWithTags(sStem, tTags, ":E", ":2p"))
   107    107       if aSugg:
   108    108           return "|".join(aSugg)
   109    109       return ""
   110    110   
   111    111   
   112    112   def suggVerbInfi (sFlex):
   113         -    return "|".join([ sStem  for sStem in stem(sFlex)  if conj.isVerb(sStem) ])
          113  +    return "|".join([ sStem  for sStem in _oSpellChecker.getLemma(sFlex)  if conj.isVerb(sStem) ])
   114    114   
   115    115   
   116    116   _dQuiEst = { "je": ":1s", "j’": ":1s", "j’en": ":1s", "j’y": ":1s", \
   117    117                "tu": ":2s", "il": ":3s", "on": ":3s", "elle": ":3s", "nous": ":1p", "vous": ":2p", "ils": ":3p", "elles": ":3p" }
   118    118   _lIndicatif = [":Ip", ":Iq", ":Is", ":If"]
   119    119   _lSubjonctif = [":Sp", ":Sq"]
   120    120   
................................................................................
   129    129           return ""
   130    130       sWho = _dQuiEst.get(sSuj.lower(), None)
   131    131       if not sWho:
   132    132           if sSuj[0:1].islower(): # pas un pronom, ni un nom propre
   133    133               return ""
   134    134           sWho = ":3s"
   135    135       aSugg = set()
   136         -    for sStem in stem(sFlex):
          136  +    for sStem in _oSpellChecker.getLemma(sFlex):
   137    137           tTags = conj._getTags(sStem)
   138    138           if tTags:
   139    139               for sTense in lMode:
   140    140                   if conj._hasConjWithTags(tTags, sTense, sWho):
   141    141                       aSugg.add(conj._getConjWithTags(sStem, tTags, sTense, sWho))
   142    142       if aSugg:
   143    143           return "|".join(aSugg)
................................................................................
   145    145   
   146    146   
   147    147   ## Nouns and adjectives
   148    148   
   149    149   def suggPlur (sFlex, sWordToAgree=None):
   150    150       "returns plural forms assuming sFlex is singular"
   151    151       if sWordToAgree:
   152         -        if sWordToAgree not in _dAnalyses and not _storeMorphFromFSA(sWordToAgree):
          152  +        lMorph = _oSpellChecker.getMorph(sFlex)
          153  +        if not lMorph:
   153    154               return ""
   154         -        sGender = cr.getGender(_dAnalyses.get(sWordToAgree, []))
          155  +        sGender = cr.getGender(lMorph)
   155    156           if sGender == ":m":
   156    157               return suggMasPlur(sFlex)
   157    158           elif sGender == ":f":
   158    159               return suggFemPlur(sFlex)
   159    160       aSugg = set()
   160    161       if "-" not in sFlex:
   161    162           if sFlex.endswith("l"):
................................................................................
   189    190       if aSugg:
   190    191           return "|".join(aSugg)
   191    192       return ""
   192    193   
   193    194   
   194    195   def suggMasSing (sFlex, bSuggSimil=False):
   195    196       "returns masculine singular forms"
   196         -    # we don’t check if word exists in _dAnalyses, for it is assumed it has been done before
   197    197       aSugg = set()
   198         -    for sMorph in _dAnalyses.get(sFlex, []):
          198  +    for sMorph in _oSpellChecker.getMorph(sFlex):
   199    199           if not ":V" in sMorph:
   200    200               # not a verb
   201    201               if ":m" in sMorph or ":e" in sMorph:
   202    202                   aSugg.add(suggSing(sFlex))
   203    203               else:
   204    204                   sStem = cr.getLemmaOfMorph(sMorph)
   205    205                   if mfsp.isFemForm(sStem):
................................................................................
   217    217       if aSugg:
   218    218           return "|".join(aSugg)
   219    219       return ""
   220    220   
   221    221   
   222    222   def suggMasPlur (sFlex, bSuggSimil=False):
   223    223       "returns masculine plural forms"
   224         -    # we don’t check if word exists in _dAnalyses, for it is assumed it has been done before
   225    224       aSugg = set()
   226         -    for sMorph in _dAnalyses.get(sFlex, []):
          225  +    for sMorph in _oSpellChecker.getMorph(sFlex):
   227    226           if not ":V" in sMorph:
   228    227               # not a verb
   229    228               if ":m" in sMorph or ":e" in sMorph:
   230    229                   aSugg.add(suggPlur(sFlex))
   231    230               else:
   232    231                   sStem = cr.getLemmaOfMorph(sMorph)
   233    232                   if mfsp.isFemForm(sStem):
................................................................................
   248    247       if aSugg:
   249    248           return "|".join(aSugg)
   250    249       return ""
   251    250   
   252    251   
   253    252   def suggFemSing (sFlex, bSuggSimil=False):
   254    253       "returns feminine singular forms"
   255         -    # we don’t check if word exists in _dAnalyses, for it is assumed it has been done before
   256    254       aSugg = set()
   257         -    for sMorph in _dAnalyses.get(sFlex, []):
          255  +    for sMorph in _oSpellChecker.getMorph(sFlex):
   258    256           if not ":V" in sMorph:
   259    257               # not a verb
   260    258               if ":f" in sMorph or ":e" in sMorph:
   261    259                   aSugg.add(suggSing(sFlex))
   262    260               else:
   263    261                   sStem = cr.getLemmaOfMorph(sMorph)
   264    262                   if mfsp.isFemForm(sStem):
................................................................................
   274    272       if aSugg:
   275    273           return "|".join(aSugg)
   276    274       return ""
   277    275   
   278    276   
   279    277   def suggFemPlur (sFlex, bSuggSimil=False):
   280    278       "returns feminine plural forms"
   281         -    # we don’t check if word exists in _dAnalyses, for it is assumed it has been done before
   282    279       aSugg = set()
   283         -    for sMorph in _dAnalyses.get(sFlex, []):
          280  +    for sMorph in _oSpellChecker.getMorph(sFlex):
   284    281           if not ":V" in sMorph:
   285    282               # not a verb
   286    283               if ":f" in sMorph or ":e" in sMorph:
   287    284                   aSugg.add(suggPlur(sFlex))
   288    285               else:
   289    286                   sStem = cr.getLemmaOfMorph(sMorph)
   290    287                   if mfsp.isFemForm(sStem):
................................................................................
   299    296               aSugg.add(e)
   300    297       if aSugg:
   301    298           return "|".join(aSugg)
   302    299       return ""
   303    300   
   304    301   
   305    302   def hasFemForm (sFlex):
   306         -    for sStem in stem(sFlex):
          303  +    for sStem in _oSpellChecker.getLemma(sFlex):
   307    304           if mfsp.isFemForm(sStem) or conj.hasConj(sStem, ":PQ", ":Q3"):
   308    305               return True
   309    306       if phonet.hasSimil(sFlex, ":f"):
   310    307           return True
   311    308       return False
   312    309   
   313    310   
   314    311   def hasMasForm (sFlex):
   315         -    for sStem in stem(sFlex):
          312  +    for sStem in _oSpellChecker.getLemma(sFlex):
   316    313           if mfsp.isFemForm(sStem) or conj.hasConj(sStem, ":PQ", ":Q1"):
   317    314               # what has a feminine form also has a masculine form
   318    315               return True
   319    316       if phonet.hasSimil(sFlex, ":m"):
   320    317           return True
   321    318       return False
   322    319   
   323    320   
   324    321   def switchGender (sFlex, bPlur=None):
   325         -    # we don’t check if word exists in _dAnalyses, for it is assumed it has been done before
   326    322       aSugg = set()
   327    323       if bPlur == None:
   328         -        for sMorph in _dAnalyses.get(sFlex, []):
          324  +        for sMorph in _oSpellChecker.getMorph(sFlex):
   329    325               if ":f" in sMorph:
   330    326                   if ":s" in sMorph:
   331    327                       aSugg.add(suggMasSing(sFlex))
   332    328                   elif ":p" in sMorph:
   333    329                       aSugg.add(suggMasPlur(sFlex))
   334    330               elif ":m" in sMorph:
   335    331                   if ":s" in sMorph:
................................................................................
   336    332                       aSugg.add(suggFemSing(sFlex))
   337    333                   elif ":p" in sMorph:
   338    334                       aSugg.add(suggFemPlur(sFlex))
   339    335                   else:
   340    336                       aSugg.add(suggFemSing(sFlex))
   341    337                       aSugg.add(suggFemPlur(sFlex))
   342    338       elif bPlur:
   343         -        for sMorph in _dAnalyses.get(sFlex, []):
          339  +        for sMorph in _oSpellChecker.getMorph(sFlex):
   344    340               if ":f" in sMorph:
   345    341                   aSugg.add(suggMasPlur(sFlex))
   346    342               elif ":m" in sMorph:
   347    343                   aSugg.add(suggFemPlur(sFlex))
   348    344       else:
   349         -        for sMorph in _dAnalyses.get(sFlex, []):
          345  +        for sMorph in _oSpellChecker.getMorph(sFlex):
   350    346               if ":f" in sMorph:
   351    347                   aSugg.add(suggMasSing(sFlex))
   352    348               elif ":m" in sMorph:
   353    349                   aSugg.add(suggFemSing(sFlex))
   354    350       if aSugg:
   355    351           return "|".join(aSugg)
   356    352       return ""
   357    353   
   358    354   
   359    355   def switchPlural (sFlex):
   360         -    # we don’t check if word exists in _dAnalyses, for it is assumed it has been done before
   361    356       aSugg = set()
   362         -    for sMorph in _dAnalyses.get(sFlex, []):
          357  +    for sMorph in _oSpellChecker.getMorph(sFlex):
   363    358           if ":s" in sMorph:
   364    359               aSugg.add(suggPlur(sFlex))
   365    360           elif ":p" in sMorph:
   366    361               aSugg.add(suggSing(sFlex))
   367    362       if aSugg:
   368    363           return "|".join(aSugg)
   369    364       return ""
................................................................................
   371    366   
   372    367   def hasSimil (sWord, sPattern=None):
   373    368       return phonet.hasSimil(sWord, sPattern)
   374    369   
   375    370   
   376    371   def suggSimil (sWord, sPattern=None, bSubst=False):
   377    372       "return list of words phonetically similar to sWord and whom POS is matching sPattern"
   378         -    # we don’t check if word exists in _dAnalyses, for it is assumed it has been done before
   379    373       aSugg = phonet.selectSimil(sWord, sPattern)
   380         -    for sMorph in _dAnalyses.get(sWord, []):
          374  +    for sMorph in _oSpellChecker.getMorph(sWord):
   381    375           aSugg.update(conj.getSimil(sWord, sMorph, bSubst))
   382    376           break
   383    377       if aSugg:
   384    378           return "|".join(aSugg)
   385    379       return ""
   386    380   
   387    381   
................................................................................
   390    384           return "cet"
   391    385       if sWord[0:1] == "h" or sWord[0:1] == "H":
   392    386           return "ce|cet"
   393    387       return "ce"
   394    388   
   395    389   
   396    390   def suggLesLa (sWord):
   397         -    # we don’t check if word exists in _dAnalyses, for it is assumed it has been done before
   398         -    if any( ":p" in sMorph  for sMorph in _dAnalyses.get(sWord, []) ):
          391  +    if any( ":p" in sMorph  for sMorph in _oSpellChecker.getMorph(sWord) ):
   399    392           return "les|la"
   400    393       return "la"
   401    394   
   402    395   
   403    396   _zBinary = re.compile("^[01]+$")
   404    397   
   405    398   def formatNumber (s):