1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2020 Pierre Ratinaud
4 #modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
7 #------------------------------------
8 # import des modules python
9 #------------------------------------
15 #------------------------------------
16 # import des modules wx
17 #------------------------------------
20 #------------------------------------
21 # import des fichiers du projet
22 #------------------------------------
23 from KeyFrame import AlcOptFrame
24 from chemins import ConstructConfigPath
25 from functions import DoConf
28 class OptionAlc(wx.Dialog):
30 def __init__(self, parent, parametres, *args, **kwds):
31 kwds['style'] = wx.DEFAULT_DIALOG_STYLE
32 wx.Dialog.__init__(self, parent, *args, **kwds)
34 self.parametres = parametres
35 self.DictPath = parametres['pathout']
36 self.AlcesteConf = parametres
38 self.svdmethod = ['svdR', 'irlba']
39 if self.parent.pref.getboolean('iramuteq','libsvdc') :
40 self.svdmethod.append('svdlibc')
41 #self.label_1 = wx.StaticText(self, -1, "Lemmatisation")
42 #self.radio_1 = wx.RadioBox(self, -1, "", choices=['oui', 'non'], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
43 self.label_12 = wx.StaticText(self, -1, _("Clustering"))
44 self.radio_box_2 = wx.RadioBox(self, -1, "", choices=[_("double on RST"), _("simple on text segments"), _("simple on texts")], majorDimension=0, style=wx.RA_SPECIFY_ROWS) #, u"simple sur UCE (non implemente)"
45 self.label_2 = wx.StaticText(self, -1, _("Size of rst1"))
46 self.spin_ctrl_1 = wx.SpinCtrl(self, -1, _("actives forms"),size = (100,30), min=0, max=1000000)
47 self.label_3 = wx.StaticText(self, -1, _("Size of rst2"))
48 self.spin_ctrl_2 = wx.SpinCtrl(self, -1, "",size = (100,30), min=0, max=1000000)
49 self.lab_nbcl = wx.StaticText(self, -1, _("Number of terminal clusters on phase 1"))
50 self.spin_nbcl = wx.SpinCtrl(self, -1, "",size = (100,30), min=2, max=1000000)
51 txt = _("Minimum frequency of text segments by clusters (0=automatic)")
52 self.label_7 = wx.StaticText(self, -1, txt)
53 self.spin_ctrl_4 = wx.SpinCtrl(self, -1, "",size = (100,30), min=0, max=1000000)
54 txt = _("Minimum frequency of an analyzed form (2=automatic)")
55 self.label_8 = wx.StaticText(self, -1, txt)
56 self.spin_ctrl_5 = wx.SpinCtrl(self, -1, "",size = (100,30), min=2, max=1000000)
57 self.label_max_actives = wx.StaticText(self, -1, _("Maximum number of analyzed forms"))
58 self.spin_max_actives = wx.SpinCtrl(self, -1, "",size = (100,30), min=20, max=1000000)
59 self.label_svd = wx.StaticText(self, -1, _("svd method"))
60 self.choicesvd = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, self.svdmethod, 0 )
61 self.label_patate = wx.StaticText(self, -1, _("Potato mode (less precise, faster)"))
62 self.check_patate = wx.CheckBox( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
63 #self.label_4 = wx.StaticText(self, -1, u"Configuration \ndes clés d'analyse")
64 #self.button_5 = wx.Button(self, wx.ID_PREFERENCES, "")
65 self.button_1 = wx.Button(self, wx.ID_CANCEL, "")
66 self.button_2 = wx.Button(self, wx.ID_DEFAULT, _("Default values"))
67 self.button_4 = wx.Button(self, wx.ID_OK, "")
68 self.static_line_1 = wx.StaticLine(self, -1)
69 self.__set_properties()
71 #self.Bind(wx.EVT_BUTTON, self.OnKeyPref, self.button_5)
72 self.Bind(wx.EVT_BUTTON, self.OnDef, self.button_2)
74 def __set_properties(self):
75 self.SetTitle(_("Settings"))
76 #lang = self.AlcesteConf.get('ALCESTE', 'lang')
77 #self.choice_dict.SetSelection(self.langues.index(lang))
78 #DefaultLem = self.parametres['lem']
80 # self.radio_1.SetSelection(0)
82 # self.radio_1.SetSelection(1)
83 self.radio_box_2.SetSelection(int(self.parametres['classif_mode']))
84 self.spin_ctrl_1.SetValue(int(self.parametres['tailleuc1']))
85 self.spin_ctrl_2.SetValue(int(self.parametres['tailleuc2']))
86 self.spin_ctrl_4.SetValue(int(self.parametres['mincl']))
87 self.spin_ctrl_5.SetValue(int(self.parametres['minforme']))
88 self.spin_ctrl_5.Disable()
89 self.spin_max_actives.SetValue(int(self.parametres['max_actives']))
90 self.spin_nbcl.SetValue(int(self.parametres['nbcl_p1']))
91 if 'svdmethod' in self.parametres :
92 self.choicesvd.SetSelection(self.svdmethod.index(self.parametres['svdmethod']))
94 self.choicesvd.SetSelection(1)
95 if 'mode.patate' in self.parametres :
96 self.check_patate.SetValue(self.parametres['mode.patate'])
98 self.check_patate.SetValue(False)
100 def __do_layout(self):
101 sizer_1 = wx.BoxSizer(wx.VERTICAL)
102 sizer_2 = wx.BoxSizer(wx.VERTICAL)
103 grid_sizer2 = wx.FlexGridSizer(0, 2, 0, 0)
104 grid_button = wx.FlexGridSizer(1, 3, 0, 0)
105 # éléments désactivés ???
106 #grid_sizer2.Add(self.label_dict, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
107 #grid_sizer2.Add(self.choice_dict, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
108 #grid_sizer2.Add(self.label_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
109 #grid_sizer2.Add(self.radio_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
110 #grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
111 #grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
113 grid_sizer2.Add(self.label_12, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
114 grid_sizer2.Add(self.radio_box_2, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
115 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
116 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
117 grid_sizer2.Add(self.label_2, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
118 grid_sizer2.Add(self.spin_ctrl_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
119 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
120 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
121 grid_sizer2.Add(self.label_3, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
122 grid_sizer2.Add(self.spin_ctrl_2, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
123 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
124 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
125 grid_sizer2.Add(self.lab_nbcl, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
126 grid_sizer2.Add(self.spin_nbcl, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
127 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
128 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
129 grid_sizer2.Add(self.label_7, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
130 grid_sizer2.Add(self.spin_ctrl_4, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
131 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
132 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
133 grid_sizer2.Add(self.label_8, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
134 grid_sizer2.Add(self.spin_ctrl_5, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
135 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
136 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
137 grid_sizer2.Add(self.label_max_actives, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
138 grid_sizer2.Add(self.spin_max_actives, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
139 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
140 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
141 grid_sizer2.Add(self.label_svd, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
142 grid_sizer2.Add(self.choicesvd, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
143 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
144 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
145 grid_sizer2.Add(self.label_patate, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
146 grid_sizer2.Add(self.check_patate, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
147 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
148 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
149 grid_button.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
150 grid_button.Add(self.button_2, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
151 grid_button.Add(self.button_4, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
152 sizer_2.Add(grid_sizer2, 3, wx.EXPAND, 0)
153 sizer_2.Add(grid_button, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
154 sizer_1.Add(sizer_2, 0, wx.EXPAND, 0)
155 self.SetSizer(sizer_1)
159 def OnKeyPref(self, event):
161 dial = AlcOptFrame(self.parent, self)
162 dial.CenterOnParent()
163 val = dial.ShowModal()
165 def OnDef(self, event):
166 ConfOri = ConstructConfigPath(self.parent.AppliPath, user=False)
167 ConfUser = ConstructConfigPath(self.parent.UserConfigPath)
168 shutil.copyfile(ConfOri['alceste'], ConfUser['alceste'])
169 corpus = self.parametres['corpus']
170 pathout = self.parametres['pathout']
171 self.parametres = DoConf(self.parent.ConfigPath['alceste']).getoptions('ALCESTE')
172 self.parametres['corpus'] = corpus
173 self.parametres['pathout'] = pathout
174 self.__set_properties()
177 class OptionPam(wx.Dialog):
179 def __init__(self, parent, *args, **kwds):
180 kwds['style'] = wx.DEFAULT_DIALOG_STYLE
181 wx.Dialog.__init__(self, *args, **kwds)
183 self.DictPath = parent.DictPath
184 self.pamconf = parent.pamconf
185 self.type = parent.type
187 self.label_1 = wx.StaticText(self, -1, "Lemmatisation")
188 self.radio_1 = wx.RadioBox(self, -1, "", choices=['oui', 'non'], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
189 #self.label_exp = wx.StaticText(self, -1, u"Utiliser le dict. des expressions")
190 #self.radio_exp = wx.RadioBox(self, -1, u"", choices=['oui', 'non'], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
191 # pourquoi le retour à la ligne ???
192 txt = """Methode de construction
193 de la matrice des distances"""
194 self.label_12 = wx.StaticText(self, -1, txt)
195 self.distance = ["binary", "euclidean", "maximum", 'manhattan', 'canberra', 'minkowski']
196 self.choice_1 = wx.Choice(self, -1, (100,50), choices=self.distance)
197 self.label_13 = wx.StaticText(self, -1, 'Analyse')
198 self.cltype = ['k-means (pam)', 'fuzzy (fanny)']
199 self.radio_box_3 = wx.RadioBox(self, -1, "", choices=self.cltype, majorDimension=0, style=wx.RA_SPECIFY_ROWS)
200 self.label_classif = wx.StaticText(self, -1, "Classification")
201 self.radio_box_classif = wx.RadioBox(self, -1, "", choices=["sur UCE", "sur UCI"], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
202 #self.label_2 = wx.StaticText(self, -1, "taille uc")
203 #self.spin_ctrl_1 = wx.SpinCtrl(self, -1, "formes actives", min=0, max=100)
204 self.label_max_actives = wx.StaticText(self, -1, "Nombre maximum de formes analysées")
205 self.spin_max_actives = wx.SpinCtrl(self, -1, "",size = (100,30), min=20, max=10000)
206 # pourquoi le retour à la ligne ???
207 txt = """Nombre de formes par uce
209 self.label_6 = wx.StaticText(self, -1, txt)
210 self.spin_ctrl_3 = wx.SpinCtrl(self, -1, "", size = (100,30), min=0, max=100000)
211 txt = "Nombre de classes"
212 self.label_7 = wx.StaticText(self, -1, txt)
213 self.spin_ctrl_4 = wx.SpinCtrl(self, -1, "", size = (100,30), min=0, max=1000)
214 self.label_4 = wx.StaticText(self, -1, "Configuration \ndes clés d'analyse")
215 self.button_5 = wx.Button(self, wx.ID_PREFERENCES, "")
216 self.button_1 = wx.Button(self, wx.ID_CANCEL, "")
217 self.button_2 = wx.Button(self, wx.ID_DEFAULT, "Valeurs par défaut")
218 self.button_4 = wx.Button(self, wx.ID_OK, "")
219 self.static_line_1 = wx.StaticLine(self, -1)
220 self.__set_properties()
222 self.Bind(wx.EVT_BUTTON, self.OnKeyPref, self.button_5)
223 self.Bind(wx.EVT_BUTTON, self.OnDef, self.button_2)
225 def __set_properties(self):
226 self.SetTitle("Options")
227 DefaultLem = self.pamconf.getboolean('pam', 'lem')
229 self.radio_1.SetSelection(0)
231 self.radio_1.SetSelection(1)
232 expressions = self.pamconf.getboolean('pam', 'expressions')
234 # self.radio_exp.SetSelection(0)
236 # self.radio_exp.SetSelection(1)
237 self.choice_1.SetSelection(self.distance.index(self.pamconf.get('pam', 'method')))
238 if self.pamconf.get('pam', 'cluster_type') == 'pam' :
239 self.radio_box_3.SetSelection(0)
241 self.radio_box_3.SetSelection(1)
242 self.radio_box_classif.SetSelection(int(self.pamconf.get('pam','type')))
243 self.spin_max_actives.SetValue(int(self.pamconf.get('pam','max_actives')))
244 self.spin_ctrl_3.SetValue(int(self.pamconf.get('pam', 'nbforme_uce')))
246 self.spin_ctrl_4.SetValue(int(self.pamconf.get('pam', cle)))
248 def __do_layout(self):
249 sizer_1 = wx.BoxSizer(wx.VERTICAL)
250 sizer_2 = wx.BoxSizer(wx.VERTICAL)
251 grid_sizer2 = wx.FlexGridSizer(11, 2, 2, 2)
252 grid_button = wx.FlexGridSizer(1, 3, 1, 1)
253 grid_sizer2.Add(self.label_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
254 grid_sizer2.Add(self.radio_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
255 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
256 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
257 grid_sizer2.Add(self.label_exp, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
258 grid_sizer2.Add(self.radio_exp, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
259 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
260 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
261 grid_sizer2.Add(self.label_12, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
262 grid_sizer2.Add(self.choice_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
263 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
264 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
265 grid_sizer2.Add(self.label_13, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
266 grid_sizer2.Add(self.radio_box_3, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
267 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
268 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
269 grid_sizer2.Add(self.label_classif, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
270 grid_sizer2.Add(self.radio_box_classif, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
271 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
272 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
274 #grid_sizer2.Add(self.label_2, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
275 #grid_sizer2.Add(self.spin_ctrl_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
276 #grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
277 #grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
279 grid_sizer2.Add(self.label_max_actives, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
280 grid_sizer2.Add(self.spin_max_actives, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
281 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
282 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
283 grid_sizer2.Add(self.label_6, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
284 grid_sizer2.Add(self.spin_ctrl_3, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
285 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
286 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
287 grid_sizer2.Add(self.label_7, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
288 grid_sizer2.Add(self.spin_ctrl_4, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
289 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
290 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
291 grid_sizer2.Add(self.label_4, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
292 grid_sizer2.Add(self.button_5, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
293 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
294 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
295 grid_button.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
296 grid_button.Add(self.button_2, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
297 grid_button.Add(self.button_4, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
298 sizer_2.Add(grid_sizer2, 3, wx.EXPAND, 0)
299 sizer_2.Add(grid_button, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
300 sizer_1.Add(sizer_2, 0, wx.EXPAND, 0)
301 self.SetSizer(sizer_1)
305 def OnKeyPref(self, event):
307 dial = AlcOptFrame(self.parent, self)
308 dial.CenterOnParent()
309 val = dial.ShowModal()
311 def OnDef(self, event):
312 ConfOri = ConstructConfigPath(self.parent.parent.AppliPath, user=False)
313 ConfUser = ConstructConfigPath(self.parent.parent.UserConfigPath)
314 shutil.copyfile(ConfOri['pam'], ConfUser['pam'])
315 self.parent.pamconf.read(self.parent.ConfigPath['pam'])
316 self.__set_properties()