Stanford nlp StanfordNLP不提取实体之间的关系

Stanford nlp StanfordNLP不提取实体之间的关系,stanford-nlp,Stanford Nlp,我正在试用StanfordNLP关系提取器,根据页面上的显示,它有4个关系可以提取:生活、定位、组织、工作 我的代码是: Properties props = new Properties(); props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref, relation"); StanfordCoreNLP pipeline = new StanfordCoreNLP(pr

我正在试用StanfordNLP关系提取器,根据页面上的显示,它有4个关系可以提取:生活、定位、组织、工作

我的代码是:

Properties props = new Properties();
    props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref, relation");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
    String text = "Mary lives in Boston.";

    Annotation document = new Annotation(text);
    pipeline.annotate(document);

    List<RelationMention> relations = document.get(MachineReadingAnnotations.RelationMentionsAnnotation.class);
Properties=newproperties();
props.setProperty(“注释器”、“标记化、ssplit、pos、引理、ner、解析、dcoref、关系”);
StanfordCoreNLP管道=新的StanfordCoreNLP(道具);
String text=“玛丽住在波士顿。”;
注释文档=新注释(文本);
管道注释(文件);
列表关系=document.get(machineradingannotations.relationsinetitionsannotation.class);
我希望得到一个Live_In relation,但relations变量为null

我在代码中遗漏了什么

谢谢

这是一个句子级注释。您应该首先迭代
注释
对象中的句子,然后尝试检索注释

下面是一个如何迭代句子的基本示例:

// these are all the sentences in this document
// a CoreMap is essentially a Map that uses class objects as keys and has values with custom types
List<CoreMap> sentences = document.get(SentencesAnnotation.class);

for(CoreMap sentence: sentences) {
    List<RelationMention> relations = sentence.get(MachineReadingAnnotations.RelationMentionsAnnotation.class);
    // ....
}
//这是本文档中的所有句子
//CoreMap本质上是一个使用类对象作为键并具有自定义类型值的映射
列出句子=document.get(SentencesAnnotation.class);
for(CoreMap句子:句子){
列表关系=句子.get(machineradingannotations.relationsinetitionsannotation.class);
// ....
}