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
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
121
122
123
124
125
126
127
128
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
|
aTense[":Ip"] = ""
else:
aTense[m.group(1)] = ""
for sTense in aTense.keys():
if sWho == ":1ś" and not conj._hasConjWithTags(tTags, sTense, ":1ś"):
sWho = ":1s"
if conj._hasConjWithTags(tTags, sTense, sWho):
aSugg.append(conj._getConjWithTags(sStem, tTags, sTense, sWho))
if funcSugg2:
sSugg2 = funcSugg2(sFlex)
if sSugg2:
aSugg.append(sSugg2)
if aSugg:
if bVC:
aSugg = [ joinVerbAndSuffix(sSugg, sSfx) for sSugg in aSugg ]
return "|".join(aSugg)
return ""
def joinVerbAndSuffix (sFlex, sSfx):
if sSfx.startswith(("-t-", "-T-")) and sFlex.endswith(("t", "d", "T", "D")):
return sFlex + sSfx[2:]
if sFlex.endswith(("e", "a", "c", "E", "A", "C")):
if re.match("(?i)-(?:en|y)$", sSfx):
return sFlex + "s" + sSfx
if re.match("(?i)-(?:ie?l|elle|on)$", sSfx):
return sFlex + "-t" + sSfx
return sFlex + sSfx
def suggVerbPpas (sFlex, sPattern=None):
"suggest past participles for <sFlex>"
aSugg = []
for sStem in _oSpellChecker.getLemma(sFlex):
tTags = conj._getTags(sStem)
if tTags:
if not sPattern:
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
if conj._hasConjWithTags(tTags, ":PQ", ":Q2"):
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2"))
if conj._hasConjWithTags(tTags, ":PQ", ":Q3"):
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3"))
if conj._hasConjWithTags(tTags, ":PQ", ":Q4"):
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4"))
elif sPattern == ":m:s":
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
elif sPattern == ":m:p":
if conj._hasConjWithTags(tTags, ":PQ", ":Q2"):
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2"))
else:
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
elif sPattern == ":f:s":
if conj._hasConjWithTags(tTags, ":PQ", ":Q3"):
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3"))
else:
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
elif sPattern == ":f:p":
if conj._hasConjWithTags(tTags, ":PQ", ":Q4"):
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4"))
else:
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
elif sPattern == ":s":
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
if conj._hasConjWithTags(tTags, ":PQ", ":Q3"):
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3"))
elif sPattern == ":p":
if conj._hasConjWithTags(tTags, ":PQ", ":Q2"):
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2"))
else:
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
if conj._hasConjWithTags(tTags, ":PQ", ":Q4"):
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4"))
else:
aSugg.append(conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1"))
if aSugg:
return "|".join(aSugg)
return ""
def suggVerbTense (sFlex, sTense, sWho):
"change <sFlex> to a verb according to <sTense> and <sWho>"
aSugg = []
for sStem in _oSpellChecker.getLemma(sFlex):
if conj.hasConj(sStem, sTense, sWho):
aSugg.append(conj.getConj(sStem, sTense, sWho))
if aSugg:
return "|".join(aSugg)
return ""
def suggVerbFrom (sStem, sFlex, sWho=""):
"conjugate <sStem> according to <sFlex> (and eventually <sWho>)"
aSugg = []
for sMorph in _oSpellChecker.getMorph(sFlex):
lTenses = [ m.group(0) for m in re.finditer(":(?:Y|I[pqsf]|S[pq]|K|P|Q)", sMorph) ]
if sWho:
for sTense in lTenses:
if conj.hasConj(sStem, sTense, sWho):
aSugg.append(conj.getConj(sStem, sTense, sWho))
else:
for sTense in lTenses:
for sWho in [ m.group(0) for m in re.finditer(":[123][sp]", sMorph) ]:
if conj.hasConj(sStem, sTense, sWho):
aSugg.append(conj.getConj(sStem, sTense, sWho))
if aSugg:
return "|".join(aSugg)
return ""
def suggVerbImpe (sFlex, bVC=False):
"change <sFlex> to a verb at imperative form"
if bVC:
sFlex, sSfx = splitVerb(sFlex)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
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
121
122
123
124
125
126
127
128
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
|
aTense[":Ip"] = ""
else:
aTense[m.group(1)] = ""
for sTense in aTense.keys():
if sWho == ":1ś" and not conj._hasConjWithTags(tTags, sTense, ":1ś"):
sWho = ":1s"
if conj._hasConjWithTags(tTags, sTense, sWho):
dSugg[conj._getConjWithTags(sStem, tTags, sTense, sWho)] = ""
if funcSugg2:
sSugg2 = funcSugg2(sFlex)
if sSugg2:
dSugg[sSugg2] = ""
if dSugg:
if bVC:
return "|".join([ joinVerbAndSuffix(sSugg, sSfx) for sSugg in dSugg.keys() ])
return "|".join(dSugg.keys())
return ""
def joinVerbAndSuffix (sFlex, sSfx):
if sSfx.startswith(("-t-", "-T-")) and sFlex.endswith(("t", "d", "T", "D")):
return sFlex + sSfx[2:]
if sFlex.endswith(("e", "a", "c", "E", "A", "C")):
if re.match("(?i)-(?:en|y)$", sSfx):
return sFlex + "s" + sSfx
if re.match("(?i)-(?:ie?l|elle|on)$", sSfx):
return sFlex + "-t" + sSfx
return sFlex + sSfx
def suggVerbPpas (sFlex, sPattern=None):
"suggest past participles for <sFlex>"
dSugg = {}
for sStem in _oSpellChecker.getLemma(sFlex):
tTags = conj._getTags(sStem)
if tTags:
if not sPattern:
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1")] = ""
if conj._hasConjWithTags(tTags, ":PQ", ":Q2"):
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2")] = ""
if conj._hasConjWithTags(tTags, ":PQ", ":Q3"):
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3")] = ""
if conj._hasConjWithTags(tTags, ":PQ", ":Q4"):
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4")] = ""
elif sPattern == ":m:s":
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1")] = ""
elif sPattern == ":m:p":
if conj._hasConjWithTags(tTags, ":PQ", ":Q2"):
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2")] = ""
else:
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1")] = ""
elif sPattern == ":f:s":
if conj._hasConjWithTags(tTags, ":PQ", ":Q3"):
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3")] = ""
else:
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1")] = ""
elif sPattern == ":f:p":
if conj._hasConjWithTags(tTags, ":PQ", ":Q4"):
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4")] = ""
else:
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1")] = ""
elif sPattern == ":s":
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1")] = ""
if conj._hasConjWithTags(tTags, ":PQ", ":Q3"):
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q3")] = ""
elif sPattern == ":p":
if conj._hasConjWithTags(tTags, ":PQ", ":Q2"):
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q2")] = ""
else:
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1")] = ""
if conj._hasConjWithTags(tTags, ":PQ", ":Q4"):
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q4")] = ""
else:
dSugg[conj._getConjWithTags(sStem, tTags, ":PQ", ":Q1")] = ""
if dSugg:
return "|".join(dSugg)
return ""
def suggVerbTense (sFlex, sTense, sWho):
"change <sFlex> to a verb according to <sTense> and <sWho>"
aSugg = []
for sStem in _oSpellChecker.getLemma(sFlex):
if conj.hasConj(sStem, sTense, sWho):
aSugg.append(conj.getConj(sStem, sTense, sWho))
if aSugg:
return "|".join(aSugg)
return ""
def suggVerbFrom (sStem, sFlex, sWho=""):
"conjugate <sStem> according to <sFlex> (and eventually <sWho>)"
dSugg = {}
for sMorph in _oSpellChecker.getMorph(sFlex):
lTenses = [ m.group(0) for m in re.finditer(":(?:Y|I[pqsf]|S[pq]|K|P|Q)", sMorph) ]
if sWho:
for sTense in lTenses:
if conj.hasConj(sStem, sTense, sWho):
dSugg[conj.getConj(sStem, sTense, sWho)] = ""
else:
for sTense in lTenses:
for sWho in [ m.group(0) for m in re.finditer(":[123][sp]", sMorph) ]:
if conj.hasConj(sStem, sTense, sWho):
dSugg[conj.getConj(sStem, sTense, sWho)] = ""
if dSugg:
return "|".join(dSugg.keys())
return ""
def suggVerbImpe (sFlex, bVC=False):
"change <sFlex> to a verb at imperative form"
if bVC:
sFlex, sSfx = splitVerb(sFlex)
|
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
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
|
if aSugg:
return "|".join(aSugg)
return ""
def suggMasSing (sFlex, bSuggSimil=False):
"returns masculine singular forms"
aSugg = []
for sMorph in _oSpellChecker.getMorph(sFlex):
if not ":V" in sMorph:
# not a verb
if ":m" in sMorph or ":e" in sMorph:
aSugg.append(suggSing(sFlex))
else:
sStem = cr.getLemmaOfMorph(sMorph)
if mfsp.isMasForm(sStem):
aSugg.append(sStem)
else:
# a verb
sVerb = cr.getLemmaOfMorph(sMorph)
if conj.hasConj(sVerb, ":PQ", ":Q1") and conj.hasConj(sVerb, ":PQ", ":Q3"):
# We also check if the verb has a feminine form.
# If not, we consider it’s better to not suggest the masculine one, as it can be considered invariable.
aSugg.append(conj.getConj(sVerb, ":PQ", ":Q1"))
if bSuggSimil:
for e in phonet.selectSimil(sFlex, ":m:[si]"):
aSugg.append(e)
if aSugg:
return "|".join(aSugg)
return ""
def suggMasPlur (sFlex, bSuggSimil=False):
"returns masculine plural forms"
aSugg = []
for sMorph in _oSpellChecker.getMorph(sFlex):
if not ":V" in sMorph:
# not a verb
if ":m" in sMorph or ":e" in sMorph:
aSugg.append(suggPlur(sFlex))
else:
sStem = cr.getLemmaOfMorph(sMorph)
if mfsp.isMasForm(sStem):
aSugg.append(suggPlur(sStem, True))
else:
# a verb
sVerb = cr.getLemmaOfMorph(sMorph)
if conj.hasConj(sVerb, ":PQ", ":Q2"):
aSugg.append(conj.getConj(sVerb, ":PQ", ":Q2"))
elif conj.hasConj(sVerb, ":PQ", ":Q1"):
sSugg = conj.getConj(sVerb, ":PQ", ":Q1")
# it is necessary to filter these flexions, like “succédé” or “agi” that are not masculine plural.
if sSugg.endswith("s"):
aSugg.append(sSugg)
if bSuggSimil:
for e in phonet.selectSimil(sFlex, ":m:[pi]"):
aSugg.append(e)
if aSugg:
return "|".join(aSugg)
return ""
def suggFemSing (sFlex, bSuggSimil=False):
"returns feminine singular forms"
aSugg = []
for sMorph in _oSpellChecker.getMorph(sFlex):
if not ":V" in sMorph:
# not a verb
if ":f" in sMorph or ":e" in sMorph:
aSugg.append(suggSing(sFlex))
else:
sStem = cr.getLemmaOfMorph(sMorph)
if mfsp.isMasForm(sStem):
aSugg.extend(mfsp.getFemForm(sStem, False))
else:
# a verb
sVerb = cr.getLemmaOfMorph(sMorph)
if conj.hasConj(sVerb, ":PQ", ":Q3"):
aSugg.append(conj.getConj(sVerb, ":PQ", ":Q3"))
if bSuggSimil:
for e in phonet.selectSimil(sFlex, ":f:[si]"):
aSugg.append(e)
if aSugg:
return "|".join(aSugg)
return ""
def suggFemPlur (sFlex, bSuggSimil=False):
"returns feminine plural forms"
aSugg = []
for sMorph in _oSpellChecker.getMorph(sFlex):
if not ":V" in sMorph:
# not a verb
if ":f" in sMorph or ":e" in sMorph:
aSugg.append(suggPlur(sFlex))
else:
sStem = cr.getLemmaOfMorph(sMorph)
if mfsp.isMasForm(sStem):
aSugg.extend(mfsp.getFemForm(sStem, True))
else:
# a verb
sVerb = cr.getLemmaOfMorph(sMorph)
if conj.hasConj(sVerb, ":PQ", ":Q4"):
aSugg.append(conj.getConj(sVerb, ":PQ", ":Q4"))
if bSuggSimil:
for e in phonet.selectSimil(sFlex, ":f:[pi]"):
aSugg.append(e)
if aSugg:
return "|".join(aSugg)
return ""
def g_suggAgree (dTokenDst, dTokenSrc):
"returns suggestions for <dTokenDst> that matches agreement with <dTokenSrc>"
lMorphSrc = dTokenSrc["lMorph"] if "lMorph" in dTokenSrc else _oSpellChecker.getMorph(dTokenSrc["sValue"])
if not lMorphSrc:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
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
|
if aSugg:
return "|".join(aSugg)
return ""
def suggMasSing (sFlex, bSuggSimil=False):
"returns masculine singular forms"
dSugg = {}
for sMorph in _oSpellChecker.getMorph(sFlex):
if not ":V" in sMorph:
# not a verb
if ":m" in sMorph or ":e" in sMorph:
dSugg[suggSing(sFlex)] = ""
else:
sStem = cr.getLemmaOfMorph(sMorph)
if mfsp.isMasForm(sStem):
dSugg[sStem] = ""
else:
# a verb
sVerb = cr.getLemmaOfMorph(sMorph)
if conj.hasConj(sVerb, ":PQ", ":Q1") and conj.hasConj(sVerb, ":PQ", ":Q3"):
# We also check if the verb has a feminine form.
# If not, we consider it’s better to not suggest the masculine one, as it can be considered invariable.
dSugg[conj.getConj(sVerb, ":PQ", ":Q1")] = ""
if bSuggSimil:
for e in phonet.selectSimil(sFlex, ":m:[si]"):
dSugg[e] = ""
if dSugg:
return "|".join(dSugg.keys())
return ""
def suggMasPlur (sFlex, bSuggSimil=False):
"returns masculine plural forms"
dSugg = {}
for sMorph in _oSpellChecker.getMorph(sFlex):
if not ":V" in sMorph:
# not a verb
if ":m" in sMorph or ":e" in sMorph:
dSugg[suggPlur(sFlex)] = ""
else:
sStem = cr.getLemmaOfMorph(sMorph)
if mfsp.isMasForm(sStem):
dSugg[suggPlur(sStem, True)] = ""
else:
# a verb
sVerb = cr.getLemmaOfMorph(sMorph)
if conj.hasConj(sVerb, ":PQ", ":Q2"):
dSugg[conj.getConj(sVerb, ":PQ", ":Q2")] = ""
elif conj.hasConj(sVerb, ":PQ", ":Q1"):
sSugg = conj.getConj(sVerb, ":PQ", ":Q1")
# it is necessary to filter these flexions, like “succédé” or “agi” that are not masculine plural.
if sSugg.endswith("s"):
dSugg[sSugg] = ""
if bSuggSimil:
for e in phonet.selectSimil(sFlex, ":m:[pi]"):
dSugg[e] = ""
if dSugg:
return "|".join(dSugg.keys())
return ""
def suggFemSing (sFlex, bSuggSimil=False):
"returns feminine singular forms"
dSugg = {}
for sMorph in _oSpellChecker.getMorph(sFlex):
if not ":V" in sMorph:
# not a verb
if ":f" in sMorph or ":e" in sMorph:
dSugg[suggSing(sFlex)] = ""
else:
sStem = cr.getLemmaOfMorph(sMorph)
if mfsp.isMasForm(sStem):
dSugg.update(dict.fromkeys(mfsp.getFemForm(sStem, False), ""))
else:
# a verb
sVerb = cr.getLemmaOfMorph(sMorph)
if conj.hasConj(sVerb, ":PQ", ":Q3"):
dSugg[conj.getConj(sVerb, ":PQ", ":Q3")] = ""
if bSuggSimil:
for e in phonet.selectSimil(sFlex, ":f:[si]"):
dSugg[e] = ""
if dSugg:
return "|".join(dSugg.keys())
return ""
def suggFemPlur (sFlex, bSuggSimil=False):
"returns feminine plural forms"
dSugg = {}
for sMorph in _oSpellChecker.getMorph(sFlex):
if not ":V" in sMorph:
# not a verb
if ":f" in sMorph or ":e" in sMorph:
dSugg[suggPlur(sFlex)] = ""
else:
sStem = cr.getLemmaOfMorph(sMorph)
if mfsp.isMasForm(sStem):
dSugg.update(dict.fromkeys(mfsp.getFemForm(sStem, True)))
else:
# a verb
sVerb = cr.getLemmaOfMorph(sMorph)
if conj.hasConj(sVerb, ":PQ", ":Q4"):
dSugg[conj.getConj(sVerb, ":PQ", ":Q4")] = ""
if bSuggSimil:
for e in phonet.selectSimil(sFlex, ":f:[pi]"):
dSugg[e] = ""
if dSugg:
return "|".join(dSugg)
return ""
def g_suggAgree (dTokenDst, dTokenSrc):
"returns suggestions for <dTokenDst> that matches agreement with <dTokenSrc>"
lMorphSrc = dTokenSrc["lMorph"] if "lMorph" in dTokenSrc else _oSpellChecker.getMorph(dTokenSrc["sValue"])
if not lMorphSrc:
|