2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008 Pierre Ratinaud
11 log = logging.getLogger('iramuteq.chemins')
15 def __init__(self, filename = None, analyse_type = '', dirout = None) :
16 if filename is not None :
17 self.filepath = os.path.abspath(filename)
18 self.filebasename = os.path.basename(filename)
19 self.directory = os.path.abspath(os.path.dirname(filename))
20 self.filename, self.fileext = os.path.splitext(self.filebasename)
21 self.analyse = analyse_type
22 #self.dirout = self.mkdirout(dirout)
23 if dirout is not None:
25 elif filename is not None and dirout is None:
26 self.dirout = self.directory
30 dirout = os.path.join(self.dirout, self.filename + '_' + self.analyse + '_')
32 tdirout = dirout + `nb`
33 while os.path.exists(tdirout) :
35 tdirout = dirout + `nb`
36 self.name = os.path.splitext(tdirout)[1]
39 def createdir(self, tdirout) :
40 if not os.path.exists(tdirout) :
43 def basefiles(self, ndict) :
46 def __getitem__(self, key) :
48 self.temp = tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\')
50 elif key not in self.d :
51 return os.path.join(self.dirout, key).replace('\\', '\\\\')
53 return os.path.join(self.dirout, self.d[key]).replace('\\', '\\\\')
56 return self.__getitem__(key).replace('\\', '/')
60 return filename.replace('\\', '\\\\')
63 return filename.replace('\\', '/')
67 'chdfunct': 'chdfunct.R',
69 'plotafcm': 'plotafcm.R',
70 'afc_graph' : 'afc_graph.R',
75 'chdquest': 'chdquest.R',
76 'pamtxt' : 'pamtxt.R',
77 'anacor' : 'anacor.R',
78 #'anacor' : 'Nanacor.R',
82 def ConstructRscriptsPath(AppliPath):
83 RScriptsPath = os.path.join(AppliPath, 'Rscripts')
84 #print('@@@@@@@@@@@PONDERATION CHDPOND.R@@@@@@@@@@@@@@@@')
85 #print('@@@@@@@@@@@ NEW SVD CHEMIN @@@@@@@@@@@@@@@@')
86 #print '@@@@@@@@@@@ NEW NCHD CHEMIN @@@@@@@@@@@@@@@@'
88 'Rfunct': ffr(os.path.join(RScriptsPath, 'Rfunct.R')),
89 'chdfunct': ffr(os.path.join(RScriptsPath, 'chdfunct.R')),
90 'Rgraph': ffr(os.path.join(RScriptsPath, 'Rgraph.R')),
91 'plotafcm': ffr(os.path.join(RScriptsPath, 'plotafcm.R')),
92 'afc_graph' : ffr(os.path.join(RScriptsPath, 'afc_graph.R')),
93 #'CHD': ffr(os.path.join(RScriptsPath, 'CHDPOND.R')),
94 'CHD': ffr(os.path.join(RScriptsPath, 'CHD.R')),
95 #'CHD' : ffr(os.path.join(RScriptsPath, 'NCHD.R')),
96 'chdtxt': ffr(os.path.join(RScriptsPath, 'chdtxt.R')),
97 'chdquest': ffr(os.path.join(RScriptsPath, 'chdquest.R')),
98 'pamtxt' : ffr(os.path.join(RScriptsPath, 'pamtxt.R')),
99 'anacor' : ffr(os.path.join(RScriptsPath, 'anacor.R')),
100 #'anacor' : ffr(os.path.join(RScriptsPath, 'Nanacor.R')),
101 'simi' : ffr(os.path.join(RScriptsPath, 'simi.R')),
105 def ConstructPathOut(Filename, analyse_type):
106 FileBaseName = os.path.basename(Filename)
107 FileBasePath = os.path.dirname(Filename)
108 PathFile = os.path.splitext(FileBaseName)
109 PathFile = os.path.join(FileBasePath, PathFile[0] + '_' + analyse_type + '_1')
110 splitpath = PathFile.split('_')
111 number = int(splitpath[len(splitpath) - 1])
112 while os.path.isdir(PathFile) :
114 PathFile = PathFile[0:len(PathFile) - 1] + str(number + 1)
116 elif (number >= 10) and (number < 100):
117 PathFile = PathFile[0:len(PathFile) - 2] + str(number + 1)
120 PathFile = PathFile[0:len(PathFile) - 3] + str(number + 1)
123 os.mkdir(os.path.join(FileBasePath, PathFile))
124 return os.path.join(FileBasePath, PathFile)
126 def ConstructConfigPath(AppliPath, user=True):
128 ConfigPath = os.path.join(AppliPath, 'configuration')
130 ConfigPath = AppliPath
132 'reinert': os.path.join(ConfigPath, 'reinert.cfg'),
133 'key': os.path.join(ConfigPath, 'key.cfg'),
134 'path': os.path.join(ConfigPath, 'path.cfg'),
135 'preferences' : os.path.join(ConfigPath, 'iramuteq.cfg'),
136 'pam' : os.path.join(ConfigPath, 'pam.cfg'),
137 'corpus' : os.path.join(ConfigPath, 'corpus.cfg'),
138 'stat' : os.path.join(ConfigPath, 'stat.cfg'),
139 'simitxt' : os.path.join(ConfigPath, 'simitxt.cfg'),
140 'matrix' : os.path.join(ConfigPath, 'matrix.cfg'),
142 return DictConfigPath
144 def ConstructGlobalPath(AppliPath):
145 ConfigPath = os.path.join(AppliPath, 'configuration')
147 'global': os.path.join(ConfigPath, 'global.cfg'),
149 return DictConfigPath
151 def ConstructDicoPath(AppliPath):
152 BasePath = os.path.join(AppliPath, 'dictionnaires')
154 'french': os.path.join(BasePath, 'lexique_fr.txt'),
155 'french_exp': os.path.join(BasePath, 'expression_fr.txt'),
156 'english': os.path.join(BasePath, 'lexique_en.txt'),
157 'english_exp': os.path.join(BasePath, 'expression_en.txt'),
158 'german' : os.path.join(BasePath, 'lexique_de.txt'),
159 'german_exp' : os.path.join(BasePath, 'expression_de.txt'),
160 'italian' : os.path.join(BasePath, 'lexique_it.txt'),
161 'italian_exp' : os.path.join(BasePath, 'expression_it.txt'),
162 'swedish' : os.path.join(BasePath, 'lexique_sw.txt'),
163 'swedish_exp' : os.path.join(BasePath, 'expression_sw.txt'),
164 'portuguese' : os.path.join(BasePath, 'lexique_pt.txt'),
165 'portuguese_exp': os.path.join(BasePath, 'expression_pt.txt'),
166 'greek' : os.path.join(BasePath, 'lexique_gr.txt'),
167 'greek_exp' : os.path.join(BasePath, 'expression_gr.txt'),
168 'spanish' : os.path.join(BasePath, 'lexique_sp.txt'),
169 'spanish_exp' : os.path.join(BasePath, 'expression_sp.txt'),
170 'galician' : os.path.join(BasePath, 'lexique_gl.txt'),
171 'galician_exp' : os.path.join(BasePath, 'expression_gl.txt'),
175 def ConstructAfcmPath(FilePath):
177 'Levels': ffr(os.path.join(FilePath, 'afcm-levels.csv')),
178 'nd': ffr(os.path.join(FilePath, 'afcm-nd.csv')),
179 'FileActTemp': ffr(os.path.join(FilePath, 'fileActTamp.csv')),
180 'FileEtTemp': ffr(os.path.join(FilePath, 'FileEtTemp')),
181 'resultat': os.path.join(FilePath, 'Resultats-afcm.html'),
182 'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1])
186 def ConstructAfcUciPath(filepath):
188 'TableCont': ffr(os.path.join(filepath, 'TableCont.csv')),
189 'TableSup': ffr(os.path.join(filepath, 'TableSup.csv')),
190 'TableEt': ffr(os.path.join(filepath, 'TableEt.csv')),
191 'AfcColAct': ffr(os.path.join(filepath, 'AfcColAct.png')),
192 'AfcColSup': ffr(os.path.join(filepath, 'AfcColSup.png')),
193 'AfcColEt': ffr(os.path.join(filepath, 'AfcColEt.png')),
194 'afcdiv4': ffr(os.path.join(filepath, 'afcdiv4_')),
195 'AfcRow': ffr(os.path.join(filepath, 'AfcRow.png')),
196 'ListAct': ffr(os.path.join(filepath, 'ListAct.csv')),
197 'ListSup': ffr(os.path.join(filepath, 'ListSup.csv')),
198 'GraphAfcTot': os.path.join(filepath, 'GraphAfcTot.html'),
199 'Rafcuci': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
200 'afc_row': ffr(os.path.join(filepath, 'afc_row.csv')),
201 'afc_col': ffr(os.path.join(filepath, 'afc_col.csv')),
202 'ira' : os.path.join(filepath, 'Analyse.ira'),
204 return DictAfcUciPath
206 ChdTxtPathOut = {'TableUc1': 'TableUc1.csv',
207 'TableUc2': 'TableUc2.csv',
208 'listeuce1': 'listeUCE1.csv',
209 'listeuce2': 'listeUCE2.csv',
210 'DicoMots': 'DicoMots.csv',
211 'DicoLem': 'DicoLem.csv',
212 'profile': 'profiles.csv',
213 'antiprofile': 'antiprofiles.csv',
215 'rapport': 'RAPPORT.txt',
216 'pre_rapport' : 'info.txt',
218 'Rchdtxt': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
219 'arbre1': 'arbre_1.png',
220 'arbre2': 'arbre_2.png',
221 'dendro1': 'dendro1.png',
222 'dendro2': 'dendro2.png',
223 'Rdendro': 'dendrogramme.RData',
224 'Contout': 'classe_mod.csv',
225 'RData': 'RData.RData',
226 'ContSupOut': 'tablesup.csv',
227 'ContEtOut': 'tableet.csv',
228 'PROFILE_OUT': 'profiles.csv',
229 'ANTIPRO_OUT': 'antiprofiles.csv',
230 'SbyClasseOut': 'SbyClasseOut.csv',
231 'chisqtable' : 'chisqtable.csv',
232 'ptable' : 'ptable.csv',
233 'ira': 'Analyse.ira',
234 'AFC2DL_OUT': 'AFC2DL.png',
235 'AFC2DSL_OUT': 'AFC2DSL.png',
236 'AFC2DEL_OUT': 'AFC2DEL.png',
237 'AFC2DCL_OUT': 'AFC2DCL.png',
238 'AFC2DCoul': 'AFC2DCoul.png',
239 'AFC2DCoulSup': 'AFC2DCoulSup.png',
240 'AFC2DCoulEt': 'AFC2DCoulEt.png',
241 'AFC2DCoulCl': 'AFC2DCoulCl.png',
242 'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
243 'R3DCoul': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
244 'RESULT_CHD': 'resultats-chd.html',
245 'RESULT_AFC': 'resultats-afc.html',
247 'Rchdquest':ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
248 'RTxtProfGraph':ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
249 'typelist': 'typelist.csv',
250 'concord':'concordancier.csv',
251 'bduceforme':'bduceforme.csv',
252 'uceuci': 'uceuci.csv',
253 'uciet': 'uciet.csv',
254 'ContTypeOut': 'tabletype.csv',
255 'liste_graph_afc' : 'liste_graph_afc.txt',
256 'liste_graph_chd' : 'liste_graph_chd.txt',
257 'afc_row': 'afc_row.csv',
258 'afc_col': 'afc_col.csv',
259 'afc_facteur': 'afc_facteur.csv',
260 'corpus_exp' : 'corpus_out.txt',
261 'segments_classes' : 'segments_classes.csv',
262 'prof_seg' : 'prof_segments.csv',
263 'antiprof_seg' : 'antiprof_segments.csv',
264 'prof_type' : 'profil_type.csv',
265 'antiprof_type' : 'antiprof_type.csv',
266 'type_cl' : 'type_cl.csv',
270 def StatTxtPathOut(pathout):
271 d = {'tableafcm':ffr(os.path.join(pathout, 'tableafcm.csv')),
272 'tabletypem': ffr(os.path.join(pathout, 'tabletypem.csv')),
273 'tablespecf': ffr(os.path.join(pathout, 'tablespecf.csv')),
274 'tablespect': ffr(os.path.join(pathout, 'tablespect.csv')),
275 'eff_relatif_forme': ffr(os.path.join(pathout, 'eff_relatif_forme.csv')),
276 'eff_relatif_type': ffr(os.path.join(pathout, 'eff_relatif_type.csv')),
277 'afcf_row' : ffr(os.path.join(pathout, 'afcf_row.png')),
278 'afcf_col' : ffr(os.path.join(pathout, 'afcf_col.png')),
279 'afct_row' : ffr(os.path.join(pathout, 'afct_row.png')),
280 'afct_col' : ffr(os.path.join(pathout, 'afct_col.png')),
281 'RData' : ffr(os.path.join(pathout, 'RData.RData')),
282 'liste_graph_afcf' : os.path.join(pathout, 'liste_graph_afcf.txt'),
283 'liste_graph_afct' : os.path.join(pathout, 'liste_graph_afct.txt'),
284 'afcf_row_csv': ffr(os.path.join(pathout, 'afcf_row.csv')),
285 'afcf_col_csv': ffr(os.path.join(pathout, 'afcf_col.csv')),
286 'afcf_facteur_csv': ffr(os.path.join(pathout, 'afcf_facteur.csv')),
287 'afct_row_csv': ffr(os.path.join(pathout, 'afct_row.csv')),
288 'afct_col_csv': ffr(os.path.join(pathout, 'afct_col.csv')),
289 'afct_facteur_csv': ffr(os.path.join(pathout, 'afct_facteur.csv')),
290 'ira' : ffr(os.path.join(pathout, 'Analyse.ira')),
291 'db' : os.path.join(pathout, 'analyse.db'),
292 'zipf' : ffr(os.path.join(pathout, 'zipf.png')),
296 #def construct_simipath(pathout):
297 # d = {'mat01' : 'mat01.csv',
298 # 'matsimi' : 'matsimi.csv',
300 # 'RData' : 'RData.RData',
301 # 'liste_graph' : 'liste_graph.txt',
302 # 'ira' : 'Analyse.ira',
304 # 'db' : 'analyse.db',
307 simipath = {'mat01' : 'mat01.csv',
308 'matsimi' : 'matsimi.csv',
310 'RData' : 'RData.RData',
311 'liste_graph' :'liste_graph.txt',
312 'ira' : 'Analyse.ira',
315 'corpus' : 'corpus.db',