Skip to content

Commit ea4309e

Browse files
authored
Update to v0.2.3
1 parent f112b5b commit ea4309e

File tree

3 files changed

+113
-44
lines changed

3 files changed

+113
-44
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ I do not have a French localized version yet, which is weird for a French langua
9090

9191
## BUGS
9292
There are probably lots of peculiarities that would need specific processing,
93-
the verbs conjugated with the "etre" auxiliary when used with a pronoun for example.
93+
the verbs conjugated with the "être" auxiliary when used with a pronoun for example.
9494

9595
Though the software is probably mostly correct, I will consider it as Beta quality
9696
till I get a better idea of the quality of the source data and offer a way to improve it...

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = pnu_conjuguer
33
description = conjugaison des verbes Français
44
long_description = file: README.md
55
long_description_content_type = text/markdown
6-
version = 0.2.0
6+
version = 0.2.3
77
license = BSD 3-Clause License
88
license_files = License
99
author = Hubert Tournier

src/conjuguer/main.py

Lines changed: 111 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .blank import blank_verb
1919

2020
# Version string used by the what(1) and ident(1) commands:
21-
ID = "@(#) $Id: conjuguer - conjugaison des verbes Français v0.2.0 (September 11, 2021) by Hubert Tournier $"
21+
ID = "@(#) $Id: conjuguer - conjugaison des verbes Français v0.2.3 (September 11, 2021) by Hubert Tournier $"
2222

