mirror of
https://github.com/fxsjy/jieba.git
synced 2025-07-10 00:01:33 +08:00
PEP8
This commit is contained in:
parent
ca97b19951
commit
b62f052927
@ -23,313 +23,313 @@ user_word_tag_tab={}
|
|||||||
initialized = False
|
initialized = False
|
||||||
|
|
||||||
def gen_trie(f_name):
|
def gen_trie(f_name):
|
||||||
lfreq = {}
|
lfreq = {}
|
||||||
trie = {}
|
trie = {}
|
||||||
ltotal = 0.0
|
ltotal = 0.0
|
||||||
with open(f_name, 'rb') as f:
|
with open(f_name, 'rb') as f:
|
||||||
lineno = 0
|
lineno = 0
|
||||||
for line in f.read().rstrip().decode('utf-8').split('\n'):
|
for line in f.read().rstrip().decode('utf-8').split('\n'):
|
||||||
lineno += 1
|
lineno += 1
|
||||||
try:
|
try:
|
||||||
word,freq,_ = line.split(' ')
|
word,freq,_ = line.split(' ')
|
||||||
freq = float(freq)
|
freq = float(freq)
|
||||||
lfreq[word] = freq
|
lfreq[word] = freq
|
||||||
ltotal+=freq
|
ltotal+=freq
|
||||||
p = trie
|
p = trie
|
||||||
for c in word:
|
for c in word:
|
||||||
if not c in p:
|
if not c in p:
|
||||||
p[c] ={}
|
p[c] ={}
|
||||||
p = p[c]
|
p = p[c]
|
||||||
p['']='' #ending flag
|
p['']='' #ending flag
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print(f_name,' at line',lineno,line, file=sys.stderr)
|
print(f_name,' at line',lineno,line, file=sys.stderr)
|
||||||
raise e
|
raise e
|
||||||
return trie, lfreq,ltotal
|
return trie, lfreq,ltotal
|
||||||
|
|
||||||
def initialize(*args):
|
def initialize(*args):
|
||||||
global trie, FREQ, total, min_freq, initialized
|
global trie, FREQ, total, min_freq, initialized
|
||||||
if len(args)==0:
|
if len(args)==0:
|
||||||
dictionary = DICTIONARY
|
dictionary = DICTIONARY
|
||||||
else:
|
else:
|
||||||
dictionary = args[0]
|
dictionary = args[0]
|
||||||
with DICT_LOCK:
|
with DICT_LOCK:
|
||||||
if initialized:
|
if initialized:
|
||||||
return
|
return
|
||||||
if trie:
|
if trie:
|
||||||
del trie
|
del trie
|
||||||
trie = None
|
trie = None
|
||||||
_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__) ) )
|
||||||
|
|
||||||
abs_path = os.path.join(_curpath,dictionary)
|
abs_path = os.path.join(_curpath,dictionary)
|
||||||
print("Building Trie..., from " + abs_path, file=sys.stderr)
|
print("Building Trie..., from " + abs_path, file=sys.stderr)
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
if abs_path == os.path.join(_curpath,"dict.txt"): #defautl dictionary
|
if abs_path == os.path.join(_curpath,"dict.txt"): #defautl dictionary
|
||||||
cache_file = os.path.join(tempfile.gettempdir(),"jieba.cache")
|
cache_file = os.path.join(tempfile.gettempdir(),"jieba.cache")
|
||||||
else: #customer dictionary
|
else: #customer dictionary
|
||||||
cache_file = os.path.join(tempfile.gettempdir(),"jieba.user."+str(hash(abs_path))+".cache")
|
cache_file = os.path.join(tempfile.gettempdir(),"jieba.user."+str(hash(abs_path))+".cache")
|
||||||
|
|
||||||
load_from_cache_fail = True
|
load_from_cache_fail = True
|
||||||
if os.path.exists(cache_file) and os.path.getmtime(cache_file)>os.path.getmtime(abs_path):
|
if os.path.exists(cache_file) and os.path.getmtime(cache_file)>os.path.getmtime(abs_path):
|
||||||
print("loading model from cache " + cache_file, file=sys.stderr)
|
print("loading model from cache " + cache_file, file=sys.stderr)
|
||||||
try:
|
try:
|
||||||
trie,FREQ,total,min_freq = marshal.load(open(cache_file,'rb'))
|
trie,FREQ,total,min_freq = marshal.load(open(cache_file,'rb'))
|
||||||
load_from_cache_fail = False
|
load_from_cache_fail = False
|
||||||
except:
|
except:
|
||||||
load_from_cache_fail = True
|
load_from_cache_fail = True
|
||||||
|
|
||||||
if load_from_cache_fail:
|
if load_from_cache_fail:
|
||||||
trie,FREQ,total = gen_trie(abs_path)
|
trie,FREQ,total = gen_trie(abs_path)
|
||||||
FREQ = dict([(k,log(float(v)/total)) for k,v in FREQ.items()]) #normalize
|
FREQ = dict([(k,log(float(v)/total)) for k,v in FREQ.items()]) #normalize
|
||||||
min_freq = min(FREQ.values())
|
min_freq = min(FREQ.values())
|
||||||
print("dumping model to file cache " + cache_file, file=sys.stderr)
|
print("dumping model to file cache " + cache_file, file=sys.stderr)
|
||||||
tmp_suffix = "."+str(random.random())
|
tmp_suffix = "."+str(random.random())
|
||||||
with open(cache_file+tmp_suffix,'wb') as temp_cache_file:
|
with open(cache_file+tmp_suffix,'wb') as temp_cache_file:
|
||||||
marshal.dump((trie,FREQ,total,min_freq),temp_cache_file)
|
marshal.dump((trie,FREQ,total,min_freq),temp_cache_file)
|
||||||
if os.name=='nt':
|
if os.name=='nt':
|
||||||
import shutil
|
import shutil
|
||||||
replace_file = shutil.move
|
replace_file = shutil.move
|
||||||
else:
|
else:
|
||||||
replace_file = os.rename
|
replace_file = os.rename
|
||||||
replace_file(cache_file+tmp_suffix,cache_file)
|
replace_file(cache_file+tmp_suffix,cache_file)
|
||||||
|
|
||||||
initialized = True
|
initialized = True
|
||||||
|
|
||||||
print("loading model cost ", time.time() - t1, "seconds.",file=sys.stderr)
|
print("loading model cost ", time.time() - t1, "seconds.",file=sys.stderr)
|
||||||
print("Trie has been built succesfully.", file=sys.stderr)
|
print("Trie has been built succesfully.", file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def require_initialized(fn):
|
def require_initialized(fn):
|
||||||
global initialized,DICTIONARY
|
global initialized,DICTIONARY
|
||||||
|
|
||||||
@wraps(fn)
|
@wraps(fn)
|
||||||
def wrapped(*args, **kwargs):
|
def wrapped(*args, **kwargs):
|
||||||
if initialized:
|
if initialized:
|
||||||
return fn(*args, **kwargs)
|
return fn(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
initialize(DICTIONARY)
|
initialize(DICTIONARY)
|
||||||
return fn(*args, **kwargs)
|
return fn(*args, **kwargs)
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
def __cut_all(sentence):
|
def __cut_all(sentence):
|
||||||
dag = get_DAG(sentence)
|
dag = get_DAG(sentence)
|
||||||
old_j = -1
|
old_j = -1
|
||||||
for k,L in dag.items():
|
for k,L in dag.items():
|
||||||
if len(L)==1 and k>old_j:
|
if len(L)==1 and k>old_j:
|
||||||
yield sentence[k:L[0]+1]
|
yield sentence[k:L[0]+1]
|
||||||
old_j = L[0]
|
old_j = L[0]
|
||||||
else:
|
else:
|
||||||
for j in L:
|
for j in L:
|
||||||
if j>k:
|
if j>k:
|
||||||
yield sentence[k:j+1]
|
yield sentence[k:j+1]
|
||||||
old_j = j
|
old_j = j
|
||||||
|
|
||||||
|
|
||||||
def calc(sentence,DAG,idx,route):
|
def calc(sentence,DAG,idx,route):
|
||||||
N = len(sentence)
|
N = len(sentence)
|
||||||
route[N] = (0.0,'')
|
route[N] = (0.0,'')
|
||||||
for idx in range(N-1,-1,-1):
|
for idx in range(N-1,-1,-1):
|
||||||
candidates = [ ( FREQ.get(sentence[idx:x+1],min_freq) + route[x+1][0],x ) for x in DAG[idx] ]
|
candidates = [ ( FREQ.get(sentence[idx:x+1],min_freq) + route[x+1][0],x ) for x in DAG[idx] ]
|
||||||
route[idx] = max(candidates)
|
route[idx] = max(candidates)
|
||||||
|
|
||||||
@require_initialized
|
@require_initialized
|
||||||
def get_DAG(sentence):
|
def get_DAG(sentence):
|
||||||
N = len(sentence)
|
N = len(sentence)
|
||||||
i,j=0,0
|
i,j=0,0
|
||||||
p = trie
|
p = trie
|
||||||
DAG = {}
|
DAG = {}
|
||||||
while i<N:
|
while i<N:
|
||||||
c = sentence[j]
|
c = sentence[j]
|
||||||
if c in p:
|
if c in p:
|
||||||
p = p[c]
|
p = p[c]
|
||||||
if '' in p:
|
if '' in p:
|
||||||
if not i in DAG:
|
if not i in DAG:
|
||||||
DAG[i]=[]
|
DAG[i]=[]
|
||||||
DAG[i].append(j)
|
DAG[i].append(j)
|
||||||
j+=1
|
j+=1
|
||||||
if j>=N:
|
if j>=N:
|
||||||
i+=1
|
i+=1
|
||||||
j=i
|
j=i
|
||||||
p=trie
|
p=trie
|
||||||
else:
|
else:
|
||||||
p = trie
|
p = trie
|
||||||
i+=1
|
i+=1
|
||||||
j=i
|
j=i
|
||||||
for i in range(len(sentence)):
|
for i in range(len(sentence)):
|
||||||
if not i in DAG:
|
if not i in DAG:
|
||||||
DAG[i] =[i]
|
DAG[i] =[i]
|
||||||
return DAG
|
return DAG
|
||||||
|
|
||||||
|
|
||||||
def __cut_DAG(sentence):
|
def __cut_DAG(sentence):
|
||||||
DAG = get_DAG(sentence)
|
DAG = get_DAG(sentence)
|
||||||
route ={}
|
route ={}
|
||||||
calc(sentence,DAG,0,route=route)
|
calc(sentence,DAG,0,route=route)
|
||||||
x = 0
|
x = 0
|
||||||
buf =''
|
buf =''
|
||||||
N = len(sentence)
|
N = len(sentence)
|
||||||
while x<N:
|
while x<N:
|
||||||
y = route[x][1]+1
|
y = route[x][1]+1
|
||||||
l_word = sentence[x:y]
|
l_word = sentence[x:y]
|
||||||
if y-x==1:
|
if y-x==1:
|
||||||
buf+= l_word
|
buf+= l_word
|
||||||
else:
|
else:
|
||||||
if len(buf)>0:
|
if len(buf)>0:
|
||||||
if len(buf)==1:
|
if len(buf)==1:
|
||||||
yield buf
|
yield buf
|
||||||
buf=''
|
buf=''
|
||||||
else:
|
else:
|
||||||
if not (buf in FREQ):
|
if not (buf in FREQ):
|
||||||
regognized = finalseg.cut(buf)
|
regognized = finalseg.cut(buf)
|
||||||
for t in regognized:
|
for t in regognized:
|
||||||
yield t
|
yield t
|
||||||
else:
|
else:
|
||||||
for elem in buf:
|
for elem in buf:
|
||||||
yield elem
|
yield elem
|
||||||
buf=''
|
buf=''
|
||||||
yield l_word
|
yield l_word
|
||||||
x =y
|
x =y
|
||||||
|
|
||||||
if len(buf)>0:
|
if len(buf)>0:
|
||||||
if len(buf)==1:
|
if len(buf)==1:
|
||||||
yield buf
|
yield buf
|
||||||
else:
|
else:
|
||||||
if not (buf in FREQ):
|
if not (buf in FREQ):
|
||||||
regognized = finalseg.cut(buf)
|
regognized = finalseg.cut(buf)
|
||||||
for t in regognized:
|
for t in regognized:
|
||||||
yield t
|
yield t
|
||||||
else:
|
else:
|
||||||
for elem in buf:
|
for elem in buf:
|
||||||
yield elem
|
yield elem
|
||||||
|
|
||||||
def cut(sentence,cut_all=False):
|
def cut(sentence,cut_all=False):
|
||||||
if( type(sentence) is bytes):
|
if( type(sentence) is bytes):
|
||||||
try:
|
try:
|
||||||
sentence = sentence.decode('utf-8')
|
sentence = sentence.decode('utf-8')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
sentence = sentence.decode('gbk','ignore')
|
sentence = sentence.decode('gbk','ignore')
|
||||||
|
|
||||||
re_han, re_skip = re.compile("([\u4E00-\u9FA5a-zA-Z0-9+#&\._]+)"), re.compile("(\s+)")
|
re_han, re_skip = re.compile("([\u4E00-\u9FA5a-zA-Z0-9+#&\._]+)"), re.compile("(\s+)")
|
||||||
|
|
||||||
if cut_all:
|
if cut_all:
|
||||||
re_han, re_skip = re.compile("([\u4E00-\u9FA5]+)"), re.compile("[^a-zA-Z0-9+#\n]")
|
re_han, re_skip = re.compile("([\u4E00-\u9FA5]+)"), re.compile("[^a-zA-Z0-9+#\n]")
|
||||||
|
|
||||||
blocks = re_han.split(sentence)
|
blocks = re_han.split(sentence)
|
||||||
cut_block = __cut_DAG
|
cut_block = __cut_DAG
|
||||||
if cut_all:
|
if cut_all:
|
||||||
cut_block = __cut_all
|
cut_block = __cut_all
|
||||||
for blk in blocks:
|
for blk in blocks:
|
||||||
if re_han.match(blk):
|
if re_han.match(blk):
|
||||||
#pprint.pprint(__cut_DAG(blk))
|
#pprint.pprint(__cut_DAG(blk))
|
||||||
for word in cut_block(blk):
|
for word in cut_block(blk):
|
||||||
yield word
|
yield word
|
||||||
else:
|
else:
|
||||||
tmp = re_skip.split(blk)
|
tmp = re_skip.split(blk)
|
||||||
for x in tmp:
|
for x in tmp:
|
||||||
if re_skip.match(x):
|
if re_skip.match(x):
|
||||||
yield x
|
yield x
|
||||||
elif not cut_all:
|
elif not cut_all:
|
||||||
for xx in x:
|
for xx in x:
|
||||||
yield xx
|
yield xx
|
||||||
else:
|
else:
|
||||||
yield x
|
yield x
|
||||||
|
|
||||||
def cut_for_search(sentence):
|
def cut_for_search(sentence):
|
||||||
words = cut(sentence)
|
words = cut(sentence)
|
||||||
for w in words:
|
for w in words:
|
||||||
if len(w)>2:
|
if len(w)>2:
|
||||||
for i in range(len(w)-1):
|
for i in range(len(w)-1):
|
||||||
gram2 = w[i:i+2]
|
gram2 = w[i:i+2]
|
||||||
if gram2 in FREQ:
|
if gram2 in FREQ:
|
||||||
yield gram2
|
yield gram2
|
||||||
if len(w)>3:
|
if len(w)>3:
|
||||||
for i in range(len(w)-2):
|
for i in range(len(w)-2):
|
||||||
gram3 = w[i:i+3]
|
gram3 = w[i:i+3]
|
||||||
if gram3 in FREQ:
|
if gram3 in FREQ:
|
||||||
yield gram3
|
yield gram3
|
||||||
yield w
|
yield w
|
||||||
|
|
||||||
@require_initialized
|
@require_initialized
|
||||||
def load_userdict(f):
|
def load_userdict(f):
|
||||||
global trie,total,FREQ
|
global trie,total,FREQ
|
||||||
if isinstance(f, (str, )):
|
if isinstance(f, (str, )):
|
||||||
f = open(f, 'rb')
|
f = open(f, 'rb')
|
||||||
content = f.read().decode('utf-8')
|
content = f.read().decode('utf-8')
|
||||||
line_no = 0
|
line_no = 0
|
||||||
for line in content.split("\n"):
|
for line in content.split("\n"):
|
||||||
line_no+=1
|
line_no+=1
|
||||||
if line.rstrip()=='': continue
|
if line.rstrip()=='': continue
|
||||||
tup =line.split(" ")
|
tup =line.split(" ")
|
||||||
word,freq = tup[0],tup[1]
|
word,freq = tup[0],tup[1]
|
||||||
if line_no==1:
|
if line_no==1:
|
||||||
word = word.replace('\ufeff',"") #remove bom flag if it exists
|
word = word.replace('\ufeff',"") #remove bom flag if it exists
|
||||||
if len(tup)==3:
|
if len(tup)==3:
|
||||||
user_word_tag_tab[word]=tup[2].strip()
|
user_word_tag_tab[word]=tup[2].strip()
|
||||||
freq = float(freq)
|
freq = float(freq)
|
||||||
FREQ[word] = log(freq / total)
|
FREQ[word] = log(freq / total)
|
||||||
p = trie
|
p = trie
|
||||||
for c in word:
|
for c in word:
|
||||||
if not c in p:
|
if not c in p:
|
||||||
p[c] ={}
|
p[c] ={}
|
||||||
p = p[c]
|
p = p[c]
|
||||||
p['']='' #ending flag
|
p['']='' #ending flag
|
||||||
|
|
||||||
__ref_cut = cut
|
__ref_cut = cut
|
||||||
__ref_cut_for_search = cut_for_search
|
__ref_cut_for_search = cut_for_search
|
||||||
|
|
||||||
def __lcut(sentence):
|
def __lcut(sentence):
|
||||||
return list(__ref_cut(sentence,False))
|
return list(__ref_cut(sentence,False))
|
||||||
def __lcut_all(sentence):
|
def __lcut_all(sentence):
|
||||||
return list(__ref_cut(sentence,True))
|
return list(__ref_cut(sentence,True))
|
||||||
def __lcut_for_search(sentence):
|
def __lcut_for_search(sentence):
|
||||||
return list(__ref_cut_for_search(sentence))
|
return list(__ref_cut_for_search(sentence))
|
||||||
|
|
||||||
@require_initialized
|
@require_initialized
|
||||||
def enable_parallel(processnum):
|
def enable_parallel(processnum):
|
||||||
global pool,cut,cut_for_search
|
global pool,cut,cut_for_search
|
||||||
if os.name=='nt':
|
if os.name=='nt':
|
||||||
raise Exception("parallel mode only supports posix system")
|
raise Exception("parallel mode only supports posix system")
|
||||||
|
|
||||||
from multiprocessing import Pool
|
from multiprocessing import Pool
|
||||||
pool = Pool(processnum)
|
pool = Pool(processnum)
|
||||||
|
|
||||||
def pcut(sentence,cut_all=False):
|
def pcut(sentence,cut_all=False):
|
||||||
parts = re.compile(b'([\r\n]+)').split(sentence)
|
parts = re.compile(b'([\r\n]+)').split(sentence)
|
||||||
if cut_all:
|
if cut_all:
|
||||||
result = pool.map(__lcut_all,parts)
|
result = pool.map(__lcut_all,parts)
|
||||||
else:
|
else:
|
||||||
result = pool.map(__lcut,parts)
|
result = pool.map(__lcut,parts)
|
||||||
for r in result:
|
for r in result:
|
||||||
for w in r:
|
for w in r:
|
||||||
yield w
|
yield w
|
||||||
|
|
||||||
def pcut_for_search(sentence):
|
def pcut_for_search(sentence):
|
||||||
parts = re.compile(b'([\r\n]+)').split(sentence)
|
parts = re.compile(b'([\r\n]+)').split(sentence)
|
||||||
result = pool.map(__lcut_for_search,parts)
|
result = pool.map(__lcut_for_search,parts)
|
||||||
for r in result:
|
for r in result:
|
||||||
for w in r:
|
for w in r:
|
||||||
yield w
|
yield w
|
||||||
|
|
||||||
cut = pcut
|
cut = pcut
|
||||||
cut_for_search = pcut_for_search
|
cut_for_search = pcut_for_search
|
||||||
|
|
||||||
def disable_parallel():
|
def disable_parallel():
|
||||||
global pool,cut,cut_for_search
|
global pool,cut,cut_for_search
|
||||||
if 'pool' in globals():
|
if 'pool' in globals():
|
||||||
pool.close()
|
pool.close()
|
||||||
pool = None
|
pool = None
|
||||||
cut = __ref_cut
|
cut = __ref_cut
|
||||||
cut_for_search = __ref_cut_for_search
|
cut_for_search = __ref_cut_for_search
|
||||||
|
|
||||||
def set_dictionary(dictionary_path):
|
def set_dictionary(dictionary_path):
|
||||||
global initialized, DICTIONARY
|
global initialized, DICTIONARY
|
||||||
with DICT_LOCK:
|
with DICT_LOCK:
|
||||||
abs_path = os.path.normpath( os.path.join( os.getcwd(), dictionary_path ) )
|
abs_path = os.path.normpath( os.path.join( os.getcwd(), dictionary_path ) )
|
||||||
if not os.path.exists(abs_path):
|
if not os.path.exists(abs_path):
|
||||||
raise Exception("path does not exists:" + abs_path)
|
raise Exception("path does not exists:" + abs_path)
|
||||||
DICTIONARY = abs_path
|
DICTIONARY = abs_path
|
||||||
initialized = False
|
initialized = False
|
||||||
|
|
||||||
def get_abs_path_dict():
|
def get_abs_path_dict():
|
||||||
_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__) ) )
|
||||||
abs_path = os.path.join(_curpath,DICTIONARY)
|
abs_path = os.path.join(_curpath,DICTIONARY)
|
||||||
return abs_path
|
return abs_path
|
||||||
|
@ -8,8 +8,8 @@ content = open(f_name,'rb').read().decode('utf-8')
|
|||||||
idf_freq = {}
|
idf_freq = {}
|
||||||
lines = content.split('\n')
|
lines = content.split('\n')
|
||||||
for line in lines:
|
for line in lines:
|
||||||
word,freq = line.split(' ')
|
word,freq = line.split(' ')
|
||||||
idf_freq[word] = float(freq)
|
idf_freq[word] = float(freq)
|
||||||
|
|
||||||
median_idf = sorted(idf_freq.values())[int(len(idf_freq)/2)]
|
median_idf = sorted(idf_freq.values())[int(len(idf_freq)/2)]
|
||||||
stop_words= set([
|
stop_words= set([
|
||||||
@ -17,18 +17,18 @@ stop_words= set([
|
|||||||
])
|
])
|
||||||
|
|
||||||
def extract_tags(sentence,topK=20):
|
def extract_tags(sentence,topK=20):
|
||||||
words = jieba.cut(sentence)
|
words = jieba.cut(sentence)
|
||||||
freq = {}
|
freq = {}
|
||||||
for w in words:
|
for w in words:
|
||||||
if len(w.strip())<2: continue
|
if len(w.strip())<2: continue
|
||||||
if w.lower() in stop_words: continue
|
if w.lower() in stop_words: continue
|
||||||
freq[w]=freq.get(w,0.0)+1.0
|
freq[w]=freq.get(w,0.0)+1.0
|
||||||
total = sum(freq.values())
|
total = sum(freq.values())
|
||||||
freq = [(k,v/total) for k,v in freq.items()]
|
freq = [(k,v/total) for k,v in freq.items()]
|
||||||
|
|
||||||
tf_idf_list = [(v * idf_freq.get(k,median_idf),k) for k,v in freq]
|
tf_idf_list = [(v * idf_freq.get(k,median_idf),k) for k,v in freq]
|
||||||
st_list = sorted(tf_idf_list,reverse=True)
|
st_list = sorted(tf_idf_list,reverse=True)
|
||||||
|
|
||||||
top_tuples= st_list[:topK]
|
top_tuples= st_list[:topK]
|
||||||
tags = [a[1] for a in top_tuples]
|
tags = [a[1] for a in top_tuples]
|
||||||
return tags
|
return tags
|
||||||
|
@ -8,66 +8,66 @@ from . import prob_emit
|
|||||||
MIN_FLOAT=-3.14e100
|
MIN_FLOAT=-3.14e100
|
||||||
|
|
||||||
PrevStatus = {
|
PrevStatus = {
|
||||||
'B':('E','S'),
|
'B':('E','S'),
|
||||||
'M':('M','B'),
|
'M':('M','B'),
|
||||||
'S':('S','E'),
|
'S':('S','E'),
|
||||||
'E':('B','M')
|
'E':('B','M')
|
||||||
}
|
}
|
||||||
|
|
||||||
def viterbi(obs, states, start_p, trans_p, emit_p):
|
def viterbi(obs, states, start_p, trans_p, emit_p):
|
||||||
V = [{}] #tabular
|
V = [{}] #tabular
|
||||||
path = {}
|
path = {}
|
||||||
for y in states: #init
|
for y in states: #init
|
||||||
V[0][y] = start_p[y] + emit_p[y].get(obs[0],MIN_FLOAT)
|
V[0][y] = start_p[y] + emit_p[y].get(obs[0],MIN_FLOAT)
|
||||||
path[y] = [y]
|
path[y] = [y]
|
||||||
for t in range(1,len(obs)):
|
for t in range(1,len(obs)):
|
||||||
V.append({})
|
V.append({})
|
||||||
newpath = {}
|
newpath = {}
|
||||||
for y in states:
|
for y in states:
|
||||||
em_p = emit_p[y].get(obs[t],MIN_FLOAT)
|
em_p = emit_p[y].get(obs[t],MIN_FLOAT)
|
||||||
(prob,state ) = max([(V[t-1][y0] + trans_p[y0].get(y,MIN_FLOAT) + em_p ,y0) for y0 in PrevStatus[y] ])
|
(prob,state ) = max([(V[t-1][y0] + trans_p[y0].get(y,MIN_FLOAT) + em_p ,y0) for y0 in PrevStatus[y] ])
|
||||||
V[t][y] =prob
|
V[t][y] =prob
|
||||||
newpath[y] = path[state] + [y]
|
newpath[y] = path[state] + [y]
|
||||||
path = newpath
|
path = newpath
|
||||||
|
|
||||||
(prob, state) = max([(V[len(obs) - 1][y], y) for y in ('E','S')])
|
(prob, state) = max([(V[len(obs) - 1][y], y) for y in ('E','S')])
|
||||||
|
|
||||||
return (prob, path[state])
|
return (prob, path[state])
|
||||||
|
|
||||||
|
|
||||||
def __cut(sentence):
|
def __cut(sentence):
|
||||||
prob, pos_list = viterbi(sentence,('B','M','E','S'), prob_start.P, prob_trans.P, prob_emit.P)
|
prob, pos_list = viterbi(sentence,('B','M','E','S'), prob_start.P, prob_trans.P, prob_emit.P)
|
||||||
begin, next = 0,0
|
begin, next = 0,0
|
||||||
#print pos_list, sentence
|
#print pos_list, sentence
|
||||||
for i,char in enumerate(sentence):
|
for i,char in enumerate(sentence):
|
||||||
pos = pos_list[i]
|
pos = pos_list[i]
|
||||||
if pos=='B':
|
if pos=='B':
|
||||||
begin = i
|
begin = i
|
||||||
elif pos=='E':
|
elif pos=='E':
|
||||||
yield sentence[begin:i+1]
|
yield sentence[begin:i+1]
|
||||||
next = i+1
|
next = i+1
|
||||||
elif pos=='S':
|
elif pos=='S':
|
||||||
yield char
|
yield char
|
||||||
next = i+1
|
next = i+1
|
||||||
if next<len(sentence):
|
if next<len(sentence):
|
||||||
yield sentence[next:]
|
yield sentence[next:]
|
||||||
|
|
||||||
def cut(sentence):
|
def cut(sentence):
|
||||||
if not ( type(sentence) is str):
|
if not ( type(sentence) is str):
|
||||||
try:
|
try:
|
||||||
sentence = sentence.decode('utf-8')
|
sentence = sentence.decode('utf-8')
|
||||||
except:
|
except:
|
||||||
sentence = sentence.decode('gbk','ignore')
|
sentence = sentence.decode('gbk','ignore')
|
||||||
|
|
||||||
re_han, re_skip = re.compile("([\u4E00-\u9FA5]+)"), re.compile("([\.0-9]+|[a-zA-Z0-9]+)")
|
re_han, re_skip = re.compile("([\u4E00-\u9FA5]+)"), re.compile("([\.0-9]+|[a-zA-Z0-9]+)")
|
||||||
|
|
||||||
blocks = re_han.split(sentence)
|
blocks = re_han.split(sentence)
|
||||||
for blk in blocks:
|
for blk in blocks:
|
||||||
if re_han.match(blk):
|
if re_han.match(blk):
|
||||||
for word in __cut(blk):
|
for word in __cut(blk):
|
||||||
yield word
|
yield word
|
||||||
else:
|
else:
|
||||||
tmp = re_skip.split(blk)
|
tmp = re_skip.split(blk)
|
||||||
for x in tmp:
|
for x in tmp:
|
||||||
if x!="":
|
if x!="":
|
||||||
yield x
|
yield x
|
||||||
|
@ -11,163 +11,163 @@ from . import char_state_tab
|
|||||||
default_encoding = sys.getfilesystemencoding()
|
default_encoding = sys.getfilesystemencoding()
|
||||||
|
|
||||||
def load_model(f_name):
|
def load_model(f_name):
|
||||||
_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__) ) )
|
||||||
prob_p_path = os.path.join(_curpath,f_name)
|
prob_p_path = os.path.join(_curpath,f_name)
|
||||||
if f_name.endswith(".py"):
|
if f_name.endswith(".py"):
|
||||||
return eval(open(prob_p_path,"rb").read())
|
return eval(open(prob_p_path,"rb").read())
|
||||||
else:
|
else:
|
||||||
result = {}
|
result = {}
|
||||||
for line in open(f_name,"rb"):
|
for line in open(f_name,"rb"):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line=="":continue
|
if line=="":continue
|
||||||
line = line.decode("utf-8")
|
line = line.decode("utf-8")
|
||||||
word, _, tag = line.split(" ")
|
word, _, tag = line.split(" ")
|
||||||
result[word]=tag
|
result[word]=tag
|
||||||
return result
|
return result
|
||||||
|
|
||||||
word_tag_tab = load_model(jieba.get_abs_path_dict())
|
word_tag_tab = load_model(jieba.get_abs_path_dict())
|
||||||
|
|
||||||
if jieba.user_word_tag_tab:
|
if jieba.user_word_tag_tab:
|
||||||
word_tag_tab.update(jieba.user_word_tag_tab)
|
word_tag_tab.update(jieba.user_word_tag_tab)
|
||||||
|
|
||||||
class pair(object):
|
class pair(object):
|
||||||
def __init__(self,word,flag):
|
def __init__(self,word,flag):
|
||||||
self.word = word
|
self.word = word
|
||||||
self.flag = flag
|
self.flag = flag
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.word+"/"+self.flag
|
return self.word+"/"+self.flag
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.__str__()
|
return self.__str__()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.__unicode__().encode(default_encoding)
|
return self.__unicode__().encode(default_encoding)
|
||||||
|
|
||||||
def encode(self,arg):
|
def encode(self,arg):
|
||||||
return self.__unicode__().encode(arg)
|
return self.__unicode__().encode(arg)
|
||||||
|
|
||||||
def __cut(sentence):
|
def __cut(sentence):
|
||||||
prob, pos_list = viterbi.viterbi(sentence,char_state_tab.P, prob_start.P, prob_trans.P, prob_emit.P)
|
prob, pos_list = viterbi.viterbi(sentence,char_state_tab.P, prob_start.P, prob_trans.P, prob_emit.P)
|
||||||
begin, next = 0,0
|
begin, next = 0,0
|
||||||
|
|
||||||
for i,char in enumerate(sentence):
|
for i,char in enumerate(sentence):
|
||||||
pos = pos_list[i][0]
|
pos = pos_list[i][0]
|
||||||
if pos=='B':
|
if pos=='B':
|
||||||
begin = i
|
begin = i
|
||||||
elif pos=='E':
|
elif pos=='E':
|
||||||
yield pair(sentence[begin:i+1], pos_list[i][1])
|
yield pair(sentence[begin:i+1], pos_list[i][1])
|
||||||
next = i+1
|
next = i+1
|
||||||
elif pos=='S':
|
elif pos=='S':
|
||||||
yield pair(char,pos_list[i][1])
|
yield pair(char,pos_list[i][1])
|
||||||
next = i+1
|
next = i+1
|
||||||
if next<len(sentence):
|
if next<len(sentence):
|
||||||
yield pair(sentence[next:], pos_list[next][1] )
|
yield pair(sentence[next:], pos_list[next][1] )
|
||||||
|
|
||||||
def __cut_detail(sentence):
|
def __cut_detail(sentence):
|
||||||
|
|
||||||
re_han, re_skip = re.compile("([\u4E00-\u9FA5]+)"), re.compile("([\.0-9]+|[a-zA-Z0-9]+)")
|
re_han, re_skip = re.compile("([\u4E00-\u9FA5]+)"), re.compile("([\.0-9]+|[a-zA-Z0-9]+)")
|
||||||
re_eng,re_num = re.compile("[a-zA-Z0-9]+"), re.compile("[\.0-9]+")
|
re_eng,re_num = re.compile("[a-zA-Z0-9]+"), re.compile("[\.0-9]+")
|
||||||
|
|
||||||
blocks = re_han.split(sentence)
|
blocks = re_han.split(sentence)
|
||||||
for blk in blocks:
|
for blk in blocks:
|
||||||
if re_han.match(blk):
|
if re_han.match(blk):
|
||||||
for word in __cut(blk):
|
for word in __cut(blk):
|
||||||
yield word
|
yield word
|
||||||
else:
|
else:
|
||||||
tmp = re_skip.split(blk)
|
tmp = re_skip.split(blk)
|
||||||
for x in tmp:
|
for x in tmp:
|
||||||
if x!="":
|
if x!="":
|
||||||
if re_num.match(x):
|
if re_num.match(x):
|
||||||
yield pair(x,'m')
|
yield pair(x,'m')
|
||||||
elif re_eng.match(x):
|
elif re_eng.match(x):
|
||||||
yield pair(x,'eng')
|
yield pair(x,'eng')
|
||||||
else:
|
else:
|
||||||
yield pair(x,'x')
|
yield pair(x,'x')
|
||||||
|
|
||||||
def __cut_DAG(sentence):
|
def __cut_DAG(sentence):
|
||||||
DAG = jieba.get_DAG(sentence)
|
DAG = jieba.get_DAG(sentence)
|
||||||
route ={}
|
route ={}
|
||||||
|
|
||||||
jieba.calc(sentence,DAG,0,route=route)
|
jieba.calc(sentence,DAG,0,route=route)
|
||||||
|
|
||||||
x = 0
|
x = 0
|
||||||
buf =''
|
buf =''
|
||||||
N = len(sentence)
|
N = len(sentence)
|
||||||
while x<N:
|
while x<N:
|
||||||
y = route[x][1]+1
|
y = route[x][1]+1
|
||||||
l_word = sentence[x:y]
|
l_word = sentence[x:y]
|
||||||
if y-x==1:
|
if y-x==1:
|
||||||
buf+= l_word
|
buf+= l_word
|
||||||
else:
|
else:
|
||||||
if len(buf)>0:
|
if len(buf)>0:
|
||||||
if len(buf)==1:
|
if len(buf)==1:
|
||||||
yield pair(buf,word_tag_tab.get(buf,'x'))
|
yield pair(buf,word_tag_tab.get(buf,'x'))
|
||||||
buf=''
|
buf=''
|
||||||
else:
|
else:
|
||||||
if not (buf in jieba.FREQ):
|
if not (buf in jieba.FREQ):
|
||||||
regognized = __cut_detail(buf)
|
regognized = __cut_detail(buf)
|
||||||
for t in regognized:
|
for t in regognized:
|
||||||
yield t
|
yield t
|
||||||
else:
|
else:
|
||||||
for elem in buf:
|
for elem in buf:
|
||||||
yield pair(elem,word_tag_tab.get(elem,'x'))
|
yield pair(elem,word_tag_tab.get(elem,'x'))
|
||||||
buf=''
|
buf=''
|
||||||
yield pair(l_word,word_tag_tab.get(l_word,'x'))
|
yield pair(l_word,word_tag_tab.get(l_word,'x'))
|
||||||
x =y
|
x =y
|
||||||
|
|
||||||
if len(buf)>0:
|
if len(buf)>0:
|
||||||
if len(buf)==1:
|
if len(buf)==1:
|
||||||
yield pair(buf,word_tag_tab.get(buf,'x'))
|
yield pair(buf,word_tag_tab.get(buf,'x'))
|
||||||
else:
|
else:
|
||||||
if not (buf in jieba.FREQ):
|
if not (buf in jieba.FREQ):
|
||||||
regognized = __cut_detail(buf)
|
regognized = __cut_detail(buf)
|
||||||
for t in regognized:
|
for t in regognized:
|
||||||
yield t
|
yield t
|
||||||
else:
|
else:
|
||||||
for elem in buf:
|
for elem in buf:
|
||||||
yield pair(elem,word_tag_tab.get(elem,'x'))
|
yield pair(elem,word_tag_tab.get(elem,'x'))
|
||||||
|
|
||||||
def __cut_internal(sentence):
|
def __cut_internal(sentence):
|
||||||
if not ( type(sentence) is str):
|
if not ( type(sentence) is str):
|
||||||
try:
|
try:
|
||||||
sentence = sentence.decode('utf-8')
|
sentence = sentence.decode('utf-8')
|
||||||
except:
|
except:
|
||||||
sentence = sentence.decode('gbk','ignore')
|
sentence = sentence.decode('gbk','ignore')
|
||||||
|
|
||||||
re_han, re_skip = re.compile("([\u4E00-\u9FA5a-zA-Z0-9+#&\._]+)"), re.compile("(\s+)")
|
re_han, re_skip = re.compile("([\u4E00-\u9FA5a-zA-Z0-9+#&\._]+)"), re.compile("(\s+)")
|
||||||
re_eng,re_num = re.compile("[a-zA-Z0-9]+"), re.compile("[\.0-9]+")
|
re_eng,re_num = re.compile("[a-zA-Z0-9]+"), re.compile("[\.0-9]+")
|
||||||
|
|
||||||
blocks = re_han.split(sentence)
|
blocks = re_han.split(sentence)
|
||||||
for blk in blocks:
|
for blk in blocks:
|
||||||
if re_han.match(blk):
|
if re_han.match(blk):
|
||||||
for word in __cut_DAG(blk):
|
for word in __cut_DAG(blk):
|
||||||
yield word
|
yield word
|
||||||
else:
|
else:
|
||||||
tmp = re_skip.split(blk)
|
tmp = re_skip.split(blk)
|
||||||
for x in tmp:
|
for x in tmp:
|
||||||
if re_skip.match(x):
|
if re_skip.match(x):
|
||||||
yield pair(x,'x')
|
yield pair(x,'x')
|
||||||
else:
|
else:
|
||||||
for xx in x:
|
for xx in x:
|
||||||
if re_num.match(xx):
|
if re_num.match(xx):
|
||||||
yield pair(xx,'m')
|
yield pair(xx,'m')
|
||||||
elif re_eng.match(x):
|
elif re_eng.match(x):
|
||||||
yield pair(xx,'eng')
|
yield pair(xx,'eng')
|
||||||
else:
|
else:
|
||||||
yield pair(xx,'x')
|
yield pair(xx,'x')
|
||||||
|
|
||||||
def __lcut_internal(sentence):
|
def __lcut_internal(sentence):
|
||||||
return list(__cut_internal(sentence))
|
return list(__cut_internal(sentence))
|
||||||
|
|
||||||
def cut(sentence):
|
def cut(sentence):
|
||||||
if (not hasattr(jieba,'pool')) or (jieba.pool==None):
|
if (not hasattr(jieba,'pool')) or (jieba.pool==None):
|
||||||
for w in __cut_internal(sentence):
|
for w in __cut_internal(sentence):
|
||||||
yield w
|
yield w
|
||||||
else:
|
else:
|
||||||
parts = re.compile('([\r\n]+)').split(sentence)
|
parts = re.compile('([\r\n]+)').split(sentence)
|
||||||
result = jieba.pool.map(__lcut_internal,parts)
|
result = jieba.pool.map(__lcut_internal,parts)
|
||||||
for r in result:
|
for r in result:
|
||||||
for w in r:
|
for w in r:
|
||||||
yield w
|
yield w
|
||||||
|
|
||||||
|
@ -2,42 +2,42 @@ import operator
|
|||||||
MIN_FLOAT=-3.14e100
|
MIN_FLOAT=-3.14e100
|
||||||
|
|
||||||
def get_top_states(t_state_v,K=4):
|
def get_top_states(t_state_v,K=4):
|
||||||
items = t_state_v.items()
|
items = t_state_v.items()
|
||||||
topK= sorted(items,key=operator.itemgetter(1),reverse=True)[:K]
|
topK= sorted(items,key=operator.itemgetter(1),reverse=True)[:K]
|
||||||
return [x[0] for x in topK]
|
return [x[0] for x in topK]
|
||||||
|
|
||||||
def viterbi(obs, states, start_p, trans_p, emit_p):
|
def viterbi(obs, states, start_p, trans_p, emit_p):
|
||||||
V = [{}] #tabular
|
V = [{}] #tabular
|
||||||
mem_path = [{}]
|
mem_path = [{}]
|
||||||
all_states = trans_p.keys()
|
all_states = trans_p.keys()
|
||||||
for y in states.get(obs[0],all_states): #init
|
for y in states.get(obs[0],all_states): #init
|
||||||
V[0][y] = start_p[y] + emit_p[y].get(obs[0],MIN_FLOAT)
|
V[0][y] = start_p[y] + emit_p[y].get(obs[0],MIN_FLOAT)
|
||||||
mem_path[0][y] = ''
|
mem_path[0][y] = ''
|
||||||
for t in range(1,len(obs)):
|
for t in range(1,len(obs)):
|
||||||
V.append({})
|
V.append({})
|
||||||
mem_path.append({})
|
mem_path.append({})
|
||||||
prev_states = get_top_states(V[t-1])
|
prev_states = get_top_states(V[t-1])
|
||||||
prev_states =[ x for x in mem_path[t-1].keys() if len(trans_p[x])>0 ]
|
prev_states =[ x for x in mem_path[t-1].keys() if len(trans_p[x])>0 ]
|
||||||
|
|
||||||
prev_states_expect_next = set( (y for x in prev_states for y in trans_p[x].keys() ) )
|
prev_states_expect_next = set( (y for x in prev_states for y in trans_p[x].keys() ) )
|
||||||
obs_states = states.get(obs[t],all_states)
|
obs_states = states.get(obs[t],all_states)
|
||||||
obs_states = set(obs_states) & set(prev_states_expect_next)
|
obs_states = set(obs_states) & set(prev_states_expect_next)
|
||||||
|
|
||||||
if len(obs_states)==0: obs_states = all_states
|
if len(obs_states)==0: obs_states = all_states
|
||||||
for y in obs_states:
|
for y in obs_states:
|
||||||
(prob,state ) = max([(V[t-1][y0] + trans_p[y0].get(y,MIN_FLOAT) + emit_p[y].get(obs[t],MIN_FLOAT) ,y0) for y0 in prev_states])
|
(prob,state ) = max([(V[t-1][y0] + trans_p[y0].get(y,MIN_FLOAT) + emit_p[y].get(obs[t],MIN_FLOAT) ,y0) for y0 in prev_states])
|
||||||
V[t][y] =prob
|
V[t][y] =prob
|
||||||
mem_path[t][y] = state
|
mem_path[t][y] = state
|
||||||
|
|
||||||
last = [(V[-1][y], y) for y in mem_path[-1].keys() ]
|
last = [(V[-1][y], y) for y in mem_path[-1].keys() ]
|
||||||
#if len(last)==0:
|
#if len(last)==0:
|
||||||
#print obs
|
#print obs
|
||||||
(prob, state) = max(last)
|
(prob, state) = max(last)
|
||||||
|
|
||||||
route = [None] * len(obs)
|
route = [None] * len(obs)
|
||||||
i = len(obs)-1
|
i = len(obs)-1
|
||||||
while i>=0:
|
while i>=0:
|
||||||
route[i] = state
|
route[i] = state
|
||||||
state = mem_path[i][state]
|
state = mem_path[i][state]
|
||||||
i-=1
|
i-=1
|
||||||
return (prob, route)
|
return (prob, route)
|
@ -13,8 +13,8 @@ opt, args = parser.parse_args()
|
|||||||
|
|
||||||
|
|
||||||
if len(args) <1:
|
if len(args) <1:
|
||||||
print(USAGE)
|
print(USAGE)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
file_name = args[0]
|
file_name = args[0]
|
||||||
|
|
||||||
|
@ -12,17 +12,17 @@ import os
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
if len(sys.argv)<2:
|
if len(sys.argv)<2:
|
||||||
print "usage: extract_topic.py directory [n_topic] [n_top_words]"
|
print "usage: extract_topic.py directory [n_topic] [n_top_words]"
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
n_topic = 10
|
n_topic = 10
|
||||||
n_top_words = 25
|
n_top_words = 25
|
||||||
|
|
||||||
if len(sys.argv)>2:
|
if len(sys.argv)>2:
|
||||||
n_topic = int(sys.argv[2])
|
n_topic = int(sys.argv[2])
|
||||||
|
|
||||||
if len(sys.argv)>3:
|
if len(sys.argv)>3:
|
||||||
n_top_words = int(sys.argv[3])
|
n_top_words = int(sys.argv[3])
|
||||||
|
|
||||||
count_vect = CountVectorizer()
|
count_vect = CountVectorizer()
|
||||||
docs = []
|
docs = []
|
||||||
@ -31,11 +31,11 @@ pattern = os.path.join(sys.argv[1],"*.txt")
|
|||||||
print "read "+pattern
|
print "read "+pattern
|
||||||
|
|
||||||
for f_name in glob.glob(pattern):
|
for f_name in glob.glob(pattern):
|
||||||
with open(f_name) as f:
|
with open(f_name) as f:
|
||||||
print "read file:", f_name
|
print "read file:", f_name
|
||||||
for line in f: #one line as a document
|
for line in f: #one line as a document
|
||||||
words = " ".join(jieba.cut(line))
|
words = " ".join(jieba.cut(line))
|
||||||
docs.append(words)
|
docs.append(words)
|
||||||
|
|
||||||
random.shuffle(docs)
|
random.shuffle(docs)
|
||||||
|
|
||||||
|
@ -15,14 +15,14 @@ import jieba
|
|||||||
default_encoding='utf-8'
|
default_encoding='utf-8'
|
||||||
|
|
||||||
if len(sys.argv)>1:
|
if len(sys.argv)>1:
|
||||||
default_encoding = sys.argv[1]
|
default_encoding = sys.argv[1]
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
line = sys.stdin.readline()
|
line = sys.stdin.readline()
|
||||||
if line=="":
|
if line=="":
|
||||||
break
|
break
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
for word in jieba.cut(line):
|
for word in jieba.cut(line):
|
||||||
print(word.encode(default_encoding))
|
print(word.encode(default_encoding))
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,15 +14,15 @@ opt, args = parser.parse_args()
|
|||||||
|
|
||||||
|
|
||||||
if len(args) <1:
|
if len(args) <1:
|
||||||
print(USAGE)
|
print(USAGE)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
file_name = args[0]
|
file_name = args[0]
|
||||||
|
|
||||||
if opt.topK==None:
|
if opt.topK==None:
|
||||||
topK=10
|
topK=10
|
||||||
else:
|
else:
|
||||||
topK = int(opt.topK)
|
topK = int(opt.topK)
|
||||||
|
|
||||||
|
|
||||||
content = open(file_name,'rb').read()
|
content = open(file_name,'rb').read()
|
||||||
|
@ -5,92 +5,92 @@ import jieba
|
|||||||
jieba.enable_parallel(4)
|
jieba.enable_parallel(4)
|
||||||
|
|
||||||
def cuttest(test_sent):
|
def cuttest(test_sent):
|
||||||
result = jieba.cut(test_sent)
|
result = jieba.cut(test_sent)
|
||||||
print( "/ ".join(result) )
|
print( "/ ".join(result) )
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
||||||
cuttest("我不喜欢日本和服。")
|
cuttest("我不喜欢日本和服。")
|
||||||
cuttest("雷猴回归人间。")
|
cuttest("雷猴回归人间。")
|
||||||
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
||||||
cuttest("我需要廉租房")
|
cuttest("我需要廉租房")
|
||||||
cuttest("永和服装饰品有限公司")
|
cuttest("永和服装饰品有限公司")
|
||||||
cuttest("我爱北京天安门")
|
cuttest("我爱北京天安门")
|
||||||
cuttest("abc")
|
cuttest("abc")
|
||||||
cuttest("隐马尔可夫")
|
cuttest("隐马尔可夫")
|
||||||
cuttest("雷猴是个好网站")
|
cuttest("雷猴是个好网站")
|
||||||
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
||||||
cuttest("草泥马和欺实马是今年的流行词汇")
|
cuttest("草泥马和欺实马是今年的流行词汇")
|
||||||
cuttest("伊藤洋华堂总府店")
|
cuttest("伊藤洋华堂总府店")
|
||||||
cuttest("中国科学院计算技术研究所")
|
cuttest("中国科学院计算技术研究所")
|
||||||
cuttest("罗密欧与朱丽叶")
|
cuttest("罗密欧与朱丽叶")
|
||||||
cuttest("我购买了道具和服装")
|
cuttest("我购买了道具和服装")
|
||||||
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
||||||
cuttest("湖北省石首市")
|
cuttest("湖北省石首市")
|
||||||
cuttest("湖北省十堰市")
|
cuttest("湖北省十堰市")
|
||||||
cuttest("总经理完成了这件事情")
|
cuttest("总经理完成了这件事情")
|
||||||
cuttest("电脑修好了")
|
cuttest("电脑修好了")
|
||||||
cuttest("做好了这件事情就一了百了了")
|
cuttest("做好了这件事情就一了百了了")
|
||||||
cuttest("人们审美的观点是不同的")
|
cuttest("人们审美的观点是不同的")
|
||||||
cuttest("我们买了一个美的空调")
|
cuttest("我们买了一个美的空调")
|
||||||
cuttest("线程初始化时我们要注意")
|
cuttest("线程初始化时我们要注意")
|
||||||
cuttest("一个分子是由好多原子组织成的")
|
cuttest("一个分子是由好多原子组织成的")
|
||||||
cuttest("祝你马到功成")
|
cuttest("祝你马到功成")
|
||||||
cuttest("他掉进了无底洞里")
|
cuttest("他掉进了无底洞里")
|
||||||
cuttest("中国的首都是北京")
|
cuttest("中国的首都是北京")
|
||||||
cuttest("孙君意")
|
cuttest("孙君意")
|
||||||
cuttest("外交部发言人马朝旭")
|
cuttest("外交部发言人马朝旭")
|
||||||
cuttest("领导人会议和第四届东亚峰会")
|
cuttest("领导人会议和第四届东亚峰会")
|
||||||
cuttest("在过去的这五年")
|
cuttest("在过去的这五年")
|
||||||
cuttest("还需要很长的路要走")
|
cuttest("还需要很长的路要走")
|
||||||
cuttest("60周年首都阅兵")
|
cuttest("60周年首都阅兵")
|
||||||
cuttest("你好人们审美的观点是不同的")
|
cuttest("你好人们审美的观点是不同的")
|
||||||
cuttest("买水果然后来世博园")
|
cuttest("买水果然后来世博园")
|
||||||
cuttest("买水果然后去世博园")
|
cuttest("买水果然后去世博园")
|
||||||
cuttest("但是后来我才知道你是对的")
|
cuttest("但是后来我才知道你是对的")
|
||||||
cuttest("存在即合理")
|
cuttest("存在即合理")
|
||||||
cuttest("的的的的的在的的的的就以和和和")
|
cuttest("的的的的的在的的的的就以和和和")
|
||||||
cuttest("I love你,不以为耻,反以为rong")
|
cuttest("I love你,不以为耻,反以为rong")
|
||||||
cuttest("因")
|
cuttest("因")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("很好但主要是基于网页形式")
|
cuttest("很好但主要是基于网页形式")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("为什么我不能拥有想要的生活")
|
cuttest("为什么我不能拥有想要的生活")
|
||||||
cuttest("后来我才")
|
cuttest("后来我才")
|
||||||
cuttest("此次来中国是为了")
|
cuttest("此次来中国是为了")
|
||||||
cuttest("使用了它就可以解决一些问题")
|
cuttest("使用了它就可以解决一些问题")
|
||||||
cuttest(",使用了它就可以解决一些问题")
|
cuttest(",使用了它就可以解决一些问题")
|
||||||
cuttest("其实使用了它就可以解决一些问题")
|
cuttest("其实使用了它就可以解决一些问题")
|
||||||
cuttest("好人使用了它就可以解决一些问题")
|
cuttest("好人使用了它就可以解决一些问题")
|
||||||
cuttest("是因为和国家")
|
cuttest("是因为和国家")
|
||||||
cuttest("老年搜索还支持")
|
cuttest("老年搜索还支持")
|
||||||
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
||||||
cuttest("大")
|
cuttest("大")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("他说的确实在理")
|
cuttest("他说的确实在理")
|
||||||
cuttest("长春市长春节讲话")
|
cuttest("长春市长春节讲话")
|
||||||
cuttest("结婚的和尚未结婚的")
|
cuttest("结婚的和尚未结婚的")
|
||||||
cuttest("结合成分子时")
|
cuttest("结合成分子时")
|
||||||
cuttest("旅游和服务是最好的")
|
cuttest("旅游和服务是最好的")
|
||||||
cuttest("这件事情的确是我的错")
|
cuttest("这件事情的确是我的错")
|
||||||
cuttest("供大家参考指正")
|
cuttest("供大家参考指正")
|
||||||
cuttest("哈尔滨政府公布塌桥原因")
|
cuttest("哈尔滨政府公布塌桥原因")
|
||||||
cuttest("我在机场入口处")
|
cuttest("我在机场入口处")
|
||||||
cuttest("邢永臣摄影报道")
|
cuttest("邢永臣摄影报道")
|
||||||
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
||||||
cuttest("南京市长江大桥")
|
cuttest("南京市长江大桥")
|
||||||
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
||||||
cuttest('长春市长春药店')
|
cuttest('长春市长春药店')
|
||||||
cuttest('邓颖超生前最喜欢的衣服')
|
cuttest('邓颖超生前最喜欢的衣服')
|
||||||
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
||||||
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
||||||
cuttest('一次性交多少钱')
|
cuttest('一次性交多少钱')
|
||||||
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
||||||
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
||||||
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
||||||
cuttest('张晓梅去人民医院做了个B超然后去买了件T恤')
|
cuttest('张晓梅去人民医院做了个B超然后去买了件T恤')
|
||||||
cuttest('AT&T是一件不错的公司,给你发offer了吗?')
|
cuttest('AT&T是一件不错的公司,给你发offer了吗?')
|
||||||
cuttest('C++和c#是什么关系?11+122=133,是吗?PI=3.14159')
|
cuttest('C++和c#是什么关系?11+122=133,是吗?PI=3.14159')
|
||||||
cuttest('你认识那个和主席握手的的哥吗?他开一辆黑色的士。')
|
cuttest('你认识那个和主席握手的的哥吗?他开一辆黑色的士。')
|
||||||
|
@ -5,88 +5,88 @@ import jieba
|
|||||||
jieba.enable_parallel(4)
|
jieba.enable_parallel(4)
|
||||||
|
|
||||||
def cuttest(test_sent):
|
def cuttest(test_sent):
|
||||||
result = jieba.cut(test_sent,cut_all=True)
|
result = jieba.cut(test_sent,cut_all=True)
|
||||||
print("/ ".join(result))
|
print("/ ".join(result))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
||||||
cuttest("我不喜欢日本和服。")
|
cuttest("我不喜欢日本和服。")
|
||||||
cuttest("雷猴回归人间。")
|
cuttest("雷猴回归人间。")
|
||||||
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
||||||
cuttest("我需要廉租房")
|
cuttest("我需要廉租房")
|
||||||
cuttest("永和服装饰品有限公司")
|
cuttest("永和服装饰品有限公司")
|
||||||
cuttest("我爱北京天安门")
|
cuttest("我爱北京天安门")
|
||||||
cuttest("abc")
|
cuttest("abc")
|
||||||
cuttest("隐马尔可夫")
|
cuttest("隐马尔可夫")
|
||||||
cuttest("雷猴是个好网站")
|
cuttest("雷猴是个好网站")
|
||||||
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
||||||
cuttest("草泥马和欺实马是今年的流行词汇")
|
cuttest("草泥马和欺实马是今年的流行词汇")
|
||||||
cuttest("伊藤洋华堂总府店")
|
cuttest("伊藤洋华堂总府店")
|
||||||
cuttest("中国科学院计算技术研究所")
|
cuttest("中国科学院计算技术研究所")
|
||||||
cuttest("罗密欧与朱丽叶")
|
cuttest("罗密欧与朱丽叶")
|
||||||
cuttest("我购买了道具和服装")
|
cuttest("我购买了道具和服装")
|
||||||
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
||||||
cuttest("湖北省石首市")
|
cuttest("湖北省石首市")
|
||||||
cuttest("湖北省十堰市")
|
cuttest("湖北省十堰市")
|
||||||
cuttest("总经理完成了这件事情")
|
cuttest("总经理完成了这件事情")
|
||||||
cuttest("电脑修好了")
|
cuttest("电脑修好了")
|
||||||
cuttest("做好了这件事情就一了百了了")
|
cuttest("做好了这件事情就一了百了了")
|
||||||
cuttest("人们审美的观点是不同的")
|
cuttest("人们审美的观点是不同的")
|
||||||
cuttest("我们买了一个美的空调")
|
cuttest("我们买了一个美的空调")
|
||||||
cuttest("线程初始化时我们要注意")
|
cuttest("线程初始化时我们要注意")
|
||||||
cuttest("一个分子是由好多原子组织成的")
|
cuttest("一个分子是由好多原子组织成的")
|
||||||
cuttest("祝你马到功成")
|
cuttest("祝你马到功成")
|
||||||
cuttest("他掉进了无底洞里")
|
cuttest("他掉进了无底洞里")
|
||||||
cuttest("中国的首都是北京")
|
cuttest("中国的首都是北京")
|
||||||
cuttest("孙君意")
|
cuttest("孙君意")
|
||||||
cuttest("外交部发言人马朝旭")
|
cuttest("外交部发言人马朝旭")
|
||||||
cuttest("领导人会议和第四届东亚峰会")
|
cuttest("领导人会议和第四届东亚峰会")
|
||||||
cuttest("在过去的这五年")
|
cuttest("在过去的这五年")
|
||||||
cuttest("还需要很长的路要走")
|
cuttest("还需要很长的路要走")
|
||||||
cuttest("60周年首都阅兵")
|
cuttest("60周年首都阅兵")
|
||||||
cuttest("你好人们审美的观点是不同的")
|
cuttest("你好人们审美的观点是不同的")
|
||||||
cuttest("买水果然后来世博园")
|
cuttest("买水果然后来世博园")
|
||||||
cuttest("买水果然后去世博园")
|
cuttest("买水果然后去世博园")
|
||||||
cuttest("但是后来我才知道你是对的")
|
cuttest("但是后来我才知道你是对的")
|
||||||
cuttest("存在即合理")
|
cuttest("存在即合理")
|
||||||
cuttest("的的的的的在的的的的就以和和和")
|
cuttest("的的的的的在的的的的就以和和和")
|
||||||
cuttest("I love你,不以为耻,反以为rong")
|
cuttest("I love你,不以为耻,反以为rong")
|
||||||
cuttest("因")
|
cuttest("因")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("很好但主要是基于网页形式")
|
cuttest("很好但主要是基于网页形式")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("为什么我不能拥有想要的生活")
|
cuttest("为什么我不能拥有想要的生活")
|
||||||
cuttest("后来我才")
|
cuttest("后来我才")
|
||||||
cuttest("此次来中国是为了")
|
cuttest("此次来中国是为了")
|
||||||
cuttest("使用了它就可以解决一些问题")
|
cuttest("使用了它就可以解决一些问题")
|
||||||
cuttest(",使用了它就可以解决一些问题")
|
cuttest(",使用了它就可以解决一些问题")
|
||||||
cuttest("其实使用了它就可以解决一些问题")
|
cuttest("其实使用了它就可以解决一些问题")
|
||||||
cuttest("好人使用了它就可以解决一些问题")
|
cuttest("好人使用了它就可以解决一些问题")
|
||||||
cuttest("是因为和国家")
|
cuttest("是因为和国家")
|
||||||
cuttest("老年搜索还支持")
|
cuttest("老年搜索还支持")
|
||||||
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
||||||
cuttest("大")
|
cuttest("大")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("他说的确实在理")
|
cuttest("他说的确实在理")
|
||||||
cuttest("长春市长春节讲话")
|
cuttest("长春市长春节讲话")
|
||||||
cuttest("结婚的和尚未结婚的")
|
cuttest("结婚的和尚未结婚的")
|
||||||
cuttest("结合成分子时")
|
cuttest("结合成分子时")
|
||||||
cuttest("旅游和服务是最好的")
|
cuttest("旅游和服务是最好的")
|
||||||
cuttest("这件事情的确是我的错")
|
cuttest("这件事情的确是我的错")
|
||||||
cuttest("供大家参考指正")
|
cuttest("供大家参考指正")
|
||||||
cuttest("哈尔滨政府公布塌桥原因")
|
cuttest("哈尔滨政府公布塌桥原因")
|
||||||
cuttest("我在机场入口处")
|
cuttest("我在机场入口处")
|
||||||
cuttest("邢永臣摄影报道")
|
cuttest("邢永臣摄影报道")
|
||||||
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
||||||
cuttest("南京市长江大桥")
|
cuttest("南京市长江大桥")
|
||||||
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
||||||
cuttest('长春市长春药店')
|
cuttest('长春市长春药店')
|
||||||
cuttest('邓颖超生前最喜欢的衣服')
|
cuttest('邓颖超生前最喜欢的衣服')
|
||||||
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
||||||
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
||||||
cuttest('一次性交多少钱')
|
cuttest('一次性交多少钱')
|
||||||
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
||||||
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
||||||
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
||||||
|
@ -5,88 +5,88 @@ import jieba
|
|||||||
jieba.enable_parallel(4)
|
jieba.enable_parallel(4)
|
||||||
|
|
||||||
def cuttest(test_sent):
|
def cuttest(test_sent):
|
||||||
result = jieba.cut_for_search(test_sent)
|
result = jieba.cut_for_search(test_sent)
|
||||||
print("/ ".join(result))
|
print("/ ".join(result))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
||||||
cuttest("我不喜欢日本和服。")
|
cuttest("我不喜欢日本和服。")
|
||||||
cuttest("雷猴回归人间。")
|
cuttest("雷猴回归人间。")
|
||||||
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
||||||
cuttest("我需要廉租房")
|
cuttest("我需要廉租房")
|
||||||
cuttest("永和服装饰品有限公司")
|
cuttest("永和服装饰品有限公司")
|
||||||
cuttest("我爱北京天安门")
|
cuttest("我爱北京天安门")
|
||||||
cuttest("abc")
|
cuttest("abc")
|
||||||
cuttest("隐马尔可夫")
|
cuttest("隐马尔可夫")
|
||||||
cuttest("雷猴是个好网站")
|
cuttest("雷猴是个好网站")
|
||||||
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
||||||
cuttest("草泥马和欺实马是今年的流行词汇")
|
cuttest("草泥马和欺实马是今年的流行词汇")
|
||||||
cuttest("伊藤洋华堂总府店")
|
cuttest("伊藤洋华堂总府店")
|
||||||
cuttest("中国科学院计算技术研究所")
|
cuttest("中国科学院计算技术研究所")
|
||||||
cuttest("罗密欧与朱丽叶")
|
cuttest("罗密欧与朱丽叶")
|
||||||
cuttest("我购买了道具和服装")
|
cuttest("我购买了道具和服装")
|
||||||
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
||||||
cuttest("湖北省石首市")
|
cuttest("湖北省石首市")
|
||||||
cuttest("湖北省十堰市")
|
cuttest("湖北省十堰市")
|
||||||
cuttest("总经理完成了这件事情")
|
cuttest("总经理完成了这件事情")
|
||||||
cuttest("电脑修好了")
|
cuttest("电脑修好了")
|
||||||
cuttest("做好了这件事情就一了百了了")
|
cuttest("做好了这件事情就一了百了了")
|
||||||
cuttest("人们审美的观点是不同的")
|
cuttest("人们审美的观点是不同的")
|
||||||
cuttest("我们买了一个美的空调")
|
cuttest("我们买了一个美的空调")
|
||||||
cuttest("线程初始化时我们要注意")
|
cuttest("线程初始化时我们要注意")
|
||||||
cuttest("一个分子是由好多原子组织成的")
|
cuttest("一个分子是由好多原子组织成的")
|
||||||
cuttest("祝你马到功成")
|
cuttest("祝你马到功成")
|
||||||
cuttest("他掉进了无底洞里")
|
cuttest("他掉进了无底洞里")
|
||||||
cuttest("中国的首都是北京")
|
cuttest("中国的首都是北京")
|
||||||
cuttest("孙君意")
|
cuttest("孙君意")
|
||||||
cuttest("外交部发言人马朝旭")
|
cuttest("外交部发言人马朝旭")
|
||||||
cuttest("领导人会议和第四届东亚峰会")
|
cuttest("领导人会议和第四届东亚峰会")
|
||||||
cuttest("在过去的这五年")
|
cuttest("在过去的这五年")
|
||||||
cuttest("还需要很长的路要走")
|
cuttest("还需要很长的路要走")
|
||||||
cuttest("60周年首都阅兵")
|
cuttest("60周年首都阅兵")
|
||||||
cuttest("你好人们审美的观点是不同的")
|
cuttest("你好人们审美的观点是不同的")
|
||||||
cuttest("买水果然后来世博园")
|
cuttest("买水果然后来世博园")
|
||||||
cuttest("买水果然后去世博园")
|
cuttest("买水果然后去世博园")
|
||||||
cuttest("但是后来我才知道你是对的")
|
cuttest("但是后来我才知道你是对的")
|
||||||
cuttest("存在即合理")
|
cuttest("存在即合理")
|
||||||
cuttest("的的的的的在的的的的就以和和和")
|
cuttest("的的的的的在的的的的就以和和和")
|
||||||
cuttest("I love你,不以为耻,反以为rong")
|
cuttest("I love你,不以为耻,反以为rong")
|
||||||
cuttest("因")
|
cuttest("因")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("很好但主要是基于网页形式")
|
cuttest("很好但主要是基于网页形式")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("为什么我不能拥有想要的生活")
|
cuttest("为什么我不能拥有想要的生活")
|
||||||
cuttest("后来我才")
|
cuttest("后来我才")
|
||||||
cuttest("此次来中国是为了")
|
cuttest("此次来中国是为了")
|
||||||
cuttest("使用了它就可以解决一些问题")
|
cuttest("使用了它就可以解决一些问题")
|
||||||
cuttest(",使用了它就可以解决一些问题")
|
cuttest(",使用了它就可以解决一些问题")
|
||||||
cuttest("其实使用了它就可以解决一些问题")
|
cuttest("其实使用了它就可以解决一些问题")
|
||||||
cuttest("好人使用了它就可以解决一些问题")
|
cuttest("好人使用了它就可以解决一些问题")
|
||||||
cuttest("是因为和国家")
|
cuttest("是因为和国家")
|
||||||
cuttest("老年搜索还支持")
|
cuttest("老年搜索还支持")
|
||||||
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
||||||
cuttest("大")
|
cuttest("大")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("他说的确实在理")
|
cuttest("他说的确实在理")
|
||||||
cuttest("长春市长春节讲话")
|
cuttest("长春市长春节讲话")
|
||||||
cuttest("结婚的和尚未结婚的")
|
cuttest("结婚的和尚未结婚的")
|
||||||
cuttest("结合成分子时")
|
cuttest("结合成分子时")
|
||||||
cuttest("旅游和服务是最好的")
|
cuttest("旅游和服务是最好的")
|
||||||
cuttest("这件事情的确是我的错")
|
cuttest("这件事情的确是我的错")
|
||||||
cuttest("供大家参考指正")
|
cuttest("供大家参考指正")
|
||||||
cuttest("哈尔滨政府公布塌桥原因")
|
cuttest("哈尔滨政府公布塌桥原因")
|
||||||
cuttest("我在机场入口处")
|
cuttest("我在机场入口处")
|
||||||
cuttest("邢永臣摄影报道")
|
cuttest("邢永臣摄影报道")
|
||||||
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
||||||
cuttest("南京市长江大桥")
|
cuttest("南京市长江大桥")
|
||||||
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
||||||
cuttest('长春市长春药店')
|
cuttest('长春市长春药店')
|
||||||
cuttest('邓颖超生前最喜欢的衣服')
|
cuttest('邓颖超生前最喜欢的衣服')
|
||||||
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
||||||
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
||||||
cuttest('一次性交多少钱')
|
cuttest('一次性交多少钱')
|
||||||
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
||||||
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
||||||
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
||||||
|
@ -14,6 +14,6 @@ tm_cost = t2-t1
|
|||||||
|
|
||||||
log_f = open("1.log","wb")
|
log_f = open("1.log","wb")
|
||||||
for w in words:
|
for w in words:
|
||||||
log_f.write(w.encode("utf-8"))
|
log_f.write(w.encode("utf-8"))
|
||||||
print('speed' , len(content)/tm_cost, " bytes/second")
|
print('speed' , len(content)/tm_cost, " bytes/second")
|
||||||
|
|
||||||
|
@ -6,94 +6,94 @@ jieba.enable_parallel(4)
|
|||||||
import jieba.posseg as pseg
|
import jieba.posseg as pseg
|
||||||
|
|
||||||
def cuttest(test_sent):
|
def cuttest(test_sent):
|
||||||
result = pseg.cut(test_sent)
|
result = pseg.cut(test_sent)
|
||||||
for w in result:
|
for w in result:
|
||||||
sys.stdout.write(w.word+ "/"+ w.flag + ", ")
|
sys.stdout.write(w.word+ "/"+ w.flag + ", ")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
||||||
cuttest("我不喜欢日本和服。")
|
cuttest("我不喜欢日本和服。")
|
||||||
cuttest("雷猴回归人间。")
|
cuttest("雷猴回归人间。")
|
||||||
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
||||||
cuttest("我需要廉租房")
|
cuttest("我需要廉租房")
|
||||||
cuttest("永和服装饰品有限公司")
|
cuttest("永和服装饰品有限公司")
|
||||||
cuttest("我爱北京天安门")
|
cuttest("我爱北京天安门")
|
||||||
cuttest("abc")
|
cuttest("abc")
|
||||||
cuttest("隐马尔可夫")
|
cuttest("隐马尔可夫")
|
||||||
cuttest("雷猴是个好网站")
|
cuttest("雷猴是个好网站")
|
||||||
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
||||||
cuttest("草泥马和欺实马是今年的流行词汇")
|
cuttest("草泥马和欺实马是今年的流行词汇")
|
||||||
cuttest("伊藤洋华堂总府店")
|
cuttest("伊藤洋华堂总府店")
|
||||||
cuttest("中国科学院计算技术研究所")
|
cuttest("中国科学院计算技术研究所")
|
||||||
cuttest("罗密欧与朱丽叶")
|
cuttest("罗密欧与朱丽叶")
|
||||||
cuttest("我购买了道具和服装")
|
cuttest("我购买了道具和服装")
|
||||||
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
||||||
cuttest("湖北省石首市")
|
cuttest("湖北省石首市")
|
||||||
cuttest("湖北省十堰市")
|
cuttest("湖北省十堰市")
|
||||||
cuttest("总经理完成了这件事情")
|
cuttest("总经理完成了这件事情")
|
||||||
cuttest("电脑修好了")
|
cuttest("电脑修好了")
|
||||||
cuttest("做好了这件事情就一了百了了")
|
cuttest("做好了这件事情就一了百了了")
|
||||||
cuttest("人们审美的观点是不同的")
|
cuttest("人们审美的观点是不同的")
|
||||||
cuttest("我们买了一个美的空调")
|
cuttest("我们买了一个美的空调")
|
||||||
cuttest("线程初始化时我们要注意")
|
cuttest("线程初始化时我们要注意")
|
||||||
cuttest("一个分子是由好多原子组织成的")
|
cuttest("一个分子是由好多原子组织成的")
|
||||||
cuttest("祝你马到功成")
|
cuttest("祝你马到功成")
|
||||||
cuttest("他掉进了无底洞里")
|
cuttest("他掉进了无底洞里")
|
||||||
cuttest("中国的首都是北京")
|
cuttest("中国的首都是北京")
|
||||||
cuttest("孙君意")
|
cuttest("孙君意")
|
||||||
cuttest("外交部发言人马朝旭")
|
cuttest("外交部发言人马朝旭")
|
||||||
cuttest("领导人会议和第四届东亚峰会")
|
cuttest("领导人会议和第四届东亚峰会")
|
||||||
cuttest("在过去的这五年")
|
cuttest("在过去的这五年")
|
||||||
cuttest("还需要很长的路要走")
|
cuttest("还需要很长的路要走")
|
||||||
cuttest("60周年首都阅兵")
|
cuttest("60周年首都阅兵")
|
||||||
cuttest("你好人们审美的观点是不同的")
|
cuttest("你好人们审美的观点是不同的")
|
||||||
cuttest("买水果然后来世博园")
|
cuttest("买水果然后来世博园")
|
||||||
cuttest("买水果然后去世博园")
|
cuttest("买水果然后去世博园")
|
||||||
cuttest("但是后来我才知道你是对的")
|
cuttest("但是后来我才知道你是对的")
|
||||||
cuttest("存在即合理")
|
cuttest("存在即合理")
|
||||||
cuttest("的的的的的在的的的的就以和和和")
|
cuttest("的的的的的在的的的的就以和和和")
|
||||||
cuttest("I love你,不以为耻,反以为rong")
|
cuttest("I love你,不以为耻,反以为rong")
|
||||||
cuttest("因")
|
cuttest("因")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("很好但主要是基于网页形式")
|
cuttest("很好但主要是基于网页形式")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("为什么我不能拥有想要的生活")
|
cuttest("为什么我不能拥有想要的生活")
|
||||||
cuttest("后来我才")
|
cuttest("后来我才")
|
||||||
cuttest("此次来中国是为了")
|
cuttest("此次来中国是为了")
|
||||||
cuttest("使用了它就可以解决一些问题")
|
cuttest("使用了它就可以解决一些问题")
|
||||||
cuttest(",使用了它就可以解决一些问题")
|
cuttest(",使用了它就可以解决一些问题")
|
||||||
cuttest("其实使用了它就可以解决一些问题")
|
cuttest("其实使用了它就可以解决一些问题")
|
||||||
cuttest("好人使用了它就可以解决一些问题")
|
cuttest("好人使用了它就可以解决一些问题")
|
||||||
cuttest("是因为和国家")
|
cuttest("是因为和国家")
|
||||||
cuttest("老年搜索还支持")
|
cuttest("老年搜索还支持")
|
||||||
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
||||||
cuttest("大")
|
cuttest("大")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("他说的确实在理")
|
cuttest("他说的确实在理")
|
||||||
cuttest("长春市长春节讲话")
|
cuttest("长春市长春节讲话")
|
||||||
cuttest("结婚的和尚未结婚的")
|
cuttest("结婚的和尚未结婚的")
|
||||||
cuttest("结合成分子时")
|
cuttest("结合成分子时")
|
||||||
cuttest("旅游和服务是最好的")
|
cuttest("旅游和服务是最好的")
|
||||||
cuttest("这件事情的确是我的错")
|
cuttest("这件事情的确是我的错")
|
||||||
cuttest("供大家参考指正")
|
cuttest("供大家参考指正")
|
||||||
cuttest("哈尔滨政府公布塌桥原因")
|
cuttest("哈尔滨政府公布塌桥原因")
|
||||||
cuttest("我在机场入口处")
|
cuttest("我在机场入口处")
|
||||||
cuttest("邢永臣摄影报道")
|
cuttest("邢永臣摄影报道")
|
||||||
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
||||||
cuttest("南京市长江大桥")
|
cuttest("南京市长江大桥")
|
||||||
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
||||||
cuttest('长春市长春药店')
|
cuttest('长春市长春药店')
|
||||||
cuttest('邓颖超生前最喜欢的衣服')
|
cuttest('邓颖超生前最喜欢的衣服')
|
||||||
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
||||||
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
||||||
cuttest('一次性交多少钱')
|
cuttest('一次性交多少钱')
|
||||||
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
||||||
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
||||||
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
||||||
cuttest('张晓梅去人民医院做了个B超然后去买了件T恤')
|
cuttest('张晓梅去人民医院做了个B超然后去买了件T恤')
|
||||||
cuttest('AT&T是一件不错的公司,给你发offer了吗?')
|
cuttest('AT&T是一件不错的公司,给你发offer了吗?')
|
||||||
cuttest('C++和c#是什么关系?11+122=133,是吗?PI=3.14159')
|
cuttest('C++和c#是什么关系?11+122=133,是吗?PI=3.14159')
|
||||||
cuttest('你认识那个和主席握手的的哥吗?他开一辆黑色的士。')
|
cuttest('你认识那个和主席握手的的哥吗?他开一辆黑色的士。')
|
||||||
|
@ -16,7 +16,7 @@ tm_cost = t2-t1
|
|||||||
|
|
||||||
log_f = open("1.log","wb")
|
log_f = open("1.log","wb")
|
||||||
for w in words:
|
for w in words:
|
||||||
print >> log_f, w.encode("utf-8"), "/" ,
|
print >> log_f, w.encode("utf-8"), "/" ,
|
||||||
|
|
||||||
print 'speed' , len(content)/tm_cost, " bytes/second"
|
print 'speed' , len(content)/tm_cost, " bytes/second"
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ sys.path.append("../")
|
|||||||
import jieba
|
import jieba
|
||||||
|
|
||||||
def cuttest(test_sent):
|
def cuttest(test_sent):
|
||||||
result = jieba.cut(test_sent)
|
result = jieba.cut(test_sent)
|
||||||
print("/ ".join(result))
|
print("/ ".join(result))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -4,24 +4,24 @@ sys.path.append("../")
|
|||||||
import jieba
|
import jieba
|
||||||
|
|
||||||
def cuttest(test_sent):
|
def cuttest(test_sent):
|
||||||
result = jieba.cut(test_sent)
|
result = jieba.cut(test_sent)
|
||||||
print(" ".join(result) )
|
print(" ".join(result) )
|
||||||
|
|
||||||
def testcase():
|
def testcase():
|
||||||
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
||||||
cuttest("我不喜欢日本和服。")
|
cuttest("我不喜欢日本和服。")
|
||||||
cuttest("雷猴回归人间。")
|
cuttest("雷猴回归人间。")
|
||||||
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
||||||
cuttest("我需要廉租房")
|
cuttest("我需要廉租房")
|
||||||
cuttest("永和服装饰品有限公司")
|
cuttest("永和服装饰品有限公司")
|
||||||
cuttest("我爱北京天安门")
|
cuttest("我爱北京天安门")
|
||||||
cuttest("abc")
|
cuttest("abc")
|
||||||
cuttest("隐马尔可夫")
|
cuttest("隐马尔可夫")
|
||||||
cuttest("雷猴是个好网站")
|
cuttest("雷猴是个好网站")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
testcase()
|
testcase()
|
||||||
jieba.set_dictionary("foobar.txt")
|
jieba.set_dictionary("foobar.txt")
|
||||||
print("================================")
|
print("================================")
|
||||||
testcase()
|
testcase()
|
||||||
|
|
||||||
|
@ -4,93 +4,93 @@ sys.path.append("../")
|
|||||||
import jieba
|
import jieba
|
||||||
|
|
||||||
def cuttest(test_sent):
|
def cuttest(test_sent):
|
||||||
result = jieba.cut_for_search(test_sent)
|
result = jieba.cut_for_search(test_sent)
|
||||||
print("/ ".join(result))
|
print("/ ".join(result))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
||||||
cuttest("我不喜欢日本和服。")
|
cuttest("我不喜欢日本和服。")
|
||||||
cuttest("雷猴回归人间。")
|
cuttest("雷猴回归人间。")
|
||||||
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
||||||
cuttest("我需要廉租房")
|
cuttest("我需要廉租房")
|
||||||
cuttest("永和服装饰品有限公司")
|
cuttest("永和服装饰品有限公司")
|
||||||
cuttest("我爱北京天安门")
|
cuttest("我爱北京天安门")
|
||||||
cuttest("abc")
|
cuttest("abc")
|
||||||
cuttest("隐马尔可夫")
|
cuttest("隐马尔可夫")
|
||||||
cuttest("雷猴是个好网站")
|
cuttest("雷猴是个好网站")
|
||||||
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
||||||
cuttest("草泥马和欺实马是今年的流行词汇")
|
cuttest("草泥马和欺实马是今年的流行词汇")
|
||||||
cuttest("伊藤洋华堂总府店")
|
cuttest("伊藤洋华堂总府店")
|
||||||
cuttest("中国科学院计算技术研究所")
|
cuttest("中国科学院计算技术研究所")
|
||||||
cuttest("罗密欧与朱丽叶")
|
cuttest("罗密欧与朱丽叶")
|
||||||
cuttest("我购买了道具和服装")
|
cuttest("我购买了道具和服装")
|
||||||
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
||||||
cuttest("湖北省石首市")
|
cuttest("湖北省石首市")
|
||||||
cuttest("湖北省十堰市")
|
cuttest("湖北省十堰市")
|
||||||
cuttest("总经理完成了这件事情")
|
cuttest("总经理完成了这件事情")
|
||||||
cuttest("电脑修好了")
|
cuttest("电脑修好了")
|
||||||
cuttest("做好了这件事情就一了百了了")
|
cuttest("做好了这件事情就一了百了了")
|
||||||
cuttest("人们审美的观点是不同的")
|
cuttest("人们审美的观点是不同的")
|
||||||
cuttest("我们买了一个美的空调")
|
cuttest("我们买了一个美的空调")
|
||||||
cuttest("线程初始化时我们要注意")
|
cuttest("线程初始化时我们要注意")
|
||||||
cuttest("一个分子是由好多原子组织成的")
|
cuttest("一个分子是由好多原子组织成的")
|
||||||
cuttest("祝你马到功成")
|
cuttest("祝你马到功成")
|
||||||
cuttest("他掉进了无底洞里")
|
cuttest("他掉进了无底洞里")
|
||||||
cuttest("中国的首都是北京")
|
cuttest("中国的首都是北京")
|
||||||
cuttest("孙君意")
|
cuttest("孙君意")
|
||||||
cuttest("外交部发言人马朝旭")
|
cuttest("外交部发言人马朝旭")
|
||||||
cuttest("领导人会议和第四届东亚峰会")
|
cuttest("领导人会议和第四届东亚峰会")
|
||||||
cuttest("在过去的这五年")
|
cuttest("在过去的这五年")
|
||||||
cuttest("还需要很长的路要走")
|
cuttest("还需要很长的路要走")
|
||||||
cuttest("60周年首都阅兵")
|
cuttest("60周年首都阅兵")
|
||||||
cuttest("你好人们审美的观点是不同的")
|
cuttest("你好人们审美的观点是不同的")
|
||||||
cuttest("买水果然后来世博园")
|
cuttest("买水果然后来世博园")
|
||||||
cuttest("买水果然后去世博园")
|
cuttest("买水果然后去世博园")
|
||||||
cuttest("但是后来我才知道你是对的")
|
cuttest("但是后来我才知道你是对的")
|
||||||
cuttest("存在即合理")
|
cuttest("存在即合理")
|
||||||
cuttest("的的的的的在的的的的就以和和和")
|
cuttest("的的的的的在的的的的就以和和和")
|
||||||
cuttest("I love你,不以为耻,反以为rong")
|
cuttest("I love你,不以为耻,反以为rong")
|
||||||
cuttest("因")
|
cuttest("因")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("很好但主要是基于网页形式")
|
cuttest("很好但主要是基于网页形式")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("为什么我不能拥有想要的生活")
|
cuttest("为什么我不能拥有想要的生活")
|
||||||
cuttest("后来我才")
|
cuttest("后来我才")
|
||||||
cuttest("此次来中国是为了")
|
cuttest("此次来中国是为了")
|
||||||
cuttest("使用了它就可以解决一些问题")
|
cuttest("使用了它就可以解决一些问题")
|
||||||
cuttest(",使用了它就可以解决一些问题")
|
cuttest(",使用了它就可以解决一些问题")
|
||||||
cuttest("其实使用了它就可以解决一些问题")
|
cuttest("其实使用了它就可以解决一些问题")
|
||||||
cuttest("好人使用了它就可以解决一些问题")
|
cuttest("好人使用了它就可以解决一些问题")
|
||||||
cuttest("是因为和国家")
|
cuttest("是因为和国家")
|
||||||
cuttest("老年搜索还支持")
|
cuttest("老年搜索还支持")
|
||||||
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
||||||
cuttest("大")
|
cuttest("大")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("他说的确实在理")
|
cuttest("他说的确实在理")
|
||||||
cuttest("长春市长春节讲话")
|
cuttest("长春市长春节讲话")
|
||||||
cuttest("结婚的和尚未结婚的")
|
cuttest("结婚的和尚未结婚的")
|
||||||
cuttest("结合成分子时")
|
cuttest("结合成分子时")
|
||||||
cuttest("旅游和服务是最好的")
|
cuttest("旅游和服务是最好的")
|
||||||
cuttest("这件事情的确是我的错")
|
cuttest("这件事情的确是我的错")
|
||||||
cuttest("供大家参考指正")
|
cuttest("供大家参考指正")
|
||||||
cuttest("哈尔滨政府公布塌桥原因")
|
cuttest("哈尔滨政府公布塌桥原因")
|
||||||
cuttest("我在机场入口处")
|
cuttest("我在机场入口处")
|
||||||
cuttest("邢永臣摄影报道")
|
cuttest("邢永臣摄影报道")
|
||||||
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
||||||
cuttest("南京市长江大桥")
|
cuttest("南京市长江大桥")
|
||||||
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
||||||
cuttest('长春市长春药店')
|
cuttest('长春市长春药店')
|
||||||
cuttest('邓颖超生前最喜欢的衣服')
|
cuttest('邓颖超生前最喜欢的衣服')
|
||||||
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
||||||
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
||||||
cuttest('一次性交多少钱')
|
cuttest('一次性交多少钱')
|
||||||
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
||||||
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
||||||
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
||||||
cuttest('张晓梅去人民医院做了个B超然后去买了件T恤')
|
cuttest('张晓梅去人民医院做了个B超然后去买了件T恤')
|
||||||
cuttest('AT&T是一件不错的公司,给你发offer了吗?')
|
cuttest('AT&T是一件不错的公司,给你发offer了吗?')
|
||||||
cuttest('C++和c#是什么关系?11+122=133,是吗?PI=3.14159')
|
cuttest('C++和c#是什么关系?11+122=133,是吗?PI=3.14159')
|
||||||
cuttest('你认识那个和主席握手的的哥吗?他开一辆黑色的士。')
|
cuttest('你认识那个和主席握手的的哥吗?他开一辆黑色的士。')
|
||||||
|
@ -4,92 +4,92 @@ sys.path.append("../")
|
|||||||
import jieba
|
import jieba
|
||||||
|
|
||||||
def cuttest(test_sent):
|
def cuttest(test_sent):
|
||||||
result = jieba.cut(test_sent,cut_all=True)
|
result = jieba.cut(test_sent,cut_all=True)
|
||||||
print("/ ".join(result))
|
print("/ ".join(result))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
||||||
cuttest("我不喜欢日本和服。")
|
cuttest("我不喜欢日本和服。")
|
||||||
cuttest("雷猴回归人间。")
|
cuttest("雷猴回归人间。")
|
||||||
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
||||||
cuttest("我需要廉租房")
|
cuttest("我需要廉租房")
|
||||||
cuttest("永和服装饰品有限公司")
|
cuttest("永和服装饰品有限公司")
|
||||||
cuttest("我爱北京天安门")
|
cuttest("我爱北京天安门")
|
||||||
cuttest("abc")
|
cuttest("abc")
|
||||||
cuttest("隐马尔可夫")
|
cuttest("隐马尔可夫")
|
||||||
cuttest("雷猴是个好网站")
|
cuttest("雷猴是个好网站")
|
||||||
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
||||||
cuttest("草泥马和欺实马是今年的流行词汇")
|
cuttest("草泥马和欺实马是今年的流行词汇")
|
||||||
cuttest("伊藤洋华堂总府店")
|
cuttest("伊藤洋华堂总府店")
|
||||||
cuttest("中国科学院计算技术研究所")
|
cuttest("中国科学院计算技术研究所")
|
||||||
cuttest("罗密欧与朱丽叶")
|
cuttest("罗密欧与朱丽叶")
|
||||||
cuttest("我购买了道具和服装")
|
cuttest("我购买了道具和服装")
|
||||||
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
||||||
cuttest("湖北省石首市")
|
cuttest("湖北省石首市")
|
||||||
cuttest("湖北省十堰市")
|
cuttest("湖北省十堰市")
|
||||||
cuttest("总经理完成了这件事情")
|
cuttest("总经理完成了这件事情")
|
||||||
cuttest("电脑修好了")
|
cuttest("电脑修好了")
|
||||||
cuttest("做好了这件事情就一了百了了")
|
cuttest("做好了这件事情就一了百了了")
|
||||||
cuttest("人们审美的观点是不同的")
|
cuttest("人们审美的观点是不同的")
|
||||||
cuttest("我们买了一个美的空调")
|
cuttest("我们买了一个美的空调")
|
||||||
cuttest("线程初始化时我们要注意")
|
cuttest("线程初始化时我们要注意")
|
||||||
cuttest("一个分子是由好多原子组织成的")
|
cuttest("一个分子是由好多原子组织成的")
|
||||||
cuttest("祝你马到功成")
|
cuttest("祝你马到功成")
|
||||||
cuttest("他掉进了无底洞里")
|
cuttest("他掉进了无底洞里")
|
||||||
cuttest("中国的首都是北京")
|
cuttest("中国的首都是北京")
|
||||||
cuttest("孙君意")
|
cuttest("孙君意")
|
||||||
cuttest("外交部发言人马朝旭")
|
cuttest("外交部发言人马朝旭")
|
||||||
cuttest("领导人会议和第四届东亚峰会")
|
cuttest("领导人会议和第四届东亚峰会")
|
||||||
cuttest("在过去的这五年")
|
cuttest("在过去的这五年")
|
||||||
cuttest("还需要很长的路要走")
|
cuttest("还需要很长的路要走")
|
||||||
cuttest("60周年首都阅兵")
|
cuttest("60周年首都阅兵")
|
||||||
cuttest("你好人们审美的观点是不同的")
|
cuttest("你好人们审美的观点是不同的")
|
||||||
cuttest("买水果然后来世博园")
|
cuttest("买水果然后来世博园")
|
||||||
cuttest("买水果然后去世博园")
|
cuttest("买水果然后去世博园")
|
||||||
cuttest("但是后来我才知道你是对的")
|
cuttest("但是后来我才知道你是对的")
|
||||||
cuttest("存在即合理")
|
cuttest("存在即合理")
|
||||||
cuttest("的的的的的在的的的的就以和和和")
|
cuttest("的的的的的在的的的的就以和和和")
|
||||||
cuttest("I love你,不以为耻,反以为rong")
|
cuttest("I love你,不以为耻,反以为rong")
|
||||||
cuttest("因")
|
cuttest("因")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("很好但主要是基于网页形式")
|
cuttest("很好但主要是基于网页形式")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("为什么我不能拥有想要的生活")
|
cuttest("为什么我不能拥有想要的生活")
|
||||||
cuttest("后来我才")
|
cuttest("后来我才")
|
||||||
cuttest("此次来中国是为了")
|
cuttest("此次来中国是为了")
|
||||||
cuttest("使用了它就可以解决一些问题")
|
cuttest("使用了它就可以解决一些问题")
|
||||||
cuttest(",使用了它就可以解决一些问题")
|
cuttest(",使用了它就可以解决一些问题")
|
||||||
cuttest("其实使用了它就可以解决一些问题")
|
cuttest("其实使用了它就可以解决一些问题")
|
||||||
cuttest("好人使用了它就可以解决一些问题")
|
cuttest("好人使用了它就可以解决一些问题")
|
||||||
cuttest("是因为和国家")
|
cuttest("是因为和国家")
|
||||||
cuttest("老年搜索还支持")
|
cuttest("老年搜索还支持")
|
||||||
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
||||||
cuttest("大")
|
cuttest("大")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("他说的确实在理")
|
cuttest("他说的确实在理")
|
||||||
cuttest("长春市长春节讲话")
|
cuttest("长春市长春节讲话")
|
||||||
cuttest("结婚的和尚未结婚的")
|
cuttest("结婚的和尚未结婚的")
|
||||||
cuttest("结合成分子时")
|
cuttest("结合成分子时")
|
||||||
cuttest("旅游和服务是最好的")
|
cuttest("旅游和服务是最好的")
|
||||||
cuttest("这件事情的确是我的错")
|
cuttest("这件事情的确是我的错")
|
||||||
cuttest("供大家参考指正")
|
cuttest("供大家参考指正")
|
||||||
cuttest("哈尔滨政府公布塌桥原因")
|
cuttest("哈尔滨政府公布塌桥原因")
|
||||||
cuttest("我在机场入口处")
|
cuttest("我在机场入口处")
|
||||||
cuttest("邢永臣摄影报道")
|
cuttest("邢永臣摄影报道")
|
||||||
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
||||||
cuttest("南京市长江大桥")
|
cuttest("南京市长江大桥")
|
||||||
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
||||||
cuttest('长春市长春药店')
|
cuttest('长春市长春药店')
|
||||||
cuttest('邓颖超生前最喜欢的衣服')
|
cuttest('邓颖超生前最喜欢的衣服')
|
||||||
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
||||||
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
||||||
cuttest('一次性交多少钱')
|
cuttest('一次性交多少钱')
|
||||||
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
||||||
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
||||||
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
||||||
cuttest('张晓梅去人民医院做了个B超然后去买了件T恤')
|
cuttest('张晓梅去人民医院做了个B超然后去买了件T恤')
|
||||||
cuttest('AT&T是一件不错的公司,给你发offer了吗?')
|
cuttest('AT&T是一件不错的公司,给你发offer了吗?')
|
||||||
cuttest('C++和c#是什么关系?11+122=133,是吗?PI=3.14159')
|
cuttest('C++和c#是什么关系?11+122=133,是吗?PI=3.14159')
|
||||||
cuttest('你认识那个和主席握手的的哥吗?他开一辆黑色的士。')
|
cuttest('你认识那个和主席握手的的哥吗?他开一辆黑色的士。')
|
||||||
|
@ -6,24 +6,24 @@ sys.path.append("../")
|
|||||||
import jieba
|
import jieba
|
||||||
|
|
||||||
class Worker(threading.Thread):
|
class Worker(threading.Thread):
|
||||||
def run(self):
|
def run(self):
|
||||||
seg_list = jieba.cut("我来到北京清华大学",cut_all=True)
|
seg_list = jieba.cut("我来到北京清华大学",cut_all=True)
|
||||||
print("Full Mode:" + "/ ".join(seg_list)) #全模式
|
print("Full Mode:" + "/ ".join(seg_list)) #全模式
|
||||||
|
|
||||||
seg_list = jieba.cut("我来到北京清华大学",cut_all=False)
|
seg_list = jieba.cut("我来到北京清华大学",cut_all=False)
|
||||||
print("Default Mode:" + "/ ".join(seg_list)) #默认模式
|
print("Default Mode:" + "/ ".join(seg_list)) #默认模式
|
||||||
|
|
||||||
seg_list = jieba.cut("他来到了网易杭研大厦")
|
seg_list = jieba.cut("他来到了网易杭研大厦")
|
||||||
print(", ".join(seg_list))
|
print(", ".join(seg_list))
|
||||||
|
|
||||||
seg_list = jieba.cut_for_search("小明硕士毕业于中国科学院计算所,后在日本京都大学深造") #搜索引擎模式
|
seg_list = jieba.cut_for_search("小明硕士毕业于中国科学院计算所,后在日本京都大学深造") #搜索引擎模式
|
||||||
print(", ".join(seg_list))
|
print(", ".join(seg_list))
|
||||||
workers = []
|
workers = []
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
worker = Worker()
|
worker = Worker()
|
||||||
workers.append(worker)
|
workers.append(worker)
|
||||||
worker.start()
|
worker.start()
|
||||||
|
|
||||||
for worker in workers:
|
for worker in workers:
|
||||||
worker.join()
|
worker.join()
|
||||||
|
|
||||||
|
176
test/test_pos.py
176
test/test_pos.py
@ -4,94 +4,94 @@ sys.path.append("../")
|
|||||||
import jieba.posseg as pseg
|
import jieba.posseg as pseg
|
||||||
|
|
||||||
def cuttest(test_sent):
|
def cuttest(test_sent):
|
||||||
result = pseg.cut(test_sent)
|
result = pseg.cut(test_sent)
|
||||||
for w in result:
|
for w in result:
|
||||||
sys.stdout.write(w.word+ "/"+ w.flag + ", ")
|
sys.stdout.write(w.word+ "/"+ w.flag + ", ")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
cuttest("这是一个伸手不见五指的黑夜。我叫孙悟空,我爱北京,我爱Python和C++。")
|
||||||
cuttest("我不喜欢日本和服。")
|
cuttest("我不喜欢日本和服。")
|
||||||
cuttest("雷猴回归人间。")
|
cuttest("雷猴回归人间。")
|
||||||
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
cuttest("工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作")
|
||||||
cuttest("我需要廉租房")
|
cuttest("我需要廉租房")
|
||||||
cuttest("永和服装饰品有限公司")
|
cuttest("永和服装饰品有限公司")
|
||||||
cuttest("我爱北京天安门")
|
cuttest("我爱北京天安门")
|
||||||
cuttest("abc")
|
cuttest("abc")
|
||||||
cuttest("隐马尔可夫")
|
cuttest("隐马尔可夫")
|
||||||
cuttest("雷猴是个好网站")
|
cuttest("雷猴是个好网站")
|
||||||
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
cuttest("“Microsoft”一词由“MICROcomputer(微型计算机)”和“SOFTware(软件)”两部分组成")
|
||||||
cuttest("草泥马和欺实马是今年的流行词汇")
|
cuttest("草泥马和欺实马是今年的流行词汇")
|
||||||
cuttest("伊藤洋华堂总府店")
|
cuttest("伊藤洋华堂总府店")
|
||||||
cuttest("中国科学院计算技术研究所")
|
cuttest("中国科学院计算技术研究所")
|
||||||
cuttest("罗密欧与朱丽叶")
|
cuttest("罗密欧与朱丽叶")
|
||||||
cuttest("我购买了道具和服装")
|
cuttest("我购买了道具和服装")
|
||||||
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
cuttest("PS: 我觉得开源有一个好处,就是能够敦促自己不断改进,避免敞帚自珍")
|
||||||
cuttest("湖北省石首市")
|
cuttest("湖北省石首市")
|
||||||
cuttest("湖北省十堰市")
|
cuttest("湖北省十堰市")
|
||||||
cuttest("总经理完成了这件事情")
|
cuttest("总经理完成了这件事情")
|
||||||
cuttest("电脑修好了")
|
cuttest("电脑修好了")
|
||||||
cuttest("做好了这件事情就一了百了了")
|
cuttest("做好了这件事情就一了百了了")
|
||||||
cuttest("人们审美的观点是不同的")
|
cuttest("人们审美的观点是不同的")
|
||||||
cuttest("我们买了一个美的空调")
|
cuttest("我们买了一个美的空调")
|
||||||
cuttest("线程初始化时我们要注意")
|
cuttest("线程初始化时我们要注意")
|
||||||
cuttest("一个分子是由好多原子组织成的")
|
cuttest("一个分子是由好多原子组织成的")
|
||||||
cuttest("祝你马到功成")
|
cuttest("祝你马到功成")
|
||||||
cuttest("他掉进了无底洞里")
|
cuttest("他掉进了无底洞里")
|
||||||
cuttest("中国的首都是北京")
|
cuttest("中国的首都是北京")
|
||||||
cuttest("孙君意")
|
cuttest("孙君意")
|
||||||
cuttest("外交部发言人马朝旭")
|
cuttest("外交部发言人马朝旭")
|
||||||
cuttest("领导人会议和第四届东亚峰会")
|
cuttest("领导人会议和第四届东亚峰会")
|
||||||
cuttest("在过去的这五年")
|
cuttest("在过去的这五年")
|
||||||
cuttest("还需要很长的路要走")
|
cuttest("还需要很长的路要走")
|
||||||
cuttest("60周年首都阅兵")
|
cuttest("60周年首都阅兵")
|
||||||
cuttest("你好人们审美的观点是不同的")
|
cuttest("你好人们审美的观点是不同的")
|
||||||
cuttest("买水果然后来世博园")
|
cuttest("买水果然后来世博园")
|
||||||
cuttest("买水果然后去世博园")
|
cuttest("买水果然后去世博园")
|
||||||
cuttest("但是后来我才知道你是对的")
|
cuttest("但是后来我才知道你是对的")
|
||||||
cuttest("存在即合理")
|
cuttest("存在即合理")
|
||||||
cuttest("的的的的的在的的的的就以和和和")
|
cuttest("的的的的的在的的的的就以和和和")
|
||||||
cuttest("I love你,不以为耻,反以为rong")
|
cuttest("I love你,不以为耻,反以为rong")
|
||||||
cuttest("因")
|
cuttest("因")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("很好但主要是基于网页形式")
|
cuttest("很好但主要是基于网页形式")
|
||||||
cuttest("hello你好人们审美的观点是不同的")
|
cuttest("hello你好人们审美的观点是不同的")
|
||||||
cuttest("为什么我不能拥有想要的生活")
|
cuttest("为什么我不能拥有想要的生活")
|
||||||
cuttest("后来我才")
|
cuttest("后来我才")
|
||||||
cuttest("此次来中国是为了")
|
cuttest("此次来中国是为了")
|
||||||
cuttest("使用了它就可以解决一些问题")
|
cuttest("使用了它就可以解决一些问题")
|
||||||
cuttest(",使用了它就可以解决一些问题")
|
cuttest(",使用了它就可以解决一些问题")
|
||||||
cuttest("其实使用了它就可以解决一些问题")
|
cuttest("其实使用了它就可以解决一些问题")
|
||||||
cuttest("好人使用了它就可以解决一些问题")
|
cuttest("好人使用了它就可以解决一些问题")
|
||||||
cuttest("是因为和国家")
|
cuttest("是因为和国家")
|
||||||
cuttest("老年搜索还支持")
|
cuttest("老年搜索还支持")
|
||||||
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
cuttest("干脆就把那部蒙人的闲法给废了拉倒!RT @laoshipukong : 27日,全国人大常委会第三次审议侵权责任法草案,删除了有关医疗损害责任“举证倒置”的规定。在医患纠纷中本已处于弱势地位的消费者由此将陷入万劫不复的境地。 ")
|
||||||
cuttest("大")
|
cuttest("大")
|
||||||
cuttest("")
|
cuttest("")
|
||||||
cuttest("他说的确实在理")
|
cuttest("他说的确实在理")
|
||||||
cuttest("长春市长春节讲话")
|
cuttest("长春市长春节讲话")
|
||||||
cuttest("结婚的和尚未结婚的")
|
cuttest("结婚的和尚未结婚的")
|
||||||
cuttest("结合成分子时")
|
cuttest("结合成分子时")
|
||||||
cuttest("旅游和服务是最好的")
|
cuttest("旅游和服务是最好的")
|
||||||
cuttest("这件事情的确是我的错")
|
cuttest("这件事情的确是我的错")
|
||||||
cuttest("供大家参考指正")
|
cuttest("供大家参考指正")
|
||||||
cuttest("哈尔滨政府公布塌桥原因")
|
cuttest("哈尔滨政府公布塌桥原因")
|
||||||
cuttest("我在机场入口处")
|
cuttest("我在机场入口处")
|
||||||
cuttest("邢永臣摄影报道")
|
cuttest("邢永臣摄影报道")
|
||||||
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
cuttest("BP神经网络如何训练才能在分类时增加区分度?")
|
||||||
cuttest("南京市长江大桥")
|
cuttest("南京市长江大桥")
|
||||||
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
cuttest("应一些使用者的建议,也为了便于利用NiuTrans用于SMT研究")
|
||||||
cuttest('长春市长春药店')
|
cuttest('长春市长春药店')
|
||||||
cuttest('邓颖超生前最喜欢的衣服')
|
cuttest('邓颖超生前最喜欢的衣服')
|
||||||
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
cuttest('胡锦涛是热爱世界和平的政治局常委')
|
||||||
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
cuttest('程序员祝海林和朱会震是在孙健的左面和右面, 范凯在最右面.再往左是李松洪')
|
||||||
cuttest('一次性交多少钱')
|
cuttest('一次性交多少钱')
|
||||||
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
cuttest('两块五一套,三块八一斤,四块七一本,五块六一条')
|
||||||
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
cuttest('小和尚留了一个像大和尚一样的和尚头')
|
||||||
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
cuttest('我是中华人民共和国公民;我爸爸是共和党党员; 地铁和平门站')
|
||||||
cuttest('张晓梅去人民医院做了个B超然后去买了件T恤')
|
cuttest('张晓梅去人民医院做了个B超然后去买了件T恤')
|
||||||
cuttest('AT&T是一件不错的公司,给你发offer了吗?')
|
cuttest('AT&T是一件不错的公司,给你发offer了吗?')
|
||||||
cuttest('C++和c#是什么关系?11+122=133,是吗?PI=3.14159')
|
cuttest('C++和c#是什么关系?11+122=133,是吗?PI=3.14159')
|
||||||
cuttest('你认识那个和主席握手的的哥吗?他开一辆黑色的士。')
|
cuttest('你认识那个和主席握手的的哥吗?他开一辆黑色的士。')
|
||||||
|
@ -15,7 +15,7 @@ tm_cost = t2-t1
|
|||||||
|
|
||||||
log_f = open("1.log","wb")
|
log_f = open("1.log","wb")
|
||||||
for w in words:
|
for w in words:
|
||||||
log_f.write(bytes(w.word+"/"+w.flag+" ",'utf-8'))
|
log_f.write(bytes(w.word+"/"+w.flag+" ",'utf-8'))
|
||||||
|
|
||||||
print('speed' , len(content)/tm_cost, " bytes/second")
|
print('speed' , len(content)/tm_cost, " bytes/second")
|
||||||
|
|
||||||
|
@ -9,12 +9,12 @@ test_sent = "李小福是创新办主任也是云计算方面的专家;"
|
|||||||
test_sent += "例如我输入一个带“韩玉赏鉴”的标题,在自定义词库中也增加了此词为N类型"
|
test_sent += "例如我输入一个带“韩玉赏鉴”的标题,在自定义词库中也增加了此词为N类型"
|
||||||
words = jieba.cut(test_sent)
|
words = jieba.cut(test_sent)
|
||||||
for w in words:
|
for w in words:
|
||||||
print(w)
|
print(w)
|
||||||
|
|
||||||
result = pseg.cut(test_sent)
|
result = pseg.cut(test_sent)
|
||||||
|
|
||||||
for w in result:
|
for w in result:
|
||||||
print(w.word, "/", w.flag, ", ")
|
print(w.word, "/", w.flag, ", ")
|
||||||
|
|
||||||
print("\n========")
|
print("\n========")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user