NLTK
有一个内置的停用词列表,由11种语言的2400个停用词组成(Porter等),请参见http://nltk.org/book/ch02.html
>>> from nltk import word_tokenize
>>> from nltk.corpus import stopwords
>>> stop = set(stopwords.words('english'))
>>> sentence = "this is a foo bar sentence"
>>> print([i for i in sentence.lower().split() if i not in stop])
['foo', 'bar', 'sentence']
>>> [i for i in word_tokenize(sentence.lower()) if i not in stop]
['foo', 'bar', 'sentence']
我建议您使用tf-idf删除停用词,请参阅词干对词频的影响?
0
我正在尝试通过使用nltk工具包删除停用词来处理用户输入的文本,但是通过停用词删除,将删除“和”,“或”,“不”之类的词。我希望这些词在停用词删除过程之后出现,因为它们是稍后将文本作为查询处理所必需的运算符。我不知道哪些字符可以作为文本查询中的运算符,我还想从文本中删除不必要的词。