为了账号安全,请及时绑定邮箱和手机立即绑定

使用 CoreNLP 解析共指

使用 CoreNLP 解析共指

POPMUISE 2021-12-10 15:45:28
我正在尝试让 CoreNLP 访问 CorefChains。我的意图是像“他,她,......”这样的词将被他们最好的提及所取代,但我无法访问 CorefChains(它们始终为空)。    public static void main (String [] args) {         Properties props = new Properties();         props.put("annotators", "tokenize,ssplit,pos,lemma,ner,parse,dcoref");         props.put("dcoref.score", true);         StanfordCoreNLP corefPipeline = new StanfordCoreNLP(props);         String text = "Barack Obama was born in Hawaii.  He is the president. Obama was elected in 2008.";         Annotation document = new Annotation(text);         corefPipeline.annotate(document);         // Chains is always null         Map<Integer, CorefChain> chains = document.get(CorefCoreAnnotations.CorefChainAnnotation.class);}
查看完整描述

1 回答

?
catspeake

TA贡献1111条经验 获得超0个赞

我认为这是一个导入类问题。这个工作正常:


import java.util.Map;

import java.util.Properties;


import edu.stanford.nlp.coref.CorefCoreAnnotations;

import edu.stanford.nlp.coref.data.CorefChain;

import edu.stanford.nlp.pipeline.Annotation;

import edu.stanford.nlp.pipeline.StanfordCoreNLP;



public class App {

    public static void main(String[] args) {

        Properties props = new Properties();

        props.put("annotators", "tokenize,ssplit,pos,lemma,ner,parse,dcoref");

        props.put("dcoref.score", true);

        StanfordCoreNLP corefPipeline = new StanfordCoreNLP(props);

        String text = "Barack Obama was born in Hawaii.  He is the president. Obama was elected in 2008.";

        Annotation document = new Annotation(text);

        corefPipeline.annotate(document);

        // Chains is always null

        Map<Integer, CorefChain> chains = document.get(CorefCoreAnnotations.CorefChainAnnotation.class);

        System.out.println(chains);

    }

}

和输出:


{1=CHAIN1-["Barack Obama" in sentence 1, "He" in sentence 2, "the president" in sentence 2, "Obama" in sentence 3], 2=CHAIN2-["Hawaii" in sentence 1], 6=CHAIN6-["2008" in sentence 3]}

这是我在 pom.xml 中的内容:


<dependencies>

    <dependency>

        <groupId>edu.stanford.nlp</groupId>

        <artifactId>stanford-corenlp</artifactId>

        <version>3.9.2</version>

    </dependency>

    <dependency>

        <groupId>edu.stanford.nlp</groupId>

        <artifactId>stanford-corenlp</artifactId>

        <version>3.9.2</version>

        <classifier>models</classifier>

    </dependency>

</dependencies>


查看完整回答
反对 回复 2021-12-10
  • 1 回答
  • 0 关注
  • 312 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号