Python:使用pyhanlp 进行分词

简介: Python:使用pyhanlp 进行分词

pyhanlp调用java实现的HanLP接口进行分词

安装

pip install pyhanlp

pyhanlp: https://github.com/hankcs/pyhanlp

HanLP: https://github.com/hankcs/HanLP

代码示例

# -*- coding: utf-8 -*-


from pyhanlp import HanLP

document = "你好,欢迎在Python中调用HanLP的API"

# 分词
print(HanLP.segment(document))
"""
[你好/vl, ,/w, 欢迎/v, 在/p, Python/nx, 中/f, 调用/v, HanLP/nx, 的/ude1, API/nx]
"""

# 关键词提取
print(HanLP.extractKeyword(document, 2))
# [中, 调用]

# 自动摘要
print(HanLP.extractSummary(document, 3))
# [欢迎在Python中调用HanLP的API]


            </div>
目录
相关文章
|
13天前
|
数据可视化 测试技术 持续交付
python分析测试结果
【4月更文挑战第21天】
21 3
|
3月前
|
缓存 Shell 开发工具
你可能不知道的 Python 技巧
你可能不知道的 Python 技巧
30 1
|
4月前
|
Python
Python喜羊羊
Python喜羊羊
41 0
|
9月前
|
Python
【从零学习python 】40.python魔法方法(一)
【从零学习python 】40.python魔法方法(一)
44 0
|
9月前
|
Python
【从零学习python 】41.python魔法方法(二)
【从零学习python 】41.python魔法方法(二)
23 0
|
Python
Python:使用2to3将Python2转Python3
Python:使用2to3将Python2转Python3
41 0
|
存储 Python
Python中namedtuple使用
Python中存储系列数据,比较常见的数据类型有list,除此之外,还有tuple数据类型。相比与list,tuple中的元素不可修改,在映射中可以当键使用。tuple元组的item只能通过index访问,collections模块的namedtuple子类不仅可以使用item的index访问item,还可以通过item的name进行访问。可以将namedtuple理解为c中的struct结构,其首先将各个item命名,然后对每个item赋予数据。
93 0
|
Python
Python之%s%d%f
Python之%s%d%f
89 0
Python之%s%d%f
|
存储 Java Go