X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=functions.py;h=6a3d9689a4298c5cfbf9bf41d78c9006a80aa886;hp=8c0c66c102ec5e4418743a54fcb432a76d3aa036;hb=ae32485b960c98387ae7987751198335ad549ab3;hpb=b84be44daa86062735190970d5c6b855f227a7d7 diff --git a/functions.py b/functions.py index 8c0c66c..6a3d968 100755 --- a/functions.py +++ b/functions.py @@ -114,6 +114,11 @@ class History : 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 = {} + d['history'] = self.history + d['matrix'] = self.matrix +# with open('/home/pierre/hystory.json', 'w') as f : +# f.write(json.dumps(d, indent=4, default=str)) def write(self) : d = shelve.open(self.filein) @@ -805,7 +810,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, et = False) : if not uci : ucestxt1 = [row for row in corpus.getconcorde(uces)] else : @@ -813,8 +818,11 @@ def doconcorde(corpus, uces, mots, uci = False) : ucestxt1 = dict(ucestxt1) ucestxt = [] ucis_txt = [] - listmot = [corpus.getlems()[lem].formes for lem in mots] - listmot = [corpus.getforme(fid).forme for lem in listmot for fid in lem] + if not et : + listmot = [corpus.getlems()[lem].formes for lem in mots] + listmot = [corpus.getforme(fid).forme for lem in listmot for fid in lem] + else : + listmot = mots mothtml = ['%s' % mot for mot in listmot] dmots = dict(zip(listmot, mothtml)) for uce in uces : @@ -877,13 +885,12 @@ def gettranslation(words, lf, lt) : .NET CLR 3.0.04506.30\ )"} base_link = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=%s&tl=%s&dt=t&q=%s" - print len(words) totrans = urllib2.quote('\n'.join(words).encode('utf8')) link = base_link % (lf, lt, totrans) request = urllib2.Request(link, headers=agent) raw_data = urllib2.urlopen(request).read() data = json.loads(raw_data) - return [line[0].decode('utf8').replace(u"'", u'_').replace(u' | ', u'|').replace(u' ', u'_').replace(u'-',u'_').replace(u'\n','') for line in data[0]] + return [line[0].decode('utf8', errors='replace').replace(u"'", u'_').replace(u' | ', u'|').replace(u' ', u'_').replace(u'-',u'_').replace(u'\n','') for line in data[0]] def makenprof(prof, trans, deb=0) : nprof=[] @@ -901,7 +908,7 @@ def treatempty(val) : else : return val -def translateprofile(corpus, dictprofile, lf='it', lt='fr', maxword = 50) : +def translateprofile(corpus, dictprofile, lf='it', lt='fr', maxword = 20) : nprof = {} lems = {} for i in range(len(dictprofile)) : @@ -943,7 +950,7 @@ def translateprofile(corpus, dictprofile, lf='it', lt='fr', maxword = 50) : nlensup = maxword else : nlensup = lensup - supori = [line[6] for line in prof[(1+lenact):(lenact+nlensup)]] + supori = [line[6] for line in prof[(1+lenact):(lenact+nlensup+1)]] sup = [val.replace(u'_', u' ') for val in supori] sup = [treatempty(val) for val in sup] sup = gettranslation(sup, lf, lt)