[英]Is there any way to classify/ remove words (Exm. “Which”, “potential”, this, “are” etc.) using python from a list
我目前正在從事與自然語言處理和文本挖掘有關的項目,我寫下了代碼來計算文本文件中唯一單詞的頻率。
Frequencey of: trypanosomiasis --> 0.0029
Frequencey of: deadly --> 0.0029
Frequencey of: yellow --> 0.0029
Frequencey of: humanassociated --> 0.0029
Frequencey of: successful --> 0.0029
Frequencey of: potential --> 0.0058
Frequencey of: which --> 0.0029
Frequencey of: cholera --> 0.01449
Frequencey of: antimicrobial --> 0.0029
Frequencey of: hostdirected --> 0.0029
Frequencey of: cameroon --> 0.0029
是否有任何庫或方法可以從文本文件中刪除常用詞,幫助動詞的形容詞等(例如,“哪個”,“潛在”,這個,“是”等),以便我可以探索或計算最多科學術語可能會出現在文本數據中。
通常在文本分析中,您會刪除停用詞-那些對文本意義不大的常用詞。 您可以使用nltk的停用詞(來自https://pythonspot.com/en/nltk-stop-words/ )將其刪除:
from nltk.tokenize import sent_tokenize, word_tokenize
from nltk.corpus import stopwords
data = "All work and no play makes jack dull boy. All work and no play makes jack a dull boy."
stopWords = set(stopwords.words('english'))
words = word_tokenize(data)
wordsFiltered = []
for w in words:
if w not in stopWords:
wordsFiltered.append(w)
print(wordsFiltered)
如果您要刪除其他字詞,可以將其添加到設置的stopWords
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.