Improving representation speed ~5%

This commit is contained in:
Ozbolt Menegatti 2019-06-02 13:50:53 +02:00
parent 5f226d0cd4
commit 460a55cb6c

12
wani.py
View File

@ -881,6 +881,7 @@ class WordMsdRenderer:
self.frequent_words = {}
self.lemma_msd = {}
self.lemma_features = lemma_features
self.memoized_msd_merges = {}
def add_words(self, words):
self.all_words.extend(words)
@ -918,8 +919,11 @@ class WordMsdRenderer:
l1 if l1 != "-" else l2 for l1, l2 in zip(lf[cmsd[0]], cmsd)
)
@staticmethod
def merge_msd(common_msd, new_msd):
def merge_msd(self, common_msd, new_msd):
key = (common_msd, new_msd)
if key in self.memoized_msd_merges:
return self.memoized_msd_merges[key]
def merge_letter(l1, l2):
if l1 == "*":
return l2
@ -928,7 +932,9 @@ class WordMsdRenderer:
else:
return l1
return "".join(merge_letter(l1, l2) for l1, l2 in zip(common_msd, new_msd))
value = "".join(merge_letter(l1, l2) for l1, l2 in zip(common_msd, new_msd))
self.memoized_msd_merges[key] = value
return value
def render(self, lemma, msd):
if lemma in self.rendered_words: