Python 结巴分词停止词及自定义词库

来源:互联网 发布:python 变量类型 编辑:程序博客网 时间:2024/05/17 08:49

# 自定义词库

f='g:/'+I[i]+'.txt'
jieba.load_userdict(f)

# 停止词

stopwords='G:/g/data/word/chinese_stopword.txt'
stop_single_words=[]  
with open(stopwords,'r') as f:  
    for line in f:  
        content=line.strip()  
        stop_single_words.append(content.decode('utf8'))  

# 分词时去除停止词

word_cut=table_x.ABSTRACT_ZH[[j,k]].apply(lambda s: [i for i in list(jieba.cut(s)) if i not in stop_single_words])