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]