X-Git-Url: http://www.iramuteq.org/git?a=blobdiff_plain;f=functions.py;h=3472b77d411a60567df32abdc2f4df7f1aba0854;hb=refs%2Fheads%2F3.0;hp=1a6d5235fb461335e6331c34a93d679e2399cdce;hpb=82dde3ff5f415750e7968fcacf8b0b7d18d2ce53;p=iramuteq diff --git a/functions.py b/functions.py index 1a6d523..add77d8 100755 --- a/functions.py +++ b/functions.py @@ -50,7 +50,7 @@ def open_folder(folder): else: opener ="open" if sys.platform == "darwin" else "xdg-open" #call([opener, folder]) - call(["%s %s &" % (opener, folder)], shell=True) + call(["%s '%s' &" % (opener, folder)], shell=True) def normpath_win32(path) : if not sys.platform == 'win32' : @@ -83,13 +83,13 @@ class TGen : def write(self, path = None): if path is None : path = self.path - with open(path, 'w') as f : + with open(path, 'w', encoding='utf8') as f : f.write('\n'.join(['\t'.join([val] + self.tgen[val]) for val in self.tgen])) def writetable(self, pathout, tgens, totocc): etoiles = list(totocc.keys()) etoiles.sort() - with open(pathout, 'w') as f : + with open(pathout, 'w', encoding='utf8') as f : line = '\t'.join(['tgens'] + etoiles) + '\n' f.write(line) for t in tgens : @@ -117,7 +117,9 @@ class History : self.read() def read(self) : - d = shelve.open(self.filein) + with open(self.filein, 'r') as fjson : + d = json.load(fjson) +# d = shelve.open(self.filein, protocol=1) self.history = d.get('history', []) self.matrix = d.get('matrix', []) self.ordercorpus = dict([[corpus['uuid'], i] for i, corpus in enumerate(self.history)]) @@ -125,13 +127,16 @@ class History : self.analyses = dict([[analyse['uuid'], analyse] for corpus in self.history for analyse in corpus.get('analyses', [])]) self.matrixanalyse = dict([[mat['uuid'], mat] for mat in self.matrix]) self.ordermatrix = dict([[matrix['uuid'], i] for i, matrix in enumerate(self.matrix)]) - d.close() +# d.close() def write(self) : - d = shelve.open(self.filein) + d = {} d['history'] = self.history d['matrix'] = self.matrix - d.close() + with open(self.filein, 'w') as f : + f.write(json.dumps(d, indent=4, default=str)) + #d = shelve.open(self.filein, protocol=1) + #d.close() def add(self, analyse) : log.info('add to history %s' % analyse.get('corpus_name', 'pas un corpus')) @@ -384,7 +389,7 @@ class DoConf : def write_tab(tab, fileout) : - csvWriter = csv.writer(open(fileout, 'w'), delimiter=';', quoting = csv.QUOTE_NONNUMERIC) + csvWriter = csv.writer(open(fileout, 'w', newline='', encoding='utf8'), delimiter=';', quoting = csv.QUOTE_NONNUMERIC) csvWriter.writerows(tab) class BugDialog(wx.Dialog): @@ -428,7 +433,7 @@ def CreateIraFile(DictPathOut, clusternb, corpname='corpus_name', section = 'ana AnalyseConf.set(section, 'clusternb', clusternb) AnalyseConf.set(section, 'corpus_name', corpname) - fileout = open(DictPathOut['ira'], 'w') + fileout = open(DictPathOut['ira'], 'w', encoding='utf8') AnalyseConf.write(fileout) fileout.close() @@ -511,10 +516,10 @@ def treat_line_alceste(i, line) : line[5] = str(float(line[5].replace(',', '.')))[0:7] return [i, int(line[0]), int(line[1]), float(line[2]), float(line[3]), line[6], line[4], line[5]] -def ReadProfileAsDico(File, Alceste=False, encoding = sys.getdefaultencoding()): +def ReadProfileAsDico(File, Alceste=False, encoding = 'utf8'): dictlem = {} print('lecture des profiles') - FileReader = codecs.open(File, 'r', encoding) + FileReader = open(File, 'r', encoding='utf8') Filecontent = FileReader.readlines() FileReader.close() DictProfile = {} @@ -674,7 +679,7 @@ def PlaySound(parent): print('pas de son') def ReadDicoAsDico(dicopath): - with codecs.open(dicopath, 'r', 'UTF8') as f: + with open(dicopath, 'r', encoding='UTF8') as f: content = f.readlines() lines = [line.rstrip('\n\r').replace('\n', '').replace('"', '').split('\t') for line in content if line != ''] return dict([[line[0], line[1:]] for line in lines]) @@ -691,9 +696,9 @@ def ReadLexique(parent, lang = 'french', filein = None): else : parent.lexique = ReadDicoAsDico(filein) -def ReadList(filein, encoding = sys.getdefaultencoding(), sep = ';'): +def ReadList(filein, encoding = 'utf8', sep = ';'): #file = open(filein) - with codecs.open(filein, 'r', encoding) as f : + with open(filein, 'r', encoding='utf8') as f : content = f.read() content = [line.replace('\n', '').replace('\r','').replace('\"', '').replace(',', '.').split(sep) for line in content.splitlines()] #file = codecs.open(filein, 'r', encoding) @@ -805,11 +810,12 @@ def launchcommand(mycommand): Popen(mycommand) def print_liste(filename,liste): - with open(filename,'w') as f : + with open(filename,'w', encoding='utf8') as f : for graph in liste : f.write(';'.join(graph) +'\n') -def read_list_file(filename, encoding = sys.getdefaultencoding()): - with codecs.open(filename,'r', encoding) as f: + +def read_list_file(filename, encoding = 'utf8'): + with open(filename,'r', encoding='utf8') as f: content=f.readlines() ncontent=[line.replace('\n','').split(';') for line in content if line.strip() != ''] return ncontent @@ -854,7 +860,7 @@ def treat_var_mod(variables) : # var_mod[var].append(variable) return var_mod -def doconcorde(corpus, uces, mots, uci = False) : +def doconcorde(corpus, uces, mots, uci = False, fontsize=16) : if not uci : ucestxt1 = [row for row in corpus.getconcorde(uces)] else : @@ -866,21 +872,23 @@ def doconcorde(corpus, uces, mots, uci = False) : listmot = [corpus.getforme(fid).forme for lem in listmot for fid in lem] mothtml = ['%s' % mot for mot in listmot] dmots = dict(list(zip(listmot, mothtml))) + presfont = '

