0
我目前正在寻找在CoreNLP开放信息抽取(OpenIE)的关系三元组(主语,谓语,宾语),其中包含在主题只有NameEntities和对象类型。但我不知道如何获取RelationTriple
对象的实体类型,即List<CoreMap>
。斯坦福CoreNLP:如何获得只有名称实体(OpenIE)的RelationTriple三元组?
下面是从https://stanfordnlp.github.io/CoreNLP/openie.html代码:
import edu.stanford.nlp.ie.util.RelationTriple;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.naturalli.NaturalLogicAnnotations;
import edu.stanford.nlp.util.CoreMap;
import java.util.Collection;
import java.util.Properties;
/**
* A demo illustrating how to call the OpenIE system programmatically.
*/
public class OpenIEDemo {
public static void main(String[] args) throws Exception {
// Create the Stanford CoreNLP pipeline
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,depparse,natlog,openie");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// Annotate an example document.
Annotation doc = new Annotation("Obama was born in Hawaii. He is our president.");
pipeline.annotate(doc);
// Loop over sentences in the document
for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
// Get the OpenIE triples for the sentence
Collection <RelationTriple> triples = sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class);
// Print the triples
for (RelationTriple triple : triples) {
// Here is where I get the entity type from a triple's subject or object
System.out.println(triple.confidence + "\t" +
triple.subjectLemmaGloss() + "\t" +
triple.relationLemmaGloss() + "\t" +
triple.objectLemmaGloss());
}
}
}
}
如果存在某种方式来获得RelationTriple
类实体类型我会的帮助表示感谢。
我想要的是获得实体的**标签**。例如,“Temer ** [PERSON] **在[巴西] [巴西] ** [LOCATION] **”中裁判。 RelationTriple类只有类型而不是标签的光泽。 –
三元符号上的.ner函数应该为您提供类型,例如PERSON。 –