繁体   English   中英

在不使用 NLTK 的情况下从 Python 中的文本中删除停止词

[英]Removing Stop Word From a Text in Python Without Using NLTK

我用我的母语在 Python 中列出了停用词。 键入文本时如何在不使用 NLTK 的情况下删除它们?

看看这个(这只有在有问题的语言可以在空格上被打破时才有效,但这还没有得到澄清——感谢 Oso):

import numpy as np
your_stop_words = ['something','sth_else','and ...']
new_string = input()
words = np.array(new_string.split())
is_stop_word = np.isin(words,your_stop_words)
filtered_words = words[~is_stop_word]
clean_text = ' '.join(filtered_words)

如果有问题的语言不能被分成空格,你可以使用这个解决方案:

your_stop_words = ['something','sth_else','and ...']
new_string = input()
clean_text = new_string
for stop_word in your_stop_words :
    clean_text = clean_text.replace(stop_word,"")

在这种情况下,您需要确保停用词不能成为另一个词的一部分。 你可以根据你的语言来做。 例如,您可以在停用词周围使用空格。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM