TextBlob 是一个用于处理文本的 Python 库,提供简单易用的 API 来进行自然语言处理任务,如情感分析、词性标注、名词短语提取等。以下是快速入门教程:
快速开始 🚀
安装
pip install textblob
基础用法
- 文本分析:
from textblob import TextBlob text = TextBlob("TextBlob makes text processing fun!") print(text.sentiment) # 输出情感极性
- 情感分析:
print(text.sentiment.polarity) # 极性值范围:-1到1
- 文本分析:
高级功能
- 词性标注:
for word, tag in text.words_tags(): print(f"{word}: {tag}")
- 名词短语提取:
print(text.noun_phrases)
- 词性标注: