Grammalecte  Check-in [e98e6badf3]

Overview
Comment:[core][fr][py] suggestions: don’t use set anymone, use list, to keep order insertion
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fr | core
Files: files | file ages | folders
SHA3-256: e98e6badf3b7695215fa2e005b2b71c9ca89f45271b9531d4f18d93828c40758
User & Date: olr on 2021-01-23 15:10:14
Other Links: manifest | tags
Context
2021-01-23
15:50
[fr] ajustements check-in: 852cbe9312 user: olr tags: fr, trunk
15:10
[core][fr][py] suggestions: don’t use set anymone, use list, to keep order insertion check-in: e98e6badf3 user: olr tags: core, fr, trunk
14:02
[core][fr][js] fix getGenderNumber() check-in: 3607227671 user: olr tags: core, fr, trunk
Changes

Modified gc_lang/fr/modules/conj.py from [7b2f58ec61] to [9d698bfb2e].

    57     57       "returns raw informations about sVerb"
    58     58       if sVerb not in _dVerb:
    59     59           return None
    60     60       return _lVtyp[_dVerb[sVerb][0]]
    61     61   
    62     62   
    63     63   def getSimil (sWord, sMorph, bSubst=False):
    64         -    "returns a set of verbal forms similar to <sWord>, according to <sMorph>"
           64  +    "returns a list of verbal forms similar to <sWord>, according to <sMorph>"
    65     65       if ":V" not in sMorph:
    66         -        return set()
           66  +        return []
    67     67       sInfi = sMorph[1:sMorph.find("/")]
    68         -    aSugg = set()
           68  +    aSugg = []
    69     69       tTags = _getTags(sInfi)
    70     70       if tTags:
    71     71           if not bSubst:
    72     72               # we suggest conjugated forms
    73     73               if ":V1" in sMorph:
    74         -                aSugg.add(sInfi)
    75         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":3s"))
    76         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":2p"))
    77         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":1s"))
    78         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3s"))
    79         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3p"))
           74  +                aSugg.append(sInfi)
           75  +                if _hasConjWithTags(tTags, ":Ip", ":3s"):
           76  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":Ip", ":3s"))
           77  +                if _hasConjWithTags(tTags, ":Ip", ":2p"):
           78  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":Ip", ":2p"))
           79  +                if _hasConjWithTags(tTags, ":Iq", ":1s"):
           80  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":Iq", ":1s"))
           81  +                if _hasConjWithTags(tTags, ":Iq", ":3s"):
           82  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":Iq", ":3s"))
           83  +                if _hasConjWithTags(tTags, ":Iq", ":3p"):
           84  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":Iq", ":3p"))
    80     85               elif ":V2" in sMorph:
    81         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":1s"))
    82         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":3s"))
           86  +                if _hasConjWithTags(tTags, ":Ip", ":1s"):
           87  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":Ip", ":1s"))
           88  +                if _hasConjWithTags(tTags, ":Ip", ":3s"):
           89  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":Ip", ":3s"))
    83     90               elif ":V3" in sMorph:
    84         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":1s"))
    85         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":3s"))
    86         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":Is", ":1s"))
    87         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":Is", ":3s"))
           91  +                if _hasConjWithTags(tTags, ":Ip", ":1s"):
           92  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":Ip", ":1s"))
           93  +                if _hasConjWithTags(tTags, ":Ip", ":3s"):
           94  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":Ip", ":3s"))
           95  +                if _hasConjWithTags(tTags, ":Is", ":1s"):
           96  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":Is", ":1s"))
           97  +                if _hasConjWithTags(tTags, ":Is", ":3s"):
           98  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":Is", ":3s"))
    88     99               elif ":V0a" in sMorph:
    89         -                aSugg.add("eus")
    90         -                aSugg.add("eut")
          100  +                aSugg.append("eus")
          101  +                aSugg.append("eut")
    91    102               else:
    92         -                aSugg.add("étais")
    93         -                aSugg.add("était")
    94         -            aSugg.discard("")
          103  +                aSugg.append("étais")
          104  +                aSugg.append("était")
    95    105           else:
    96    106               if sInfi in _dVerbNames:
    97    107                   # there are names derivated from the verb
    98         -                aSugg.update(_dVerbNames[sInfi])
          108  +                aSugg.extend(_dVerbNames[sInfi])
    99    109               else:
   100    110                   # we suggest past participles
   101         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q1"))
   102         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q2"))
   103         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q3"))
   104         -                aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q4"))
   105         -                aSugg.discard("")
          111  +                aSugg.append(_getConjWithTags(sInfi, tTags, ":PQ", ":Q1"))
          112  +                if _hasConjWithTags(tTags, ":PQ", ":Q2"):
          113  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":PQ", ":Q2"))
          114  +                if _hasConjWithTags(tTags, ":PQ", ":Q3"):
          115  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":PQ", ":Q3"))
          116  +                if _hasConjWithTags(tTags, ":PQ", ":Q4"):
          117  +                    aSugg.append(_getConjWithTags(sInfi, tTags, ":PQ", ":Q4"))
   106    118                   # if there is only one past participle (epi inv), unreliable.
   107    119                   if len(aSugg) == 1:
   108         -                    aSugg.clear()
          120  +                    return []
   109    121       return aSugg
   110    122   
   111    123   
   112    124   def getConjSimilInfiV1 (sInfi):
   113    125       "returns verbal forms phonetically similar to infinitive form (for verb in group 1)"
   114    126       if sInfi not in _dVerb:
   115         -        return set()
   116         -    aSugg = set()
          127  +        return []
          128  +    aSugg = []
   117    129       tTags = _getTags(sInfi)
   118    130       if tTags:
          131  +        if _hasConjWithTags(tTags, ":Iq", ":2s"):
   119    132           aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":2s"))
          133  +        if _hasConjWithTags(tTags, ":Iq", ":3s"):
   120    134           aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3s"))
          135  +        if _hasConjWithTags(tTags, ":Iq", ":3p"):
   121    136           aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3p"))
          137  +        if _hasConjWithTags(tTags, ":Is", ":1s"):
   122    138           aSugg.add(_getConjWithTags(sInfi, tTags, ":Is", ":1s"))
          139  +        if _hasConjWithTags(tTags, ":Ip", ":2p"):
   123    140           aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":2p"))
          141  +        if _hasConjWithTags(tTags, ":Iq", ":2p"):
   124    142           aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":2p"))
   125         -        aSugg.discard("")
   126    143       return aSugg
   127    144   
   128    145   
   129    146   def _getTags (sVerb):
   130    147       "returns tuple of tags (usable with functions _getConjWithTags and _hasConjWithTags)"
   131    148       if sVerb not in _dVerb:
   132    149           return None

