1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2011 Pierre Ratinaud
6 from chemins import ConstructPathOut, construct_simipath
7 from corpus import Corpus
9 from ConfigParser import RawConfigParser
10 from guifunct import getPage, getCorpus
11 from dialog import StatDialog
12 from functions import indices_simi, progressbar, treat_var_mod
13 from tableau import Tableau
14 from tabsimi import DoSimi
19 def __init__(self, parent, cmd = False, param = None):
22 self.ConfigPath = parent.ConfigPath
23 self.DictPath = parent.DictPath
24 self.KeyConf = RawConfigParser()
25 self.KeyConf.read(self.ConfigPath['key'])
26 self.indices = indices_simi
27 self.paramsimi = {'coeff' : 0,
49 'cola' : (200,200,200),
58 page = getPage(self.parent)
60 self.corpus = getCorpus(page)
61 if self.corpus is not None :
62 self.pathout = ConstructPathOut(self.corpus.parametre['openpath'], 'simitxt')
63 self.dictpathout = construct_simipath(self.pathout)
68 self.corpus = Corpus(parent)
69 self.corpus.content = self.parent.content
70 self.corpus.parametre['encodage'] = parent.corpus_encodage
71 self.corpus.parametre['lang'] = parent.corpus_lang
72 self.corpus.parametre['filename'] = parent.filename
73 self.corpus.parametre['eff_min_uce'] = None
74 self.pathout = ConstructPathOut(self.corpus.parametre['filename'], 'simitxt')
75 self.dictpathout = construct_simipath(self.pathout)
76 dial = StatDialog(self, self.parent)
77 dial.check_uce.SetValue(True)
78 dial.check_uce.Enable(False)
79 dial.OnCheckUce(wx.EVT_MENU)
80 self.val = dial.ShowModal()
81 if self.val == wx.ID_OK :
82 with open(self.parent.ConfigPath['key'], 'w') as f:
84 if dial.radio_lem.GetSelection() == 0 : lem = True
86 if dial.exp.GetSelection() == 0 : exp = True
89 self.corpus.parametre['lem'] = lem
90 self.corpus.parametre['expressions'] = exp
91 self.corpus.parametre['nbforme_uce'] = dial.spin_ctrl_4.GetValue()
92 self.corpus.parametre['eff_min_forme'] = dial.spin_ctrl_5.GetValue()
93 self.corpus.parametre['max_actives'] = dial.spin_max_actives.GetValue()
100 def make_corpus(self) :
103 dlg = progressbar(self, maxi = 6)
104 self.corpus.supplementaires = [option for option in self.KeyConf.options('KEYS') if self.KeyConf.get('KEYS', option) == "2"]
105 self.corpus.typeactive = [option for option in self.KeyConf.options('KEYS') if self.KeyConf.get('KEYS', option) == "1"]
106 ucis_txt, ucis_paras_txt = self.corpus.start_analyse(self.parent, dlg = dlg, cmd = self.cmd)
110 dlg.Update(5, '%i ucis - Construction des uces' % len(ucis_paras_txt))
111 self.corpus.make_ucis_paras_uces(ucis_paras_txt, make_uce = True)
114 if self.corpus.para_coords != [[] for val in self.corpus.para_coords] :
115 self.corpus.parametre['para'] = True
117 self.corpus.parametre['para'] = False
118 self.corpus.make_etoiles(self.corpus.para_coords)
119 print 'len(ucis_paras_uces)', len(self.corpus.ucis_paras_uces)
122 dlg.Update(6, u'Dictionnaires')
123 uces, self.orderuces = self.corpus.make_forms_and_uces()
124 self.corpus.ucenb = len(uces)
125 self.corpus.make_lems(self.parent.lexique)
127 self.corpus.make_var_actives()
128 self.corpus.make_var_supp()
129 self.corpus.lems_eff = self.corpus.make_lem_eff()
131 #variables = treat_var_mod(listet)
133 #self.corpus.write_etoiles(self.dictpathout['etoiles'])
137 def make_table(self) :
138 if 'orderuces' not in dir(self) :
139 self.orderuces = [(i,j,k) for i, uci in enumerate(self.corpus.ucis_paras_uces) for j, para in enumerate(uci) for k, uce in enumerate(para)]
140 self.orderuces = dict([[val, i] for i, val in enumerate(self.orderuces)])
141 self.corpus.ucenb = len(self.orderuces)
142 #tabuc1 = self.corpus.make_table_with_uce(self.orderuces)
143 #tabuc1.insert(0,self.corpus.actives)
144 #tabuc1 = self.corpus.make_sparse_matrix_with_uce(self.orderuces)
145 #self.corpus.write_sparse_matrix(self.dictpathout['mat01'], tabuc1, self.corpus.ucenb, len(self.corpus.actives))
146 if self.corpus.actives is None :
147 self.corpus.typeactive = [option for option in self.KeyConf.options('KEYS') if self.KeyConf.get('KEYS', option) == "1"]
148 self.corpus.min_eff_formes()
149 self.corpus.make_var_actives()
150 self.corpus.make_and_write_sparse_matrix_from_uce(self.orderuces, self.dictpathout['mat01'])
151 #self.corpus.write_tab(tabuc1,self.dictpathout['mat01'])
153 def make_simi(self) :
154 self.tableau = Tableau(self.parent, '')
155 self.tableau.listactives = self.corpus.actives
156 self.tableau.parametre['fromtxt'] = True
157 if 'lems_eff' not in dir(self.corpus) :
158 self.corpus.lems_eff = self.corpus.make_lem_eff()
159 #print('ATTENTION ETOILES')
160 #self.paramsimi['bystar'] = True
161 self.listet = self.corpus.get_unique_etoiles()
163 self.tableau.listet = copy(self.listet)
164 self.paramsimi['stars'] = copy(self.listet)
165 #self.paramsimi['cexfromchi'] = True
166 self.paramsimi['sfromchi'] = False
167 #self.paramsimi['vlabcolor'] = True
168 self.tableau.actives = dict([[lem, self.corpus.lems_eff[lem]] for lem in self.corpus.actives])
169 self.corpus.save_corpus(self.dictpathout['corpus'])
170 DoSimi(self, fromprof = self.dictpathout['mat01'], param = self.paramsimi, pathout = self.pathout)