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 'history' : os.path.join(ConfigPath, 'history.db'),
121 'corpus' : os.path.join(ConfigPath, 'corpus.cfg'),
122 'stat' : os.path.join(ConfigPath, 'stat.cfg'),
123 'simitxt' : os.path.join(ConfigPath, 'simitxt.cfg'),
125 return DictConfigPath
127 def ConstructGlobalPath(AppliPath):
128 ConfigPath = os.path.join(AppliPath, 'configuration')
130 'global': os.path.join(ConfigPath, 'global.cfg'),
132 return DictConfigPath
134 def ConstructDicoPath(AppliPath):
135 BasePath = os.path.join(AppliPath, 'dictionnaires')
137 'french': os.path.join(BasePath, 'lexique_fr.txt'),
138 'french_exp': os.path.join(BasePath, 'expression_fr.txt'),
139 'english': os.path.join(BasePath, 'lexique_en.txt'),
140 'english_exp': os.path.join(BasePath, 'expression_en.txt'),
141 'german' : os.path.join(BasePath, 'lexique_de.txt'),
142 'german_exp' : os.path.join(BasePath, 'expression_de.txt'),
143 'italian' : os.path.join(BasePath, 'lexique_it.txt'),
144 'italian_exp' : os.path.join(BasePath, 'expression_it.txt'),
145 'swedish' : os.path.join(BasePath, 'lexique_sw.txt'),
146 'swedish_exp' : os.path.join(BasePath, 'expression_sw.txt'),
147 'portuguese' : os.path.join(BasePath, 'lexique_pt.txt'),
148 'portuguese_exp': os.path.join(BasePath, 'expression_pt.txt'),
149 'greek' : os.path.join(BasePath, 'lexique_gr.txt'),
150 'greek_exp' : os.path.join(BasePath, 'expression_gr.txt'),
154 def ConstructAfcmPath(FilePath):
156 'Levels': ffr(os.path.join(FilePath, 'afcm-levels.csv')),
157 'nd': ffr(os.path.join(FilePath, 'afcm-nd.csv')),
158 'FileActTemp': ffr(os.path.join(FilePath, 'fileActTamp.csv')),
159 'FileEtTemp': ffr(os.path.join(FilePath, 'FileEtTemp')),
160 'resultat': os.path.join(FilePath, 'Resultats-afcm.html'),
161 'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1])
165 def ConstructAfcUciPath(filepath):
167 'TableCont': ffr(os.path.join(filepath, 'TableCont.csv')),
168 'TableSup': ffr(os.path.join(filepath, 'TableSup.csv')),
169 'TableEt': ffr(os.path.join(filepath, 'TableEt.csv')),
170 'AfcColAct': ffr(os.path.join(filepath, 'AfcColAct.png')),
171 'AfcColSup': ffr(os.path.join(filepath, 'AfcColSup.png')),
172 'AfcColEt': ffr(os.path.join(filepath, 'AfcColEt.png')),
173 'afcdiv4': ffr(os.path.join(filepath, 'afcdiv4_')),
174 'AfcRow': ffr(os.path.join(filepath, 'AfcRow.png')),
175 'ListAct': ffr(os.path.join(filepath, 'ListAct.csv')),
176 'ListSup': ffr(os.path.join(filepath, 'ListSup.csv')),
177 'GraphAfcTot': os.path.join(filepath, 'GraphAfcTot.html'),
178 'Rafcuci': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
179 'afc_row': ffr(os.path.join(filepath, 'afc_row.csv')),
180 'afc_col': ffr(os.path.join(filepath, 'afc_col.csv')),
181 'ira' : os.path.join(filepath, 'Analyse.ira'),
183 return DictAfcUciPath
185 ChdTxtPathOut = {'TableUc1': 'TableUc1.csv',
186 'TableUc2': 'TableUc2.csv',
187 'listeuce1': 'listeUCE1.csv',
188 'listeuce2': 'listeUCE2.csv',
189 'DicoMots': 'DicoMots.csv',
190 'DicoLem': 'DicoLem.csv',
191 'profile': 'profiles.csv',
192 'antiprofile': 'antiprofiles.csv',
194 'rapport': 'RAPPORT.txt',
195 'pre_rapport' : 'info.txt',
197 'Rchdtxt': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
198 'arbre1': 'arbre_1.png',
199 'arbre2': 'arbre_2.png',
200 'dendro1': 'dendro1.png',
201 'dendro2': 'dendro2.png',
202 'Rdendro': 'dendrogramme.RData',
203 'Contout': 'classe_mod.csv',
204 'RData': 'RData.RData',
205 'ContSupOut': 'tablesup.csv',
206 'ContEtOut': 'tableet.csv',
207 'PROFILE_OUT': 'profiles.csv',
208 'ANTIPRO_OUT': 'antiprofiles.csv',
209 'SbyClasseOut': 'SbyClasseOut.csv',
210 'chisqtable' : 'chisqtable.csv',
211 'ptable' : 'ptable.csv',
212 'ira': 'Analyse.ira',
213 'AFC2DL_OUT': 'AFC2DL.png',
214 'AFC2DSL_OUT': 'AFC2DSL.png',
215 'AFC2DEL_OUT': 'AFC2DEL.png',
216 'AFC2DCL_OUT': 'AFC2DCL.png',
217 'AFC2DCoul': 'AFC2DCoul.png',
218 'AFC2DCoulSup': 'AFC2DCoulSup.png',
219 'AFC2DCoulEt': 'AFC2DCoulEt.png',
220 'AFC2DCoulCl': 'AFC2DCoulCl.png',
221 'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
222 'R3DCoul': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
223 'RESULT_CHD': 'resultats-chd.html',
224 'RESULT_AFC': 'resultats-afc.html',
225 'Act01': 'Act01.csv',
227 'Rchdquest':ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
228 'RTxtProfGraph':ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
229 'typelist': 'typelist.csv',
230 'concord':'concordancier.csv',
231 'bduceforme':'bduceforme.csv',
232 'uceuci': 'uceuci.csv',
233 'uciet': 'uciet.csv',
234 'ContTypeOut': 'tabletype.csv',
235 'liste_graph_afc' : 'liste_graph_afc.txt',
236 'liste_graph_chd' : 'liste_graph_chd.txt',
237 'afc_row': 'afc_row.csv',
238 'afc_col': 'afc_col.csv',
239 'afc_facteur': 'afc_facteur.csv',
240 'corpus_exp' : 'corpus_out.txt',
241 'segments_classes' : 'segments_classes.csv',
242 'prof_seg' : 'prof_segments.csv',
243 'antiprof_seg' : 'antiprof_segments.csv',
244 'prof_type' : 'profil_type.csv',
245 'antiprof_type' : 'antiprof_type.csv',
246 'type_cl' : 'type_cl.csv',
250 def StatTxtPathOut(pathout):
251 d = {'tableafcm':ffr(os.path.join(pathout, 'tableafcm.csv')),
252 'tabletypem': ffr(os.path.join(pathout, 'tabletypem.csv')),
253 'tablespecf': ffr(os.path.join(pathout, 'tablespecf.csv')),
254 'tablespect': ffr(os.path.join(pathout, 'tablespect.csv')),
255 'eff_relatif_forme': ffr(os.path.join(pathout, 'eff_relatif_forme.csv')),
256 'eff_relatif_type': ffr(os.path.join(pathout, 'eff_relatif_type.csv')),
257 'afcf_row' : ffr(os.path.join(pathout, 'afcf_row.png')),
258 'afcf_col' : ffr(os.path.join(pathout, 'afcf_col.png')),
259 'afct_row' : ffr(os.path.join(pathout, 'afct_row.png')),
260 'afct_col' : ffr(os.path.join(pathout, 'afct_col.png')),
261 'RData' : ffr(os.path.join(pathout, 'RData.RData')),
262 'liste_graph_afcf' : os.path.join(pathout, 'liste_graph_afcf.txt'),
263 'liste_graph_afct' : os.path.join(pathout, 'liste_graph_afct.txt'),
264 'afcf_row_csv': ffr(os.path.join(pathout, 'afcf_row.csv')),
265 'afcf_col_csv': ffr(os.path.join(pathout, 'afcf_col.csv')),
266 'afcf_facteur_csv': ffr(os.path.join(pathout, 'afcf_facteur.csv')),
267 'afct_row_csv': ffr(os.path.join(pathout, 'afct_row.csv')),
268 'afct_col_csv': ffr(os.path.join(pathout, 'afct_col.csv')),
269 'afct_facteur_csv': ffr(os.path.join(pathout, 'afct_facteur.csv')),
270 'ira' : ffr(os.path.join(pathout, 'Analyse.ira')),
271 'db' : os.path.join(pathout, 'analyse.db'),
272 'zipf' : ffr(os.path.join(pathout, 'zipf.png')),
276 def construct_simipath(pathout):
277 d = {'mat01' : ffr(os.path.join(pathout, 'mat01.csv')),
278 'matsimi' : ffr(os.path.join(pathout, 'matsimi.csv')),
279 'eff' : ffr(os.path.join(pathout, 'eff.csv')),
280 'RData' : ffr(os.path.join(pathout, 'RData.RData')),
281 'liste_graph' : os.path.join(pathout, 'liste_graph.txt'),
282 'ira' : os.path.join(pathout, 'Analyse.ira'),
283 'film' : ffr(pathout),
284 'db' : os.path.join(pathout, 'analyse.db'),
285 'corpus' : os.path.join(pathout, 'corpus.db'),
289 simipath = {'mat01' : 'mat01.csv',
290 'matsimi' : 'matsimi.csv',
292 'RData' : 'RData.RData',
293 'liste_graph' :'liste_graph.txt',
294 'ira' : 'Analyse.ira',
297 'corpus' : 'corpus.db',