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 #------------------------------------
16 log = logging.getLogger('iramuteq.chemins')
19 def normpath_win32(path) :
20 if not sys.platform == 'win32' :
22 while '\\\\' in path :
23 path = path.replace('\\\\', '\\')
24 if sys.platform == 'win32' and path.startswith('\\') and not path.startswith('\\\\') :
29 def __init__(self, filename = None, analyse_type = '', dirout = None) :
30 if filename is not None :
31 self.filepath = os.path.abspath(filename)
32 self.filebasename = os.path.basename(filename)
33 self.directory = os.path.abspath(os.path.dirname(filename))
34 self.filename, self.fileext = os.path.splitext(self.filebasename)
35 self.analyse = analyse_type
36 #self.dirout = self.mkdirout(dirout)
37 if dirout is not None:
38 self.dirout = os.path.abspath(dirout)
39 elif filename is not None and dirout is None:
40 self.dirout = os.path.abspath(self.directory)
44 dirout = os.path.join(self.dirout, self.filename + '_' + self.analyse + '_')
46 tdirout = dirout + repr(nb)
47 while os.path.exists(tdirout) :
49 tdirout = dirout + repr(nb)
50 self.name = os.path.splitext(tdirout)[1]
53 def makenew(self, filename, ext):
55 newfile = '_'.join([os.path.join(self.dirout, filename), '%i' % nb]) + '.' + ext
56 while os.path.exists(newfile) :
58 newfile = '_'.join([os.path.join(self.dirout, filename), '%i' % nb]) + '.' + ext
61 def createdir(self, tdirout) :
62 if not os.path.exists(tdirout) :
65 def basefiles(self, ndict) :
68 def __getitem__(self, key) :
70 self.temp = tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\')
72 elif key not in self.d :
73 f = os.path.join(self.dirout, key).replace('\\', '\\\\')
74 return normpath_win32(f)
75 #return os.path.join(self.dirout, key).replace('\\', '\\\\')
77 f = os.path.join(self.dirout, self.d[key]).replace('\\', '\\\\')
78 return normpath_win32(f)
79 #return os.path.join(self.dirout, self.d[key]).replace('\\', '\\\\')
82 return self.__getitem__(key).replace('\\', '/')
85 return filename.replace('\\', '\\\\')
88 return filename.replace('\\', '/')
92 'chdfunct': 'chdfunct.R',
94 'plotafcm': 'plotafcm.R',
95 'afc_graph' : 'afc_graph.R',
100 'chdquest': 'chdquest.R',
101 'pamtxt' : 'pamtxt.R',
102 'anacor' : 'anacor.R',
103 #'anacor' : 'Nanacor.R',
107 def ConstructRscriptsPath(AppliPath):
108 RScriptsPath = os.path.join(AppliPath, 'Rscripts')
109 #print('@@@@@@@@@@@PONDERATION CHDPOND.R@@@@@@@@@@@@@@@@')
110 #print('@@@@@@@@@@@ NEW SVD CHEMIN @@@@@@@@@@@@@@@@')
111 #print '@@@@@@@@@@@ NEW NCHD CHEMIN @@@@@@@@@@@@@@@@'
113 'Rfunct': ffr(os.path.join(RScriptsPath, 'Rfunct.R')),
114 'chdfunct': ffr(os.path.join(RScriptsPath, 'chdfunct.R')),
115 'Rgraph': ffr(os.path.join(RScriptsPath, 'Rgraph.R')),
116 'plotafcm': ffr(os.path.join(RScriptsPath, 'plotafcm.R')),
117 'afc_graph' : ffr(os.path.join(RScriptsPath, 'afc_graph.R')),
118 #'CHD': ffr(os.path.join(RScriptsPath, 'CHDPOND.R')),
119 'CHD': ffr(os.path.join(RScriptsPath, 'CHD.R')),
120 #'CHD' : ffr(os.path.join(RScriptsPath, 'NCHD.R')),
121 'chdtxt': ffr(os.path.join(RScriptsPath, 'chdtxt.R')),
122 'chdquest': ffr(os.path.join(RScriptsPath, 'chdquest.R')),
123 'pamtxt' : ffr(os.path.join(RScriptsPath, 'pamtxt.R')),
124 'anacor' : ffr(os.path.join(RScriptsPath, 'anacor.R')),
125 #'anacor' : ffr(os.path.join(RScriptsPath, 'Nanacor.R')),
126 'simi' : ffr(os.path.join(RScriptsPath, 'simi.R')),
130 def ConstructPathOut(Filename, analyse_type):
131 FileBaseName = os.path.basename(Filename)
132 FileBasePath = os.path.dirname(Filename)
133 PathFile = os.path.splitext(FileBaseName)
134 PathFile = os.path.join(FileBasePath, PathFile[0] + '_' + analyse_type + '_1')
135 splitpath = PathFile.split('_')
136 number = int(splitpath[len(splitpath) - 1])
137 while os.path.isdir(PathFile) :
139 PathFile = PathFile[0:len(PathFile) - 1] + str(number + 1)
141 elif (number >= 10) and (number < 100):
142 PathFile = PathFile[0:len(PathFile) - 2] + str(number + 1)
145 PathFile = PathFile[0:len(PathFile) - 3] + str(number + 1)
148 os.mkdir(os.path.join(FileBasePath, PathFile))
149 return os.path.join(FileBasePath, PathFile)
151 def ConstructConfigPath(AppliPath, user=True):
153 ConfigPath = os.path.join(AppliPath, 'configuration')
155 ConfigPath = AppliPath
157 'reinert': os.path.join(ConfigPath, 'reinert.cfg'),
158 'key': os.path.join(ConfigPath, 'key.cfg'),
159 'path': os.path.join(ConfigPath, 'path.cfg'),
160 'preferences' : os.path.join(ConfigPath, 'iramuteq.cfg'),
161 'pam' : os.path.join(ConfigPath, 'pam.cfg'),
162 'corpus' : os.path.join(ConfigPath, 'corpus.cfg'),
163 'stat' : os.path.join(ConfigPath, 'stat.cfg'),
164 'simitxt' : os.path.join(ConfigPath, 'simitxt.cfg'),
165 'matrix' : os.path.join(ConfigPath, 'matrix.cfg'),
167 return DictConfigPath
169 def ConstructGlobalPath(AppliPath):
170 ConfigPath = os.path.join(AppliPath, 'configuration')
172 'global': os.path.join(ConfigPath, 'global.cfg'),
173 'preferences': os.path.join(ConfigPath, 'iramuteq.cfg'),
175 return DictConfigPath
177 def ConstructDicoPath(AppliPath):
178 BasePath = os.path.join(AppliPath, 'dictionnaires')
180 'french': os.path.join(BasePath, 'lexique_fr.txt'),
181 'french_exp': os.path.join(BasePath, 'expression_fr.txt'),
182 'english': os.path.join(BasePath, 'lexique_en.txt'),
183 'english_exp': os.path.join(BasePath, 'expression_en.txt'),
184 'german' : os.path.join(BasePath, 'lexique_de.txt'),
185 'german_exp' : os.path.join(BasePath, 'expression_de.txt'),
186 'italian' : os.path.join(BasePath, 'lexique_it.txt'),
187 'italian_exp' : os.path.join(BasePath, 'expression_it.txt'),
188 'swedish' : os.path.join(BasePath, 'lexique_sw.txt'),
189 'swedish_exp' : os.path.join(BasePath, 'expression_sw.txt'),
190 'portuguese' : os.path.join(BasePath, 'lexique_pt.txt'),
191 'portuguese_exp': os.path.join(BasePath, 'expression_pt.txt'),
192 'greek' : os.path.join(BasePath, 'lexique_gr.txt'),
193 'greek_exp' : os.path.join(BasePath, 'expression_gr.txt'),
194 'spanish' : os.path.join(BasePath, 'lexique_sp.txt'),
195 'spanish_exp' : os.path.join(BasePath, 'expression_sp.txt'),
196 'galician' : os.path.join(BasePath, 'lexique_gl.txt'),
197 'galician_exp' : os.path.join(BasePath, 'expression_gl.txt'),
201 def ConstructAfcmPath(FilePath):
203 'Levels': ffr(os.path.join(FilePath, 'afcm-levels.csv')),
204 'nd': ffr(os.path.join(FilePath, 'afcm-nd.csv')),
205 'FileActTemp': ffr(os.path.join(FilePath, 'fileActTamp.csv')),
206 'FileEtTemp': ffr(os.path.join(FilePath, 'FileEtTemp')),
207 'resultat': os.path.join(FilePath, 'Resultats-afcm.html'),
208 'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1])
212 def ConstructAfcUciPath(filepath):
214 'TableCont': ffr(os.path.join(filepath, 'TableCont.csv')),
215 'TableSup': ffr(os.path.join(filepath, 'TableSup.csv')),
216 'TableEt': ffr(os.path.join(filepath, 'TableEt.csv')),
217 'AfcColAct': ffr(os.path.join(filepath, 'AfcColAct.png')),
218 'AfcColSup': ffr(os.path.join(filepath, 'AfcColSup.png')),
219 'AfcColEt': ffr(os.path.join(filepath, 'AfcColEt.png')),
220 'afcdiv4': ffr(os.path.join(filepath, 'afcdiv4_')),
221 'AfcRow': ffr(os.path.join(filepath, 'AfcRow.png')),
222 'ListAct': ffr(os.path.join(filepath, 'ListAct.csv')),
223 'ListSup': ffr(os.path.join(filepath, 'ListSup.csv')),
224 'GraphAfcTot': os.path.join(filepath, 'GraphAfcTot.html'),
225 'Rafcuci': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
226 'afc_row': ffr(os.path.join(filepath, 'afc_row.csv')),
227 'afc_col': ffr(os.path.join(filepath, 'afc_col.csv')),
228 'ira' : os.path.join(filepath, 'Analyse.ira'),
230 return DictAfcUciPath
232 ChdTxtPathOut = {'TableUc1': 'TableUc1.csv',
233 'TableUc2': 'TableUc2.csv',
234 'listeuce1': 'listeUCE1.csv',
235 'listeuce2': 'listeUCE2.csv',
236 'DicoMots': 'DicoMots.csv',
237 'DicoLem': 'DicoLem.csv',
238 'profile': 'profiles.csv',
239 'antiprofile': 'antiprofiles.csv',
241 'rapport': 'RAPPORT.txt',
242 'pre_rapport' : 'info.txt',
244 'Rchdtxt': tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\'),
245 'arbre1': 'arbre_1.png',
246 'arbre2': 'arbre_2.png',
247 'dendro1': 'dendro1.png',
248 'dendro2': 'dendro2.png',
249 'Rdendro': 'dendrogramme.RData',
250 'Contout': 'classe_mod.csv',
251 'RData': 'RData.RData',
252 'ContSupOut': 'tablesup.csv',
253 'ContEtOut': 'tableet.csv',
254 'PROFILE_OUT': 'profiles.csv',
255 'ANTIPRO_OUT': 'antiprofiles.csv',
256 'SbyClasseOut': 'SbyClasseOut.csv',
257 'chisqtable' : 'chisqtable.csv',
258 'ptable' : 'ptable.csv',
259 'ira': 'Analyse.ira',
260 'AFC2DL_OUT': 'AFC2DL.png',
261 'AFC2DSL_OUT': 'AFC2DSL.png',
262 'AFC2DEL_OUT': 'AFC2DEL.png',
263 'AFC2DCL_OUT': 'AFC2DCL.png',
264 'AFC2DCoul': 'AFC2DCoul.png',
265 'AFC2DCoulSup': 'AFC2DCoulSup.png',
266 'AFC2DCoulEt': 'AFC2DCoulEt.png',
267 'AFC2DCoulCl': 'AFC2DCoulCl.png',
268 'Rafc3d': tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\'),
269 'R3DCoul': tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\'),
270 'RESULT_CHD': 'resultats-chd.html',
271 'RESULT_AFC': 'resultats-afc.html',
273 'Rchdquest':tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\'),
274 'RTxtProfGraph':tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\'),
275 'typelist': 'typelist.csv',
276 'concord':'concordancier.csv',
277 'bduceforme':'bduceforme.csv',
278 'uceuci': 'uceuci.csv',
279 'uciet': 'uciet.csv',
280 'ContTypeOut': 'tabletype.csv',
281 'liste_graph_afc' : 'liste_graph_afc.txt',
282 'liste_graph_chd' : 'liste_graph_chd.txt',
283 'afc_row': 'afc_row.csv',
284 'afc_col': 'afc_col.csv',
285 'afc_facteur': 'afc_facteur.csv',
286 'corpus_exp' : 'corpus_out.txt',
287 'segments_classes' : 'segments_classes.csv',
288 'prof_seg' : 'prof_segments.csv',
289 'antiprof_seg' : 'antiprof_segments.csv',
290 'prof_type' : 'profil_type.csv',
291 'antiprof_type' : 'antiprof_type.csv',
292 'type_cl' : 'type_cl.csv',
296 def StatTxtPathOut(pathout):
297 d = {'tableafcm':ffr(os.path.join(pathout, 'tableafcm.csv')),
298 'tabletypem': ffr(os.path.join(pathout, 'tabletypem.csv')),
299 'tablespecf': ffr(os.path.join(pathout, 'tablespecf.csv')),
300 'tablespect': ffr(os.path.join(pathout, 'tablespect.csv')),
301 'eff_relatif_forme': ffr(os.path.join(pathout, 'eff_relatif_forme.csv')),
302 'eff_relatif_type': ffr(os.path.join(pathout, 'eff_relatif_type.csv')),
303 'afcf_row' : ffr(os.path.join(pathout, 'afcf_row.png')),
304 'afcf_col' : ffr(os.path.join(pathout, 'afcf_col.png')),
305 'afct_row' : ffr(os.path.join(pathout, 'afct_row.png')),
306 'afct_col' : ffr(os.path.join(pathout, 'afct_col.png')),
307 'RData' : ffr(os.path.join(pathout, 'RData.RData')),
308 'liste_graph_afcf' : os.path.join(pathout, 'liste_graph_afcf.txt'),
309 'liste_graph_afct' : os.path.join(pathout, 'liste_graph_afct.txt'),
310 'afcf_row_csv': ffr(os.path.join(pathout, 'afcf_row.csv')),
311 'afcf_col_csv': ffr(os.path.join(pathout, 'afcf_col.csv')),
312 'afcf_facteur_csv': ffr(os.path.join(pathout, 'afcf_facteur.csv')),
313 'afct_row_csv': ffr(os.path.join(pathout, 'afct_row.csv')),
314 'afct_col_csv': ffr(os.path.join(pathout, 'afct_col.csv')),
315 'afct_facteur_csv': ffr(os.path.join(pathout, 'afct_facteur.csv')),
316 'ira' : ffr(os.path.join(pathout, 'Analyse.ira')),
317 'db' : os.path.join(pathout, 'analyse.db'),
318 'zipf' : ffr(os.path.join(pathout, 'zipf.png')),
323 #def construct_simipath(pathout):
324 # d = {'mat01' : 'mat01.csv',
325 # 'matsimi' : 'matsimi.csv',
327 # 'RData' : 'RData.RData',
328 # 'liste_graph' : 'liste_graph.txt',
329 # 'ira' : 'Analyse.ira',
331 # 'db' : 'analyse.db',
334 simipath = {'mat01' : 'mat01.csv',
335 'matsimi' : 'matsimi.csv',
337 'RData' : 'RData.RData',
338 'liste_graph' :'liste_graph.txt',
339 'ira' : 'Analyse.ira',
342 'corpus' : 'corpus.db',