更详细情况参考:http://python.jobbole.com/88874/
在使用nltk之前,要通过运行以下代码来安装相关需要的NLTK扩展包,在直接面板安装。
from nltk.tokenize import word_tokenize, sent_tokenize。
word_tokenize(str),从提供的本中分离出包含每个句子列表。
sent_tokenize(str),从提供的句子中分离出包含每个单词的列表。
from nltk.corpus import stopwords
stopwords.words(‘english’),其实就是得到一个内置停用词的列表,如下:
class 'list'> ['the', 'because', 'ma', 'hadn', 'of', 'i', 'both', 'm', 'how', 'between', 'down', "doesn't", 'under', 'that', 'have', 'or', 'by', 'your', 'other', 'about', 'will', 'to', 'he', 'now', 'wouldn', 'while', 'nor', "shan't", 'o', 'with', 'doesn', 'can', 'has', "you'd", 'any', "don't", 'ain', 're', 'themselves', 'herself', 'needn', 'over', 'here', 'from', "couldn't", "needn't", 'yours', 'for', 'such', 'there', 'his', 'me', 'itself', 'below', 'hers', 'be', 'her', 'not', 'as', 'no', 'yourselves', 'mightn', 'myself', 'why', 'couldn', 'again', 'won', 'after', 'same', "that'll", 's', 'at', "hasn't", 'were', 'am', "didn't", 'some', 'too', 'we', 'just', 'you', 'd', 'its', 'on', 'whom', "mustn't", 'she', 'this', 'an', 'most', 'own', 'into', 'shan', 'hasn', "shouldn't", "wouldn't", 'ours', 'haven', 'and', "you'll", 'until', 'through', 'during', 'up', 'do', 'then', "aren't", "you've", 'off', 'when', 'does', 'are', 've', "mightn't", 'mustn', 'having', 'out', 'if', 'wasn', 'theirs', 'they', 'against', "won't", 'which', 'only', "you're", 'was', "should've", 'once', 'doing', 'been', 'their', 'is', 'before', 'being', 'aren', 'himself', 'few', 'y', "hadn't", 'don', 'so', 'those', 'above', 'a', "wasn't", "haven't", 'isn', "isn't", 'weren', 'did', 'yourself', 'in', 'than', 'very', "it's", 'these', 'had', "weren't", 'who', 'our', 'll', 't', 'but', 'didn', 'all', 'my', 'them', 'what', 'ourselves', 'should', 'each', 'where', 'him', 'it', "she's", 'more', 'further', 'shouldn']
也可以照自己特定需要,自己做一个这样的列表。