如何使用斯坦福解析器查找单词的父级和子级?

时间:2016-04-21 02:40:34

标签: stanford-nlp

我是对的(句子中父母和孩子的提取是否正确。)

String sentence = "Kumi is the girl who likes dogs.";
Tree parse = lp.parse(sentence);
SemanticGraph graph = SemanticGraphFactory.makeFromTree(parse);
IndexedWord wordConnective = graph.getNodeByIndexSafe(i);//i is the index of the word
List<IndexedWord> parentWords = graph.getParentList(wordConnective);
List<IndexedWord> childWord = graph.getChildList(wordConnective);

如果我想在这句话中提取的头,我该怎么办?

1 个答案:

答案 0 :(得分:0)

使用simple API的简单解决方案可能是:

new Sentence("Kumi is the girl who likes dogs").governor(4);