我正在使用 spacy 的依赖解析。我对这两个非常相似的句子感到困惑。
第 1 句:
text='He noted his father was a nice guy.'
请注意,这句话中的“father”显然是“father was a nice guy”的主语:
[(0, 'He', '-PRON-', 'PRON', 'PRP', 'nsubj'), (1, 'noted', 'note', 'VERB', 'VBD', 'ROOT'), (2, 'his', '-PRON-', 'DET', 'PRP$', 'poss'), (3, 'father', 'father', 'NOUN', 'NN', 'nsubj'), (4, 'was', 'be', 'VERB', 'VBD', 'ccomp'), (5, 'a', 'a', 'DET', 'DT', 'det'), (6, 'nice', 'nice', 'ADJ', 'JJ', 'amod'), (7, 'guy', 'guy', 'NOUN', 'NN', 'attr'), (8, '.', '.', 'PUNCT', '.', 'punct')]
noted
________|_____
| | was
| | _____|___
| | father guy
| | | ___|___
He . his a nice
for child in the_verb.children:
print(child,child.dep_)
>> father nsubj
>> guy attr
for ancestor in the_verb.ancestors:
print(ancestor,ancestor.dep_)
>> noted ROOT
第 2 句:
text='He noted his father, as \"a man with different attributes\", was a nice guy.'
这是上一句的一个小变化。“父亲”不再是主题。
[(0, 'He', '-PRON-', 'PRON', 'PRP', 'nsubj'), (1, 'noted', 'note', 'VERB', 'VBD', 'ROOT'), (2, 'his', '-PRON-', 'DET', 'PRP$', 'poss'), (3, 'father', 'father', 'NOUN', 'NN', 'dobj'), (4, ',', ',', 'PUNCT', ',', 'punct'), (5, 'as', 'as', 'ADP', 'IN', 'prep'), (6, '"', '"', 'PUNCT', '``', 'punct'), (7, 'a', 'a', 'DET', 'DT', 'det'), (8, 'man', 'man', 'NOUN', 'NN', 'pobj'), (9, 'with', 'with', 'ADP', 'IN', 'prep'), (10, 'different', 'different', 'ADJ', 'JJ', 'amod'), (11, 'attributes', 'attribute', 'NOUN', 'NNS', 'pobj'), (12, '"', '"', 'PUNCT', "''", 'punct'), (13, ',', ',', 'PUNCT', ',', 'punct'), (14, 'was', 'be', 'VERB', 'VBD', 'conj'), (15, 'a', 'a', 'DET', 'DT', 'det'), (16, 'nice', 'nice', 'ADJ', 'JJ', 'amod'), (17, 'guy', 'guy', 'NOUN', 'NN', 'attr'), (18, '.', '.', 'PUNCT', '.', 'punct')]
noted
________________|____________________________
| | | | | as |
| | | | | | |
| | | | | man |
| | | | | ___|______ |
| | | | | | | with was
| | | | | | | | |
| | | | father | a attributes guy
| | | | | | | | ___|___
He , , . his " " different a nice
the_verb=spacy_doc[14]
for child in the_verb.children:
print(child,child.dep_)
>> guy attr
for ancestor in the_verb.ancestors:
print(ancestor,ancestor.dep_)
>> noted ROOT
我试图了解 spacy 如何对句子进行分类。第二种情况是错误分类错误吗?我的意思是“父亲”仍然应该是主题吗?