1
2
3
4
5
6
7
8
|
# Grammalecte - Conjugueur
# License: GPL 3
import re
import traceback
from .conj_data import lVtyp as _lVtyp
from .conj_data import lTags as _lTags
|
>
|
>
>
|
1
2
3
4
5
6
7
8
9
10
11
|
"""
Grammalecte - Conjugueur
"""
# License: GPL 3
import re
import traceback
from .conj_data import lVtyp as _lVtyp
from .conj_data import lTags as _lTags
|
︙ | | | ︙ | |
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
_dGroup = { "0": "auxiliaire", "1": "1ᵉʳ groupe", "2": "2ᵉ groupe", "3": "3ᵉ groupe" }
_dTenseIdx = { ":PQ": 0, ":Ip": 1, ":Iq": 2, ":Is": 3, ":If": 4, ":K": 5, ":Sp": 6, ":Sq": 7, ":E": 8 }
def isVerb (sVerb):
return sVerb in _dVerb
def getConj (sVerb, sTense, sWho):
"returns conjugation (can be an empty string)"
if sVerb not in _dVerb:
return None
|
>
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
_dGroup = { "0": "auxiliaire", "1": "1ᵉʳ groupe", "2": "2ᵉ groupe", "3": "3ᵉ groupe" }
_dTenseIdx = { ":PQ": 0, ":Ip": 1, ":Iq": 2, ":Is": 3, ":If": 4, ":K": 5, ":Sp": 6, ":Sq": 7, ":E": 8 }
def isVerb (sVerb):
"return True if it’s a existing verb"
return sVerb in _dVerb
def getConj (sVerb, sTense, sWho):
"returns conjugation (can be an empty string)"
if sVerb not in _dVerb:
return None
|
︙ | | | ︙ | |
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
"returns raw informations about sVerb"
if sVerb not in _dVerb:
return None
return _lVtyp[_dVerb[sVerb][0]]
def getSimil (sWord, sMorph, bSubst=False):
if ":V" not in sMorph:
return set()
sInfi = sMorph[1:sMorph.find(" ")]
aSugg = set()
tTags = _getTags(sInfi)
if tTags:
if not bSubst:
# we suggest conjugated forms
if ":V1" in sMorph:
aSugg.add(sInfi)
|
>
|
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
"returns raw informations about sVerb"
if sVerb not in _dVerb:
return None
return _lVtyp[_dVerb[sVerb][0]]
def getSimil (sWord, sMorph, bSubst=False):
"returns a set of verbal forms similar to <sWord>, according to <sMorph>"
if ":V" not in sMorph:
return set()
sInfi = sMorph[1:sMorph.find("/")]
aSugg = set()
tTags = _getTags(sInfi)
if tTags:
if not bSubst:
# we suggest conjugated forms
if ":V1" in sMorph:
aSugg.add(sInfi)
|
︙ | | | ︙ | |
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# if there is only one past participle (epi inv), unreliable.
if len(aSugg) == 1:
aSugg.clear()
return aSugg
def getConjSimilInfiV1 (sInfi):
if sInfi not in _dVerb:
return set()
aSugg = set()
tTags = _getTags(sInfi)
if tTags:
aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":2s"))
aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3s"))
|
>
|
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# if there is only one past participle (epi inv), unreliable.
if len(aSugg) == 1:
aSugg.clear()
return aSugg
def getConjSimilInfiV1 (sInfi):
"returns verbal forms phonetically similar to infinitive form (for verb in group 1)"
if sInfi not in _dVerb:
return set()
aSugg = set()
tTags = _getTags(sInfi)
if tTags:
aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":2s"))
aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3s"))
|
︙ | | | ︙ | |
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
"returns sWord modified by sSfx"
if not sSfx:
return ""
if sSfx == "0":
return sWord
try:
return sWord[:-(ord(sSfx[0])-48)] + sSfx[1:] if sSfx[0] != '0' else sWord + sSfx[1:] # 48 is the ASCII code for "0"
except:
return "## erreur, code : " + str(sSfx) + " ##"
class Verb ():
def __init__ (self, sVerb, sVerbPattern=""):
# conjugate a unknown verb with rules from sVerbPattern
if not isinstance(sVerb, str):
raise TypeError("sVerb should be a string")
if not sVerb:
raise ValueError("Empty string.")
|
|
|
>
>
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
"returns sWord modified by sSfx"
if not sSfx:
return ""
if sSfx == "0":
return sWord
try:
return sWord[:-(ord(sSfx[0])-48)] + sSfx[1:] if sSfx[0] != '0' else sWord + sSfx[1:] # 48 is the ASCII code for "0"
except (IndexError, TypeError):
return "## erreur, code : " + str(sSfx) + " ##"
class Verb ():
"Verb and its conjugation"
def __init__ (self, sVerb, sVerbPattern=""):
# conjugate a unknown verb with rules from sVerbPattern
if not isinstance(sVerb, str):
raise TypeError("sVerb should be a string")
if not sVerb:
raise ValueError("Empty string.")
|
︙ | | | ︙ | |
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
sInfo = "# erreur - code : " + self._sRawInfo
return sGroup + " · " + sInfo
except:
traceback.print_exc()
return "# erreur"
def infinitif (self, bPro, bNeg, bTpsCo, bInt, bFem):
try:
if bTpsCo:
sInfi = self.sVerbAux if not bPro else "être"
else:
sInfi = self.sVerb
if bPro:
if self.bProWithEn:
|
>
|
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
sInfo = "# erreur - code : " + self._sRawInfo
return sGroup + " · " + sInfo
except:
traceback.print_exc()
return "# erreur"
def infinitif (self, bPro, bNeg, bTpsCo, bInt, bFem):
"returns string (conjugaison à l’infinitif)"
try:
if bTpsCo:
sInfi = self.sVerbAux if not bPro else "être"
else:
sInfi = self.sVerb
if bPro:
if self.bProWithEn:
|
︙ | | | ︙ | |
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
sInfi += " … ?"
return sInfi
except:
traceback.print_exc()
return "# erreur"
def participePasse (self, sWho):
try:
return self.dConj[":Q"][sWho]
except:
traceback.print_exc()
return "# erreur"
def participePresent (self, bPro, bNeg, bTpsCo, bInt, bFem):
try:
if not self.dConj[":P"][":"]:
return ""
if bTpsCo:
sPartPre = _getConjWithTags(self.sVerbAux, self._tTagsAux, ":PQ", ":P") if not bPro else getConj("être", ":PQ", ":P")
else:
sPartPre = self.dConj[":P"][":"]
|
>
>
|
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
sInfi += " … ?"
return sInfi
except:
traceback.print_exc()
return "# erreur"
def participePasse (self, sWho):
"returns past participle according to <sWho>"
try:
return self.dConj[":Q"][sWho]
except:
traceback.print_exc()
return "# erreur"
def participePresent (self, bPro, bNeg, bTpsCo, bInt, bFem):
"returns string (conjugaison du participe présent)"
try:
if not self.dConj[":P"][":"]:
return ""
if bTpsCo:
sPartPre = _getConjWithTags(self.sVerbAux, self._tTagsAux, ":PQ", ":P") if not bPro else getConj("être", ":PQ", ":P")
else:
sPartPre = self.dConj[":P"][":"]
|
︙ | | | ︙ | |
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
sPartPre += " … ?"
return sPartPre
except:
traceback.print_exc()
return "# erreur"
def conjugue (self, sTemps, sWho, bPro, bNeg, bTpsCo, bInt, bFem):
try:
if not self.dConj[sTemps][sWho]:
return ""
if not bTpsCo and bInt and sWho == ":1s" and self.dConj[sTemps].get(":1ś", False):
sWho = ":1ś"
if bTpsCo:
sConj = _getConjWithTags(self.sVerbAux, self._tTagsAux, sTemps, sWho) if not bPro else getConj("être", sTemps, sWho)
|
>
|
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
sPartPre += " … ?"
return sPartPre
except:
traceback.print_exc()
return "# erreur"
def conjugue (self, sTemps, sWho, bPro, bNeg, bTpsCo, bInt, bFem):
"returns string (conjugue le verbe au temps <sTemps> pour <sWho>) "
try:
if not self.dConj[sTemps][sWho]:
return ""
if not bTpsCo and bInt and sWho == ":1s" and self.dConj[sTemps].get(":1ś", False):
sWho = ":1ś"
if bTpsCo:
sConj = _getConjWithTags(self.sVerbAux, self._tTagsAux, sTemps, sWho) if not bPro else getConj("être", sTemps, sWho)
|
︙ | | | ︙ | |
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
|
else:
sConj = _dProObjEl[sWho] + "en " + sConj
if bNeg:
sConj = "n’" + sConj if bEli and not bPro else "ne " + sConj
if bInt:
if sWho == ":3s" and not _zNeedTeuph.search(sConj):
sConj += "-t"
sConj += "-" + self._getPronom(sWho, bFem)
else:
if sWho == ":1s" and bEli and not bNeg and not bPro:
sConj = "j’" + sConj
else:
sConj = self._getPronom(sWho, bFem) + " " + sConj
if bNeg:
sConj += " pas"
if bTpsCo:
sConj += " " + self._seekPpas(bPro, bFem, sWho.endswith("p") or self._sRawInfo[5] == "r")
if bInt:
sConj += " … ?"
return sConj
except:
traceback.print_exc()
return "# erreur"
def _getPronom (self, sWho, bFem):
try:
if sWho == ":3s":
if self._sRawInfo[5] == "r":
return "on"
elif bFem:
return "elle"
elif sWho == ":3p" and bFem:
return "elles"
return _dProSuj[sWho]
except:
traceback.print_exc()
return "# erreur"
def imperatif (self, sWho, bPro, bNeg, bTpsCo, bFem):
try:
if not self.dConj[":E"][sWho]:
return ""
if bTpsCo:
sImpe = _getConjWithTags(self.sVerbAux, self._tTagsAux, ":E", sWho) if not bPro else getConj(u"être", ":E", sWho)
else:
sImpe = self.dConj[":E"][sWho]
|
|
|
|
>
|
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
|
else:
sConj = _dProObjEl[sWho] + "en " + sConj
if bNeg:
sConj = "n’" + sConj if bEli and not bPro else "ne " + sConj
if bInt:
if sWho == ":3s" and not _zNeedTeuph.search(sConj):
sConj += "-t"
sConj += "-" + self._getPronomSujet(sWho, bFem)
else:
if sWho == ":1s" and bEli and not bNeg and not bPro:
sConj = "j’" + sConj
else:
sConj = self._getPronomSujet(sWho, bFem) + " " + sConj
if bNeg:
sConj += " pas"
if bTpsCo:
sConj += " " + self._seekPpas(bPro, bFem, sWho.endswith("p") or self._sRawInfo[5] == "r")
if bInt:
sConj += " … ?"
return sConj
except:
traceback.print_exc()
return "# erreur"
def _getPronomSujet (self, sWho, bFem):
try:
if sWho == ":3s":
if self._sRawInfo[5] == "r":
return "on"
elif bFem:
return "elle"
elif sWho == ":3p" and bFem:
return "elles"
return _dProSuj[sWho]
except:
traceback.print_exc()
return "# erreur"
def imperatif (self, sWho, bPro, bNeg, bTpsCo, bFem):
"returns string (conjugaison à l’impératif)"
try:
if not self.dConj[":E"][sWho]:
return ""
if bTpsCo:
sImpe = _getConjWithTags(self.sVerbAux, self._tTagsAux, ":E", sWho) if not bPro else getConj(u"être", ":E", sWho)
else:
sImpe = self.dConj[":E"][sWho]
|
︙ | | | ︙ | |