2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008 Pierre Ratinaud
12 log = logging.getLogger('iramuteq.chemins')
15 def normpath_win32(path) :
16 if not sys.platform == 'win32' :
18 while '\\\\' in path :
19 path = path.replace('\\\\', '\\')
20 if sys.platform == 'win32' and path.startswith('\\') and not path.startswith('\\\\') :
25 def __init__(self, filename = None, analyse_type = '', dirout = None) :
26 if filename is not None :
27 self.filepath = os.path.abspath(filename)
28 self.filebasename = os.path.basename(filename)
29 self.directory = os.path.abspath(os.path.dirname(filename))
30 self.filename, self.fileext = os.path.splitext(self.filebasename)
31 self.analyse = analyse_type
32 #self.dirout = self.mkdirout(dirout)
33 if dirout is not None:
34 self.dirout = os.path.abspath(dirout)
35 elif filename is not None and dirout is None:
36 self.dirout = os.path.abspath(self.directory)
40 dirout = os.path.join(self.dirout, self.filename + '_' + self.analyse + '_')
42 tdirout = dirout + `nb`
43 while os.path.exists(tdirout) :
45 tdirout = dirout + `nb`
46 self.name = os.path.splitext(tdirout)[1]
49 def makenew(self, filename, ext):
51 newfile = '_'.join([os.path.join(self.dirout, filename), '%i' % nb]) + '.' + ext
52 while os.path.exists(newfile) :
54 newfile = '_'.join([os.path.join(self.dirout, filename), '%i' % nb]) + '.' + ext
57 def createdir(self, tdirout) :
58 if not os.path.exists(tdirout) :
61 def basefiles(self, ndict) :
64 def __getitem__(self, key) :
66 self.temp = tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\')
68 elif key not in self.d :
69 f = os.path.join(self.dirout, key).replace('\\', '\\\\')
70 return normpath_win32(f)
71 #return os.path.join(self.dirout, key).replace('\\', '\\\\')
73 f = os.path.join(self.dirout, self.d[key]).replace('\\', '\\\\')
74 return normpath_win32(f)
75 #return os.path.join(self.dirout, self.d[key]).replace('\\', '\\\\')
78 return self.__getitem__(key).replace('\\', '/')
82 return filename.replace('\\', '\\\\')
85 return filename.replace('\\', '/')
89 'chdfunct': 'chdfunct.R',
91 'plotafcm': 'plotafcm.R',
92 'afc_graph' : 'afc_graph.R',
97 'chdquest': 'chdquest.R',
98 'pamtxt' : 'pamtxt.R',
99 'anacor' : 'anacor.R',
100 #'anacor' : 'Nanacor.R',
104 def ConstructRscriptsPath(AppliPath):
105 RScriptsPath = os.path.join(AppliPath, 'Rscripts')
106 #print('@@@@@@@@@@@PONDERATION CHDPOND.R@@@@@@@@@@@@@@@@')
107 #print('@@@@@@@@@@@ NEW SVD CHEMIN @@@@@@@@@@@@@@@@')
108 #print '@@@@@@@@@@@ NEW NCHD CHEMIN @@@@@@@@@@@@@@@@'
110 'Rfunct': ffr(os.path.join(RScriptsPath, 'Rfunct.R')),
111 'chdfunct': ffr(os.path.join(RScriptsPath, 'chdfunct.R')),
112 'Rgraph': ffr(os.path.join(RScriptsPath, 'Rgraph.R')),
113 'plotafcm': ffr(os.path.join(RScriptsPath, 'plotafcm.R')),
114 'afc_graph' : ffr(os.path.join(RScriptsPath, 'afc_graph.R')),
115 #'CHD': ffr(os.path.join(RScriptsPath, 'CHDPOND.R')),
116 'CHD': ffr(os.path.join(RScriptsPath, 'CHD.R')),
117 #'CHD' : ffr(os.path.join(RScriptsPath, 'NCHD.R')),
118 'chdtxt': ffr(os.path.join(RScriptsPath, 'chdtxt.R')),
119 'chdquest': ffr(os.path.join(RScriptsPath, 'chdquest.R')),
120 'pamtxt' : ffr(os.path.join(RScriptsPath, 'pamtxt.R')),
121 'anacor' : ffr(os.path.join(RScriptsPath, 'anacor.R')),
122 #'anacor' : ffr(os.path.join(RScriptsPath, 'Nanacor.R')),
123 'simi' : ffr(os.path.join(RScriptsPath, 'simi.R')),
127 def ConstructPathOut(Filename, analyse_type):
128 FileBaseName = os.path.basename(Filename)
129 FileBasePath = os.path.dirname(Filename)
130 PathFile = os.path.splitext(FileBaseName)
131 PathFile = os.path.join(FileBasePath, PathFile[0] + '_' + analyse_type + '_1')
132 splitpath = PathFile.split('_')
133 number = int(splitpath[len(splitpath) - 1])
134 while os.path.isdir(PathFile) :
136 PathFile = PathFile[0:len(PathFile) - 1] + str(number + 1)
138 elif (number >= 10) and (number < 100):
139 PathFile = PathFile[0:len(PathFile) - 2] + str(number + 1)
142 PathFile = PathFile[0:len(PathFile) - 3] + str(number + 1)
145 os.mkdir(os.path.join(FileBasePath, PathFile))
146 return os.path.join(FileBasePath, PathFile)
148 def ConstructConfigPath(AppliPath, user=True):
150 ConfigPath = os.path.join(AppliPath, 'configuration')
152 ConfigPath = AppliPath
154 'reinert': os.path.join(ConfigPath, 'reinert.cfg'),
155 'key': os.path.join(ConfigPath, 'key.cfg'),
156 'path': os.path.join(ConfigPath, 'path.cfg'),
157 'preferences' : os.path.join(ConfigPath, 'iramuteq.cfg'),
158 'pam' : os.path.join(ConfigPath, 'pam.cfg'),
159 'corpus' : os.path.join(ConfigPath, 'corpus.cfg'),
160 'stat' : os.path.join(ConfigPath, 'stat.cfg'),
161 'simitxt' : os.path.join(ConfigPath, 'simitxt.cfg'),
162 'matrix' : os.path.join(ConfigPath, 'matrix.cfg'),
164 return DictConfigPath
166 def ConstructGlobalPath(AppliPath):
167 ConfigPath = os.path.join(AppliPath, 'configuration')
169 'global': os.path.join(ConfigPath, 'global.cfg'),
170 'preferences': os.path.join(ConfigPath, 'iramuteq.cfg'),
172 return DictConfigPath
174 def ConstructDicoPath(AppliPath):
175 BasePath = os.path.join(AppliPath, 'dictionnaires')
177 'french': os.path.join(BasePath, 'lexique_fr.txt'),
178 'french_exp': os.path.join(BasePath, 'expression_fr.txt'),
179 'english': os.path.join(BasePath, 'lexique_en.txt'),
180 'english_exp': os.path.join(BasePath, 'expression_en.txt'),
181 'german' : os.path.join(BasePath, 'lexique_de.txt'),
182 'german_exp' : os.path.join(BasePath, 'expression_de.txt'),
183 'italian' : os.path.join(BasePath, 'lexique_it.txt'),
184 'italian_exp' : os.path.join(BasePath, 'expression_it.txt'),
185 'swedish' : os.path.join(BasePath, 'lexique_sw.txt'),
186 'swedish_exp' : os.path.join(BasePath, 'expression_sw.txt'),
187 'portuguese' : os.path.join(BasePath, 'lexique_pt.txt'),
188 'portuguese_exp': os.path.join(BasePath, 'expression_pt.txt'),
189 'greek' : os.path.join(BasePath, 'lexique_gr.txt'),
190 'greek_exp' : os.path.join(BasePath, 'expression_gr.txt'),
191 'spanish' : os.path.join(BasePath, 'lexique_sp.txt'),
192 'spanish_exp' : os.path.join(BasePath, 'expression_sp.txt'),
193 'galician' : os.path.join(BasePath, 'lexique_gl.txt'),
194 'galician_exp' : os.path.join(BasePath, 'expression_gl.txt'),
198 def ConstructAfcmPath(FilePath):
200 'Levels': ffr(os.path.join(FilePath, 'afcm-levels.csv')),
201 'nd': ffr(os.path.join(FilePath, 'afcm-nd.csv')),
202 'FileActTemp': ffr(os.path.join(FilePath, 'fileActTamp.csv')),
203 'FileEtTemp': ffr(os.path.join(FilePath, 'FileEtTemp')),
204 'resultat': os.path.join(FilePath, 'Resultats-afcm.html'),
205 'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1])
209 def ConstructAfcUciPath(filepath):
211 'TableCont': ffr(os.path.join(filepath, 'TableCont.csv')),
212 'TableSup': ffr(os.path.join(filepath, 'TableSup.csv')),
213 'TableEt': ffr(os.path.join(filepath, 'TableEt.csv')),
214 'AfcColAct': ffr(os.path.join(filepath, 'AfcColAct.png')),
215 'AfcColSup': ffr(os.path.join(filepath, 'AfcColSup.png')),
216 'AfcColEt': ffr(os.path.join(filepath, 'AfcColEt.png')),
217 'afcdiv4': ffr(os.path.join(filepath, 'afcdiv4_')),
218 'AfcRow': ffr(os.path.join(filepath, 'AfcRow.png')),
219 'ListAct': ffr(os.path.join(filepath, 'ListAct.csv')),
220 'ListSup': ffr(os.path.join(filepath, 'ListSup.csv')),
221 'GraphAfcTot': os.path.join(filepath, 'GraphAfcTot.html'),
222 'Rafcuci': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
223 'afc_row': ffr(os.path.join(filepath, 'afc_row.csv')),
224 'afc_col': ffr(os.path.join(filepath, 'afc_col.csv')),
225 'ira' : os.path.join(filepath, 'Analyse.ira'),
227 return DictAfcUciPath
229 ChdTxtPathOut = {'TableUc1': 'TableUc1.csv',
230 'TableUc2': 'TableUc2.csv',
231 'listeuce1': 'listeUCE1.csv',
232 'listeuce2': 'listeUCE2.csv',
233 'DicoMots': 'DicoMots.csv',
234 'DicoLem': 'DicoLem.csv',
235 'profile': 'profiles.csv',
236 'antiprofile': 'antiprofiles.csv',
238 'rapport': 'RAPPORT.txt',
239 'pre_rapport' : 'info.txt',
241 'Rchdtxt': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
242 'arbre1': 'arbre_1.png',
243 'arbre2': 'arbre_2.png',
244 'dendro1': 'dendro1.png',
245 'dendro2': 'dendro2.png',
246 'Rdendro': 'dendrogramme.RData',
247 'Contout': 'classe_mod.csv',
248 'RData': 'RData.RData',
249 'ContSupOut': 'tablesup.csv',
250 'ContEtOut': 'tableet.csv',
251 'PROFILE_OUT': 'profiles.csv',
252 'ANTIPRO_OUT': 'antiprofiles.csv',
253 'SbyClasseOut': 'SbyClasseOut.csv',
254 'chisqtable' : 'chisqtable.csv',
255 'ptable' : 'ptable.csv',
256 'ira': 'Analyse.ira',
257 'AFC2DL_OUT': 'AFC2DL.png',
258 'AFC2DSL_OUT': 'AFC2DSL.png',
259 'AFC2DEL_OUT': 'AFC2DEL.png',
260 'AFC2DCL_OUT': 'AFC2DCL.png',
261 'AFC2DCoul': 'AFC2DCoul.png',
262 'AFC2DCoulSup': 'AFC2DCoulSup.png',
263 'AFC2DCoulEt': 'AFC2DCoulEt.png',
264 'AFC2DCoulCl': 'AFC2DCoulCl.png',
265 'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
266 'R3DCoul': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
267 'RESULT_CHD': 'resultats-chd.html',
268 'RESULT_AFC': 'resultats-afc.html',
270 'Rchdquest':ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
271 'RTxtProfGraph':ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
272 'typelist': 'typelist.csv',
273 'concord':'concordancier.csv',
274 'bduceforme':'bduceforme.csv',
275 'uceuci': 'uceuci.csv',
276 'uciet': 'uciet.csv',
277 'ContTypeOut': 'tabletype.csv',
278 'liste_graph_afc' : 'liste_graph_afc.txt',
279 'liste_graph_chd' : 'liste_graph_chd.txt',
280 'afc_row': 'afc_row.csv',
281 'afc_col': 'afc_col.csv',
282 'afc_facteur': 'afc_facteur.csv',
283 'corpus_exp' : 'corpus_out.txt',
284 'segments_classes' : 'segments_classes.csv',
285 'prof_seg' : 'prof_segments.csv',
286 'antiprof_seg' : 'antiprof_segments.csv',
287 'prof_type' : 'profil_type.csv',
288 'antiprof_type' : 'antiprof_type.csv',
289 'type_cl' : 'type_cl.csv',
293 def StatTxtPathOut(pathout):
294 d = {'tableafcm':ffr(os.path.join(pathout, 'tableafcm.csv')),
295 'tabletypem': ffr(os.path.join(pathout, 'tabletypem.csv')),
296 'tablespecf': ffr(os.path.join(pathout, 'tablespecf.csv')),
297 'tablespect': ffr(os.path.join(pathout, 'tablespect.csv')),
298 'eff_relatif_forme': ffr(os.path.join(pathout, 'eff_relatif_forme.csv')),
299 'eff_relatif_type': ffr(os.path.join(pathout, 'eff_relatif_type.csv')),
300 'afcf_row' : ffr(os.path.join(pathout, 'afcf_row.png')),
301 'afcf_col' : ffr(os.path.join(pathout, 'afcf_col.png')),
302 'afct_row' : ffr(os.path.join(pathout, 'afct_row.png')),
303 'afct_col' : ffr(os.path.join(pathout, 'afct_col.png')),
304 'RData' : ffr(os.path.join(pathout, 'RData.RData')),
305 'liste_graph_afcf' : os.path.join(pathout, 'liste_graph_afcf.txt'),
306 'liste_graph_afct' : os.path.join(pathout, 'liste_graph_afct.txt'),
307 'afcf_row_csv': ffr(os.path.join(pathout, 'afcf_row.csv')),
308 'afcf_col_csv': ffr(os.path.join(pathout, 'afcf_col.csv')),
309 'afcf_facteur_csv': ffr(os.path.join(pathout, 'afcf_facteur.csv')),
310 'afct_row_csv': ffr(os.path.join(pathout, 'afct_row.csv')),
311 'afct_col_csv': ffr(os.path.join(pathout, 'afct_col.csv')),
312 'afct_facteur_csv': ffr(os.path.join(pathout, 'afct_facteur.csv')),
313 'ira' : ffr(os.path.join(pathout, 'Analyse.ira')),
314 'db' : os.path.join(pathout, 'analyse.db'),
315 'zipf' : ffr(os.path.join(pathout, 'zipf.png')),
319 #def construct_simipath(pathout):
320 # d = {'mat01' : 'mat01.csv',
321 # 'matsimi' : 'matsimi.csv',
323 # 'RData' : 'RData.RData',
324 # 'liste_graph' : 'liste_graph.txt',
325 # 'ira' : 'Analyse.ira',
327 # 'db' : 'analyse.db',
330 simipath = {'mat01' : 'mat01.csv',
331 'matsimi' : 'matsimi.csv',
333 'RData' : 'RData.RData',
334 'liste_graph' :'liste_graph.txt',
335 'ira' : 'Analyse.ira',
338 'corpus' : 'corpus.db',