use of edu.stanford.nlp.coref.data.CorefChain in project CoreNLP by stanfordnlp.
the class XMLOutputter method addCorefGraphInfo.
/**
* Generates the XML content for the coreference chain object.
*/
private static boolean addCorefGraphInfo(Options options, Element corefInfo, List<CoreMap> sentences, Map<Integer, CorefChain> corefChains, String curNS) {
boolean foundCoref = false;
for (CorefChain chain : corefChains.values()) {
if (!options.printSingletons && chain.getMentionsInTextualOrder().size() <= 1)
continue;
foundCoref = true;
Element chainElem = new Element("coreference", curNS);
CorefChain.CorefMention source = chain.getRepresentativeMention();
addCorefMention(options, chainElem, curNS, sentences, source, true);
for (CorefChain.CorefMention mention : chain.getMentionsInTextualOrder()) {
if (mention == source)
continue;
addCorefMention(options, chainElem, curNS, sentences, mention, false);
}
corefInfo.appendChild(chainElem);
}
return foundCoref;
}
use of edu.stanford.nlp.coref.data.CorefChain in project CoreNLP by stanfordnlp.
the class Sentence method coref.
/**
* Get the coreference chain for just this sentence.
* Note that this method is actually fairly computationally expensive to call, as it constructs and prunes
* the coreference data structure for the entire document.
*
* @return A coreference chain, but only for this sentence
*/
public Map<Integer, CorefChain> coref() {
// Get the raw coref structure
Map<Integer, CorefChain> allCorefs = document.coref();
// Delete coreference chains not in this sentence
Set<Integer> toDeleteEntirely = new HashSet<>();
for (Map.Entry<Integer, CorefChain> integerCorefChainEntry : allCorefs.entrySet()) {
CorefChain chain = integerCorefChainEntry.getValue();
List<CorefChain.CorefMention> mentions = new ArrayList<>(chain.getMentionsInTextualOrder());
mentions.stream().filter(m -> m.sentNum != this.sentenceIndex() + 1).forEach(chain::deleteMention);
if (chain.getMentionsInTextualOrder().isEmpty()) {
toDeleteEntirely.add(integerCorefChainEntry.getKey());
}
}
// Clean up dangling empty chains
toDeleteEntirely.forEach(allCorefs::remove);
// Return
return allCorefs;
}
Aggregations