Example usage for edu.stanford.nlp.coref.data CorefChain getMentionsInTextualOrder

List of usage examples for edu.stanford.nlp.coref.data CorefChain getMentionsInTextualOrder

Introduction

In this page you can find the example usage for edu.stanford.nlp.coref.data CorefChain getMentionsInTextualOrder.

Prototype

public List<CorefMention> getMentionsInTextualOrder() 

Source Link

Document

get List of CorefMentions

Usage

From source file:de.tudarmstadt.ukp.dkpro.core.corenlp.internal.CoreNlp2DKPro.java

License:Open Source License

public static void convertCorefChains(JCas aJCas, Annotation aDocument) {
    List<CoreMap> sentences = aDocument.get(SentencesAnnotation.class);
    Map<Integer, CorefChain> chains = aDocument.get(CorefCoreAnnotations.CorefChainAnnotation.class);
    if (chains != null) {
        for (CorefChain chain : chains.values()) {
            CoreferenceLink last = null;
            for (CorefMention mention : chain.getMentionsInTextualOrder()) {
                CoreLabel beginLabel = sentences.get(mention.sentNum - 1).get(TokensAnnotation.class)
                        .get(mention.startIndex - 1);
                CoreLabel endLabel = sentences.get(mention.sentNum - 1).get(TokensAnnotation.class)
                        .get(mention.endIndex - 2);
                CoreferenceLink link = new CoreferenceLink(aJCas, beginLabel.get(TokenKey.class).getBegin(),
                        endLabel.get(TokenKey.class).getEnd());

                if (mention.mentionType != null) {
                    link.setReferenceType(mention.mentionType.toString());
                }//www  .  java 2  s . co m

                if (last == null) {
                    // This is the first mention. Here we'll initialize the chain
                    CoreferenceChain corefChain = new CoreferenceChain(aJCas);
                    corefChain.setFirst(link);
                    corefChain.addToIndexes();
                } else {
                    // For the other mentions, we'll add them to the chain.
                    last.setNext(link);
                }
                last = link;

                link.addToIndexes();
            }
        }
    }
}

From source file:edu.illinois.cs.cogcomp.pipeline.handlers.StanfordCorefHandler.java

License:Open Source License

@Override
protected void addView(TextAnnotation ta) throws AnnotatorException {
    Annotation document = new Annotation(ta.text);
    pipeline.annotate(document);/*from  ww w  . j ava 2s  . co m*/
    CoreferenceView vu = new CoreferenceView(viewName, ta);

    Map corefChain = document.get(CorefCoreAnnotations.CorefChainAnnotation.class);
    for (Object key : corefChain.keySet()) {
        CorefChain chain = (CorefChain) corefChain.get(key);
        Constituent representative = createConstituentGivenMention(document, chain,
                chain.getRepresentativeMention(), ta);
        List<Constituent> consList = new ArrayList<>();
        for (CorefChain.CorefMention m : chain.getMentionsInTextualOrder()) {
            consList.add(createConstituentGivenMention(document, chain, m, ta));
        }
        consList.remove(representative); // remove the representative itself
        vu.addCorefEdges(representative, consList);
    }
    ta.addView(viewName, vu);
}