Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed bug where scored analyses for MLE disambiguation are not stored… #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion camel_tools/disambig/mle.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,13 @@ def _scored_analyses(self, word_dd):
return scored_analyses[0:self._top]

def _scored_analyses_cached(self, word_dd):
return self._cache.get(word_dd, self._scored_analyses(word_dd))
if word_dd in self._cache:
scored_analyses = self._cache[word_dd]
else:
scored_analyses = self._scored_analyses(word_dd)
self._cache[word_dd] = scored_analyses

return scored_analyses

def _disambiguate_word(self, word):
word_dd = dediac_ar(word)
Expand Down
17 changes: 17 additions & 0 deletions camel_tools/disambig/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from cachetools import LFUCache, cached
import time

class TestClass:
def __init__(self):
self._cache = LFUCache(100000)

@cached(cache=lambda self: self._cache, key=lambda self, word_dd: word_dd)
def test_cached(self, word_dd):
return word_dd


# Example usage:
test = TestClass()
test.test_cached("hello")

test.test_cached("hello")