fixed performance bug for representations

No more creating millions of namedtuple classes. Works about 15x faster
This commit is contained in:
Ozbolt Menegatti 2019-06-11 10:26:10 +02:00
parent 3be4118dc0
commit c0939fbbd4

18
wani.py
View File

@ -261,9 +261,7 @@ class WordFormMsdCR(WordFormAnyCR):
def _render(self):
msd = self.word_renderer.get_lemma_msd(self.lemma, self.msd)
WordLemma = namedtuple('WordLemmaOnly', 'msd most_frequent_text lemma text')
backup_word = WordLemma(msd=msd, most_frequent_text=lambda *x: None, lemma=None, text=None)
self.words.append(backup_word)
self.words.append(WordMsdOnly(msd))
return super()._render()
@ -832,12 +830,16 @@ def get_msd(comp):
logging.error(d, file=sys.stderr)
raise NotImplementedError("MSD?")
def lemma_only_word(msd):
if msd is None:
class WordMsdOnly:
def __init__(self, msd):
self.msd = msd
self.lemma = None
self.text = None
def most_frequent_text(self, _):
return None
else:
WordLemma = namedtuple('WordLemmaOnly', 'msd most_frequent_text lemma text')
return WordLemma(msd=msd, most_frequent_text=lambda *x: None, lemma=None, text=None)
class Word:
def __init__(self, xml, do_msd_translate):