Разрешение Coreference с CoreNLP - PullRequest
0 голосов
/ 27 октября 2018

Я пытаюсь получить 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 Ответ

0 голосов
/ 27 октября 2018

Я думаю, что это проблема классов импорта.Этот работает нормально:

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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...