2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2010 Pierre Ratinaud
8 from optparse import OptionParser
13 sys.setdefaultencoding(locale.getpreferredencoding())
14 from chemins import ConstructConfigPath, ConstructDicoPath, ConstructRscriptsPath
15 from functions import ReadLexique, DoConf, History
16 from ConfigParser import *
17 #######################################
18 #from textchdalc import AnalyseAlceste
19 #from textdist import PamTxt
20 #from textafcuci import AfcUci
21 from textaslexico import Lexico
22 from textstat import Stat
24 ######################################
25 print '#######LOGGING TEST###########'
27 log = logging.getLogger('iramuteq')
28 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
29 ch = logging.StreamHandler()
30 ch.setFormatter(formatter)
32 log.setLevel(logging.DEBUG)
33 #######################################
35 log.debug('----------TEST corpusNG-----------------')
36 from analysetxt import Alceste, gramact, gramsup
37 from corpusNG import *
41 AppliPath = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0])))
42 if os.getenv('HOME') != None:
43 user_home = os.getenv('HOME')
45 user_home = os.getenv('HOMEPATH')
46 UserConfigPath = os.path.abspath(os.path.join(user_home, '.iramuteq'))
50 self.DictPath = ConstructDicoPath(AppliPath)
51 self.ConfigPath = ConstructConfigPath(UserConfigPath)
52 self.syscoding = sys.getdefaultencoding()
53 parser = OptionParser()
55 parser.add_option("-f", "--file", dest="filename", help="chemin du corpus", metavar="FILE", default=False)
56 parser.add_option("-t", "--type", dest="type_analyse", help="type d'analyse", metavar="TYPE D'ANALYSE", default='False')
58 parser.add_option("-c", "--conf", dest="configfile", help="chemin du fichier de configuration", metavar="CONF", default=False)
59 parser.add_option("-e", "--enc", dest="encodage", help="encodage du corpus", metavar="ENC", default=locale.getpreferredencoding())
60 parser.add_option("-l", "--lang", dest="language", help="langue du corpus", metavar="LANG", default='french')
61 parser.add_option("-r", "--read", dest="read", help="lire un corpus", metavar="READ", default = False)
63 (options, args) = parser.parse_args()
66 if options.configfile :
67 self.ConfigPath[options.type_analyse] = os.path.abspath(options.configfile)
68 self.TEMPDIR = tempfile.mkdtemp('iramuteq')
69 self.RscriptsPath = ConstructRscriptsPath(AppliPath)
70 self.PathPath = ConfigParser()
71 self.PathPath.read(self.ConfigPath['path'])
72 self.RPath = self.PathPath.get('PATHS', 'rpath')
73 self.pref = RawConfigParser()
74 self.pref.read(self.ConfigPath['preferences'])
75 self.history = History(self.ConfigPath['history'])
77 if options.filename or options.read or options.build:
78 self.corpus_encodage = options.encodage
79 self.corpus_lang = options.language
82 #print 'PAS DE CODECS POUR CABLE'
83 ReadLexique(self, lang = options.language)
84 self.expressions = ReadDicoAsDico(self.DictPath.get(options.language + '_exp', 'french_exp'))
86 self.filename = os.path.abspath(options.filename)
87 corpus_parametres = DoConf('/home/pierre/.iramuteq/corpus.cfg').getoptions('corpus')
88 corpus_parametres['filename'] = self.filename
89 corpus_parametres['encoding'] = self.corpus_encodage
90 corpus_parametres['syscoding'] = 'utf8'
91 corpus_parametres['pathout'] = PathOut(options.filename, 'corpus').dirout
92 corpus = BuildFromAlceste(self.filename, corpus_parametres, self.lexique, self.expressions).corpus
93 self.history.add(corpus.parametres)
95 #with codecs.open(self.filename, 'r', self.corpus_encodage) as f:
97 corpus = Corpus(self, parametres = DoConf(options.read).getoptions('corpus'), read = options.read)
98 corpus.parametres['path'] = os.path.abspath(options.read)
99 pathout = os.path.dirname(os.path.dirname(os.path.abspath(options.read)))
103 corpus.parse_active(gramact, gramsup)
104 # self.content = f.read()
105 #self.content = self.content.replace('\r','')
106 if options.type_analyse == 'alceste' :
107 log.debug('ATTENTION : ANALYSE NG')
108 #print corpus.make_etoiles()
110 #corpus.read_corpus()
111 #corpus.parse_active(gramact, gramsup)
112 Alceste(self, corpus)
113 # self.Text = AnalyseAlceste(self, cmd = True, big = True)
114 #self.Text = AnalyseAlceste(self, cmd = True)
115 elif options.type_analyse == 'pam' :
116 self.Text = PamTxt(self, cmd = True)
117 elif options.type_analyse == 'afcuci' :
118 self.Text = AfcUci(self, cmd = True)
119 elif options.type_analyse == 'stat' :
120 self.Text = Stat(self, corpus, config = {'type' : 'stat'})
121 elif options.type_analyse == 'spec' :
122 self.Text = Lexico(self, corpus, config = {'type' : 'spec'})
123 #print self.Text.corpus.hours, 'h', self.Text.corpus.minutes,'min', self.Text.corpus.seconds, 's'
124 # self.Text.corpus.make_colored_corpus('colored.html')
126 if __name__ == '__main__':