本教程将带您了解如何使用 Natural Language Toolkit (NLTK) 进行自然语言处理。NLTK 是一个强大的 Python 库,用于处理文本数据,非常适合初学者和专业人士。
安装 NLTK
首先,您需要安装 NLTK 库。您可以通过以下命令安装:
pip install nltk
基础用法
加载文本
from nltk.tokenize import word_tokenize
text = "Hello, world!"
tokens = word_tokenize(text)
print(tokens)
词频统计
from nltk.probability import FreqDist
freq_dist = FreqDist(tokens)
print(freq_dist.most_common())
词性标注
from nltk import pos_tag
pos_tags = pos_tag(tokens)
print(pos_tags)
更多内容
想了解更多关于 NLTK 的内容,请访问我们的 NLTK 教程页面。
Python
NLTK