Modified gc_lang/fr/modules/gce_suggestions.py from [1f53e39acb] to [9319456bd1].

    19     19       return sVerb, sSuffix
    20     20   
    21     21   
    22     22   def suggVerb (sFlex, sWho, funcSugg2=None, bVC=False):
    23     23       "change <sFlex> conjugation according to <sWho>"
    24     24       if bVC:
    25     25           sFlex, sSfx = splitVerb(sFlex)
    26         -    aSugg = set()
           26  +    aSugg = []
    27     27       for sStem in _oSpellChecker.getLemma(sFlex):
    28     28           tTags = conj._getTags(sStem)
    29     29           if tTags:
    30     30               # we get the tense
    31         -            aTense = set()
           31  +            aTense = {} # we use dict as ordered set
    32     32               for sMorph in _oSpellChecker.getMorph(sFlex):
    33     33                   for m in re.finditer(">"+sStem+"/.*?(:(?:Y|I[pqsf]|S[pq]|K|P|Q))", sMorph):
    34     34                       # stem must be used in regex to prevent confusion between different verbs (e.g. sauras has 2 stems: savoir and saurer)
    35     35                       if m:
    36     36                           if m.group(1) == ":Y" or m.group(1) == ":Q":
    37         -                            aTense.add(":Ip")
    38         -                            aTense.add(":Iq")
    39         -                            aTense.add(":Is")
           37  +                            aTense[":Ip"] = ""
           38  +                            aTense[":Iq"] = ""
           39  +                            aTense[":Is"] = ""
    40     40                           elif m.group(1) == ":P":
    41         -                            aTense.add(":Ip")
           41  +                            aTense[":Ip"] = ""
    42     42                           else:
    43         -                            aTense.add(m.group(1))
    44         -            for sTense in aTense:
           43  +                            aTense[m.group(1)] = ""
           44  +            for sTense in aTense.keys():
    45     45                   if sWho == ":1ś" and not conj._hasConjWithTags(tTags, sTense, ":1ś"):
    46     46                       sWho = ":1s"
    47     47                   if conj._hasConjWithTags(tTags, sTense, sWho):
    48         -                    aSugg.add(conj._getConjWithTags(sStem, tTags, sTense, sWho))
           48  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, sTense, sWho))
    49     49       if funcSugg2:
    50     50           sSugg2 = funcSugg2(sFlex)
    51     51           if sSugg2:
    52         -            aSugg.add(sSugg2)
           52  +            aSugg.append(sSugg2)
    53     53       if aSugg:
    54     54           if bVC:
    55     55               aSugg = [ joinVerbAndSuffix(sSugg, sSfx)  for sSugg in aSugg ]
    56     56           return "|".join(aSugg)
    57     57       return ""
    58     58   
    59     59   
................................................................................
    66     66           if re.match("(?i)-(?:ie?l|elle|on)$", sSfx):
    67     67               return sFlex + "-t" + sSfx
    68     68       return sFlex + sSfx
    69     69   
    70     70   
    71     71   def suggVerbPpas (sFlex, sPattern=None):
    72     72       "suggest past participles for <sFlex>"
    73         -    aSugg = set()
           73  +    aSugg = []
    74     74       for sStem in _oSpellChecker.getLemma(sFlex):
    75     75           tTags = conj._getTags(sStem)
    76     76           if tTags:
    77     77               if not sPattern:
    78         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
    79         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2"))
    80         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3"))
    81         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4"))
    82         -                aSugg.discard("")
           78  +                aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
           79  +                if conj._hasConjWithTags(tTags, ":PQ", ":Q2"):
           80  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2"))
           81  +                if conj._hasConjWithTags(tTags, ":PQ", ":Q3"):
           82  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3"))
           83  +                if conj._hasConjWithTags(tTags, ":PQ", ":Q4"):
           84  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4"))
    83     85               elif sPattern == ":m:s":
    84         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
           86  +                aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
    85     87               elif sPattern == ":m:p":
    86     88                   if conj._hasConjWithTags(tTags, ":PQ", ":Q2"):
    87         -                    aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2"))
           89  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2"))
    88     90                   else:
    89         -                    aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
           91  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
    90     92               elif sPattern == ":f:s":
    91     93                   if conj._hasConjWithTags(tTags, ":PQ", ":Q3"):
    92         -                    aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3"))
           94  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3"))
    93     95                   else:
    94         -                    aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
           96  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
    95     97               elif sPattern == ":f:p":
    96     98                   if conj._hasConjWithTags(tTags, ":PQ", ":Q4"):
    97         -                    aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4"))
           99  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4"))
    98    100                   else:
    99         -                    aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
          101  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
   100    102               elif sPattern == ":s":
   101         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
   102         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3"))
   103         -                aSugg.discard("")
          103  +                aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
          104  +                if conj._hasConjWithTags(tTags, ":PQ", ":Q3"):
          105  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3"))
   104    106               elif sPattern == ":p":
   105         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2"))
   106         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4"))
   107         -                aSugg.discard("")
          107  +                if conj._hasConjWithTags(tTags, ":PQ", ":Q2"):
          108  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2"))
   108    109               else:
   109         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
          110  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
          111  +                if conj._hasConjWithTags(tTags, ":PQ", ":Q4"):
          112  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4"))
          113  +            else:
          114  +                aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
   110    115       if aSugg:
   111    116           return "|".join(aSugg)
   112    117       return ""
   113    118   
   114    119   
   115    120   def suggVerbTense (sFlex, sTense, sWho):
   116    121       "change <sFlex> to a verb according to <sTense> and <sWho>"
   117         -    aSugg = set()
          122  +    aSugg = []
   118    123       for sStem in _oSpellChecker.getLemma(sFlex):
   119    124           if conj.hasConj(sStem, sTense, sWho):
   120         -            aSugg.add(conj.getConj(sStem, sTense, sWho))
          125  +            aSugg.append(conj.getConj(sStem, sTense, sWho))
   121    126       if aSugg:
   122    127           return "|".join(aSugg)
   123    128       return ""
   124    129   
   125    130   
   126    131   def suggVerbFrom (sStem, sFlex, sWho=""):
   127    132       "conjugate <sStem> according to <sFlex> (and eventually <sWho>)"
   128         -    aSugg = set()
          133  +    aSugg = []
   129    134       for sMorph in _oSpellChecker.getMorph(sFlex):
   130    135           lTenses = [ m.group(0)  for m in re.finditer(":(?:Y|I[pqsf]|S[pq]|K|P|Q)", sMorph) ]
   131    136           if sWho:
   132    137               for sTense in lTenses:
   133    138                   if conj.hasConj(sStem, sTense, sWho):
   134         -                    aSugg.add(conj.getConj(sStem, sTense, sWho))
          139  +                    aSugg.append(conj.getConj(sStem, sTense, sWho))
   135    140           else:
   136    141               for sTense in lTenses:
   137    142                   for sWho in [ m.group(0)  for m in re.finditer(":[123][sp]", sMorph) ]:
   138    143                       if conj.hasConj(sStem, sTense, sWho):
   139         -                        aSugg.add(conj.getConj(sStem, sTense, sWho))
          144  +                        aSugg.append(conj.getConj(sStem, sTense, sWho))
   140    145       if aSugg:
   141    146           return "|".join(aSugg)
   142    147       return ""
   143    148   
   144    149   
   145    150   def suggVerbImpe (sFlex, bVC=False):
   146    151       "change <sFlex> to a verb at imperative form"
   147    152       if bVC:
   148    153           sFlex, sSfx = splitVerb(sFlex)
   149         -    aSugg = set()
          154  +    aSugg = []
   150    155       for sStem in _oSpellChecker.getLemma(sFlex):
   151    156           tTags = conj._getTags(sStem)
   152    157           if tTags:
   153    158               if conj._hasConjWithTags(tTags, ":E", ":2s"):
   154         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":E", ":2s"))
          159  +                aSugg.append(conj._getConjWithTags(sStem, tTags, ":E", ":2s"))
   155    160               if conj._hasConjWithTags(tTags, ":E", ":1p"):
   156         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":E", ":1p"))
          161  +                aSugg.append(conj._getConjWithTags(sStem, tTags, ":E", ":1p"))
   157    162               if conj._hasConjWithTags(tTags, ":E", ":2p"):
   158         -                aSugg.add(conj._getConjWithTags(sStem, tTags, ":E", ":2p"))
          163  +                aSugg.append(conj._getConjWithTags(sStem, tTags, ":E", ":2p"))
   159    164       if aSugg:
   160    165           if bVC:
   161    166               aSugg = [ joinVerbAndSuffix(sSugg, sSfx)  for sSugg in aSugg ]
   162    167           return "|".join(aSugg)
   163    168       return ""
   164    169   
   165    170   
