nagisa icon indicating copy to clipboard operation
nagisa copied to clipboard

add cache layer to Tagger

Open bung87 opened this issue 6 years ago • 4 comments

if instantiating Tagger at function level it will load dictionary every time, if instantiating Tagger at module level it will load dictionary therefore may not actually use refer to https://github.com/fxsjy/jieba/blob/master/jieba/init.py

bung87 avatar May 19 '18 14:05 bung87

Thanks for the advice. I interpreted adding some lines tagger = Tagger() and functions (e.g, tagging = tagger.taggging) to __init__.py. , is it correct?

taishi-i avatar May 20 '18 06:05 taishi-i

you may add a singleton tagger instance to init.py as a shorthand method that use the default dictionary and implement a initialize method for actually make io happen and use a cache layer, when call tagger.tagging or some else methods for end developer interface,check if it is initialized,if not initialize it.

bung87 avatar May 20 '18 07:05 bung87

Regarding a cache layer, should I refer to methods written on lines 91 to 168 in https://github.com/fxsjy/jieba/blob/master/jieba/init.py and add them to the class Tagger?

taishi-i avatar May 20 '18 16:05 taishi-i

not sure about.that ,you.may consider use https://docs.python.org/3/library/functools.html#functools.lru_cache for keep code simple

bung87 avatar May 20 '18 16:05 bung87