Skip to content

Commit c7730ee

Browse files
committed
MLE disambig init no longer overwrites instance method for caching.
1 parent 01438bb commit c7730ee

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

camel_tools/disambig/mle.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,13 @@ def __init__(self, analyzer, mle_path=None, top=1, cache_size=100000):
133133
top = 1
134134
self._top = top
135135

136-
if cache_size < 0:
136+
if cache_size <= 0:
137137
cache_size = 0
138-
139-
self._cache = LFUCache(cache_size)
140-
self._scored_analyses = cached(self._cache)(
141-
self._scored_analyses)
138+
self._cache = None
139+
self._score_fn = self._scored_analyses
140+
else:
141+
self._cache = LFUCache(cache_size)
142+
self._score_fn = self._scored_analyses_cached
142143

143144
@staticmethod
144145
def pretrained(model_name=None, analyzer=None, top=1, cache_size=100000):
@@ -208,10 +209,13 @@ def _scored_analyses(self, word_dd):
208209
w.analysis['diac']))
209210

210211
return scored_analyses[0:self._top]
212+
213+
def _scored_analyses_cached(self, word_dd):
214+
return self._cache.get(word_dd, self._scored_analyses(word_dd))
211215

212216
def _disambiguate_word(self, word):
213217
word_dd = dediac_ar(word)
214-
scored_analyses = self._scored_analyses(word_dd)
218+
scored_analyses = self._score_fn(word_dd)
215219

216220
return DisambiguatedWord(word, scored_analyses)
217221

0 commit comments

Comments
 (0)