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