Skip to content

Commit

Permalink
MLE disambig init no longer overwrites instance method for caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
owo committed May 17, 2022
1 parent 01438bb commit c7730ee
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions camel_tools/disambig/mle.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ def __init__(self, analyzer, mle_path=None, top=1, cache_size=100000):
top = 1
self._top = top

if cache_size < 0:
if cache_size <= 0:
cache_size = 0

self._cache = LFUCache(cache_size)
self._scored_analyses = cached(self._cache)(
self._scored_analyses)
self._cache = None
self._score_fn = self._scored_analyses
else:
self._cache = LFUCache(cache_size)
self._score_fn = self._scored_analyses_cached

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

return scored_analyses[0:self._top]

def _scored_analyses_cached(self, word_dd):
return self._cache.get(word_dd, self._scored_analyses(word_dd))

def _disambiguate_word(self, word):
word_dd = dediac_ar(word)
scored_analyses = self._scored_analyses(word_dd)
scored_analyses = self._score_fn(word_dd)

return DisambiguatedWord(word, scored_analyses)

Expand Down

0 comments on commit c7730ee

Please sign in to comment.