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 createdir(self, tdirout) :
50 if not os.path.exists(tdirout) :
53 def basefiles(self, ndict) :
56 def __getitem__(self, key) :
58 self.temp = tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\')
60 elif key not in self.d :
61 f = os.path.join(self.dirout, key).replace('\\', '\\\\')
62 return normpath_win32(f)
63 #return os.path.join(self.dirout, key).replace('\\', '\\\\')
65 f = os.path.join(self.dirout, self.d[key]).replace('\\', '\\\\')
66 return normpath_win32(f)
67 #return os.path.join(self.dirout, self.d[key]).replace('\\', '\\\\')
70 return self.__getitem__(key).replace('\\', '/')
74 return filename.replace('\\', '\\\\')
77 return filename.replace('\\', '/')
81 'chdfunct': 'chdfunct.R',
83 'plotafcm': 'plotafcm.R',
84 'afc_graph' : 'afc_graph.R',
89 'chdquest': 'chdquest.R',
90 'pamtxt' : 'pamtxt.R',
91 'anacor' : 'anacor.R',
92 #'anacor' : 'Nanacor.R',
96 def ConstructRscriptsPath(AppliPath):
97 RScriptsPath = os.path.join(AppliPath, 'Rscripts')
98 #print('@@@@@@@@@@@PONDERATION CHDPOND.R@@@@@@@@@@@@@@@@')
99 #print('@@@@@@@@@@@ NEW SVD CHEMIN @@@@@@@@@@@@@@@@')
100 #print '@@@@@@@@@@@ NEW NCHD CHEMIN @@@@@@@@@@@@@@@@'
102 'Rfunct': ffr(os.path.join(RScriptsPath, 'Rfunct.R')),
103 'chdfunct': ffr(os.path.join(RScriptsPath, 'chdfunct.R')),
104 'Rgraph': ffr(os.path.join(RScriptsPath, 'Rgraph.R')),
105 'plotafcm': ffr(os.path.join(RScriptsPath, 'plotafcm.R')),
106 'afc_graph' : ffr(os.path.join(RScriptsPath, 'afc_graph.R')),
107 #'CHD': ffr(os.path.join(RScriptsPath, 'CHDPOND.R')),
108 'CHD': ffr(os.path.join(RScriptsPath, 'CHD.R')),
109 #'CHD' : ffr(os.path.join(RScriptsPath, 'NCHD.R')),
110 'chdtxt': ffr(os.path.join(RScriptsPath, 'chdtxt.R')),
111 'chdquest': ffr(os.path.join(RScriptsPath, 'chdquest.R')),
112 'pamtxt' : ffr(os.path.join(RScriptsPath, 'pamtxt.R')),
113 'anacor' : ffr(os.path.join(RScriptsPath, 'anacor.R')),
114 #'anacor' : ffr(os.path.join(RScriptsPath, 'Nanacor.R')),
115 'simi' : ffr(os.path.join(RScriptsPath, 'simi.R')),
119 def ConstructPathOut(Filename, analyse_type):
120 FileBaseName = os.path.basename(Filename)
121 FileBasePath = os.path.dirname(Filename)
122 PathFile = os.path.splitext(FileBaseName)
123 PathFile = os.path.join(FileBasePath, PathFile[0] + '_' + analyse_type + '_1')
124 splitpath = PathFile.split('_')
125 number = int(splitpath[len(splitpath) - 1])
126 while os.path.isdir(PathFile) :
128 PathFile = PathFile[0:len(PathFile) - 1] + str(number + 1)
130 elif (number >= 10) and (number < 100):
131 PathFile = PathFile[0:len(PathFile) - 2] + str(number + 1)
134 PathFile = PathFile[0:len(PathFile) - 3] + str(number + 1)
137 os.mkdir(os.path.join(FileBasePath, PathFile))
138 return os.path.join(FileBasePath, PathFile)
140 def ConstructConfigPath(AppliPath, user=True):
142 ConfigPath = os.path.join(AppliPath, 'configuration')
144 ConfigPath = AppliPath
146 'reinert': os.path.join(ConfigPath, 'reinert.cfg'),
147 'key': os.path.join(ConfigPath, 'key.cfg'),
148 'path': os.path.join(ConfigPath, 'path.cfg'),
149 'preferences' : os.path.join(ConfigPath, 'iramuteq.cfg'),
150 'pam' : os.path.join(ConfigPath, 'pam.cfg'),
151 'corpus' : os.path.join(ConfigPath, 'corpus.cfg'),
152 'stat' : os.path.join(ConfigPath, 'stat.cfg'),
153 'simitxt' : os.path.join(ConfigPath, 'simitxt.cfg'),
154 'matrix' : os.path.join(ConfigPath, 'matrix.cfg'),
156 return DictConfigPath
158 def ConstructGlobalPath(AppliPath):
159 ConfigPath = os.path.join(AppliPath, 'configuration')
161 'global': os.path.join(ConfigPath, 'global.cfg'),
162 'preferences': os.path.join(ConfigPath, 'iramuteq.cfg'),
164 return DictConfigPath
166 def ConstructDicoPath(AppliPath):
167 BasePath = os.path.join(AppliPath, 'dictionnaires')
169 'french': os.path.join(BasePath, 'lexique_fr.txt'),
170 'french_exp': os.path.join(BasePath, 'expression_fr.txt'),
171 'english': os.path.join(BasePath, 'lexique_en.txt'),
172 'english_exp': os.path.join(BasePath, 'expression_en.txt'),
173 'german' : os.path.join(BasePath, 'lexique_de.txt'),
174 'german_exp' : os.path.join(BasePath, 'expression_de.txt'),
175 'italian' : os.path.join(BasePath, 'lexique_it.txt'),
176 'italian_exp' : os.path.join(BasePath, 'expression_it.txt'),
177 'swedish' : os.path.join(BasePath, 'lexique_sw.txt'),
178 'swedish_exp' : os.path.join(BasePath, 'expression_sw.txt'),
179 'portuguese' : os.path.join(BasePath, 'lexique_pt.txt'),
180 'portuguese_exp': os.path.join(BasePath, 'expression_pt.txt'),
181 'greek' : os.path.join(BasePath, 'lexique_gr.txt'),
182 'greek_exp' : os.path.join(BasePath, 'expression_gr.txt'),
183 'spanish' : os.path.join(BasePath, 'lexique_sp.txt'),
184 'spanish_exp' : os.path.join(BasePath, 'expression_sp.txt'),
185 'galician' : os.path.join(BasePath, 'lexique_gl.txt'),
186 'galician_exp' : os.path.join(BasePath, 'expression_gl.txt'),
190 def ConstructAfcmPath(FilePath):
192 'Levels': ffr(os.path.join(FilePath, 'afcm-levels.csv')),
193 'nd': ffr(os.path.join(FilePath, 'afcm-nd.csv')),
194 'FileActTemp': ffr(os.path.join(FilePath, 'fileActTamp.csv')),
195 'FileEtTemp': ffr(os.path.join(FilePath, 'FileEtTemp')),
196 'resultat': os.path.join(FilePath, 'Resultats-afcm.html'),
197 'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1])
201 def ConstructAfcUciPath(filepath):
203 'TableCont': ffr(os.path.join(filepath, 'TableCont.csv')),
204 'TableSup': ffr(os.path.join(filepath, 'TableSup.csv')),
205 'TableEt': ffr(os.path.join(filepath, 'TableEt.csv')),
206 'AfcColAct': ffr(os.path.join(filepath, 'AfcColAct.png')),
207 'AfcColSup': ffr(os.path.join(filepath, 'AfcColSup.png')),
208 'AfcColEt': ffr(os.path.join(filepath, 'AfcColEt.png')),
209 'afcdiv4': ffr(os.path.join(filepath, 'afcdiv4_')),
210 'AfcRow': ffr(os.path.join(filepath, 'AfcRow.png')),
211 'ListAct': ffr(os.path.join(filepath, 'ListAct.csv')),
212 'ListSup': ffr(os.path.join(filepath, 'ListSup.csv')),
213 'GraphAfcTot': os.path.join(filepath, 'GraphAfcTot.html'),
214 'Rafcuci': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
215 'afc_row': ffr(os.path.join(filepath, 'afc_row.csv')),
216 'afc_col': ffr(os.path.join(filepath, 'afc_col.csv')),
217 'ira' : os.path.join(filepath, 'Analyse.ira'),
219 return DictAfcUciPath
221 ChdTxtPathOut = {'TableUc1': 'TableUc1.csv',
222 'TableUc2': 'TableUc2.csv',
223 'listeuce1': 'listeUCE1.csv',
224 'listeuce2': 'listeUCE2.csv',
225 'DicoMots': 'DicoMots.csv',
226 'DicoLem': 'DicoLem.csv',
227 'profile': 'profiles.csv',
228 'antiprofile': 'antiprofiles.csv',
230 'rapport': 'RAPPORT.txt',
231 'pre_rapport' : 'info.txt',
233 'Rchdtxt': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
234 'arbre1': 'arbre_1.png',
235 'arbre2': 'arbre_2.png',
236 'dendro1': 'dendro1.png',
237 'dendro2': 'dendro2.png',
238 'Rdendro': 'dendrogramme.RData',
239 'Contout': 'classe_mod.csv',
240 'RData': 'RData.RData',
241 'ContSupOut': 'tablesup.csv',
242 'ContEtOut': 'tableet.csv',
243 'PROFILE_OUT': 'profiles.csv',
244 'ANTIPRO_OUT': 'antiprofiles.csv',
245 'SbyClasseOut': 'SbyClasseOut.csv',
246 'chisqtable' : 'chisqtable.csv',
247 'ptable' : 'ptable.csv',
248 'ira': 'Analyse.ira',
249 'AFC2DL_OUT': 'AFC2DL.png',
250 'AFC2DSL_OUT': 'AFC2DSL.png',
251 'AFC2DEL_OUT': 'AFC2DEL.png',
252 'AFC2DCL_OUT': 'AFC2DCL.png',
253 'AFC2DCoul': 'AFC2DCoul.png',
254 'AFC2DCoulSup': 'AFC2DCoulSup.png',
255 'AFC2DCoulEt': 'AFC2DCoulEt.png',
256 'AFC2DCoulCl': 'AFC2DCoulCl.png',
257 'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
258 'R3DCoul': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
259 'RESULT_CHD': 'resultats-chd.html',
260 'RESULT_AFC': 'resultats-afc.html',
262 'Rchdquest':ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
263 'RTxtProfGraph':ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
264 'typelist': 'typelist.csv',
265 'concord':'concordancier.csv',
266 'bduceforme':'bduceforme.csv',
267 'uceuci': 'uceuci.csv',
268 'uciet': 'uciet.csv',
269 'ContTypeOut': 'tabletype.csv',
270 'liste_graph_afc' : 'liste_graph_afc.txt',
271 'liste_graph_chd' : 'liste_graph_chd.txt',
272 'afc_row': 'afc_row.csv',
273 'afc_col': 'afc_col.csv',
274 'afc_facteur': 'afc_facteur.csv',
275 'corpus_exp' : 'corpus_out.txt',
276 'segments_classes' : 'segments_classes.csv',
277 'prof_seg' : 'prof_segments.csv',
278 'antiprof_seg' : 'antiprof_segments.csv',
279 'prof_type' : 'profil_type.csv',
280 'antiprof_type' : 'antiprof_type.csv',
281 'type_cl' : 'type_cl.csv',
285 def StatTxtPathOut(pathout):
286 d = {'tableafcm':ffr(os.path.join(pathout, 'tableafcm.csv')),
287 'tabletypem': ffr(os.path.join(pathout, 'tabletypem.csv')),
288 'tablespecf': ffr(os.path.join(pathout, 'tablespecf.csv')),
289 'tablespect': ffr(os.path.join(pathout, 'tablespect.csv')),
290 'eff_relatif_forme': ffr(os.path.join(pathout, 'eff_relatif_forme.csv')),
291 'eff_relatif_type': ffr(os.path.join(pathout, 'eff_relatif_type.csv')),
292 'afcf_row' : ffr(os.path.join(pathout, 'afcf_row.png')),
293 'afcf_col' : ffr(os.path.join(pathout, 'afcf_col.png')),
294 'afct_row' : ffr(os.path.join(pathout, 'afct_row.png')),
295 'afct_col' : ffr(os.path.join(pathout, 'afct_col.png')),
296 'RData' : ffr(os.path.join(pathout, 'RData.RData')),
297 'liste_graph_afcf' : os.path.join(pathout, 'liste_graph_afcf.txt'),
298 'liste_graph_afct' : os.path.join(pathout, 'liste_graph_afct.txt'),
299 'afcf_row_csv': ffr(os.path.join(pathout, 'afcf_row.csv')),
300 'afcf_col_csv': ffr(os.path.join(pathout, 'afcf_col.csv')),
301 'afcf_facteur_csv': ffr(os.path.join(pathout, 'afcf_facteur.csv')),
302 'afct_row_csv': ffr(os.path.join(pathout, 'afct_row.csv')),
303 'afct_col_csv': ffr(os.path.join(pathout, 'afct_col.csv')),
304 'afct_facteur_csv': ffr(os.path.join(pathout, 'afct_facteur.csv')),
305 'ira' : ffr(os.path.join(pathout, 'Analyse.ira')),
306 'db' : os.path.join(pathout, 'analyse.db'),
307 'zipf' : ffr(os.path.join(pathout, 'zipf.png')),
311 #def construct_simipath(pathout):
312 # d = {'mat01' : 'mat01.csv',
313 # 'matsimi' : 'matsimi.csv',
315 # 'RData' : 'RData.RData',
316 # 'liste_graph' : 'liste_graph.txt',
317 # 'ira' : 'Analyse.ira',
319 # 'db' : 'analyse.db',
322 simipath = {'mat01' : 'mat01.csv',
323 'matsimi' : 'matsimi.csv',
325 'RData' : 'RData.RData',
326 'liste_graph' :'liste_graph.txt',
327 'ira' : 'Analyse.ira',
330 'corpus' : 'corpus.db',