문장이 있습니다. John이 가게에서 화려한 모자를 보았습니다.
어떻게하면 아래와 같이 종속성 트리로 나타낼 수 있습니까? 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