我正在使用斯坦福NLP库中的OpenIE工具从句子中获取最小子句。以下是我迄今为止的成果(在很大程度上受到他们演示代码的启发):
我现在希望使用PTB成分树作为输入,而不是纯文本,然后仅使用depparse、natlog和openie注释器来获取从句。
我知道可以将PTB树作为输入传递给斯坦福解析器(如此处所述),但尚未找出如何将其集成到流水线中。
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,depparse,natlog,openie");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation doc = new Annotation("Obama was born in Hawaii. He is our president.");
pipeline.annotate(doc);
for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
OpenIE split = new OpenIE(props);
List<SentenceFragment> clauses = split.clausesInSentence(sentence);
for (SentenceFragment clause : clauses) {
List<SentenceFragment> short_clauses = split.entailmentsFromClause(clause);
for (SentenceFragment short_clause : short_clauses){
System.out.println(short_clause.parseTree);
}
}
}
}
我现在希望使用PTB成分树作为输入,而不是纯文本,然后仅使用depparse、natlog和openie注释器来获取从句。
我知道可以将PTB树作为输入传递给斯坦福解析器(如此处所述),但尚未找出如何将其集成到流水线中。
annotate()
方法? - VictorCOpenIE#clausesInSentence(SemanticGraph)
即可。但是您仍然需要引用词形变化。另一个选择是直接使用Penn Treebank中的痕迹--这正是从句分裂器训练的内容。 - Gabor Angeli