中文自然语言处理--HanLP 中文分词

HanLP 主项目采用 Java 开发

from pyhanlp import HanLP, CustomDictionary

content = "现如今,机器学习和深度学习带动人工智能飞速的发展,并在图片处理、语音识别领域取得巨大成功。"

# 分词
print(HanLP.segment(content))

# 自定义词典分词
# 在没有使用自定义字典时的分词
txt = "铁甲网是中国最大的工程机械交易平台。王者荣耀是一款游戏。"
print(HanLP.segment(txt))

# 添加自定义新词
# 动态增加
CustomDictionary.add("铁甲网", "nz 2")
CustomDictionary.add("王者荣耀", "nz 2")
# CustomDictionary.remove("王者荣耀")  # 删除词语
# 强行插入
CustomDictionary.insert("工程机械", "nz 1024")
CustomDictionary.add("交易平台", "nz 20 n 1")
# 展示该单词词典中的词频统计 展示分词
print(CustomDictionary.get("中国"))
print(CustomDictionary.get("天猫"))
print(CustomDictionary.get("王者荣耀"))
print(CustomDictionary.get("交易平台"))
print(HanLP.segment(txt))

原文链接:
https://soyoger.blog.csdn.net/article/details/108729415

猜你喜欢

转载自blog.csdn.net/fgg1234567890/article/details/114242897