当前位置:   article > 正文

用spacy切词,筛选特定词性_spacy vbd vbz

spacy vbd vbz
import spacy
nlp = spacy.load("en_core_web_lg")
  • 1
  • 2
# 读取停用词列表
from nltk.corpus import stopwords  
stopword_list = list(stopwords.words('english'))
add_stopword_list = ["'s",'also','even']
stopword_list+=add_stopword_list
  • 1
  • 2
  • 3
  • 4
  • 5
# pos_tag = ['JJ','JJR','JJS','RB','RBR','RBS','VB','VBD','VBG','VBN','VBP','VBZ','NN','NNP','NNPS','NNS']
pos_tag = ['JJ','JJR','JJS','RB','RBR','RBS']

def dataPrepro(corpus,stopword_list,pos_tag):
    """corpus:语料,str格式;stopword_list停用词列表;pos_tag:词性列表,筛选出指定词性的词"""
    token_list = []
    for token in nlp(corpus):
        if token.text not in stopword_list and token.tag_ in pos_tag: # 去停用词 + 词性筛选
            token_list.append(token.text)
    
    output = " ".join(token_list)
    return output
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/355478
推荐阅读
相关标签
  

闽ICP备14008679号