1.
# encoding=utf-8
import jieba
import jieba.posseg as pseg
print("\njieba分词全模式:")
seg_list = jieba.cut("我来到北京清华大学", cut_all=True)
print("Full Mode: " + "/、 ".join(seg_list)) # 全模式
strings="是广泛使用的中文分词工具,具有以下特点:"
words = pseg.cut(strings)
print("\njieba词性标注:")
for word, flag in words:
print('%s %s' % (word, flag))
结果:
jieba分词全模式:
Building prefix dict from the default dictionary ...
Loading model from cache C:\Users\ADMINI~1\AppData\Local\Temp\jieba.cache
Loading model cost 1.566 seconds.
Prefix dict has been built succesfully.
Full Mode: 我/、 来到/、 北京/、 清华/、 清华大学/、 华大/、 大学
jieba词性标注:
是 v
广泛 a
使用 v
的 uj
中文 nz
分词 n
工具 n
, x
具有 v
以下 f
特点 n
: x
2.
# -*- coding: utf-8 -*-
import jieba.analyse as analyse
#f = open('text.txt',mode='r',encoding='utf-8')
lines="恶性肿瘤的分期越高,患者预后越差。通过对肿瘤不同恶性程度的划分,TNM分期在预测预后方面不断完善。"
for i in analyse.extract_tags(lines, topK=20, withWeight=True, allowPOS=(['ns', 'n', 'vn', 'v','nr'])):
print (i)
#analyse.textrank(lines, topK=20, withWeight=False, allowPOS=('ns', 'n', 'vn', 'v'
print (" ".join(analyse.textrank(lines, topK=20, withWeight=False, allowPOS=('ns', 'n', 'vn', 'v','nr'))))
import jieba.posseg as pseg
words = pseg.cut("我爱自然语言处理")
for word, flag in words:
print('%s %s' % (word, flag))
结果:('分期', 1.9490619860111111)
('恶性', 0.9609338026588888)
('肿瘤', 0.8611194315033334)
('划分', 0.7362442325777778)
('患者', 0.7053239519733334)
('预测', 0.6613265774622222)
('程度', 0.5738165478488889)
('方面', 0.47367896445666663)
分期 程度 划分 恶性 预测 方面 肿瘤 患者
我 r
爱 v
自然语言 l
处理 v