mirror of
https://github.com/fxsjy/jieba.git
synced 2025-07-10 00:01:33 +08:00
fix version; fix spaces at end of line
This commit is contained in:
parent
51df77831b
commit
bb1e6000c6
@ -3,7 +3,7 @@ import sys
|
|||||||
import jieba
|
import jieba
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
parser = ArgumentParser(usage="%s -m jieba [options] filename" % sys.executable, description="Jieba command line interface.", version="Jieba " + jieba.__version__, epilog="If no filename specified, use STDIN instead.")
|
parser = ArgumentParser(usage="%s -m jieba [options] filename" % sys.executable, description="Jieba command line interface.", epilog="If no filename specified, use STDIN instead.")
|
||||||
parser.add_argument("-d", "--delimiter", metavar="DELIM", default=' / ',
|
parser.add_argument("-d", "--delimiter", metavar="DELIM", default=' / ',
|
||||||
nargs='?', const=' ',
|
nargs='?', const=' ',
|
||||||
help="use DELIM instead of ' / ' for word delimiter; use a space if it is without DELIM")
|
help="use DELIM instead of ' / ' for word delimiter; use a space if it is without DELIM")
|
||||||
@ -14,6 +14,8 @@ parser.add_argument("-n", "--no-hmm", dest="hmm", action="store_false",
|
|||||||
default=True, help="don't use the Hidden Markov Model")
|
default=True, help="don't use the Hidden Markov Model")
|
||||||
parser.add_argument("-q", "--quiet", action="store_true", default=False,
|
parser.add_argument("-q", "--quiet", action="store_true", default=False,
|
||||||
help="don't print loading messages to stderr")
|
help="don't print loading messages to stderr")
|
||||||
|
parser.add_argument("-V", '--version', action='version',
|
||||||
|
version="Jieba " + jieba.__version__)
|
||||||
parser.add_argument("filename", nargs='?', help="input file")
|
parser.add_argument("filename", nargs='?', help="input file")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -23,19 +23,19 @@ def load_model():
|
|||||||
|
|
||||||
start_p = {}
|
start_p = {}
|
||||||
abs_path = os.path.join(_curpath, PROB_START_P)
|
abs_path = os.path.join(_curpath, PROB_START_P)
|
||||||
with open(abs_path, mode='rb') as f:
|
with open(abs_path, mode='r') as f:
|
||||||
start_p = marshal.load(f)
|
start_p = marshal.load(f)
|
||||||
f.closed
|
f.closed
|
||||||
|
|
||||||
trans_p = {}
|
trans_p = {}
|
||||||
abs_path = os.path.join(_curpath, PROB_TRANS_P)
|
abs_path = os.path.join(_curpath, PROB_TRANS_P)
|
||||||
with open(abs_path, 'rb') as f:
|
with open(abs_path, 'r') as f:
|
||||||
trans_p = marshal.load(f)
|
trans_p = marshal.load(f)
|
||||||
f.closed
|
f.closed
|
||||||
|
|
||||||
emit_p = {}
|
emit_p = {}
|
||||||
abs_path = os.path.join(_curpath, PROB_EMIT_P)
|
abs_path = os.path.join(_curpath, PROB_EMIT_P)
|
||||||
with file(abs_path, 'rb') as f:
|
with open(abs_path, 'r') as f:
|
||||||
emit_p = marshal.load(f)
|
emit_p = marshal.load(f)
|
||||||
f.closed
|
f.closed
|
||||||
|
|
||||||
|
@ -18,10 +18,11 @@ def load_model(f_name, isJython=True):
|
|||||||
_curpath = os.path.normpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
_curpath = os.path.normpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
with file(f_name, "rb") as f:
|
with open(f_name, "r") as f:
|
||||||
for line in open(f_name,"rb"):
|
for line in f:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line=="":continue
|
if not line:
|
||||||
|
continue
|
||||||
word, _, tag = line.split(' ')
|
word, _, tag = line.split(' ')
|
||||||
result[word.decode('utf-8')] = tag
|
result[word.decode('utf-8')] = tag
|
||||||
f.closed
|
f.closed
|
||||||
@ -30,25 +31,25 @@ def load_model(f_name, isJython=True):
|
|||||||
|
|
||||||
start_p = {}
|
start_p = {}
|
||||||
abs_path = os.path.join(_curpath, PROB_START_P)
|
abs_path = os.path.join(_curpath, PROB_START_P)
|
||||||
with open(abs_path, mode='rb') as f:
|
with open(abs_path, mode='r') as f:
|
||||||
start_p = marshal.load(f)
|
start_p = marshal.load(f)
|
||||||
f.closed
|
f.closed
|
||||||
|
|
||||||
trans_p = {}
|
trans_p = {}
|
||||||
abs_path = os.path.join(_curpath, PROB_TRANS_P)
|
abs_path = os.path.join(_curpath, PROB_TRANS_P)
|
||||||
with open(abs_path, 'rb') as f:
|
with open(abs_path, 'r') as f:
|
||||||
trans_p = marshal.load(f)
|
trans_p = marshal.load(f)
|
||||||
f.closed
|
f.closed
|
||||||
|
|
||||||
emit_p = {}
|
emit_p = {}
|
||||||
abs_path = os.path.join(_curpath, PROB_EMIT_P)
|
abs_path = os.path.join(_curpath, PROB_EMIT_P)
|
||||||
with file(abs_path, 'rb') as f:
|
with open(abs_path, 'r') as f:
|
||||||
emit_p = marshal.load(f)
|
emit_p = marshal.load(f)
|
||||||
f.closed
|
f.closed
|
||||||
|
|
||||||
state = {}
|
state = {}
|
||||||
abs_path = os.path.join(_curpath, CHAR_STATE_TAB_P)
|
abs_path = os.path.join(_curpath, CHAR_STATE_TAB_P)
|
||||||
with file(abs_path, 'rb') as f:
|
with open(abs_path, 'r') as f:
|
||||||
state = marshal.load(f)
|
state = marshal.load(f)
|
||||||
f.closed
|
f.closed
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ def makesure_userdict_loaded(fn):
|
|||||||
|
|
||||||
@wraps(fn)
|
@wraps(fn)
|
||||||
def wrapped(*args,**kwargs):
|
def wrapped(*args,**kwargs):
|
||||||
if len(jieba.user_word_tag_tab)>0:
|
if jieba.user_word_tag_tab:
|
||||||
word_tag_tab.update(jieba.user_word_tag_tab)
|
word_tag_tab.update(jieba.user_word_tag_tab)
|
||||||
jieba.user_word_tag_tab = {}
|
jieba.user_word_tag_tab = {}
|
||||||
return fn(*args,**kwargs)
|
return fn(*args,**kwargs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user