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('\\', '/')
65 def ConstructRscriptsPath(AppliPath):
66 RScriptsPath = os.path.join(AppliPath, 'Rscripts')
67 #print('@@@@@@@@@@@PONDERATION CHDPOND.R@@@@@@@@@@@@@@@@')
68 #print('@@@@@@@@@@@ NEW SVD CHEMIN @@@@@@@@@@@@@@@@')
69 #print '@@@@@@@@@@@ NEW NCHD CHEMIN @@@@@@@@@@@@@@@@'
71 'Rfunct': ffr(os.path.join(RScriptsPath, 'Rfunct.R')),
72 'chdfunct': ffr(os.path.join(RScriptsPath, 'chdfunct.R')),
73 'Rgraph': ffr(os.path.join(RScriptsPath, 'Rgraph.R')),
74 'plotafcm': ffr(os.path.join(RScriptsPath, 'plotafcm.R')),
75 'afc_graph' : ffr(os.path.join(RScriptsPath, 'afc_graph.R')),
76 #'CHD': ffr(os.path.join(RScriptsPath, 'CHDPOND.R')),
77 'CHD': ffr(os.path.join(RScriptsPath, 'CHD.R')),
78 #'CHD' : ffr(os.path.join(RScriptsPath, 'NCHD.R')),
79 'chdtxt': ffr(os.path.join(RScriptsPath, 'chdtxt.R')),
80 'chdquest': ffr(os.path.join(RScriptsPath, 'chdquest.R')),
81 'pamtxt' : ffr(os.path.join(RScriptsPath, 'pamtxt.R')),
82 'anacor' : ffr(os.path.join(RScriptsPath, 'anacor.R')),
83 #'anacor' : ffr(os.path.join(RScriptsPath, 'Nanacor.R')),
84 'simi' : ffr(os.path.join(RScriptsPath, 'simi.R')),
88 def ConstructPathOut(Filename, analyse_type):
89 FileBaseName = os.path.basename(Filename)
90 FileBasePath = os.path.dirname(Filename)
91 PathFile = os.path.splitext(FileBaseName)
92 PathFile = os.path.join(FileBasePath, PathFile[0] + '_' + analyse_type + '_1')
93 splitpath = PathFile.split('_')
94 number = int(splitpath[len(splitpath) - 1])
95 while os.path.isdir(PathFile) :
97 PathFile = PathFile[0:len(PathFile) - 1] + str(number + 1)
99 elif (number >= 10) and (number < 100):
100 PathFile = PathFile[0:len(PathFile) - 2] + str(number + 1)
103 PathFile = PathFile[0:len(PathFile) - 3] + str(number + 1)
106 os.mkdir(os.path.join(FileBasePath, PathFile))
107 return os.path.join(FileBasePath, PathFile)
109 def ConstructConfigPath(AppliPath, user=True):
111 ConfigPath = os.path.join(AppliPath, 'configuration')
113 ConfigPath = AppliPath
115 'alceste': os.path.join(ConfigPath, 'alceste.cfg'),
116 'key': os.path.join(ConfigPath, 'key.cfg'),
117 'path': os.path.join(ConfigPath, 'path.cfg'),
118 'preferences' : os.path.join(ConfigPath, 'iramuteq.cfg'),
119 'pam' : os.path.join(ConfigPath, 'pam.cfg'),
120 'corpus' : os.path.join(ConfigPath, 'corpus.cfg'),
121 'stat' : os.path.join(ConfigPath, 'stat.cfg'),
122 'simitxt' : os.path.join(ConfigPath, 'simitxt.cfg'),
124 return DictConfigPath
126 def ConstructGlobalPath(AppliPath):
127 ConfigPath = os.path.join(AppliPath, 'configuration')
129 'global': os.path.join(ConfigPath, 'global.cfg'),
131 return DictConfigPath
133 def ConstructDicoPath(AppliPath):
134 BasePath = os.path.join(AppliPath, 'dictionnaires')
136 'french': os.path.join(BasePath, 'lexique_fr.txt'),
137 'french_exp': os.path.join(BasePath, 'expression_fr.txt'),
138 'english': os.path.join(BasePath, 'lexique_en.txt'),
139 'english_exp': os.path.join(BasePath, 'expression_en.txt'),
140 'german' : os.path.join(BasePath, 'lexique_de.txt'),
141 'german_exp' : os.path.join(BasePath, 'expression_de.txt'),
142 'italian' : os.path.join(BasePath, 'lexique_it.txt'),
143 'italian_exp' : os.path.join(BasePath, 'expression_it.txt'),
144 'swedish' : os.path.join(BasePath, 'lexique_sw.txt'),
145 'swedish_exp' : os.path.join(BasePath, 'expression_sw.txt'),
146 'portuguese' : os.path.join(BasePath, 'lexique_pt.txt'),
147 'portuguese_exp': os.path.join(BasePath, 'expression_pt.txt'),
148 'greek' : os.path.join(BasePath, 'lexique_gr.txt'),
149 'greek_exp' : os.path.join(BasePath, 'expression_gr.txt'),
153 def ConstructAfcmPath(FilePath):
155 'Levels': ffr(os.path.join(FilePath, 'afcm-levels.csv')),
156 'nd': ffr(os.path.join(FilePath, 'afcm-nd.csv')),
157 'FileActTemp': ffr(os.path.join(FilePath, 'fileActTamp.csv')),
158 'FileEtTemp': ffr(os.path.join(FilePath, 'FileEtTemp')),
159 'resultat': os.path.join(FilePath, 'Resultats-afcm.html'),
160 'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1])
164 def ConstructAfcUciPath(filepath):
166 'TableCont': ffr(os.path.join(filepath, 'TableCont.csv')),
167 'TableSup': ffr(os.path.join(filepath, 'TableSup.csv')),
168 'TableEt': ffr(os.path.join(filepath, 'TableEt.csv')),
169 'AfcColAct': ffr(os.path.join(filepath, 'AfcColAct.png')),
170 'AfcColSup': ffr(os.path.join(filepath, 'AfcColSup.png')),
171 'AfcColEt': ffr(os.path.join(filepath, 'AfcColEt.png')),
172 'afcdiv4': ffr(os.path.join(filepath, 'afcdiv4_')),
173 'AfcRow': ffr(os.path.join(filepath, 'AfcRow.png')),
174 'ListAct': ffr(os.path.join(filepath, 'ListAct.csv')),
175 'ListSup': ffr(os.path.join(filepath, 'ListSup.csv')),
176 'GraphAfcTot': os.path.join(filepath, 'GraphAfcTot.html'),
177 'Rafcuci': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
178 'afc_row': ffr(os.path.join(filepath, 'afc_row.csv')),
179 'afc_col': ffr(os.path.join(filepath, 'afc_col.csv')),
180 'ira' : os.path.join(filepath, 'Analyse.ira'),
182 return DictAfcUciPath
184 ChdTxtPathOut = {'TableUc1': 'TableUc1.csv',
185 'TableUc2': 'TableUc2.csv',
186 'listeuce1': 'listeUCE1.csv',
187 'listeuce2': 'listeUCE2.csv',
188 'DicoMots': 'DicoMots.csv',
189 'DicoLem': 'DicoLem.csv',
190 'profile': 'profiles.csv',
191 'antiprofile': 'antiprofiles.csv',
193 'rapport': 'RAPPORT.txt',
194 'pre_rapport' : 'info.txt',
196 'Rchdtxt': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
197 'arbre1': 'arbre_1.png',
198 'arbre2': 'arbre_2.png',
199 'dendro1': 'dendro1.png',
200 'dendro2': 'dendro2.png',
201 'Rdendro': 'dendrogramme.RData',
202 'Contout': 'classe_mod.csv',
203 'RData': 'RData.RData',
204 'ContSupOut': 'tablesup.csv',
205 'ContEtOut': 'tableet.csv',
206 'PROFILE_OUT': 'profiles.csv',
207 'ANTIPRO_OUT': 'antiprofiles.csv',
208 'SbyClasseOut': 'SbyClasseOut.csv',
209 'chisqtable' : 'chisqtable.csv',
210 'ptable' : 'ptable.csv',
211 'ira': 'Analyse.ira',
212 'AFC2DL_OUT': 'AFC2DL.png',
213 'AFC2DSL_OUT': 'AFC2DSL.png',
214 'AFC2DEL_OUT': 'AFC2DEL.png',
215 'AFC2DCL_OUT': 'AFC2DCL.png',
216 'AFC2DCoul': 'AFC2DCoul.png',
217 'AFC2DCoulSup': 'AFC2DCoulSup.png',
218 'AFC2DCoulEt': 'AFC2DCoulEt.png',
219 'AFC2DCoulCl': 'AFC2DCoulCl.png',
220 'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
221 'R3DCoul': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
222 'RESULT_CHD': 'resultats-chd.html',
223 'RESULT_AFC': 'resultats-afc.html',
225 'Rchdquest':ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
226 'RTxtProfGraph':ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
227 'typelist': 'typelist.csv',
228 'concord':'concordancier.csv',
229 'bduceforme':'bduceforme.csv',
230 'uceuci': 'uceuci.csv',
231 'uciet': 'uciet.csv',
232 'ContTypeOut': 'tabletype.csv',
233 'liste_graph_afc' : 'liste_graph_afc.txt',
234 'liste_graph_chd' : 'liste_graph_chd.txt',
235 'afc_row': 'afc_row.csv',
236 'afc_col': 'afc_col.csv',
237 'afc_facteur': 'afc_facteur.csv',
238 'corpus_exp' : 'corpus_out.txt',
239 'segments_classes' : 'segments_classes.csv',
240 'prof_seg' : 'prof_segments.csv',
241 'antiprof_seg' : 'antiprof_segments.csv',
242 'prof_type' : 'profil_type.csv',
243 'antiprof_type' : 'antiprof_type.csv',
244 'type_cl' : 'type_cl.csv',
248 def StatTxtPathOut(pathout):
249 d = {'tableafcm':ffr(os.path.join(pathout, 'tableafcm.csv')),
250 'tabletypem': ffr(os.path.join(pathout, 'tabletypem.csv')),
251 'tablespecf': ffr(os.path.join(pathout, 'tablespecf.csv')),
252 'tablespect': ffr(os.path.join(pathout, 'tablespect.csv')),
253 'eff_relatif_forme': ffr(os.path.join(pathout, 'eff_relatif_forme.csv')),
254 'eff_relatif_type': ffr(os.path.join(pathout, 'eff_relatif_type.csv')),
255 'afcf_row' : ffr(os.path.join(pathout, 'afcf_row.png')),
256 'afcf_col' : ffr(os.path.join(pathout, 'afcf_col.png')),
257 'afct_row' : ffr(os.path.join(pathout, 'afct_row.png')),
258 'afct_col' : ffr(os.path.join(pathout, 'afct_col.png')),
259 'RData' : ffr(os.path.join(pathout, 'RData.RData')),
260 'liste_graph_afcf' : os.path.join(pathout, 'liste_graph_afcf.txt'),
261 'liste_graph_afct' : os.path.join(pathout, 'liste_graph_afct.txt'),
262 'afcf_row_csv': ffr(os.path.join(pathout, 'afcf_row.csv')),
263 'afcf_col_csv': ffr(os.path.join(pathout, 'afcf_col.csv')),
264 'afcf_facteur_csv': ffr(os.path.join(pathout, 'afcf_facteur.csv')),
265 'afct_row_csv': ffr(os.path.join(pathout, 'afct_row.csv')),
266 'afct_col_csv': ffr(os.path.join(pathout, 'afct_col.csv')),
267 'afct_facteur_csv': ffr(os.path.join(pathout, 'afct_facteur.csv')),
268 'ira' : ffr(os.path.join(pathout, 'Analyse.ira')),
269 'db' : os.path.join(pathout, 'analyse.db'),
270 'zipf' : ffr(os.path.join(pathout, 'zipf.png')),
274 def construct_simipath(pathout):
275 d = {'mat01' : ffr(os.path.join(pathout, 'mat01.csv')),
276 'matsimi' : ffr(os.path.join(pathout, 'matsimi.csv')),
277 'eff' : ffr(os.path.join(pathout, 'eff.csv')),
278 'RData' : ffr(os.path.join(pathout, 'RData.RData')),
279 'liste_graph' : os.path.join(pathout, 'liste_graph.txt'),
280 'ira' : os.path.join(pathout, 'Analyse.ira'),
281 'film' : ffr(pathout),
282 'db' : os.path.join(pathout, 'analyse.db'),
283 'corpus' : os.path.join(pathout, 'corpus.db'),
287 simipath = {'mat01' : 'mat01.csv',
288 'matsimi' : 'matsimi.csv',
290 'RData' : 'RData.RData',
291 'liste_graph' :'liste_graph.txt',
292 'ira' : 'Analyse.ira',
295 'corpus' : 'corpus.db',