................................................................................
   178    183       elif cMode == ":S":
   179    184           lMode = [":Sp", ":Sq"]
   180    185       elif cMode.startswith((":I", ":S")):
   181    186           lMode = [cMode]
   182    187       else:
   183    188           return ""
   184    189       sWho = _dQuiEst.get(sSuj.lower(), ":3s")
   185         -    aSugg = set()
          190  +    aSugg = []
   186    191       for sStem in _oSpellChecker.getLemma(sFlex):
   187    192           tTags = conj._getTags(sStem)
   188    193           if tTags:
   189    194               for sTense in lMode:
   190    195                   if conj._hasConjWithTags(tTags, sTense, sWho):
   191         -                    aSugg.add(conj._getConjWithTags(sStem, tTags, sTense, sWho))
          196  +                    aSugg.append(conj._getConjWithTags(sStem, tTags, sTense, sWho))
   192    197       if aSugg:
   193    198           return "|".join(aSugg)
   194    199       return ""
   195    200   
   196    201   
   197    202   ## Nouns and adjectives
   198    203   
   199    204   def suggPlur (sFlex, bSelfSugg=False):
   200    205       "returns plural forms assuming sFlex is singular"
   201         -    aSugg = set()
          206  +    aSugg = []
   202    207       if sFlex.endswith("l"):
   203    208           if sFlex.endswith("al") and len(sFlex) > 2 and _oSpellChecker.isValid(sFlex[:-1]+"ux"):
   204         -            aSugg.add(sFlex[:-1]+"ux")
          209  +            aSugg.append(sFlex[:-1]+"ux")
   205    210           if sFlex.endswith("ail") and len(sFlex) > 3 and _oSpellChecker.isValid(sFlex[:-2]+"ux"):
   206         -            aSugg.add(sFlex[:-2]+"ux")
          211  +            aSugg.append(sFlex[:-2]+"ux")
   207    212       if sFlex.endswith("L"):
   208    213           if sFlex.endswith("AL") and len(sFlex) > 2 and _oSpellChecker.isValid(sFlex[:-1]+"UX"):
   209         -            aSugg.add(sFlex[:-1]+"UX")
          214  +            aSugg.append(sFlex[:-1]+"UX")
   210    215           if sFlex.endswith("AIL") and len(sFlex) > 3 and _oSpellChecker.isValid(sFlex[:-2]+"UX"):
   211         -            aSugg.add(sFlex[:-2]+"UX")
          216  +            aSugg.append(sFlex[:-2]+"UX")
   212    217       if sFlex[-1:].islower():
   213    218           if _oSpellChecker.isValid(sFlex+"s"):
   214         -            aSugg.add(sFlex+"s")
          219  +            aSugg.append(sFlex+"s")
   215    220           if _oSpellChecker.isValid(sFlex+"x"):
   216         -            aSugg.add(sFlex+"x")
          221  +            aSugg.append(sFlex+"x")
   217    222       else:
   218    223           if _oSpellChecker.isValid(sFlex+"S"):
   219         -            aSugg.add(sFlex+"S")
          224  +            aSugg.append(sFlex+"S")
   220    225           if _oSpellChecker.isValid(sFlex+"X"):
   221         -            aSugg.add(sFlex+"X")
          226  +            aSugg.append(sFlex+"X")
   222    227       if mfsp.hasMiscPlural(sFlex):
   223         -        aSugg.update(mfsp.getMiscPlural(sFlex))
          228  +        aSugg.extend(mfsp.getMiscPlural(sFlex))
   224    229       if not aSugg and bSelfSugg and sFlex.endswith(("s", "x", "S", "X")):
   225         -        aSugg.add(sFlex)
   226         -    aSugg.discard("")
          230  +        aSugg.append(sFlex)
   227    231       if aSugg:
   228    232           return "|".join(aSugg)
   229    233       return ""
   230    234   
   231    235   
   232    236   def suggSing (sFlex, bSelfSugg=True):
   233    237       "returns singular forms assuming sFlex is plural"
   234         -    aSugg = set()
          238  +    aSugg = []
   235    239       if sFlex.endswith("ux"):
   236    240           if _oSpellChecker.isValid(sFlex[:-2]+"l"):
   237         -            aSugg.add(sFlex[:-2]+"l")
          241  +            aSugg.append(sFlex[:-2]+"l")
   238    242           if _oSpellChecker.isValid(sFlex[:-2]+"il"):
   239         -            aSugg.add(sFlex[:-2]+"il")
          243  +            aSugg.append(sFlex[:-2]+"il")
   240    244       if sFlex.endswith("UX"):
   241    245           if _oSpellChecker.isValid(sFlex[:-2]+"L"):
   242         -            aSugg.add(sFlex[:-2]+"L")
          246  +            aSugg.append(sFlex[:-2]+"L")
   243    247           if _oSpellChecker.isValid(sFlex[:-2]+"IL"):
   244         -            aSugg.add(sFlex[:-2]+"IL")
          248  +            aSugg.append(sFlex[:-2]+"IL")
   245    249       if sFlex.endswith(("s", "x", "S", "X")) and _oSpellChecker.isValid(sFlex[:-1]):
   246         -        aSugg.add(sFlex[:-1])
          250  +        aSugg.append(sFlex[:-1])
   247    251       if bSelfSugg and not aSugg:
   248         -        aSugg.add(sFlex)
   249         -    aSugg.discard("")
          252  +        aSugg.append(sFlex)
   250    253       if aSugg:
   251    254           return "|".join(aSugg)
   252    255       return ""
   253    256   
   254    257   
   255    258   def suggMasSing (sFlex, bSuggSimil=False):
   256    259       "returns masculine singular forms"
   257         -    aSugg = set()
          260  +    aSugg = []
   258    261       for sMorph in _oSpellChecker.getMorph(sFlex):
   259    262           if not ":V" in sMorph:
   260    263               # not a verb
   261    264               if ":m" in sMorph or ":e" in sMorph:
   262         -                aSugg.add(suggSing(sFlex))
          265  +                aSugg.append(suggSing(sFlex))
   263    266               else:
   264    267                   sStem = cr.getLemmaOfMorph(sMorph)
   265    268                   if mfsp.isMasForm(sStem):
   266         -                    aSugg.add(sStem)
          269  +                    aSugg.append(sStem)
   267    270           else:
   268    271               # a verb
   269    272               sVerb = cr.getLemmaOfMorph(sMorph)
   270    273               if conj.hasConj(sVerb, ":PQ", ":Q1") and conj.hasConj(sVerb, ":PQ", ":Q3"):
   271    274                   # We also check if the verb has a feminine form.
   272    275                   # If not, we consider it’s better to not suggest the masculine one, as it can be considered invariable.
   273         -                aSugg.add(conj.getConj(sVerb, ":PQ", ":Q1"))
          276  +                aSugg.append(conj.getConj(sVerb, ":PQ", ":Q1"))
   274    277       if bSuggSimil:
   275    278           for e in phonet.selectSimil(sFlex, ":m:[si]"):
   276         -            aSugg.add(e)
   277         -    aSugg.discard("")
          279  +            aSugg.append(e)
   278    280       if aSugg:
   279    281           return "|".join(aSugg)
   280    282       return ""
   281    283   
   282    284   
   283    285   def suggMasPlur (sFlex, bSuggSimil=False):
   284    286       "returns masculine plural forms"
   285         -    aSugg = set()
          287  +    aSugg = []
   286    288       for sMorph in _oSpellChecker.getMorph(sFlex):
   287    289           if not ":V" in sMorph:
   288    290               # not a verb
   289    291               if ":m" in sMorph or ":e" in sMorph:
   290         -                aSugg.add(suggPlur(sFlex))
          292  +                aSugg.append(suggPlur(sFlex))
   291    293               else:
   292    294                   sStem = cr.getLemmaOfMorph(sMorph)
   293    295                   if mfsp.isMasForm(sStem):
   294         -                    aSugg.add(suggPlur(sStem, True))
          296  +                    aSugg.append(suggPlur(sStem, True))
   295    297           else:
   296    298               # a verb
   297    299               sVerb = cr.getLemmaOfMorph(sMorph)
   298    300               if conj.hasConj(sVerb, ":PQ", ":Q2"):
   299         -                aSugg.add(conj.getConj(sVerb, ":PQ", ":Q2"))
          301  +                aSugg.append(conj.getConj(sVerb, ":PQ", ":Q2"))
   300    302               elif conj.hasConj(sVerb, ":PQ", ":Q1"):
   301    303                   sSugg = conj.getConj(sVerb, ":PQ", ":Q1")
   302    304                   # it is necessary to filter these flexions, like “succédé” or “agi” that are not masculine plural.
   303    305                   if sSugg.endswith("s"):
   304         -                    aSugg.add(sSugg)
          306  +                    aSugg.append(sSugg)
   305    307       if bSuggSimil:
   306    308           for e in phonet.selectSimil(sFlex, ":m:[pi]"):
   307         -            aSugg.add(e)
   308         -    aSugg.discard("")
          309  +            aSugg.append(e)
   309    310       if aSugg:
   310    311           return "|".join(aSugg)
   311    312       return ""
   312    313   
   313    314   
   314    315   def suggFemSing (sFlex, bSuggSimil=False):
   315    316       "returns feminine singular forms"
   316         -    aSugg = set()
          317  +    aSugg = []
   317    318       for sMorph in _oSpellChecker.getMorph(sFlex):
   318    319           if not ":V" in sMorph:
   319    320               # not a verb
   320    321               if ":f" in sMorph or ":e" in sMorph:
   321         -                aSugg.add(suggSing(sFlex))
          322  +                aSugg.append(suggSing(sFlex))
   322    323               else:
   323    324                   sStem = cr.getLemmaOfMorph(sMorph)
   324    325                   if mfsp.isMasForm(sStem):
   325         -                    aSugg.update(mfsp.getFemForm(sStem, False))
          326  +                    aSugg.extend(mfsp.getFemForm(sStem, False))
   326    327           else:
   327    328               # a verb
   328    329               sVerb = cr.getLemmaOfMorph(sMorph)
   329    330               if conj.hasConj(sVerb, ":PQ", ":Q3"):
   330         -                aSugg.add(conj.getConj(sVerb, ":PQ", ":Q3"))
          331  +                aSugg.append(conj.getConj(sVerb, ":PQ", ":Q3"))
   331    332       if bSuggSimil:
   332    333           for e in phonet.selectSimil(sFlex, ":f:[si]"):
   333         -            aSugg.add(e)
   334         -    aSugg.discard("")
          334  +            aSugg.append(e)
   335    335       if aSugg:
   336    336           return "|".join(aSugg)
   337    337       return ""
   338    338   
   339    339   
   340    340   def suggFemPlur (sFlex, bSuggSimil=False):
   341    341       "returns feminine plural forms"
   342         -    aSugg = set()
          342  +    aSugg = []
   343    343       for sMorph in _oSpellChecker.getMorph(sFlex):
   344    344           if not ":V" in sMorph:
   345    345               # not a verb
   346    346               if ":f" in sMorph or ":e" in sMorph:
   347         -                aSugg.add(suggPlur(sFlex))
          347  +                aSugg.append(suggPlur(sFlex))
   348    348               else:
   349    349                   sStem = cr.getLemmaOfMorph(sMorph)
   350    350                   if mfsp.isMasForm(sStem):
   351         -                    aSugg.update(mfsp.getFemForm(sStem, True))
          351  +                    aSugg.extend(mfsp.getFemForm(sStem, True))
   352    352           else:
   353    353               # a verb
   354    354               sVerb = cr.getLemmaOfMorph(sMorph)
   355    355               if conj.hasConj(sVerb, ":PQ", ":Q4"):
   356         -                aSugg.add(conj.getConj(sVerb, ":PQ", ":Q4"))
          356  +                aSugg.append(conj.getConj(sVerb, ":PQ", ":Q4"))
   357    357       if bSuggSimil:
   358    358           for e in phonet.selectSimil(sFlex, ":f:[pi]"):
   359         -            aSugg.add(e)
   360         -    aSugg.discard("")
          359  +            aSugg.append(e)
   361    360       if aSugg:
   362    361           return "|".join(aSugg)
   363    362       return ""
   364    363   
   365    364   
   366    365   def g_suggAgree (dTokenDst, dTokenSrc):
   367    366       "returns suggestions for <dTokenDst> that matches agreement with <dTokenSrc>"
