mirror of
https://github.com/fxsjy/jieba.git
synced 2025-07-10 00:01:33 +08:00
Merge pull request #179 from changyy/master
新增自訂 cache_file 產生的目錄位置,可支援 jieba 運行在 Read-Only File System,如: Embedded Linux、Google App Engine 和 Heroku 等
This commit is contained in:
commit
1b4721ebb8
@ -23,6 +23,7 @@ total = 0
|
|||||||
user_word_tag_tab = {}
|
user_word_tag_tab = {}
|
||||||
initialized = False
|
initialized = False
|
||||||
pool = None
|
pool = None
|
||||||
|
tmp_dir = None
|
||||||
|
|
||||||
_curpath = os.path.normpath(
|
_curpath = os.path.normpath(
|
||||||
os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
||||||
@ -61,7 +62,7 @@ def gen_pfdict(f_name):
|
|||||||
|
|
||||||
|
|
||||||
def initialize(dictionary=None):
|
def initialize(dictionary=None):
|
||||||
global FREQ, total, initialized, DICTIONARY, DICT_LOCK
|
global FREQ, total, initialized, DICTIONARY, DICT_LOCK, tmp_dir
|
||||||
if not dictionary:
|
if not dictionary:
|
||||||
dictionary = DICTIONARY
|
dictionary = DICTIONARY
|
||||||
with DICT_LOCK:
|
with DICT_LOCK:
|
||||||
@ -73,9 +74,9 @@ def initialize(dictionary=None):
|
|||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
# default dictionary
|
# default dictionary
|
||||||
if abs_path == os.path.join(_curpath, "dict.txt"):
|
if abs_path == os.path.join(_curpath, "dict.txt"):
|
||||||
cache_file = os.path.join(tempfile.gettempdir(), "jieba.cache")
|
cache_file = os.path.join(tmp_dir if tmp_dir else tempfile.gettempdir(),"jieba.cache")
|
||||||
else: # custom dictionary
|
else: # custom dictionary
|
||||||
cache_file = os.path.join(tempfile.gettempdir(), "jieba.u%s.cache" % md5(
|
cache_file = os.path.join(tmp_dir if tmp_dir else tempfile.gettempdir(),"jieba.u%s.cache" % md5(
|
||||||
abs_path.encode('utf-8', 'replace')).hexdigest())
|
abs_path.encode('utf-8', 'replace')).hexdigest())
|
||||||
|
|
||||||
load_from_cache_fail = True
|
load_from_cache_fail = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user