【发布时间】:2020-07-29 19:38:43
【问题描述】:
我想从使用Spacy 的句子中找到主题。下面的代码运行良好并提供了一个依赖关系树。
import spacy
from nltk import Tree
en_nlp = spacy.load('en')
doc = en_nlp("The quick brown fox jumps over the lazy dog.")
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]
从这个依赖树代码中,我能找到这句话的主语吗?
【问题讨论】:
-
this 有帮助吗?
-
@mbatchkarov 您建议的链接位于
Stanford Corenlp。但我想要NLTK。