python - 在 Python NLTK 中从文件中定义自己的语言特定的停用词集
问题描述
有没有办法自定义这个
stopWords = set(stopwords.words('english'))
或任何其他方式,所以我可以在 Python 的 NLTK 中使用我的语言中的停用词的文本文件?
如果我的文本文件是 my_stop_words.txt,我怎么能告诉 NLTK 使用这组单词而不是设置为“英语”?
非常感谢!
解决方案
是的,您可以阅读自己的停用词文件,但值得一提的是,NLTK 的停用词支持多种语言。
尝试类似:
with open("stopwords.txt", "r") as f:
new_stopwords = []
for line in f.readlines()
new_stopwords.append(line)
new_stopwords_set = set(new_stopwords)
推荐阅读
- javascript - 为什么 fetch 并不总是访问 nodejs 路由
- java - 如何更新 Scala 中日期格式的列
- android - AutoSizeTextTypeUniform 不适用于三星
- servicestack - 使用客户端和 ApiKeyAuthProvider “找不到与任何提供者匹配的已注册身份验证提供者”
- kubernetes - 监控 GKE 上运行的 Cronjob
- python - 无限循环中的Python脚本
- r - 如何合并2个数据集?
- pyspark - 如何将前导零添加到 pyspark 数据框列
- react-native - 将数据发送到 bottomTabNavigator 中的每个屏幕
- scala - 在 Scala 中读取带有多行字符串的 CSV 文件