2323
# Default parameters. Can be overcome by environment variables, then command line options
2424
parameters = {
@@ -52,8 +52,14 @@ def display_help():
5252
print("usage: conjuguer [--debug] [--help|-?] [--version]", file=sys.stderr)
5353
print(" [-c|--columns NUMBER] [-d|--dictionary PATH] [-n|--nocolor]", file=sys.stderr)
5454
print(" [--] verb [...]", file=sys.stderr)
55-
print(" ---------------- -----------------------------------------------------", file=sys.stderr)
56-
print(" -c|--columns NUM Choose number of columns to display between 1, 2 or 4", file=sys.stderr)
55+
print(
56+
" ---------------- -----------------------------------------------------",
57+
file=sys.stderr
58+
)
59+
print(
60+
" -c|--columns NUM Choose number of columns to display between 1, 2 or 4",
61+
file=sys.stderr
62+
)
5763
print(" -d|--dictionary PATH Select a specific dictionary", file=sys.stderr)
5864
print(" -n|--nocolor Disable color output", file=sys.stderr)
5965
print(" --debug Enable debug mode", file=sys.stderr)
@@ -202,7 +208,9 @@ def process_command_line():
202208
parameters["Dictionary path"] = argument
203209
parameters["Dictionary type"] = detect_dictionary_type()
204210
if parameters["Dictionary type"] not in ("ABU", "DELA"):
205-
logging.critical("The selected dictionary doesn't seem to be of ABU or DELA type")
211+
logging.critical(
212+
"The selected dictionary doesn't seem to be of ABU or DELA type"
213+
)
206214
sys.exit(1)
207215
else:
208216
logging.critical("Option -d/--dictionary is expecting a valid pathname")
@@ -247,7 +255,10 @@ def load_all_verbs_from_dictionary():
247255
verbs.append(line)
248256

249257
time_stop = time.time()
250-
logging.debug("load_all_verbs_from_dictionary() time: %f / lines: %d", time_stop - time_start, len(verbs))
258+
logging.debug(
259+
"load_all_verbs_from_dictionary() time: %f / lines: %d",
260+
time_stop - time_start, len(verbs)
261+
)
251262

252263
return verbs
253264

@@ -288,7 +299,10 @@ def select_verb_from_verbs(verb, verbs):
288299
conjugations.append(line)
289300

290301
time_stop = time.time()
291-
logging.debug("select_verb_from_verbs() time: %f / conjugations: %d", time_stop - time_start, len(conjugations))
302+
logging.debug(
303+
"select_verb_from_verbs() time: %f / conjugations: %d",
304+
time_stop - time_start, len(conjugations)
305+
)
292306

293307
return conjugations
294308

@@ -305,64 +319,85 @@ def fill_verb_from_dela_dictionary_data(verb, conjugations, auxiliary):
305319
conjugated_verb["Infinitif"]["Présent"] = verb
306320

307321
# We first need to find the "Participe passé" tense for this verb:
308-
suffix = ""
322+
suffix_s = ""
323+
suffix_p = ""
309324
for line in conjugations:
310325
for inflection in line.split(":")[1:]:
311326
if inflection == "Kms":
312-
suffix = " " + line.split(",")[0]
313-
break
314-
if not suffix:
327+
suffix_s = " " + line.split(",")[0]
328+
if inflection == "Kmp":
329+
suffix_p = " " + line.split(",")[0]
330+
if not suffix_s:
315331
logging.warning("Infinitif passé not found for %s", verb)
316332
else:
317-
conjugated_verb["Infinitif"]["Passé"] = auxiliary + suffix
333+
conjugated_verb["Infinitif"]["Passé"] = auxiliary + suffix_s
334+
if not suffix_p:
335+
suffix_p = suffix_s
318336

319337
for line in conjugations:
320338
conjugation = line.split(",")[0]
321339
for inflection in line.split(":")[1:]:
322340
part = list(inflection)
341+
suffix = suffix_s
342+
if auxiliary == "être" and len(part) == 3 and part[2] == "p":
343+
suffix = suffix_p
344+
323345
if part[0] == "P":
324346
conjugated_verb["Indicatif"]["Présent"][part[2]][part[1]] = conjugation
325347
if suffix:
326-
conjugated_verb["Indicatif"]["Passé composé"][part[2]][part[1]] = aux[auxiliary]["Indicatif"]["Présent"][part[2]][part[1]] + suffix
348+
conjugated_verb["Indicatif"]["Passé composé"][part[2]][part[1]] = \
349+
aux[auxiliary]["Indicatif"]["Présent"][part[2]][part[1]] + suffix
327350
elif part[0] == "I":
328351
conjugated_verb["Indicatif"]["Imparfait"][part[2]][part[1]] = conjugation
329352
if suffix:
330-
conjugated_verb["Indicatif"]["Plus-que-parfait"][part[2]][part[1]] = aux[auxiliary]["Indicatif"]["Imparfait"][part[2]][part[1]] + suffix
353+
conjugated_verb["Indicatif"]["Plus-que-parfait"][part[2]][part[1]] = \
354+
aux[auxiliary]["Indicatif"]["Imparfait"][part[2]][part[1]] + suffix
331355
elif part[0] == "J":
332356
conjugated_verb["Indicatif"]["Passé simple"][part[2]][part[1]] = conjugation
333357
if suffix:
334-
conjugated_verb["Indicatif"]["Passé antérieur"][part[2]][part[1]] = aux[auxiliary]["Indicatif"]["Passé simple"][part[2]][part[1]] + suffix
358+
conjugated_verb["Indicatif"]["Passé antérieur"][part[2]][part[1]] = \
359+
aux[auxiliary]["Indicatif"]["Passé simple"][part[2]][part[1]] + suffix
335360
elif part[0] == "F":
336361
conjugated_verb["Indicatif"]["Futur simple"][part[2]][part[1]] = conjugation
337362
if suffix:
338-
conjugated_verb["Indicatif"]["Futur antérieur"][part[2]][part[1]] = aux[auxiliary]["Indicatif"]["Futur simple"][part[2]][part[1]] + suffix
363+
conjugated_verb["Indicatif"]["Futur antérieur"][part[2]][part[1]] = \
364+
aux[auxiliary]["Indicatif"]["Futur simple"][part[2]][part[1]] + suffix
339365
elif part[0] == "C":
340366
conjugated_verb["Conditionnel"]["Présent"][part[2]][part[1]] = conjugation
341367
if suffix:
342-
conjugated_verb["Conditionnel"]["Passé"][part[2]][part[1]] = aux[auxiliary]["Conditionnel"]["Présent"][part[2]][part[1]] + suffix
368+
conjugated_verb["Conditionnel"]["Passé"][part[2]][part[1]] = \
369+
aux[auxiliary]["Conditionnel"]["Présent"][part[2]][part[1]] + suffix
343370
elif part[0] == "S":
344371
conjugated_verb["Subjonctif"]["Présent"][part[2]][part[1]] = conjugation
345372
if suffix:
346-
conjugated_verb["Subjonctif"]["Passé"][part[2]][part[1]] = aux[auxiliary]["Subjonctif"]["Présent"][part[2]][part[1]] + suffix
373+
conjugated_verb["Subjonctif"]["Passé"][part[2]][part[1]] = \
374+
aux[auxiliary]["Subjonctif"]["Présent"][part[2]][part[1]] + suffix
347375
elif part[0] == "T":
348376
conjugated_verb["Subjonctif"]["Imparfait"][part[2]][part[1]] = conjugation
349377
if suffix:
350-
conjugated_verb["Subjonctif"]["Plus-que-parfait"][part[2]][part[1]] = aux[auxiliary]["Subjonctif"]["Imparfait"][part[2]][part[1]] + suffix
378+
conjugated_verb["Subjonctif"]["Plus-que-parfait"][part[2]][part[1]] = \
379+
aux[auxiliary]["Subjonctif"]["Imparfait"][part[2]][part[1]] + suffix
351380
elif part[0] == "Y":
352381
conjugated_verb["Impératif"]["Présent"][part[2]][part[1]] = conjugation
353382
if suffix:
354-
conjugated_verb["Impératif"]["Passé"][part[2]][part[1]] = aux[auxiliary]["Impératif"]["Présent"][part[2]][part[1]] + suffix
383+
conjugated_verb["Impératif"]["Passé"][part[2]][part[1]] = \
384+
aux[auxiliary]["Impératif"]["Présent"][part[2]][part[1]] + suffix
355385
elif part[0] == "G":
356386
conjugated_verb["Participe"]["Présent"] = conjugation
357387
conjugated_verb["Gérondif"]["Présent"] = conjugation
358388
if suffix:
359-
conjugated_verb["Participe"]["Passé"]["a"] = aux[auxiliary]["Participe"]["Présent"] + suffix
360-
conjugated_verb["Gérondif"]["Passé"] = conjugated_verb["Participe"]["Passé"]["a"]
389+
conjugated_verb["Participe"]["Passé"]["a"] = \
390+
aux[auxiliary]["Participe"]["Présent"] + suffix
391+
conjugated_verb["Gérondif"]["Passé"] = \
392+
conjugated_verb["Participe"]["Passé"]["a"]
361393
elif part[0] == "K":
362394
conjugated_verb["Participe"]["Passé"][part[2]][part[1]] = conjugation
363395

364396
time_stop = time.time()
365-
logging.debug("fill_verb_from_dela_dictionary_data() time: %f / conjugations: %d", time_stop - time_start, len(conjugations))
397+
logging.debug(
398+
"fill_verb_from_dela_dictionary_data() time: %f / conjugations: %d",
399+
time_stop - time_start, len(conjugations)
400+
)
366401

367402
return conjugated_verb
368403

@@ -379,16 +414,20 @@ def fill_verb_from_abu_dictionary_data(verb, conjugations, auxiliary):
379414
conjugated_verb["Infinitif"]["Présent"] = verb
380415

381416
# We first need to find the "Participe passé" tense for this verb:
382-
suffix = ""
417+
suffix_s = ""
418+
suffix_p = ""
383419
for line in conjugations:
384420
for inflection in line.split(":")[1:]:
385421
if inflection == "PPas+Mas+SG":
386-
suffix = " " + line.split(" ")[0]
387-
break
388-
if not suffix:
422+
suffix_s = " " + line.split(" ")[0]
423+
if inflection == "PPas+Mas+PL":
424+
suffix_p = " " + line.split(" ")[0]
425+
if not suffix_s:
389426
logging.warning("Infinitif passé not found for %s", verb)
390427
else:
391-
conjugated_verb["Infinitif"]["Passé"] = auxiliary + suffix
428+
conjugated_verb["Infinitif"]["Passé"] = auxiliary + suffix_s
429+
if not suffix_p:
430+
suffix_p = suffix_s
392431

393432
for line in conjugations:
394433
conjugation = line.split(" ")[0]
@@ -418,50 +457,66 @@ def fill_verb_from_abu_dictionary_data(verb, conjugations, auxiliary):
418457
person = "2"
419458
elif part[2] == "P3":
420459
person = "3"
460+
suffix = suffix_s
461+
if auxiliary == "être" and number == "p":
462+
suffix = suffix_p
421463

422464
if part[0] == "IPre":
423465
conjugated_verb["Indicatif"]["Présent"][number][person] = conjugation
424466
if suffix:
425-
conjugated_verb["Indicatif"]["Passé composé"][number][person] = aux[auxiliary]["Indicatif"]["Présent"][number][person] + suffix
467+
conjugated_verb["Indicatif"]["Passé composé"][number][person] = \
468+
aux[auxiliary]["Indicatif"]["Présent"][number][person] + suffix
426469
elif part[0] == "IImp":
427470
conjugated_verb["Indicatif"]["Imparfait"][number][person] = conjugation
428471
if suffix:
429-
conjugated_verb["Indicatif"]["Plus-que-parfait"][number][person] = aux[auxiliary]["Indicatif"]["Imparfait"][number][person] + suffix
472+
conjugated_verb["Indicatif"]["Plus-que-parfait"][number][person] = \
473+
aux[auxiliary]["Indicatif"]["Imparfait"][number][person] + suffix
430474
elif part[0] == "IPSim":
431475
conjugated_verb["Indicatif"]["Passé simple"][number][person] = conjugation
432476
if suffix:
433-
conjugated_verb["Indicatif"]["Passé antérieur"][number][person] = aux[auxiliary]["Indicatif"]["Passé simple"][number][person] + suffix
477+
conjugated_verb["Indicatif"]["Passé antérieur"][number][person] = \
478+
aux[auxiliary]["Indicatif"]["Passé simple"][number][person] + suffix
434479
elif part[0] == "IFut":
435480
conjugated_verb["Indicatif"]["Futur simple"][number][person] = conjugation
436481
if suffix:
437-
conjugated_verb["Indicatif"]["Futur antérieur"][number][person] = aux[auxiliary]["Indicatif"]["Futur simple"][number][person] + suffix
482+
conjugated_verb["Indicatif"]["Futur antérieur"][number][person] = \
483+
aux[auxiliary]["Indicatif"]["Futur simple"][number][person] + suffix
438484
elif part[0] == "CPre":
439485
conjugated_verb["Conditionnel"]["Présent"][number][person] = conjugation
440486
if suffix:
441-
conjugated_verb["Conditionnel"]["Passé"][number][person] = aux[auxiliary]["Conditionnel"]["Présent"][number][person] + suffix
487+
conjugated_verb["Conditionnel"]["Passé"][number][person] = \
488+
aux[auxiliary]["Conditionnel"]["Présent"][number][person] + suffix
442489
elif part[0] == "SPre":
443490
conjugated_verb["Subjonctif"]["Présent"][number][person] = conjugation
444491
if suffix:
445-
conjugated_verb["Subjonctif"]["Passé"][number][person] = aux[auxiliary]["Subjonctif"]["Présent"][number][person] + suffix
492+
conjugated_verb["Subjonctif"]["Passé"][number][person] = \
493+
aux[auxiliary]["Subjonctif"]["Présent"][number][person] + suffix
446494
elif part[0] == "SImp":
447495
conjugated_verb["Subjonctif"]["Imparfait"][number][person] = conjugation
448496
if suffix:
449-
conjugated_verb["Subjonctif"]["Plus-que-parfait"][number][person] = aux[auxiliary]["Subjonctif"]["Imparfait"][number][person] + suffix
497+
conjugated_verb["Subjonctif"]["Plus-que-parfait"][number][person] = \
498+
aux[auxiliary]["Subjonctif"]["Imparfait"][number][person] + suffix
450499
elif part[0] == "ImPre":
451500
conjugated_verb["Impératif"]["Présent"][number][person] = conjugation
452501
if suffix:
453-
conjugated_verb["Impératif"]["Passé"][number][person] = aux[auxiliary]["Impératif"]["Présent"][number][person] + suffix
502+
conjugated_verb["Impératif"]["Passé"][number][person] = \
503+
aux[auxiliary]["Impératif"]["Présent"][number][person] + suffix
454504
elif part[0] == "PPre":
455505
conjugated_verb["Participe"]["Présent"] = conjugation
456506
conjugated_verb["Gérondif"]["Présent"] = conjugation
457507
if suffix:
458-
conjugated_verb["Participe"]["Passé"]["a"] = aux[auxiliary]["Participe"]["Présent"] + suffix
459-
conjugated_verb["Gérondif"]["Passé"] = conjugated_verb["Participe"]["Passé"]["a"]
508+
conjugated_verb["Participe"]["Passé"]["a"] = \
509+
aux[auxiliary]["Participe"]["Présent"] + suffix
510+
conjugated_verb["Gérondif"]["Passé"] = \
511+
conjugated_verb["Participe"]["Passé"]["a"]
460512
elif part[0] == "PPas":
461513
conjugated_verb["Participe"]["Passé"][number][gender] = conjugation
462514

463515
time_stop = time.time()
464-
logging.debug("fill_verb_from_abu_dictionary_data() time: %f / conjugations: %d", time_stop - time_start, len(conjugations))
516+
logging.debug(
517+
"fill_verb_from_abu_dictionary_data() time: %f / conjugations: %d",
518+
time_stop - time_start, len(conjugations)
519+
)
465520

466521
return conjugated_verb
467522

@@ -482,7 +537,12 @@ def print_verb(verb):
482537
"""Return lines describing the conjugated verb"""
483538
lines = []
484539
if parameters["Color display"]:
485-
lines.append(VERB_COLOR + "Tableau de conjugaison du verbe " + colorama.Style.RESET_ALL + verb)
540+
lines.append(
541+
VERB_COLOR
542+
+ "Tableau de conjugaison du verbe "
543+
+ colorama.Style.RESET_ALL
544+
+ verb
545+
)
486546
else:
487547
lines.append("Tableau de conjugaison du verbe " + verb)
488548
lines.append("")
@@ -528,7 +588,10 @@ def get_pronoun(mode, number, person, conjugated_verb):
528588
elif mode == "Subjonctif":
529589
if number == "s":
530590
if person == "1":
531-
if conjugated_verb[0] in ['a', 'e', 'i', 'o', 'u', 'y']:
591+
if conjugated_verb[0] in [
592+
'a', 'â', 'à', 'ä', 'e', 'ê', 'é', 'è', 'ë',
593+
'i', 'î', 'ï', 'o', 'ô', 'ö', 'u', 'ù', 'y'
594+
]:
532595
pronoun = "que j' "
533596
else:
534597
pronoun = "que je "
@@ -546,7 +609,10 @@ def get_pronoun(mode, number, person, conjugated_verb):
546609
else:
547610
if number == "s":
548611
if person == "1":
549-
if conjugated_verb[0] in ['a', 'e', 'i', 'o', 'u', 'y']:
612+
if conjugated_verb[0] in [
613+
'a', 'â', 'à', 'ä', 'e', 'ê', 'é', 'è', 'ë',
614+
'i', 'î', 'ï', 'o', 'ô', 'ö', 'u', 'ù', 'y'
615+
]:
550616
pronoun = "j' "
551617
else:
552618
pronoun = "je "
@@ -643,7 +709,10 @@ def print_verb_conjugation_odd_columns(conjugation):
643709
column += print_verb(conjugation["Infinitif"]["Présent"])
644710

645711
column += print_mode("Indicatif")
646-
for tense in ["Présent", "Imparfait", "Passé simple", "Futur simple", "Passé composé", "Plus-que-parfait", "Passé antérieur", "Futur antérieur"]:
712+
for tense in [
713+
"Présent", "Imparfait", "Passé simple", "Futur simple",
714+
"Passé composé", "Plus-que-parfait", "Passé antérieur", "Futur antérieur"
715+
]:
647716
column += get_tense_conjugation("Indicatif", tense, conjugation)
648717

649718
column += print_mode("Conditionnel")

0 commit comments

Comments
 (0)