french dictionary
[iramuteq] / chemins.py
1 #!/bin/env python
2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008 Pierre Ratinaud
5 #Lisense: GNU/GPL
6
7 import os
8 import tempfile
9 import logging
10
11 log = logging.getLogger('iramuteq.chemins')
12
13
14 class PathOut :
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: 
24             self.dirout = dirout
25         elif filename is not None and dirout is None:
26             self.dirout = self.directory
27         self.d = {} 
28
29     def mkdirout(self) :
30         dirout = os.path.join(self.dirout, self.filename + '_' + self.analyse + '_')
31         nb = 1
32         tdirout = dirout + `nb`
33         while os.path.exists(tdirout) :
34             nb += 1
35             tdirout = dirout + `nb`
36         self.name = os.path.splitext(tdirout)[1]
37         return tdirout
38
39     def createdir(self, tdirout) :
40         if not os.path.exists(tdirout) :
41             os.mkdir(tdirout)
42
43     def basefiles(self, ndict) :
44         self.d = ndict
45
46     def __getitem__(self, key) :
47         if key == 'temp' :
48             self.temp = tempfile.mkstemp(prefix='iramuteq')[1].replace('\\', '\\\\')
49             return self.temp
50         elif key not in self.d :
51             return os.path.join(self.dirout, key).replace('\\', '\\\\')
52         else :
53             return os.path.join(self.dirout, self.d[key]).replace('\\', '\\\\')
54     
55     def getF(self, key) :
56         return self.__getitem__(key).replace('\\', '/')
57
58
59 def ffr(filename):
60     return filename.replace('\\', '\\\\')
61     
62 def FFF(filename):
63     return filename.replace('\\', '/')
64
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 @@@@@@@@@@@@@@@@'
70     DictRscripts = {
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')),
85     }
86     return DictRscripts
87
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) :
96         if number < 10:
97             PathFile = PathFile[0:len(PathFile) - 1] + str(number + 1)
98             pass
99         elif (number >= 10) and (number < 100):
100             PathFile = PathFile[0:len(PathFile) - 2] + str(number + 1)
101             pass
102         elif number >= 100 :
103             PathFile = PathFile[0:len(PathFile) - 3] + str(number + 1)
104             pass
105         number += 1
106     os.mkdir(os.path.join(FileBasePath, PathFile))
107     return os.path.join(FileBasePath, PathFile)
108
109 def ConstructConfigPath(AppliPath, user=True):
110     if not user:
111         ConfigPath = os.path.join(AppliPath, 'configuration')
112     else :
113         ConfigPath = AppliPath
114     DictConfigPath = {
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'),
123     }
124     return DictConfigPath
125
126 def ConstructGlobalPath(AppliPath):
127     ConfigPath = os.path.join(AppliPath, 'configuration')
128     DictConfigPath = {
129             'global': os.path.join(ConfigPath, 'global.cfg'),
130             }
131     return DictConfigPath
132
133 def ConstructDicoPath(AppliPath):
134     BasePath = os.path.join(AppliPath, 'dictionnaires')
135     DictPath = {
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'),
150         'spanish' :  os.path.join(BasePath, 'lexique_sp.txt'),
151         'spanish_exp' :  os.path.join(BasePath, 'expression_sp.txt'),
152     }
153     return DictPath
154
155 def ConstructAfcmPath(FilePath):
156     DictAfcmPath = {
157         'Levels': ffr(os.path.join(FilePath, 'afcm-levels.csv')),
158         'nd': ffr(os.path.join(FilePath, 'afcm-nd.csv')),
159         'FileActTemp': ffr(os.path.join(FilePath, 'fileActTamp.csv')),
160         'FileEtTemp': ffr(os.path.join(FilePath, 'FileEtTemp')),
161         'resultat': os.path.join(FilePath, 'Resultats-afcm.html'),
162         'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1])
163     }
164     return DictAfcmPath
165
166 def ConstructAfcUciPath(filepath):
167     DictAfcUciPath = {
168         'TableCont': ffr(os.path.join(filepath, 'TableCont.csv')),
169         'TableSup': ffr(os.path.join(filepath, 'TableSup.csv')),
170         'TableEt': ffr(os.path.join(filepath, 'TableEt.csv')),
171         'AfcColAct': ffr(os.path.join(filepath, 'AfcColAct.png')),
172         'AfcColSup': ffr(os.path.join(filepath, 'AfcColSup.png')),
173         'AfcColEt': ffr(os.path.join(filepath, 'AfcColEt.png')),
174         'afcdiv4': ffr(os.path.join(filepath, 'afcdiv4_')),
175         'AfcRow': ffr(os.path.join(filepath, 'AfcRow.png')),
176         'ListAct': ffr(os.path.join(filepath, 'ListAct.csv')),
177         'ListSup': ffr(os.path.join(filepath, 'ListSup.csv')),
178         'GraphAfcTot': os.path.join(filepath, 'GraphAfcTot.html'),
179         'Rafcuci': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
180         'afc_row': ffr(os.path.join(filepath, 'afc_row.csv')),
181         'afc_col': ffr(os.path.join(filepath, 'afc_col.csv')),
182         'ira' : os.path.join(filepath, 'Analyse.ira'),
183     }
184     return DictAfcUciPath
185
186 ChdTxtPathOut = {'TableUc1': 'TableUc1.csv',
187         'TableUc2': 'TableUc2.csv',
188         'listeuce1':  'listeUCE1.csv',
189         'listeuce2':  'listeUCE2.csv',
190         'DicoMots':  'DicoMots.csv',
191         'DicoLem':  'DicoLem.csv',
192         'profile':  'profiles.csv',
193         'antiprofile':  'antiprofiles.csv',
194         'afc':  'AFC.csv',
195         'rapport':  'RAPPORT.txt',
196         'pre_rapport' : 'info.txt',
197         'uce':  'uce.csv',
198         'Rchdtxt': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
199         'arbre1':  'arbre_1.png',
200         'arbre2':  'arbre_2.png',
201         'dendro1':  'dendro1.png',
202         'dendro2':  'dendro2.png',
203         'Rdendro':  'dendrogramme.RData',
204         'Contout':  'classe_mod.csv',
205         'RData':  'RData.RData',
206         'ContSupOut':  'tablesup.csv',
207         'ContEtOut':  'tableet.csv',
208         'PROFILE_OUT':  'profiles.csv',
209         'ANTIPRO_OUT':  'antiprofiles.csv',
210         'SbyClasseOut':  'SbyClasseOut.csv',
211         'chisqtable' :  'chisqtable.csv',
212         'ptable' :  'ptable.csv',
213         'ira': 'Analyse.ira',
214         'AFC2DL_OUT':  'AFC2DL.png',
215         'AFC2DSL_OUT':  'AFC2DSL.png',
216         'AFC2DEL_OUT':  'AFC2DEL.png',
217         'AFC2DCL_OUT':  'AFC2DCL.png',
218         'AFC2DCoul':  'AFC2DCoul.png',
219         'AFC2DCoulSup':  'AFC2DCoulSup.png',
220         'AFC2DCoulEt':  'AFC2DCoulEt.png',
221         'AFC2DCoulCl':  'AFC2DCoulCl.png',
222         'Rafc3d': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
223         'R3DCoul': ffr(tempfile.mkstemp(prefix='iramuteq')[1]),
224         'RESULT_CHD':  'resultats-chd.html',
225         'RESULT_AFC':  'resultats-afc.html',
226         'Et01':  'Et01.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',
247         'db' : 'analyse.db',
248     }
249
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')),
273     }
274     return d
275
276 #def construct_simipath(pathout):
277 #    d = {'mat01' : 'mat01.csv',
278 #          'matsimi' : 'matsimi.csv',
279 #          'eff' : 'eff.csv',
280 #          'RData' : 'RData.RData',
281 #          'liste_graph' : 'liste_graph.txt',
282 #          'ira' : 'Analyse.ira',
283 #          'film' : '',
284 #          'db' : 'analyse.db',
285 #        }
286
287 simipath = {'mat01' :  'mat01.csv',
288           'matsimi' : 'matsimi.csv',
289           'eff' : 'eff.csv',
290           'RData' : 'RData.RData',
291           'liste_graph' :'liste_graph.txt',
292           'ira' : 'Analyse.ira',
293           'film' : '',
294           'db' : 'analyse.db',
295           'corpus' : 'corpus.db',
296         }
297