文本处理与分析:NLTK实用指南
在自然语言处理(NLP)领域,文本处理和分析是基础且关键的步骤。本文将详细介绍使用Python的NLTK库进行文本处理的多种技术,包括词干提取、词形还原、停用词去除、词频统计、稀有词和短词去除、标点符号去除以及n - 元组拼接等操作。
1. 词干提取
词干提取是将单词转换为其基本词干的过程,通常是简单地截断词尾。NLTK提供了Porter和Lancaster两种词干提取器。以下是使用 07/03_stemming.py 文件中的代码示例,对输入文件的第一句进行词干提取:
from nltk.stem import PorterStemmer
from nltk.stem.lancaster import LancasterStemmer
from nltk.tokenize import regexp_tokenize
pst = PorterStemmer()
lst = LancasterStemmer()
print("Stemming results:")
for token in regexp_tokenize(sentences[0], pattern='\w+'):
print(token, pst.stem(token), lst.stem(token))
运行结果如下:
Stemming results:
We We we
are are ar
seeking seek seek
developers d
超级会员免费看
订阅专栏 解锁全文
16

被折叠的 条评论
为什么被折叠?



