X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=tools.py;fp=tools.py;h=e35ea4b790f1fe9146aece68f2e4c5d5b1f6c6b1;hp=7db0e9e20ea092d0ac2f5e4d7c8531e698fce4e2;hb=eb614c725930bc65a7ad43eda1b769b504433f88;hpb=b1508377fa575a61f1127273d328766608237014 diff --git a/tools.py b/tools.py index 7db0e9e..e35ea4b 100644 --- a/tools.py +++ b/tools.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- #Author: Pierre Ratinaud #Copyright (c) 2008-2013, Pierre Ratinaud -#Lisense: GNU GPL +#License: GNU GPL import codecs import os @@ -68,19 +68,19 @@ class SplitFromVar : keepline = False filedict = {} with codecs.open(self.filein, 'r', self.encodein) as fin : - for line in fin : - if istext(line) : - varmod = testvar(line, self.var) - if varmod : - keepline = True - if varmod not in filedict : - filename = os.path.join(self.basepath, varmod + '.txt') - filedict[varmod] = open(filename, 'w') - fileout = filedict[varmod] - else : - keepline = False - if keepline : - fileout.write(line.encode(self.encodeout)) + for line in fin : + if istext(line) : + varmod = testvar(line, self.var) + if varmod : + keepline = True + if varmod not in filedict : + filename = os.path.join(self.basepath, varmod + '.txt') + filedict[varmod] = open(filename, 'w') + fileout = filedict[varmod] + else : + keepline = False + if keepline : + fileout.write(line.encode(self.encodeout)) for f in filedict : filedict[f].close() @@ -101,22 +101,22 @@ class ExtractMods : keepline = False filedict = {} with codecs.open(self.filein, 'r', self.encodein) as fin : - for line in fin : - if istext(line) : - modinline = testmod(line, self.mods) - if modinline : - keepline = True - if not self.onefile : + for line in fin : + if istext(line) : + modinline = testmod(line, self.mods) + if modinline : + keepline = True + if not self.onefile : if modinline not in filedict : filename = os.path.join(self.basepath, modinline + '.txt') filedict[modinline] = open(filename, 'w') fileout = filedict[modinline] - else : - fileout = self.fileout - else : - keepline = False - if keepline : - fileout.write(line.encode(self.encodeout)) + else : + fileout = self.fileout + else : + keepline = False + if keepline : + fileout.write(line.encode(self.encodeout)) if not self.onefile : for f in filedict : filedict[f].close() @@ -150,7 +150,16 @@ class SubCorpus(Corpus) : def getlemuces(self, lem) : return list(set(self.sgts).intersection(self.corpus.getlemuces(lem))) - +def converttabletocorpus(table, fileout, enc='UTF8') : + var = table.pop(0) + var = var[0:len(var)-1] + print var + et = [zip(var, line[0:len(line)-1]) for line in table] + et = ['**** ' + ' '.join(['*' + '_'.join(val) for val in line]) for line in et] + txt = ['\n'.join([et[i], line[-1]]) for i, line in enumerate(table)] + print '\n'.join(txt) + #with open(fileout, 'w') as f : +