Вот код:
public static void main(String[] args) {
String text = "Loryn lives across the street from me. "
+ "She is 19 years old. "
+ "Sydney goes to my school. "
+ "She graduated last year. ";
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse,depparse,coref,kbp,quote");
props.setProperty("coref.algorithm", "neural");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
CoreDocument document = new CoreDocument(text);
pipeline.annotate(document);
for (Entry<Integer, CorefChain> e : document.corefChains().entrySet()) {
System.out.println(e.getValue() + " - " + e.getKey());
for (CorefMention s : e.getValue().getMentionsInTextualOrder()) {
System.out.println(" - " + s);
}
}
Вот что выводит код:
CHAIN7-["me" in sentence 1, "my" in sentence 3] - 7
- "me" in sentence 1
- "my" in sentence 3
CHAIN8-["Loryn" in sentence 1, "She" in sentence 2, "She" in sentence 4] - 8
- "Loryn" in sentence 1
- "She" in sentence 2
- "She" in sentence 4
Почему * 401 из 4-го предложения относится к Лорин? Как я могу сделать это, чтобы обратиться к Сиднею
Желаемый результат должен выглядеть примерно так:
CHAIN7-["me" in sentence 1, "my" in sentence 3] - 7
- "me" in sentence 1
- "my" in sentence 3
CHAIN8-["Loryn" in sentence 1, "She" in sentence 2] - 8
- "Loryn" in sentence 1
- "She" in sentence 2
CHAIN9-["Sydney" in sentence 3, "She" in sentence 4] - 8
- "Sydney" in sentence 3
- "She" in sentence 4