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