stanzaを使ってみる 3
以前の投稿でstanzaを使ってみたことをまとめた.
今回はその続きで依存構造解析(Dependency Parsing)をstanzaで行ってみたい.
コードは下記.
import stanza
stanza.download('en')
nlp = stanza.Pipeline('en')
text = "The quick brown fox jumps over the lazy dog."
doc = nlp(text)
for sentence in doc.sentences:
print("Dependency Parse:")
for word in sentence.words:
print(f"{word.text} <--{word.deprel}-- {sentence.words[word.head - 1].text if word.head > 0 else 'ROOT'}")
Output例
Dependency Parse:
The <–det– fox
quick <–amod– fox
brown <–amod– fox
fox <–nsubj– jumps
jumps <–root– ROOT
over <–case– dog
the <–det– dog
lazy <–amod– dog
dog <–obl– jumps
. <–punct– jumps