mam zdanie John zobaczył jaskrawy kapelusz w sklepie
Jak do reprezentowania w postaci drzewa zależności jak poniżej?Zależność parsowania drzewa Spacy
(S
(NP (NNP John))
(VP
(VBD saw)
(NP (DT a) (JJ flashy) (NN hat))
(PP (IN at) (NP (DT the) (NN store)))))
Mam ten skrypt z 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]
otrzymuję następujący ale szukam formacie drzewa (NLTK).
saw
____|_______________
| | at
| | |
| hat store
| ___|____ |
John a flashy the