................................................................................
   409    408       if phonet.hasSimil(sFlex, ":m"):
   410    409           return True
   411    410       return False
   412    411   
   413    412   
   414    413   def switchGender (sFlex, bPlur=None):
   415    414       "return feminine or masculine form(s) of <sFlex>"
   416         -    aSugg = set()
          415  +    aSugg = []
   417    416       if bPlur is None:
   418    417           for sMorph in _oSpellChecker.getMorph(sFlex):
   419    418               if ":f" in sMorph:
   420    419                   if ":s" in sMorph:
   421         -                    aSugg.add(suggMasSing(sFlex))
          420  +                    aSugg.append(suggMasSing(sFlex))
   422    421                   elif ":p" in sMorph:
   423         -                    aSugg.add(suggMasPlur(sFlex))
          422  +                    aSugg.append(suggMasPlur(sFlex))
   424    423               elif ":m" in sMorph:
   425    424                   if ":s" in sMorph:
   426         -                    aSugg.add(suggFemSing(sFlex))
          425  +                    aSugg.append(suggFemSing(sFlex))
   427    426                   elif ":p" in sMorph:
   428         -                    aSugg.add(suggFemPlur(sFlex))
          427  +                    aSugg.append(suggFemPlur(sFlex))
   429    428                   else:
   430         -                    aSugg.add(suggFemSing(sFlex))
   431         -                    aSugg.add(suggFemPlur(sFlex))
          429  +                    aSugg.append(suggFemSing(sFlex))
          430  +                    aSugg.append(suggFemPlur(sFlex))
   432    431       elif bPlur:
   433    432           for sMorph in _oSpellChecker.getMorph(sFlex):
   434    433               if ":f" in sMorph:
   435         -                aSugg.add(suggMasPlur(sFlex))
          434  +                aSugg.append(suggMasPlur(sFlex))
   436    435               elif ":m" in sMorph:
   437         -                aSugg.add(suggFemPlur(sFlex))
          436  +                aSugg.append(suggFemPlur(sFlex))
   438    437       else:
   439    438           for sMorph in _oSpellChecker.getMorph(sFlex):
   440    439               if ":f" in sMorph:
   441         -                aSugg.add(suggMasSing(sFlex))
          440  +                aSugg.append(suggMasSing(sFlex))
   442    441               elif ":m" in sMorph:
   443         -                aSugg.add(suggFemSing(sFlex))
          442  +                aSugg.append(suggFemSing(sFlex))
   444    443       if aSugg:
   445    444           return "|".join(aSugg)
   446    445       return ""
   447    446   
   448    447   
   449    448   def switchPlural (sFlex):
   450    449       "return plural or singular form(s) of <sFlex>"
   451         -    aSugg = set()
          450  +    aSugg = []
   452    451       for sMorph in _oSpellChecker.getMorph(sFlex):
   453    452           if ":s" in sMorph:
   454         -            aSugg.add(suggPlur(sFlex))
          453  +            aSugg.append(suggPlur(sFlex))
   455    454           elif ":p" in sMorph:
   456         -            aSugg.add(suggSing(sFlex))
          455  +            aSugg.append(suggSing(sFlex))
   457    456       if aSugg:
   458    457           return "|".join(aSugg)
   459    458       return ""
   460    459   
   461    460   
   462    461   def hasSimil (sWord, sPattern=None):
   463    462       "return True if there is words phonetically similar to <sWord> (according to <sPattern> if required)"
