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>
目录
相关文章
|
3月前
|
缓存 Shell 开发工具
你可能不知道的 Python 技巧
你可能不知道的 Python 技巧
30 1
|
4月前
|
机器学习/深度学习 数据采集 运维
python实际应用
python实际应用
27 1
|
6月前
|
Python
09 python - if判断语句
09 python - if判断语句
22 0
|
人工智能 前端开发 JavaScript
更多了解 Python: 一些有趣的知识介绍
更多了解 Python: 一些有趣的知识介绍
89 0
更多了解 Python: 一些有趣的知识介绍
|
Python
几个Python技巧
几个Python技巧
87 0
|
机器学习/深度学习 Python
(Python)矩阵旋转
(Python)矩阵旋转
84 0
|
数据采集 机器学习/深度学习 人工智能
初识 Python
人生苦短,我用 Python —— Life is short, you need Python
|
Python
Python中的“in”和“not in”
Python中的“in”和“not in”, “in”是用来检查字典中是否包含指定的键, “not in”是检查字典中是否不包含指定的键,这两个正好相反。
412 0
Python中的“in”和“not in”
|
数据安全/隐私保护 Python
|
Python
python:for-else和while-else应用
python: for-else while-else
946 0