[英]Python: Chunking others than noun phrases (e.g. prepositional) using Spacy, etc
自从有人告诉我 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
用法:
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']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.