我想从使用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]
从这个依赖树代码中,我能找到这个句子的主语吗?在
我不确定是否要使用nltk解析树编写代码(请参见How to identify the subject of a sentence?)。但是,spacy也会使用单词.dep\u财产。在
提醒你,可能有更复杂的情况下,有一个以上。在
^{pr2}$相关问题 更多 >
编程相关推荐