import re import objects import sys def _parse_analysis(txt): lines = txt.split('\n') words = objects.Pipe() for l in lines: # l = l.decode('utf-8') if not l: mi = None continue if l.strip() == '""' or l.strip() == '""': mi = None continue if l.startswith('"'): l=l.strip() mi = objects.Word(l[2:-2]) words.append(mi) if l.startswith('\t'): if mi: mi.addInfo(l.strip()) return words def loeLopud(txt): lines = txt.split('\n') words = objects.Pipe() for l in lines: m=l.split(";") w=objects.Word(m[0].strip()) words.append(w) wi=m[1].split(",") for inf in wi: inf=inf.strip() if len(inf)>0: w.addInfo(inf) return words f = open('fromfiles/input.txt', 'rb') #f=sys.stdin contents = f.read() f.close() words=_parse_analysis(contents) f=open('lopud.csv', 'rb') contents=f.read() f.close() lopud=loeLopud(contents) #for lopp in lopud: # print lopp.getWord(), ' ja ' , lopp.getInfo() for w in words: #print w.getWord(),' ja ', w.getInfo() sobib=False klinfd=[] klopud=[] for winf in w.getInfo(): for lopp in lopud: lnr=0 for linf in lopp.getInfo(): tunnus=linf.split() koik=True for t in tunnus: #print winf,' j ', tunnus if winf.find(t)==-1: koik=False if koik: if w.getWord().endswith(lopp.getWord()) or lopp.getWord()=='0': sobib=True klinfd.append(linf) klopud.append(lopp.getWord()) if sobib: ainulttyhi=True for klopp in klopud: if klopp!='0': ainulttyhi=False seletus="jah" if ainulttyhi: seletus="kahtlane" print seletus, ' ', w.getWord(), klinfd, klopud else: print "ei ", w.getWord()