栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Stanford CoreNLP的共指解析

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用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);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/455263.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号