【发布时间】:2020-03-24 13:49:52
【问题描述】:
我想从文本中提取名词短语,我将 python 与 NLTK 结合使用。 我在互联网上发现了一种使用 RegexpParser 的模式,如下所示:
grammar = r"""
NBAR:
{<NN.*|JJ>*<NN.*>} # Nouns and Adjectives, terminated with Nouns
NP:
{<NBAR>}
{<NBAR><IN><NBAR>} # Above, connected with in/of/etc...
"""
cp = nltk.RegexpParser(grammar)
我想修改语法变量以添加“名词的名词”或“名词中的名词”的情况(例如“cup of coffee”或“water in cup”) 我的测试字符串是:'邮政编码是新的交付方式' 我想收到短语列表:['portal code', 'new method','new method of delivery']
【问题讨论】: