使用Stanford CoreNLP的共指解析

使用Stanford CoreNLP的共指解析,第1张

使用Stanford CoreNLP的共指解析

如果您有已标记化的句子列表,则有一个带参数的

Annotation

构造
List<CoreMap>sentences
函数可设置文档。

您要为每个句子创建一个

CoreMap
对象,如下所示。(请注意,我还分别向每个句子和标记对象添加了一个句子和标记索引。)

int sentenceIdx = 1;List<CoreMap> sentences = new ArrayList<CoreMap>();for (parsedSentence : parsedSentences) {    CoreMap sentence = new CoreLabel();    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.setLemma(lemma);        token.setTag(posTag);        token.setNER(namedEntity);        token.setIndex(tokenCount + 1);        tokens.add(token);    }    // set tokens annotations and id of sentence     sentence.set(TokensAnnotation.class, tokens);    sentence.set(SentenceIndexAnnotation.class, sentenceIdx++);    // set parse tree annotations to annotation    Tree stanfordParseTree = Tree.valueOf(inputParseTree);    sentence.set(TreeAnnotation.class, stanfordParseTree);    // add sentence to list of sentences    sentences.add(sentence);}

然后,您可以

Annotation
使用
sentences
列表创建一个实例:

Annotation annotation = new Annotation(sentences);


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5430789.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存