我正在尝试检索句子的斯坦福依赖关系表示。像这样:
nsubj(makes-8, Bell-1)
nsubj(distributes-10, Bell-1)
vmod(Bell-1, based-3)
我正在使用带有ddeparse注释器的coreNLP管道。以下代码以类似但不友好的格式生成输出。
private void printDepParse(Annotation document) {
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
IoUtils.prln("---Dependencies---");
for(CoreMap sentence: sentences) {
// this is the Stanford dependency graph of the current sentence
SemanticGraph dependencies = sentence.get(BasicDependenciesAnnotation.class);
IoUtils.prln(dependencies.toString());
}
IoUtils.prln("---End Dependencies---");
}
产生类似的东西:
-> fed/VBD (root)
-> Jimmy/NNP (nsubj)
-> dog/NN (xcomp)
-> Billy/NNP (nsubj)
-> the/DT (det)
-> ./. (punct)
是否有一种简单的方法可以产生前者,更普遍接受的格式?
答案 0 :(得分:1)
要获得Stanford Dependencies表示,您需要使用GrammaticalStructures类。这应该有效:
for (CoreMap sentence: sentences) {
Tree tree = sentence.get(TreeAnnotation.class);
TreebankLanguagePack tlp = new PennTreebankLanguagePack();
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(tree);
Collection<TypedDependency> tdl = gs.typedDependenciesCCprocessed();
System.out.println(tdl);
}