这是获取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
Run Code Online (Sandbox Code Playgroud)
用法:
import spacy
nlp = spacy.load('en')
ex = 'A short man in blue jeans is working in the kitchen.'
doc = nlp(ex)
print(get_pps(doc))
Run Code Online (Sandbox Code Playgroud)
打印:
['in blue jeans', 'in the kitchen']
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1244 次 |
最近记录: |