自从我得知 Spacy 是一个用于自然语音处理的强大 Python 模块以来,我现在拼命寻找一种方法,将单词组合在一起,不仅仅是名词短语,最重要的是介词短语。
我怀疑是否有 Spacy 函数,但这将是我猜想的最简单的方法(SpacySpaCy 导入已在我的项目中实现)。
尽管如此,我对任何短语识别/分块的可能性持开放态度。
这里有一个获取PP的解决方案。一般来说,您可以使用以下方式获取短语subtree
.
def get_pps(doc):
"Function to get PPs from a parsed document."
pps = []
for token in doc:
# Try this with other parts of speech for different subtrees.
if token.pos_ == 'ADP':
pp = ' '.join([tok.orth_ for tok in token.subtree])
pps.append(pp)
return pps
Usage:
import spacy
nlp = spacy.load('en_core_web_sm')
ex = 'A short man in blue jeans is working in the kitchen.'
doc = nlp(ex)
print(get_pps(doc))
这打印:
['in blue jeans', 'in the kitchen']
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)