180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
return ""
sGender = cr.getGender(lMorph)
if sGender == ":m":
return suggMasPlur(sFlex)
if sGender == ":f":
return suggFemPlur(sFlex)
aSugg = set()
if "-" not in sFlex:
if sFlex.endswith("l"):
if sFlex.endswith("al") and len(sFlex) > 2 and _oSpellChecker.isValid(sFlex[:-1]+"ux"):
aSugg.add(sFlex[:-1]+"ux")
if sFlex.endswith("ail") and len(sFlex) > 3 and _oSpellChecker.isValid(sFlex[:-2]+"ux"):
aSugg.add(sFlex[:-2]+"ux")
if _oSpellChecker.isValid(sFlex+"s"):
aSugg.add(sFlex+"s")
if _oSpellChecker.isValid(sFlex+"x"):
aSugg.add(sFlex+"x")
if mfsp.hasMiscPlural(sFlex):
aSugg.update(mfsp.getMiscPlural(sFlex))
if aSugg:
return "|".join(aSugg)
return ""
def suggSing (sFlex):
"returns singular forms assuming sFlex is plural"
if "-" in sFlex:
return ""
aSugg = set()
if sFlex.endswith("ux"):
if _oSpellChecker.isValid(sFlex[:-2]+"l"):
aSugg.add(sFlex[:-2]+"l")
if _oSpellChecker.isValid(sFlex[:-2]+"il"):
aSugg.add(sFlex[:-2]+"il")
if _oSpellChecker.isValid(sFlex[:-1]):
|
<
|
|
|
|
|
|
|
|
|
<
<
|
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
return ""
sGender = cr.getGender(lMorph)
if sGender == ":m":
return suggMasPlur(sFlex)
if sGender == ":f":
return suggFemPlur(sFlex)
aSugg = set()
if sFlex.endswith("l"):
if sFlex.endswith("al") and len(sFlex) > 2 and _oSpellChecker.isValid(sFlex[:-1]+"ux"):
aSugg.add(sFlex[:-1]+"ux")
if sFlex.endswith("ail") and len(sFlex) > 3 and _oSpellChecker.isValid(sFlex[:-2]+"ux"):
aSugg.add(sFlex[:-2]+"ux")
if _oSpellChecker.isValid(sFlex+"s"):
aSugg.add(sFlex+"s")
if _oSpellChecker.isValid(sFlex+"x"):
aSugg.add(sFlex+"x")
if mfsp.hasMiscPlural(sFlex):
aSugg.update(mfsp.getMiscPlural(sFlex))
if aSugg:
return "|".join(aSugg)
return ""
def suggSing (sFlex):
"returns singular forms assuming sFlex is plural"
aSugg = set()
if sFlex.endswith("ux"):
if _oSpellChecker.isValid(sFlex[:-2]+"l"):
aSugg.add(sFlex[:-2]+"l")
if _oSpellChecker.isValid(sFlex[:-2]+"il"):
aSugg.add(sFlex[:-2]+"il")
if _oSpellChecker.isValid(sFlex[:-1]):
|
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
if any( ":p" in sMorph for sMorph in _oSpellChecker.getMorph(sWord) ):
return "les|la"
return "la"
_zBinary = re.compile("^[01]+$")
def formatNumber (s):
"add spaces or hyphens to big numbers"
nLen = len(s)
if nLen < 4:
return s
sRes = ""
# nombre ordinaire
nEnd = nLen
while nEnd > 0:
nStart = max(nEnd-3, 0)
sRes = s[nStart:nEnd] + " " + sRes if sRes else s[nStart:nEnd]
nEnd = nEnd - 3
# binaire
if _zBinary.search(s):
nEnd = nLen
sBin = ""
while nEnd > 0:
nStart = max(nEnd-4, 0)
sBin = s[nStart:nEnd] + " " + sBin if sBin else s[nStart:nEnd]
nEnd = nEnd - 4
sRes += "|" + sBin
# numéros de téléphone
if nLen == 10:
if s.startswith("0"):
sRes += "|" + s[0:2] + " " + s[2:4] + " " + s[4:6] + " " + s[6:8] + " " + s[8:] # téléphone français
if s[1] == "4" and (s[2]=="7" or s[2]=="8" or s[2]=="9"):
sRes += "|" + s[0:4] + " " + s[4:6] + " " + s[6:8] + " " + s[8:] # mobile belge
sRes += "|" + s[0:3] + " " + s[3:6] + " " + s[6:8] + " " + s[8:] # téléphone suisse
sRes += "|" + s[0:4] + " " + s[4:7] + "-" + s[7:] # téléphone canadien ou américain
elif nLen == 9 and s.startswith("0"):
sRes += "|" + s[0:3] + " " + s[3:5] + " " + s[5:7] + " " + s[7:9] # fixe belge 1
sRes += "|" + s[0:2] + " " + s[2:5] + " " + s[5:7] + " " + s[7:9] # fixe belge 2
return sRes
def formatNF (s):
"typography: format NF reference (norme française)"
try:
m = re.match("NF[ -]?(C|E|P|Q|S|X|Z|EN(?:[ -]ISO|))[ -]?([0-9]+(?:[/‑-][0-9]+|))", s)
|
|
|
|
>
|
|
<
<
<
<
|
|
<
<
<
<
<
<
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
|
>
>
>
>
>
>
>
|
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
if any( ":p" in sMorph for sMorph in _oSpellChecker.getMorph(sWord) ):
return "les|la"
return "la"
_zBinary = re.compile("^[01]+$")
def formatNumber (sNumber):
"add spaces or hyphens to big numbers"
nLen = len(sNumber)
if nLen < 4:
return sNumber
sRes = ""
if "," not in sNumber:
# nombre entier
sRes = _formatNumber(sNumber, 3)
# binaire
if _zBinary.search(sNumber):
sRes += "|" + _formatNumber(sNumber, 4)
# numéros de téléphone
if nLen == 10:
if sNumber.startswith("0"):
sRes += "|" + _formatNumber(sNumber, 2) # téléphone français
if sNumber[1] == "4" and (sNumber[2]=="7" or sNumber[2]=="8" or sNumber[2]=="9"):
sRes += "|" + sNumber[0:4] + " " + sNumber[4:6] + " " + sNumber[6:8] + " " + sNumber[8:] # mobile belge
sRes += "|" + sNumber[0:3] + " " + sNumber[3:6] + " " + sNumber[6:8] + " " + sNumber[8:] # téléphone suisse
sRes += "|" + sNumber[0:4] + " " + sNumber[4:7] + "-" + sNumber[7:] # téléphone canadien ou américain
elif nLen == 9 and sNumber.startswith("0"):
sRes += "|" + sNumber[0:3] + " " + sNumber[3:5] + " " + sNumber[5:7] + " " + sNumber[7:9] # fixe belge 1
sRes += "|" + sNumber[0:2] + " " + sNumber[2:5] + " " + sNumber[5:7] + " " + sNumber[7:9] # fixe belge 2
else:
# Nombre réel
sInt, sFloat = sNumber.split(",", 1)
sRes = _formatNumber(sInt, 3) + "," + sFloat
return sRes
def _formatNumber (sNumber, nGroup=3):
sRes = ""
nEnd = len(sNumber)
while nEnd > 0:
nStart = max(nEnd-nGroup, 0)
sRes = sNumber[nStart:nEnd] + " " + sRes if sRes else sNumber[nStart:nEnd]
nEnd = nEnd - nGroup
return sRes
def formatNF (s):
"typography: format NF reference (norme française)"
try:
m = re.match("NF[ -]?(C|E|P|Q|S|X|Z|EN(?:[ -]ISO|))[ -]?([0-9]+(?:[/‑-][0-9]+|))", s)
|
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
|
return "_"
_xNormalizedCharsForInclusiveWriting = str.maketrans({
'(': '_', ')': '_',
'.': '_', '·': '_',
'–': '_', '—': '_',
'/': '_'
})
def normalizeInclusiveWriting (sToken):
"typography: replace word separators used in inclusive writing by underscore (_)"
return sToken.translate(_xNormalizedCharsForInclusiveWriting)
|
|
|
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
return "_"
_xNormalizedCharsForInclusiveWriting = str.maketrans({
'(': '_', ')': '_',
'.': '_', '·': '_', '•': '_',
'–': '_', '—': '_',
'/': '_'
})
def normalizeInclusiveWriting (sToken):
"typography: replace word separators used in inclusive writing by underscore (_)"
return sToken.translate(_xNormalizedCharsForInclusiveWriting)
|