首页 > 其他 > 详细

优化代码 如何去除停顿词

时间:2019-08-28 18:14:09      阅读:106      评论:0      收藏:0      [点我收藏+]
# 方法一:暴力法,对每个词进行判断----传统方法
def remove_stopwords1(text):
    words = text.split( )
    new_words = list()
    for word in words:
        if word not in stopwords:
            new_words.append(word)
    return new_words

# 方法二:先构建停用词的映射---推荐方法
for word in stopwords:
    if word in words_count.index:
        words_count[word] = -1

def remove_stopwords2(text):
    words = text.split( )
    new_words = list()
    for word in words:
        if words_count[word] != -1:
            new_words.append(word)
    return new_words

 

优化代码 如何去除停顿词

原文:https://www.cnblogs.com/cupleo/p/11425098.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!