44Author: Hubert Tournier
55"""
66
7+ import collections
78import copy
89import getopt
910import gettext
2021from .blank import blank_verb
2122
2223# Version string used by the what(1) and ident(1) commands:
23- ID = "@(#) $Id: conjuguer - conjugaison des verbes Français v0.4 .0 (October 2 , 2021) by Hubert Tournier $"
24+ ID = "@(#) $Id: conjuguer - conjugaison des verbes Français v0.5 .0 (October 3 , 2021) by Hubert Tournier $"
2425
2526# Default parameters. Can be overcome by environment variables, then command line options
2627parameters = {
2728 "Dictionary path" : "" ,
2829 "Dictionary type" : "" ,
2930 "Color display" : True ,
3031 "Display columns" : 4 ,
32+ "DELA output" : False ,
33+ "ABU output" : False ,
3134 "DictPath" : [],
3235}
3336
@@ -103,12 +106,13 @@ def display_help():
103106 print (_ ("usage: conjuguer [--debug] [--help|-?] [--locale LANG] [--version]" ), file = sys .stderr )
104107 print (
105108 " "
106- + _ ("[-c|--columns NUMBER] [-d |--dictionary PATH ] [-n |--nocolor ]" ),
109+ + _ ("[-c|--columns NUMBER] [-n |--nocolor] [-D|--DELA ] [-A |--ABU ]" ),
107110 file = sys .stderr
108111 )
112+ print (" " + _ ("[-d|--dictionary PATH]" ), file = sys .stderr )
109113 print (" " + _ ("[--] verb [...]" ), file = sys .stderr )
110114 print (
111- " " + _ ("---------------- -----------------------------------------------------" ),
115+ " " + _ ("-------------------- -----------------------------------------------------" ),
112116 file = sys .stderr
113117 )
114118 print (
@@ -117,6 +121,8 @@ def display_help():
117121 )
118122 print (" " + _ ("-d|--dictionary PATH Select a specific dictionary" ), file = sys .stderr )
119123 print (" " + _ ("-n|--nocolor Disable color output" ), file = sys .stderr )
124+ print (" " + _ ("-D|--DELA Enable DELA format output" ), file = sys .stderr )
125+ print (" " + _ ("-A|--ABU Enable ABU format output" ), file = sys .stderr )
120126 print (" " + _ ("--debug Enable debug mode" ), file = sys .stderr )
121127 print (
122128 " " + _ ("--help|-? Print usage and this help message and exit" ),
@@ -231,10 +237,12 @@ def process_command_line(program_name):
231237
232238 # option letters followed by : expect an argument
233239 # same for option strings followed by =
234- character_options = "c :d:n ?"
240+ character_options = "Ac :d:Dn ?"
235241 string_options = [
242+ "ABU" ,
236243 "columns=" ,
237244 "debug" ,
245+ "DELA" ,
238246 "dictionary=" ,
239247 "help" ,
240248 "locale=" ,
@@ -253,7 +261,11 @@ def process_command_line(program_name):
253261
254262 for option , argument in options :
255263
256- if option in ("-c" , "--columns" ):
264+ if option in ("-A" , "--ABU" ):
265+ parameters ["ABU output" ] = True
266+ parameters ["DELA output" ] = False
267+
268+ elif option in ("-c" , "--columns" ):
257269 try :
258270 parameters ["Display columns" ] = int (argument )
259271 except ValueError :
@@ -266,6 +278,10 @@ def process_command_line(program_name):
266278 elif option == "--debug" :
267279 logging .disable (logging .NOTSET )
268280
281+ elif option in ("-D" , "--DELA" ):
282+ parameters ["DELA output" ] = True
283+ parameters ["ABU output" ] = False
284+
269285 elif option in ("-d" , "--dictionary" ):
270286 if os .path .isfile (argument ):
271287 parameters ["Dictionary path" ] = argument
@@ -952,10 +968,85 @@ def print_verb_conjugation_even_columns(conjugation):
952968 print (text )
953969
954970
971+ ################################################################################
972+ def add_inflection (inflected_list , key , value ):
973+ """ """
974+ if key :
975+ if key in inflected_list .keys ():
976+ inflected_list [key ] += value
977+ else :
978+ inflected_list [key ] = value
979+
980+ return inflected_list
981+
982+
983+ ################################################################################
984+ def print_ABU_inflections (verb ):
985+ """Print a verb conjugations in ABU format"""
986+ inflected_verb = {}
987+ inflected_verb = add_inflection (inflected_verb , verb ["Infinitif" ]["Présent" ], ":Inf" )
988+ for plural in [["s" , "+SG" ], ["p" , "+PL" ]]:
989+ for person in [["1" , "+P1" ], ["2" , "+P2" ], ["3" , "+P3" ]]:
990+ inflected_verb = add_inflection (inflected_verb , verb ["Indicatif" ]["Présent" ][plural [0 ]][person [0 ]], ":IPre" + plural [1 ] + person [1 ])
991+ inflected_verb = add_inflection (inflected_verb , verb ["Indicatif" ]["Imparfait" ][plural [0 ]][person [0 ]], ":IImp" + plural [1 ] + person [1 ])
992+ inflected_verb = add_inflection (inflected_verb , verb ["Indicatif" ]["Passé simple" ][plural [0 ]][person [0 ]], ":IPSim" + plural [1 ] + person [1 ])
993+ inflected_verb = add_inflection (inflected_verb , verb ["Indicatif" ]["Futur simple" ][plural [0 ]][person [0 ]], ":IFut" + plural [1 ] + person [1 ])
994+ inflected_verb = add_inflection (inflected_verb , verb ["Conditionnel" ]["Présent" ][plural [0 ]][person [0 ]], ":CPre" + plural [1 ] + person [1 ])
995+ inflected_verb = add_inflection (inflected_verb , verb ["Subjonctif" ]["Présent" ][plural [0 ]][person [0 ]], ":SPre" + plural [1 ] + person [1 ])
996+ inflected_verb = add_inflection (inflected_verb , verb ["Subjonctif" ]["Imparfait" ][plural [0 ]][person [0 ]], ":SImp" + plural [1 ] + person [1 ])
997+ inflected_verb = add_inflection (inflected_verb , verb ["Participe" ]["Présent" ], ":PPre" )
998+ inflected_verb = add_inflection (inflected_verb , verb ["Participe" ]["Passé" ]["s" ]["m" ], ":PPas+Mas+SG" )
999+ inflected_verb = add_inflection (inflected_verb , verb ["Participe" ]["Passé" ]["s" ]["f" ], ":PPas+Fem+SG" )
1000+ inflected_verb = add_inflection (inflected_verb , verb ["Participe" ]["Passé" ]["p" ]["m" ], ":PPas+Mas+PL" )
1001+ inflected_verb = add_inflection (inflected_verb , verb ["Participe" ]["Passé" ]["p" ]["f" ], ":PPas+Fem+PL" )
1002+ inflected_verb = add_inflection (inflected_verb , verb ["Impératif" ]["Présent" ]["s" ]["2" ], ":ImPre+SG+P2" )
1003+ inflected_verb = add_inflection (inflected_verb , verb ["Impératif" ]["Présent" ]["p" ]["1" ], ":ImPre+PL+P1" )
1004+ inflected_verb = add_inflection (inflected_verb , verb ["Impératif" ]["Présent" ]["p" ]["2" ], ":ImPre+PL+P2" )
1005+ inflected_verb = collections .OrderedDict (sorted (inflected_verb .items ()))
1006+
1007+ for key in inflected_verb .keys ():
1008+ print ("{} {} Ver{}" .format (key , verb ["Infinitif" ]["Présent" ], inflected_verb [key ]))
1009+
1010+
1011+ ################################################################################
1012+ def print_DELA_inflections (verb ):
1013+ """Print a verb conjugations in DELA format"""
1014+ inflected_verb = {}
1015+ inflected_verb = add_inflection (inflected_verb , verb ["Infinitif" ]["Présent" ], ":W" )
1016+ for plural in ["s" , "p" ]:
1017+ for person in ["1" , "2" , "3" ]:
1018+ inflected_verb = add_inflection (inflected_verb , verb ["Indicatif" ]["Présent" ][plural ][person ], ":P" + person + plural )
1019+ inflected_verb = add_inflection (inflected_verb , verb ["Indicatif" ]["Imparfait" ][plural ][person ], ":I" + person + plural )
1020+ inflected_verb = add_inflection (inflected_verb , verb ["Indicatif" ]["Passé simple" ][plural ][person ], ":J" + person + plural )
1021+ inflected_verb = add_inflection (inflected_verb , verb ["Indicatif" ]["Futur simple" ][plural ][person ], ":F" + person + plural )
1022+ inflected_verb = add_inflection (inflected_verb , verb ["Conditionnel" ]["Présent" ][plural ][person ], ":C" + person + plural )
1023+ inflected_verb = add_inflection (inflected_verb , verb ["Subjonctif" ]["Présent" ][plural ][person ], ":S" + person + plural )
1024+ inflected_verb = add_inflection (inflected_verb , verb ["Subjonctif" ]["Imparfait" ][plural ][person ], ":T" + person + plural )
1025+ inflected_verb = add_inflection (inflected_verb , verb ["Participe" ]["Présent" ], ":G" )
1026+ inflected_verb = add_inflection (inflected_verb , verb ["Participe" ]["Passé" ]["s" ]["m" ], ":Kms" )
1027+ inflected_verb = add_inflection (inflected_verb , verb ["Participe" ]["Passé" ]["s" ]["f" ], ":Kfs" )
1028+ inflected_verb = add_inflection (inflected_verb , verb ["Participe" ]["Passé" ]["p" ]["m" ], ":Kmp" )
1029+ inflected_verb = add_inflection (inflected_verb , verb ["Participe" ]["Passé" ]["p" ]["f" ], ":Kfp" )
1030+ inflected_verb = add_inflection (inflected_verb , verb ["Impératif" ]["Présent" ]["s" ]["2" ], ":Y2s" )
1031+ inflected_verb = add_inflection (inflected_verb , verb ["Impératif" ]["Présent" ]["p" ]["1" ], ":Y1p" )
1032+ inflected_verb = add_inflection (inflected_verb , verb ["Impératif" ]["Présent" ]["p" ]["2" ], ":Y2p" )
1033+ inflected_verb = collections .OrderedDict (sorted (inflected_verb .items ()))
1034+
1035+ for key in inflected_verb .keys ():
1036+ if key == verb ["Infinitif" ]["Présent" ]:
1037+ print ("{},.V{}" .format (key , inflected_verb [key ]))
1038+ else :
1039+ print ("{},{}.V{}" .format (key , verb ["Infinitif" ]["Présent" ], inflected_verb [key ]))
1040+
1041+
9551042################################################################################
9561043def print_verb_conjugation (verb ):
957- """Print a 1, 2 or 4 columns verb conjugation"""
958- if parameters ["Display columns" ] == 1 :
1044+ """Print a verb conjugations in different output formats"""
1045+ if parameters ["ABU output" ]:
1046+ print_ABU_inflections (verb )
1047+ elif parameters ["DELA output" ]:
1048+ print_DELA_inflections (verb )
1049+ elif parameters ["Display columns" ] == 1 :
9591050 print_verb_conjugation_odd_columns (verb )
9601051 else :
9611052 print_verb_conjugation_even_columns (verb )
@@ -986,17 +1077,23 @@ def main():
9861077 for argument in arguments :
9871078 conjugations = select_verb_from_verbs (argument , verbs )
9881079 if conjugations :
1080+ verb = None
1081+ verb2 = None
1082+
9891083 if argument in etre_aux :
9901084 verb = conjuguer (argument , conjugations , "être" )
991- print_verb_conjugation (verb )
9921085 elif argument in both_aux :
993- verb1 = conjuguer (argument , conjugations , "être" )
994- print_verb_conjugation (verb1 )
1086+ verb = conjuguer (argument , conjugations , "être" )
9951087 verb2 = conjuguer (argument , conjugations , "avoir" )
996- print_verb_conjugation (verb2 )
9971088 else :
9981089 verb = conjuguer (argument , conjugations , "avoir" )
999- print_verb_conjugation (verb )
1090+
1091+ print_verb_conjugation (verb )
1092+ if argument in both_aux \
1093+ and not parameters ["ABU output" ] \
1094+ and not parameters ["DELA output" ]:
1095+ print_verb_conjugation (verb2 )
1096+
10001097 else :
10011098 logging .error ("%s " + _ ("is not in the dictionary used" ), argument )
10021099 pattern , group , model = analyze_verb (argument )
0 commit comments