' % fontsize + font = '' % fontsize for uce in uces : ucetxt = ucestxt1[uce].split() ucetxt = ' '.join([dmots.get(mot, mot) for mot in ucetxt]) if not uci : uciid = corpus.getucefromid(uce).uci - ucis_txt.append('

' + ' '.join(corpus.ucis[corpus.getucefromid(uce).uci].etoiles) + ' *%i_%i

' % (uciid, uce, uciid, uce)) + ucis_txt.append(presfont + ' '.join(corpus.ucis[corpus.getucefromid(uce).uci].etoiles) + ' *%i_%i

' % (uciid, uce, uciid, uce)) else : - ucis_txt.append('

' + ' '.join(corpus.ucis[uce].etoiles) + '

') - ucestxt.append(ucetxt) + ucis_txt.append(presfont + ' '.join(corpus.ucis[uce].etoiles) + '

') + ucestxt.append(font + ucetxt + '') return ucis_txt, ucestxt def getallstcarac(corpus, analyse) : pathout = PathOut(analyse['ira']) - profils = ReadProfileAsDico(pathout['PROFILE_OUT'], Alceste, self.encoding) + profils = ReadProfileAsDico(pathout['PROFILE_OUT'], Alceste, 'utf8') print(profils) def read_chd(filein, fileout): @@ -1016,7 +1024,7 @@ def translateprofile(corpus, dictprofile, lf='it', lt='fr', maxword = 50) : def write_translation_profile(prof, lems, language, dictpathout) : if os.path.exists(dictpathout['translations.txt']) : - with codecs.open(dictpathout['translations.txt'], 'r', 'utf8') as f : + with open(dictpathout['translations.txt'], 'r', encoding='utf8') as f : translist = f.read() translist = [line.split('\t') for line in translist.splitlines()] else : @@ -1034,13 +1042,13 @@ def write_translation_profile(prof, lems, language, dictpathout) : elif line[0] == '*****' : rest[i] = ['*****','*','*', '*', '*', '*'] toprint += rest - with open(dictpathout['translation_profile_%s.csv' % language], 'w') as f : + with open(dictpathout['translation_profile_%s.csv' % language], 'w', encoding='utf8') as f : f.write('\n'.join([';'.join(line) for line in toprint])) - with open(dictpathout['translation_words_%s.csv' % language], 'w') as f : + with open(dictpathout['translation_words_%s.csv' % language], 'w', encoding='utf8') as f : f.write('\n'.join(['\t'.join([val, lems[val]]) for val in lems])) if 'translation_profile_%s.csv' % language not in [val[0] for val in translist] : translist.append(['translation_profile_%s.csv' % language, 'translation_words_%s.csv' % language]) - with open(dictpathout['translations.txt'], 'w') as f : + with open(dictpathout['translations.txt'], 'w', encoding='utf8') as f : f.write('\n'.join(['\t'.join(line) for line in translist])) def makesentidict(infile, language) :