赞
踩
curl https://bootstrap.pypa.io/get-pip.py | python3
你可以接着输入
pip --version
看到pip的版本
pip install jieba
import jieba import jieba.posseg as psg # 词性标注入口 s = "我爱北京天安门" for x in jieba.cut(s): print(x) print(jieba.lcut(s, cut_all=True)) # 全模式 s = "李明硕士毕业于中国科学院计算所" result = jieba.lcut_for_search(s) # 搜索引擎 在精确模式基础上 再对长词切分 print(result) test_sent = "李元帅是计科系主任也是云计算方面的专家" words = jieba.cut(test_sent) print("/".join(words)) words = jieba.cut(test_sent) jieba.add_word("云计算") # 添加一个词 不让 云/计算 而是 云计算 print("/".join(words)) jieba.load_userdict("words.txt") # 加载自定义词库《字典》 words = jieba.cut(test_sent) print("/".join(words)) test = "我和同学一起去北京故宫玩" seg = psg.lcut(test) # 词性标注 print(seg) for els in seg: if els.flag == 'ns': print(els, end=" ") print() lst = [x.word for x in seg if x.flag == 'ns'] # 筛选 print(lst)
Building prefix dict from the default dictionary ... Loading model from cache /var/folders/s0/zmlxbj21347470whgkgz35p00000gn/T/jieba.cache 我 爱 北京 天安门 ['我', '爱', '北京', '天安', '天安门'] ['李明', '硕士', '毕业', '于', '中国', '科学', '学院', '科学院', '中国科学院', '计算', '计算所'] 李/元帅/是/计科/系主任/也/是/云/计算/方面/的/专家 李/元帅/是/计科/系主任/也/是/云计算/方面/的/专家 李元帅/是/计科系主任/也/是/云计算/方面/的/专家 [pair('我', 'r'), pair('和', 'c'), pair('同学', 'n'), pair('一起', 'm'), pair('去', 'v'), pair('北京故宫', 'ns'), pair('玩', 'v')] 北京故宫/ns ['北京故宫'] Loading model cost 0.736 seconds. Prefix dict has been built successfully.
from jieba import analyse
text = '''最近在学习python学到jieba库的操作,本想在电脑上练练手发现还得安装,好麻烦。在网上找了半天怎么安装jieba库,没有找到看得懂的安装教程。。。可能是我太小白了。。。
就像下面这张图说的,啥全自动半自动啊。。看不懂,当然我也是有点基础的,全自动安装里提到里pip,书里也提到过啊,是第三方库安装工具,那就先安装pip吧。
'''
keywords = analyse.extract_tags(text, topK=10, withWeight=True)
print(keywords)
for keyword in keywords:
print("{:<5} weight:{:4.2f}".format(keyword[0], keyword[1]))
Building prefix dict from the default dictionary ... Loading model from cache /var/folders/s0/zmlxbj21347470whgkgz35p00000gn/T/jieba.cache Loading model cost 0.656 seconds. Prefix dict has been built successfully. [('安装', 0.9139764647549999), ('jieba', 0.5433985228590908), ('pip', 0.5433985228590908), ('全自动', 0.4344032831872727), ('提到', 0.3008143851077273), ('练练手', 0.2844178020659091), ('python', 0.2716992614295454), ('看得懂', 0.2594493409590909), ('书里', 0.2427682233431818), ('图说', 0.23385817589318184)] 安装 weight:0.91 jieba weight:0.54 pip weight:0.54 全自动 weight:0.43 提到 weight:0.30 练练手 weight:0.28 python weight:0.27 看得懂 weight:0.26 书里 weight:0.24 图说 weight:0.23 Process finished with exit code 0
网络分析算法
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。