#!/usr/bin/python from os import path class Morfo(object): def __init__(self): self._cache = {} #print "start caching..." #print path.abspath('wordlist.out') f = open(path.abspath('wordlist.out'), 'r') currBuff = [] startCapture = False while 1: line = f.readline() if len(line) == 0: #EOF break l = line.strip() if startCapture and l != '#:)': if len(l) > 0: currBuff.append(unicode(line, 'iso-8859-1')) if l == '#:)': if startCapture: word, vari = self.handleBlock(currBuff) self._cache[word] = vari currBuff = [] startCapture = True # last block word, vari = self.handleBlock(currBuff) self._cache[word] = vari f.close() #print "... done" def handleBlock(self, lines): """ handle block """ w = lines[0].strip() variants = lines[1:] if len(variants) == 0: raise 'oo, zero!', lines res = [] for v in variants: res.append(v.strip()) return w, res def getinfo(self, word): if not isinstance(word, unicode): raise 'not a unicode!' m = self._cache.get(word) if m is not None and len(m)>0: for x in m: if '_Y_' in x: return None return m