簡體   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