关于港口和移民的法案是由堪萨斯州共和党参议员布朗巴克提交的。
从上述句子中,我希望获得以下类型化的依赖关系:
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所示。
使用下面的代码,我只能实现以下依赖结构(代码输出如下):
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);
}
}
}发布于 2017-07-27 19:43:08
如果您想通过NN依赖解析器获得一个句子的CCprocessed和折叠斯坦福依赖项(SD),那么您必须设置一个属性来避免CoreNLP中的一个小错误。
但是,请注意,我们不再维护斯坦福依赖项代码,除非您有充分的理由使用SD,否则我们建议在任何新项目中使用通用依赖项。有关UD表示的更多信息,请查看通用依赖(UD)文档和舒斯特和曼宁(2016)。
要获得CCprocessed和折叠SD表示,请将depparse.language属性设置为:
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");
properties.setProperty("depparse.language", "English")
AnnotationPipeline pipeline = new StanfordCoreNLP(properties);
pipeline.annotate(annotation);
for (CoreMap sentence : annotation.get(SentencesAnnotation.class)) {
SemanticGraph sg = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
Collection<TypedDependency> dependencies = sg.typedDependencies();
for (TypedDependency td : dependencies) {
System.out.println(td);
}
}
}发布于 2017-07-20 06:41:06
CoreNLP最近从旧的斯坦福依赖关系格式(最上面示例中的格式)切换到普遍属地格式。我的第一个建议是尽可能使用新格式。对解析器的持续开发将使用通用依赖项,格式在许多方面类似于旧格式的模块化外观更改(例如,prep -> nmod)。
但是,如果您想要获得旧的依赖格式,则可以使用CollapsedCCProcessedDependenciesAnnotation注释来实现。
https://stackoverflow.com/questions/45202486
复制相似问题