2024-04-26 11:57:01 发布
网友
我想从英文文本中摘录正在销售的产品的名称。在
例如:
"I'm selling my xbox brand new""Selling rarely used 27 inch TV"
"I'm selling my xbox brand new"
"Selling rarely used 27 inch TV"
应该给我"xbox"和{}
"xbox"
目前我唯一能想到的就是在一个庞大的重要名词和形容词列表中硬编码:['tv', 'fridge', 'xbox', 'laptop', etc]
['tv', 'fridge', 'xbox', 'laptop', etc]
有更好的方法吗?在
看起来nltk会给你一个单词和词类的列表。既然你只对名词感兴趣?this将提供给您
>>> from nltk import pos_tag, word_tokenize >>> pos_tag(word_tokenize("John's big idea isn't all that bad.")) [('John', 'NNP'), ("'s", 'POS'), ('big', 'JJ'), ('idea', 'NN'), ('is', 'VBZ'), ("n't", 'RB'), ('all', 'DT'), ('that', 'DT'), ('bad', 'JJ'), ('.', '.')]
看起来nltk会给你一个单词和词类的列表。既然你只对名词感兴趣?this将提供给您
相关问题 更多 >
编程相关推荐