我是斯坦福 CoreNLP 工具包的新手,并尝试将其用于解决新闻文本中的共指问题的项目。为了使用斯坦福 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);
但是,我正在使用其他工具进行预处理,只需要一个独立的共指解析系统。创建标记和解析树注释并将它们设置为注释非常容易:
// 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。
有任何想法吗?
顺便说一句,如果我使用处理工具提供的标记和解析树注释,并且仅使用斯坦福核心自然语言处理管道提供的句子注释并应用斯坦福核心自然语言处理独立共指解析系统,我将得到正确的结果。因此,完整的独立共指解析系统唯一缺少的部分是从标记注释创建句子注释的能力。