我从文本文档中检索了以下关键字。
natural language processing
sequential labeling
programmable
spell checking
techniques
forensics
important issue
categorial grammar
girls
applications现在,我想从这个关键字列表中删除不想要的单词,比如programmable, techniques, important issue, girls, applications。有办法实现自动化吗?我能考虑一些pos模式来做这个吗?
请帮帮我!
发布于 2017-12-14 21:24:15
不知道你到底在找什么。有很多方法可以做到这一点。一个简单的方法就是这样,
word_list = ['natural language processing', 'sequential labeling', 'programmable', 'spell checking', 'techniques', 'forensics', 'important issue', 'categorial grammar', 'girls', 'applications']既然你说了一串关键词,
stopwords = ['programmable','techniques', 'important issue', 'girls', 'applications']
resultwords = [word for word in word_list if word.lower() not in stopwords]
result = ' '.join(resultwords)
print (result)这会屈服,
>> natural language processing sequential labeling spell checking forensics categorial grammar否则,如果您只有一个文本字符串,请使用split()方法将每个单词放入按空格拆分的列表中。
querywords = word_list.split()
resultwords = [word for word in querywords if word.lower() not in stopwords]
result = ' '.join(resultwords)您可以始终将它们扭曲成一个函数并将其自动化。正如我说过的,有很多方法可以做到这一点,而不知道您尝试了什么,这是一种不使用nltk库的简单方法。
https://datascience.stackexchange.com/questions/25429
复制相似问题