第一个数字是(表示令牌,这代表了相同实体)的群集ID,见SieveCoreferenceSystem#coref(Document)
源代码。这对数字outout CorefChain#的toString()的:
public String toString(){
return position.toString();
}
,其中位置是一组实体现在的位置是对提的(让他们使用CorefChain.getCorefMentions()
)。下面是一个完整的代码(groovy),这表明如何从位置标记的例子:
class Example {
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);
pipeline = new StanfordCoreNLP(props);
Annotation document = new Annotation("The atom is a basic unit of matter, it consists of a dense central nucleus surrounded by a cloud of negatively charged electrons.");
pipeline.annotate(document);
Map<Integer, CorefChain> graph = document.get(CorefChainAnnotation.class);
println aText
for(Map.Entry<Integer, CorefChain> entry : graph) {
CorefChain c = entry.getValue();
println "ClusterId: " + entry.getKey();
CorefMention cm = c.getRepresentativeMention();
println "Representative Mention: " + aText.subSequence(cm.startIndex, cm.endIndex);
List<CorefMention> cms = c.getCorefMentions();
println "Mentions: ";
cms.each { it ->
print aText.subSequence(it.startIndex, it.endIndex) + "|";
}
}
}
}
输出(我不明白其中“s”来自):
The atom is a basic unit of matter, it consists of a dense central nucleus surrounded by a cloud of negatively charged electrons.
ClusterId: 1
Representative Mention: he
Mentions: he|atom |s|
ClusterId: 6
Representative Mention: basic unit
Mentions: basic unit |
ClusterId: 8
Representative Mention: unit
Mentions: unit |
ClusterId: 10
Representative Mention: it
Mentions: it |
ps。我认为默认设置(模型)不适用于您的域。 stanford核心nlp似乎更适合从新闻,文章等中提取语义。例如,Stanford NER--核心NLP的一部分 - 在CoNLL 2002和2003语料库上进行了训练并进行了测试。 – Skarab
这个算法是部分有用的,并且使我找到了正确的算法,但是这里的输出对于句子来说是不正确的,在句子或者“s”中没有“他”,并且“it”恰好映射到它本身,共同决议的重点。 – user1084563
我认为你认为'startIndex'和'endIndex'就好像它们是字符索引(从0开始),但它们是标记索引(从1开始)。另外,你没有定义'aText'。假设你的意思是注解中的文字,而不是“他”(字符1和2),你应该有“原子”(单词1和2)等。 –