-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pickle dictionary store, +memoize on reloads
- Loading branch information
David Wright
committed
Mar 10, 2021
1 parent
941b211
commit d996dc4
Showing
3 changed files
with
135 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import phunspell | ||
import inspect | ||
import unittest | ||
|
||
dicts_words = { | ||
"af_ZA": "voortgewoed", | ||
"an_ES": "vengar", | ||
"be_BY": "ідалапаклонніцкі", | ||
"bg_BG": "удържехме", | ||
"br_FR": "c'huñvderioù", | ||
"de_DE": "schilffrei", | ||
"en_GB": "indict", | ||
"es_MX": "pianista", | ||
"fr_FR": "zoomorphe", | ||
} | ||
|
||
# use cache if already seen | ||
dicts_words_cached = { | ||
"an_ES": "vengar", | ||
"be_BY": "ідалапаклонніцкі", | ||
"bg_BG": "удържехме", | ||
} | ||
|
||
|
||
class TestMultiLoadCache(unittest.TestCase): | ||
pspell = phunspell.Phunspell() | ||
|
||
def test_multi_load_cache(self): | ||
for loc in dicts_words.keys(): | ||
self.assertTrue(self.pspell.lookup(dicts_words[loc], locs=loc)) | ||
|
||
for loc in dicts_words_cached.keys(): | ||
self.assertTrue(self.pspell.lookup(dicts_words[loc], locs=loc)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import phunspell | ||
import inspect | ||
import unittest | ||
|
||
dicts_words = { | ||
"af_ZA": "voortgewoed", | ||
"an_ES": "vengar", | ||
"be_BY": "ідалапаклонніцкі", | ||
"bg_BG": "удържехме", | ||
"br_FR": "c'huñvderioù", | ||
"de_DE": "schilffrei", | ||
"en_GB": "indict", | ||
"es_MX": "pianista", | ||
"fr_FR": "zoomorphe", | ||
} | ||
|
||
dicts_words_cached = { | ||
"an_ES": "vengar", | ||
"be_BY": "ідалапаклонніцкі", | ||
"bg_BG": "удържехме", | ||
} | ||
|
||
# TODO: | ||
# fix this upstream | ||
# re: reloading dictionaries is not handled upstream | ||
# ResourceWarning: Enable tracemalloc to get the object allocation traceback | ||
# /Users/dwright/Dev/python/misc/dw/lib/python3.8/site-packages/spylls/hunspell/dictionary.py:141: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/dwright/Dev/python/Phunspell/phunspell/data/dictionary/de/de_DE.aff' mode='r' encoding='ISO8859-1'> | ||
# aff, context = readers.read_aff(FileReader(path + '.aff')) | ||
# ResourceWarning: Enable tracemalloc to get the object allocation traceback | ||
|
||
|
||
class TestMultiLoadNoCache(unittest.TestCase): | ||
def test_multi_load_no_cache(self): | ||
for loc in dicts_words.keys(): | ||
# slower performance | ||
pspell = phunspell.Phunspell(loc) | ||
self.assertTrue(pspell.lookup(dicts_words[loc], locs=loc)) | ||
|
||
for loc in dicts_words_cached.keys(): | ||
# slower performance | ||
pspell = phunspell.Phunspell(loc) | ||
self.assertTrue(pspell.lookup(dicts_words[loc], locs=loc)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |