[英]not be able to remove stopword
我有停用詞列表,但程序無法刪除語料庫中的停用詞
我使用的代碼
stop_factory = StopWordRemoverFactory()
more_stopword = ['selamat','halo','hallo','hi']
dok_word = ['Dok','dok?', 'dok,', 'dok.', 'dok-', 'dok!', 'dok:', 'dok;', 'dok', 'dok.,','dok,.','dok?.',
'Dokter','dokter?', 'dokter,', 'dokter.', 'dokter-', 'dokter!', 'dokter:', 'dokter;']
data = stop_factory.get_stop_words()+more_stopword+dok_word
# cleaning
def clean_text(text):
new_text = []
text = text.lower() # Lowercase
# Loop each word in a sentence
for kata in text.split():
# Keep word not in slang or standard word
if kata not in std_word_replace:
new_text.append(kata)
# Replace non-formal word with standard word
elif kata in std_word_replace:
new_text+=std_word_replace[kata].split()
# Join words without stopwords after stemming
new_text = ' '.join(
stemmer.stem(word) for word in new_text if word not in data
)
# Remove punctuations
text = text.translate(str.maketrans('', '', string.punctuation))
return new_text
所以我用這段代碼xtrain['question'].apply(lambda x: clean_text(x))
到我的語料庫,行是這樣的,並以第一個索引為例
話: 'Dok,anak saya sudah imunisasi DPT'
output: 'dok anak imunisasi dpt'
“dok”這個詞仍然存在,我該如何解決這個問題?
在您的代碼中,您創建了 dok_word 但未使用它。 您還需要仔細檢查,因為 text_dok = "dok,anak saya sepertinya" 如果您只是按空格分開,那么停用詞仍然不會影響。
你在最后一行有錯誤,你應該像stopwordexample.remove(dok_word)
一樣使用它
stop_factory = StopWordRemoverFactory()
dok_word = ['Dok','dok?', 'dok,', 'dok.', 'dok-', 'dok!', 'dok:', 'dok;', 'dok', 'dok.,','dok,.','dok?.',
'Dokter','dokter?', 'dokter,', 'dokter.', 'dokter-', 'dokter!', 'dokter:', 'dokter;']
text_dok = "dok,anak saya sepertinya"
stopwordexample = stop_factory.create_stop_word_remover()
text_dok = stopwordexample.remove(dok_word)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.