pyltp库的使用进行文本分析

pyltp目前支持puthon3.6不支持3.7

用python3.7安装了很久都没有安装成功

无奈换成了3.6

 分句

from pyltp import SentenceSplitter
sents = SentenceSplitter.split('元芳你怎么看?我就趴窗口上看呗!')  # 分句
print('\n'.join(sents))

切割句子。

 

 分词

import os
from pyltp import Segmentor
LTP_DATA_DIR='D:\Python3.6\ltp3.4\ltp3.4'
cws_model_path=os.path.join(LTP_DATA_DIR,'cws.model')
segmentor=Segmentor()
segmentor.load(cws_model_path)
words=segmentor.segment('熊高雄你吃饭了吗')
print(type(words))
print('\t'.join(words))
segmentor.release()

 

 来源https://www.jianshu.com/p/f78453f5d1ca

posted @ 2020-03-15 11:08  张利杰j  阅读(443)  评论(0编辑  收藏  举报