【发布时间】:2018-08-23 20:14:05
【问题描述】:
代码如下:
import spacy
from nltk import Tree
en_nlp = spacy.load('en')
parsed = en_nlp(u"Photos under low lighting are poor, both front and back cameras.")
print(u'sentence:{0}'.format(parsed.text))
try2 = []
print(u'parsed_sentence_children::{0}'.format([(x.text,x.pos_,x.dep_,[(x.text,x.dep_) for x in list(x.children)]) for x in parsed]))
print("\n\n")
for x in parsed:
if x.pos_=="NOUN" and x.dep_=="nsubj":
print(u'Noun and noun subject:{0}'.format(try2 =[(x.text,x.pos_,x.dep_,[(x.text,x.pos_)for x in list(x.ancestors)])])
对此的输出是:[(u'Photos', u'NOUN', u'nsubj', [(u'are', u'VERB')]
现在我想打印acomp 的孩子:[(u'are', u'VERB')]
这是:[(u'Photos', u'NOUN', u'nsubj')]
我该怎么做?
【问题讨论】:
-
那么让孩子们的孩子们?
-
祖先的孩子在技术上是兄弟姐妹...... ;)