Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用斯坦福CoreNLP的共指消解_Java_Nlp_Stanford Nlp - Fatal编程技术网

Java 使用斯坦福CoreNLP的共指消解

Java 使用斯坦福CoreNLP的共指消解,java,nlp,stanford-nlp,Java,Nlp,Stanford Nlp,我是斯坦福大学CoreNLP工具包的新手,尝试将其用于解决新闻文本中的相互引用问题。为了使用Stanford CoreNLP共指代系统,我们通常会创建一个管道,它需要标记化、句子分割、词性标记、引语化、命名实体识别和解析。例如: Properties props = new Properties(); props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref"); StanfordCoreN

我是斯坦福大学CoreNLP工具包的新手,尝试将其用于解决新闻文本中的相互引用问题。为了使用Stanford CoreNLP共指代系统,我们通常会创建一个管道,它需要标记化、句子分割、词性标记、引语化、命名实体识别和解析。例如:

Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

// read some text in the text variable
String text = "As competition heats up in Spain's crowded bank market, Banco Exterior de Espana is seeking to shed its image of a state-owned bank and move into new activities.";

// create an empty Annotation just with the given text
Annotation document = new Annotation(text);

// run all Annotators on this text
pipeline.annotate(document);
然后,我们可以通过以下方式轻松获得句子注释:

List<CoreMap> sentences = document.get(SentencesAnnotation.class);
列出句子=document.get(SentencesAnnotation.class);
然而,我正在使用其他工具进行预处理,只需要一个独立的共指消解系统。创建标记和解析树注释并将其设置为注释非常容易:

// create new annotation
Annotation annotation = new Annotation();

// create token annotations for each sentence from the input file
List<CoreLabel> tokens = new ArrayList<>();
for(int tokenCount = 0; tokenCount < parsedSentence.size(); tokenCount++) {

        ArrayList<String> parsedLine = parsedSentence.get(tokenCount);
        String word = parsedLine.get(1);
        String lemma = parsedLine.get(2);
        String posTag = parsedLine.get(3);
        String namedEntity = parsedLine.get(4); 
        String partOfParseTree = parsedLine.get(6);

        CoreLabel token = new CoreLabel();
        token.setWord(word);
        token.setWord(lemma);
        token.setTag(posTag);
        token.setNER(namedEntity);
        tokens.add(token);
    }

// set tokens annotations to annotation
annotation.set(TokensAnnotation.class, tokens);

// set parse tree annotations to annotation
Tree stanfordParseTree = Tree.valueOf(inputParseTree);
annotation.set(TreeAnnotation.class, stanfordParseTree);
List<CoreMap> sentences = new ArrayList<CoreMap>();
annotation.set(SentencesAnnotation.class, sentences);
//创建新注释
注释=新注释();
//为输入文件中的每个句子创建标记注释
List tokens=new ArrayList();
for(int-tokenCount=0;tokenCount
然而,创建句子注释是相当棘手的,因为据我所知,没有文档可以详细解释它。我能够为句子注释创建数据结构,并将其设置为注释:

// create new annotation
Annotation annotation = new Annotation();

// create token annotations for each sentence from the input file
List<CoreLabel> tokens = new ArrayList<>();
for(int tokenCount = 0; tokenCount < parsedSentence.size(); tokenCount++) {

        ArrayList<String> parsedLine = parsedSentence.get(tokenCount);
        String word = parsedLine.get(1);
        String lemma = parsedLine.get(2);
        String posTag = parsedLine.get(3);
        String namedEntity = parsedLine.get(4); 
        String partOfParseTree = parsedLine.get(6);

        CoreLabel token = new CoreLabel();
        token.setWord(word);
        token.setWord(lemma);
        token.setTag(posTag);
        token.setNER(namedEntity);
        tokens.add(token);
    }

// set tokens annotations to annotation
annotation.set(TokensAnnotation.class, tokens);

// set parse tree annotations to annotation
Tree stanfordParseTree = Tree.valueOf(inputParseTree);
annotation.set(TreeAnnotation.class, stanfordParseTree);
List<CoreMap> sentences = new ArrayList<CoreMap>();
annotation.set(SentencesAnnotation.class, sentences);
列出句子=新建ArrayList();
注释.set(SentencesAnnotation.class,句子);
我相信这不会那么困难,但是没有关于如何从标记注释创建句子注释的文档,即如何用实际的句子注释填充ArrayList

有什么想法吗


顺便说一句,如果我使用由我的处理工具提供的标记和解析树注释,并且只使用由StanfordCoreNLP管道提供的句子注释,并应用StanfordCoreNLP独立的共同引用解析系统,我将得到正确的结果。因此,一个完整的独立共指消解系统唯一缺少的部分是从标记注释创建句子注释的能力。

有一个
注释
,带有一个
列表句子
参数,如果您有一个已标记句子的列表,该参数将设置文档

对于每个要创建
CoreMap
对象的句子,如下所示。 (注意,我还分别为每个句子和标记对象添加了一个句子和标记索引。)


有一个
注释
,带有一个
列出句子
参数,如果您有一个已标记句子的列表,该参数将设置文档

对于每个要创建
CoreMap
对象的句子,如下所示。 (注意,我还分别为每个句子和标记对象添加了一个句子和标记索引。)


@塞巴斯蒂安·舒斯特非常感谢你,他的作品很有魅力。刚刚添加了
token.setValue(word)
设置标记值,并
设置句子。set(ValueAnnotation.class,句子内容)
设置句子值。@Sebastian Schuster非常感谢您,非常有用。刚刚添加了
token.setValue(word)
设置标记值,set(ValueAnnotation.class,句子内容)
设置句子值。