From: pierre Date: Wed, 4 Nov 2020 20:38:17 +0000 (+0100) Subject: remove history.json hack X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=commitdiff_plain;h=ae32485b960c98387ae7987751198335ad549ab3;ds=sidebyside remove history.json hack --- diff --git a/functions.py b/functions.py index c74f352..6a3d968 100755 --- a/functions.py +++ b/functions.py @@ -117,8 +117,8 @@ class History : 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)) +# 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) @@ -885,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', error='replace').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=[] @@ -951,7 +950,7 @@ def translateprofile(corpus, dictprofile, lf='it', lt='fr', maxword = 20) : 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)