StanfordNLP 不提取实体之间的关系
StanfordNLP does not extract relations between entities
我正在试用 StanfordNLP 关系提取器,根据 http://nlp.stanford.edu/software/relationExtractor.shtml 的页面,它有 4 个可以提取的关系:Live_In、Located_In、OrgBased_In , Work_For.
我的代码是:
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);
我希望获得 Live_In 关系,但关系变量为空。
我在代码中遗漏了什么?
谢谢
RelationMentionsAnnotation
是句子级标注。您应该首先遍历 Annotation
对象中的句子,然后尝试检索注释。
这是一个如何遍历句子的基本示例:
// 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);
// ....
}
我正在试用 StanfordNLP 关系提取器,根据 http://nlp.stanford.edu/software/relationExtractor.shtml 的页面,它有 4 个可以提取的关系:Live_In、Located_In、OrgBased_In , Work_For.
我的代码是:
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);
我希望获得 Live_In 关系,但关系变量为空。
我在代码中遗漏了什么?
谢谢
RelationMentionsAnnotation
是句子级标注。您应该首先遍历 Annotation
对象中的句子,然后尝试检索注释。
这是一个如何遍历句子的基本示例:
// 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);
// ....
}