解析树我有一个句子约翰看到在商店华而不实的帽子
如下图所示如何表示这是一个依赖关系树?依赖于Spacy
(S
(NP (NNP John))
(VP
(VBD saw)
(NP (DT a) (JJ flashy) (NN hat))
(PP (IN at) (NP (DT the) (NN store)))))
我从here
import spacy
from nltk import Tree
en_nlp = spacy.load('en')
doc = en_nlp("John saw a flashy hat at the store")
def to_nltk_tree(node):
if node.n_lefts + node.n_rights > 0:
return Tree(node.orth_, [to_nltk_tree(child) for child in node.children])
else:
return node.orth_
[to_nltk_tree(sent.root).pretty_print() for sent in doc.sents]
我正在以下,但我找一棵树(NLTK)格式得到这个脚本。
saw
____|_______________
| | at
| | |
| hat store
| ___|____ |
John a flashy the