首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CoreNLP斯坦福依赖格式

CoreNLP斯坦福依赖格式
EN

Stack Overflow用户
提问于 2017-07-19 23:07:16
回答 2查看 918关注 0票数 2

关于港口和移民的法案是由堪萨斯州共和党参议员布朗巴克提交的。

从上述句子中,我希望获得以下类型化的依赖关系:

代码语言:javascript
复制
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所示。

使用下面的代码,我只能实现以下依赖结构(代码输出如下):

代码语言:javascript
复制
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)

问题--如何实现上面所需的输出?

代码语言:javascript
复制
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);
        }
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-27 19:43:08

如果您想通过NN依赖解析器获得一个句子的CCprocessed和折叠斯坦福依赖项(SD),那么您必须设置一个属性来避免CoreNLP中的一个小错误。

但是,请注意,我们不再维护斯坦福依赖项代码,除非您有充分的理由使用SD,否则我们建议在任何新项目中使用通用依赖项。有关UD表示的更多信息,请查看通用依赖(UD)文档舒斯特和曼宁(2016)

要获得CCprocessed和折叠SD表示,请将depparse.language属性设置为:

代码语言:javascript
复制
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);
    }
  }
}
票数 1
EN

Stack Overflow用户

发布于 2017-07-20 06:41:06

CoreNLP最近从旧的斯坦福依赖关系格式(最上面示例中的格式)切换到普遍属地格式。我的第一个建议是尽可能使用新格式。对解析器的持续开发将使用通用依赖项,格式在许多方面类似于旧格式的模块化外观更改(例如,prep -> nmod)。

但是,如果您想要获得旧的依赖格式,则可以使用CollapsedCCProcessedDependenciesAnnotation注释来实现。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45202486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档