1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2009 Pierre Ratinaud
8 from KeyFrame import AlcOptFrame
9 from chemins import ConstructConfigPath
10 from functions import DoConf
14 class OptionAlc(wx.Dialog):
15 def __init__(self, parent, parametres, *args, **kwds):
16 kwds['style'] = wx.DEFAULT_DIALOG_STYLE
17 wx.Dialog.__init__(self, parent, *args, **kwds)
19 self.parametres = parametres
20 self.DictPath = parametres['pathout']
21 self.AlcesteConf = parametres
23 self.svdmethod = ['svdR', 'irlba']
24 if self.parent.pref.getboolean('iramuteq','libsvdc') :
25 self.svdmethod.append('svdlibc')
26 #self.label_1 = wx.StaticText(self, -1, u"Lemmatisation")
27 #self.radio_1 = wx.RadioBox(self, -1, u"", choices=['oui', 'non'], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
29 self.label_12 = wx.StaticText(self, -1, _(u"Clustering").decode('utf8'))
30 self.radio_box_2 = wx.RadioBox(self, -1, u"", choices=[_(u"double on RST").decode('utf8'), _(u"simple on text segments").decode('utf8'), _(u"simple on texts").decode('utf8')], majorDimension=0, style=wx.RA_SPECIFY_ROWS) #, u"simple sur UCE (non implemente)"
31 self.label_2 = wx.StaticText(self, -1, _(u"Size of rst1").decode('utf8'))
32 self.spin_ctrl_1 = wx.SpinCtrl(self, -1, _(u"actives forms").decode('utf8'),size = (100,30), min=0, max=1000000)
33 self.label_3 = wx.StaticText(self, -1, _(u"Size of rst2").decode('utf8'))
34 self.spin_ctrl_2 = wx.SpinCtrl(self, -1, "",size = (100,30), min=0, max=1000000)
35 self.lab_nbcl = wx.StaticText(self, -1, _(u"Number of terminal clusters on phase 1").decode('utf8'))
36 self.spin_nbcl = wx.SpinCtrl(self, -1, "",size = (100,30), min=2, max=1000000)
37 txt = _(u"Minimum frequency of text segments by clusters (0=automatic)").decode('utf8')
38 self.label_7 = wx.StaticText(self, -1, txt)
39 self.spin_ctrl_4 = wx.SpinCtrl(self, -1, "",size = (100,30), min=0, max=1000000)
40 txt = _(u"Minimum frequency of an analyzed form (2=automatic)").decode('utf8')
41 self.label_8 = wx.StaticText(self, -1, txt)
42 self.spin_ctrl_5 = wx.SpinCtrl(self, -1, "",size = (100,30), min=2, max=1000000)
43 self.label_max_actives = wx.StaticText(self, -1, _(u"Maximum number of analyzed forms").decode('utf8'))
44 self.spin_max_actives = wx.SpinCtrl(self, -1, "",size = (100,30), min=20, max=1000000)
45 self.label_svd = wx.StaticText(self, -1, _(u"svd method").decode('utf8'))
46 self.choicesvd = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, self.svdmethod, 0 )
47 self.label_patate = wx.StaticText(self, -1, _(u"Potato mode (less precise, faster)").decode('utf8'))
48 self.check_patate = wx.CheckBox( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
49 #self.label_4 = wx.StaticText(self, -1, u"Configuration \ndes clés d'analyse")
50 #self.button_5 = wx.Button(self, wx.ID_PREFERENCES, "")
51 self.button_1 = wx.Button(self, wx.ID_CANCEL, "")
52 self.button_2 = wx.Button(self, wx.ID_DEFAULT, _(u"Default values").decode('utf8'))
53 self.button_4 = wx.Button(self, wx.ID_OK, "")
54 self.static_line_1 = wx.StaticLine(self, -1)
56 self.__set_properties()
59 #self.Bind(wx.EVT_BUTTON, self.OnKeyPref, self.button_5)
60 self.Bind(wx.EVT_BUTTON, self.OnDef, self.button_2)
62 def __set_properties(self):
63 self.SetTitle(_(u"Settings").decode('utf8'))
64 #lang = self.AlcesteConf.get('ALCESTE', 'lang')
65 #self.choice_dict.SetSelection(self.langues.index(lang))
66 #DefaultLem = self.parametres['lem']
68 # self.radio_1.SetSelection(0)
70 # self.radio_1.SetSelection(1)
71 self.radio_box_2.SetSelection(int(self.parametres['classif_mode']))
72 self.spin_ctrl_1.SetValue(int(self.parametres['tailleuc1']))
73 self.spin_ctrl_2.SetValue(int(self.parametres['tailleuc2']))
74 self.spin_ctrl_4.SetValue(int(self.parametres['mincl']))
75 self.spin_ctrl_5.SetValue(int(self.parametres['minforme']))
76 self.spin_ctrl_5.Disable()
77 self.spin_max_actives.SetValue(int(self.parametres['max_actives']))
78 self.spin_nbcl.SetValue(int(self.parametres['nbcl_p1']))
79 if 'svdmethod' in self.parametres :
80 self.choicesvd.SetSelection(self.svdmethod.index(self.parametres['svdmethod']))
82 self.choicesvd.SetSelection(1)
83 if 'mode.patate' in self.parametres :
84 self.check_patate.SetValue(self.parametres['mode.patate'])
86 self.check_patate.SetValue(False)
89 def __do_layout(self):
90 sizer_1 = wx.BoxSizer(wx.VERTICAL)
91 sizer_2 = wx.BoxSizer(wx.VERTICAL)
92 grid_sizer2 = wx.FlexGridSizer(0, 2, 0, 0)
93 grid_button = wx.FlexGridSizer(1, 3, 0, 0)
95 #grid_sizer2.Add(self.label_dict, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
96 #grid_sizer2.Add(self.choice_dict, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
98 #grid_sizer2.Add(self.label_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
99 #grid_sizer2.Add(self.radio_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
100 #grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
101 #grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
103 grid_sizer2.Add(self.label_12, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
104 grid_sizer2.Add(self.radio_box_2, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
105 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
106 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
108 grid_sizer2.Add(self.label_2, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
109 grid_sizer2.Add(self.spin_ctrl_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_3, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
114 grid_sizer2.Add(self.spin_ctrl_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)
118 grid_sizer2.Add(self.lab_nbcl, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
119 grid_sizer2.Add(self.spin_nbcl, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
120 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
121 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
123 grid_sizer2.Add(self.label_7, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
124 grid_sizer2.Add(self.spin_ctrl_4, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
125 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
126 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
128 grid_sizer2.Add(self.label_8, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
129 grid_sizer2.Add(self.spin_ctrl_5, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
130 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
131 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
133 grid_sizer2.Add(self.label_max_actives, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
134 grid_sizer2.Add(self.spin_max_actives, 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)
138 grid_sizer2.Add(self.label_svd, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
139 grid_sizer2.Add(self.choicesvd, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
140 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
141 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
143 grid_sizer2.Add(self.label_patate, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
144 grid_sizer2.Add(self.check_patate, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
145 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
146 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
148 grid_button.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
149 grid_button.Add(self.button_2, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
150 grid_button.Add(self.button_4, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
151 sizer_2.Add(grid_sizer2, 3, wx.EXPAND, 0)
152 sizer_2.Add(grid_button, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
153 sizer_1.Add(sizer_2, 0, wx.EXPAND, 0)
154 self.SetSizer(sizer_1)
158 def OnKeyPref(self, event):
160 dial = AlcOptFrame(self.parent, self)
161 dial.CenterOnParent()
162 val = dial.ShowModal()
164 def OnDef(self, event):
165 ConfOri = ConstructConfigPath(self.parent.AppliPath, user=False)
166 ConfUser = ConstructConfigPath(self.parent.UserConfigPath)
167 shutil.copyfile(ConfOri['alceste'], ConfUser['alceste'])
168 corpus = self.parametres['corpus']
169 pathout = self.parametres['pathout']
170 self.parametres = DoConf(self.parent.ConfigPath['alceste']).getoptions('ALCESTE')
171 self.parametres['corpus'] = corpus
172 self.parametres['pathout'] = pathout
173 self.__set_properties()
175 ###################################################################################@
177 class OptionPam(wx.Dialog):
178 def __init__(self, parent, *args, **kwds):
179 kwds['style'] = wx.DEFAULT_DIALOG_STYLE
180 wx.Dialog.__init__(self, *args, **kwds)
182 self.DictPath = parent.DictPath
183 self.pamconf = parent.pamconf
184 self.type = parent.type
187 self.label_1 = wx.StaticText(self, -1, u"Lemmatisation")
188 self.radio_1 = wx.RadioBox(self, -1, u"", 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 txt = u"""Methode de construction
192 de la matrice des distances"""
193 self.label_12 = wx.StaticText(self, -1, txt)
194 self.distance = [u"binary", u"euclidean", u"maximum", u'manhattan', u'canberra', u'minkowski']
195 self.choice_1 = wx.Choice(self, -1, (100,50), choices=self.distance)
196 self.label_13 = wx.StaticText(self, -1, u'Analyse')
197 self.cltype = [u'k-means (pam)', u'fuzzy (fanny)']
198 self.radio_box_3 = wx.RadioBox(self, -1, u"", choices=self.cltype, majorDimension=0, style=wx.RA_SPECIFY_ROWS)
199 self.label_classif = wx.StaticText(self, -1, u"Classification")
200 self.radio_box_classif = wx.RadioBox(self, -1, u"", choices=[u"sur UCE", u"sur UCI"], majorDimension=0, style=wx.RA_SPECIFY_ROWS)
201 #self.label_2 = wx.StaticText(self, -1, "taille uc")
202 #self.spin_ctrl_1 = wx.SpinCtrl(self, -1, "formes actives", min=0, max=100)
203 self.label_max_actives = wx.StaticText(self, -1, u"Nombre maximum de formes analysées")
204 self.spin_max_actives = wx.SpinCtrl(self, -1, "",size = (100,30), min=20, max=10000)
205 txt = """Nombre de formes par uce
207 self.label_6 = wx.StaticText(self, -1, txt)
208 self.spin_ctrl_3 = wx.SpinCtrl(self, -1, "", size = (100,30), min=0, max=100000)
209 txt = "Nombre de classes"
210 self.label_7 = wx.StaticText(self, -1, txt)
211 self.spin_ctrl_4 = wx.SpinCtrl(self, -1, "", size = (100,30), min=0, max=1000)
212 self.label_4 = wx.StaticText(self, -1, u"Configuration \ndes clés d'analyse")
213 self.button_5 = wx.Button(self, wx.ID_PREFERENCES, "")
214 self.button_1 = wx.Button(self, wx.ID_CANCEL, "")
215 self.button_2 = wx.Button(self, wx.ID_DEFAULT, u"Valeurs par défaut")
216 self.button_4 = wx.Button(self, wx.ID_OK, "")
217 self.static_line_1 = wx.StaticLine(self, -1)
219 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') == u'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)
258 grid_sizer2.Add(self.label_exp, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
259 grid_sizer2.Add(self.radio_exp, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
260 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
261 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
263 grid_sizer2.Add(self.label_12, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
264 grid_sizer2.Add(self.choice_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
265 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
266 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
268 grid_sizer2.Add(self.label_13, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
269 grid_sizer2.Add(self.radio_box_3, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
270 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
271 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
273 grid_sizer2.Add(self.label_classif, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
274 grid_sizer2.Add(self.radio_box_classif, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
275 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
276 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
278 #grid_sizer2.Add(self.label_2, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
279 #grid_sizer2.Add(self.spin_ctrl_1, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
280 #grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
281 #grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
283 grid_sizer2.Add(self.label_max_actives, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
284 grid_sizer2.Add(self.spin_max_actives, 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)
288 grid_sizer2.Add(self.label_6, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
289 grid_sizer2.Add(self.spin_ctrl_3, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
290 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
291 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
293 grid_sizer2.Add(self.label_7, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
294 grid_sizer2.Add(self.spin_ctrl_4, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
295 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
296 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
298 grid_sizer2.Add(self.label_4, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
299 grid_sizer2.Add(self.button_5, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 0)
300 grid_sizer2.Add(wx.StaticLine(self), 0, wx.EXPAND | wx.ALL, 1)
301 grid_sizer2.Add(wx.StaticLine(self, -1), 0, wx.EXPAND | wx.ALL, 1)
303 grid_button.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
304 grid_button.Add(self.button_2, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
305 grid_button.Add(self.button_4, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
306 sizer_2.Add(grid_sizer2, 3, wx.EXPAND, 0)
307 sizer_2.Add(grid_button, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 0)
308 sizer_1.Add(sizer_2, 0, wx.EXPAND, 0)
309 self.SetSizer(sizer_1)
313 def OnKeyPref(self, event):
315 dial = AlcOptFrame(self.parent, self)
316 dial.CenterOnParent()
317 val = dial.ShowModal()
319 def OnDef(self, event):
320 ConfOri = ConstructConfigPath(self.parent.parent.AppliPath, user=False)
321 ConfUser = ConstructConfigPath(self.parent.parent.UserConfigPath)
322 shutil.copyfile(ConfOri['pam'], ConfUser['pam'])
323 self.parent.pamconf.read(self.parent.ConfigPath['pam'])
324 self.__set_properties()