From e1afafe353d0804a233e54d279e10a279464fb03 Mon Sep 17 00:00:00 2001 From: fxsjy Date: Sun, 23 Jun 2013 12:50:28 +0800 Subject: [PATCH] fix a bug of cxfree support --- jieba/__init__.py | 5 +++++ jieba/posseg/__init__.py | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/jieba/__init__.py b/jieba/__init__.py index dd43f46..1714ed4 100644 --- a/jieba/__init__.py +++ b/jieba/__init__.py @@ -324,3 +324,8 @@ def set_dictionary(dictionary_path): raise Exception("path does not exists:" + abs_path) DICTIONARY = abs_path initialized = False + +def get_abs_path_dict(): + _curpath=os.path.normpath( os.path.join( os.getcwd(), os.path.dirname(__file__) ) ) + abs_path = os.path.join(_curpath,DICTIONARY) + return abs_path diff --git a/jieba/posseg/__init__.py b/jieba/posseg/__init__.py index 233ffc1..de62765 100644 --- a/jieba/posseg/__init__.py +++ b/jieba/posseg/__init__.py @@ -17,14 +17,14 @@ def load_model(f_name): return eval(open(prob_p_path,"rb").read()) else: result = {} - for line in open(prob_p_path,"rb"): + for line in open(f_name,"rb"): line = line.strip() if line=="":continue word, _, tag = line.split(' ') result[word.decode('utf-8')]=tag return result -word_tag_tab = load_model("../dict.txt") +word_tag_tab = load_model(jieba.get_abs_path_dict()) if jieba.user_word_tag_tab: word_tag_tab.update(jieba.user_word_tag_tab) @@ -142,7 +142,7 @@ def __cut_internal(sentence): tmp = re_skip.split(blk) for x in tmp: if re_skip.match(x): - yield pair(x,'') + yield pair(x,'x') else: for xx in x: if re_num.match(xx):