................................................................................
   467    466   def suggSimil (sWord, sPattern=None, bSubst=False, bVC=False):
   468    467       "return list of words phonetically similar to sWord and whom POS is matching sPattern"
   469    468       if bVC:
   470    469           sWord, sSfx = splitVerb(sWord)
   471    470       aSugg = phonet.selectSimil(sWord, sPattern)
   472    471       if not aSugg or not bSubst:
   473    472           for sMorph in _oSpellChecker.getMorph(sWord):
   474         -            aSugg.update(conj.getSimil(sWord, sMorph, bSubst))
          473  +            aSugg.extend(conj.getSimil(sWord, sMorph, bSubst))
   475    474               break
   476    475       if aSugg:
   477    476           if bVC:
   478    477               aSugg = [ joinVerbAndSuffix(sSugg, sSfx)  for sSugg in aSugg ]
   479    478           return "|".join(aSugg)
   480    479       return ""
   481    480   

Modified gc_lang/fr/modules/phonet.py from [cf22067e41] to [5f35e74371].

    38     38           sWord = sWord.lower()
    39     39           if sWord in _dWord:
    40     40               return _lSet[_dWord[sWord]]
    41     41       return []
    42     42   
    43     43   
    44     44   def selectSimil (sWord, sPattern):
    45         -    "return a set of words phonetically similar to <sWord> and whom POS is matching <sPattern>"
           45  +    "return a list of words phonetically similar to <sWord> and whom POS is matching <sPattern>"
    46     46       if not sPattern:
    47         -        return set(getSimil(sWord))
    48         -    aSelect = set()
           47  +        return getSimil(sWord)
           48  +    aSelect = []
    49     49       for sSimil in getSimil(sWord):
    50     50           for sMorph in _dMorph.get(sSimil, []):
    51     51               if re.search(sPattern, sMorph):
    52         -                aSelect.add(sSimil)
           52  +                aSelect.append(sSimil)
    53     53       return aSelect
    54     54   
    55     55   
    56     56   def _getSetNumber (sWord):
    57     57       "return the set number where <sWord> belongs, else -1"
    58     58       if sWord in _dWord:
    59     59           return _dWord[sWord]