上的端口和移民法案提交由参议员布朗巴克,堪萨斯CoreNLP斯坦福依赖格式
的 共和党从上面的句子,我期待得到以下类型的依赖关系:
nsubjpass(submitted, Bills)
auxpass(submitted, were)
agent(submitted, Brownback)
nn(Brownback, Senator)
appos(Brownback, Republican)
prep_of(Republican, Kansas)
prep_on(Bills, ports)
conj_and(ports, immigration)
prep_on(Bills, immigration)
这应该是可能根据表1,图1的文件Stanford Dependencies。
使用下面的代码,我只能够达到以下依赖化妆(代码输出,这一点):
root(ROOT-0, submitted-7)
nmod:on(Bills-1, ports-3)
nmod:on(Bills-1, immigration-5)
case(ports-3, on-2)
cc(ports-3, and-4)
conj:and(ports-3, immigration-5)
nsubjpass(submitted-7, Bills-1)
auxpass(submitted-7, were-6)
nmod:agent(submitted-7, Brownback-10)
case(Brownback-10, by-8)
compound(Brownback-10, Senator-9)
punct(Brownback-10, ,-11)
appos(Brownback-10, Republican-12)
nmod:of(Republican-12, Kansas-14)
case(Kansas-14, of-13)
问题 - 如何实现上述期望的输出?
代码
public void processTestCoreNLP() {
String text = "Bills on ports and immigration were submitted " +
"by Senator Brownback, Republican of Kansas";
Annotation annotation = new Annotation(text);
Properties properties = PropertiesUtils.asProperties(
"annotators", "tokenize,ssplit,pos,lemma,depparse"
);
AnnotationPipeline pipeline = new StanfordCoreNLP(properties);
pipeline.annotate(annotation);
for (CoreMap sentence : annotation.get(SentencesAnnotation.class)) {
SemanticGraph sg = sentence.get(EnhancedPlusPlusDependenciesAnnotation.class);
Collection<TypedDependency> dependencies = sg.typedDependencies();
for (TypedDependency td : dependencies) {
System.out.println(td);
}
}
}
是什么代码实际打印出来,然后呢? – errantlinguist
不明确的道歉。代码输出第二个依赖关系块。我编辑得更清楚。 – gimg1