Example usage for edu.stanford.nlp.ie.machinereading.structure EntityMention getHeadTokenStart

List of usage examples for edu.stanford.nlp.ie.machinereading.structure EntityMention getHeadTokenStart

Introduction

In this page you can find the example usage for edu.stanford.nlp.ie.machinereading.structure EntityMention getHeadTokenStart.

Prototype

public int getHeadTokenStart() 

Source Link

Usage

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

License:Open Source License

/**
 * It gets the Stanford EntityMEntion and finds its equivalent CogComp Consittuent.
 * This mapping is done by comparing char offsets.
 *//*from  w  w w  .ja v a  2 s.  c o  m*/
private static Constituent createConstituentGivenMention(EntityMention rm, TextAnnotation ta) {
    List<CoreLabel> tokens = rm.getSentence().get(CoreAnnotations.TokensAnnotation.class);
    int extentCharStart = tokens.get(rm.getExtentTokenStart()).beginPosition();
    int extentCharEnd = tokens.get(rm.getExtentTokenEnd()).endPosition();
    int headCharStart = tokens.get(rm.getHeadTokenStart()).beginPosition();
    int headCharEnd = tokens.get(rm.getHeadTokenEnd()).endPosition();

    List<Constituent> extentCons = ta.getView(ViewNames.TOKENS)
            .getConstituentsOverlappingCharSpan(extentCharStart, extentCharEnd);
    int startIndex = extentCons.stream().min(Comparator.comparing(Constituent::getStartSpan)).get()
            .getStartSpan();
    int endIndex = extentCons.stream().max(Comparator.comparing(Constituent::getEndSpan)).get().getEndSpan();

    List<Constituent> headCons = ta.getView(ViewNames.TOKENS).getConstituentsOverlappingCharSpan(headCharStart,
            headCharEnd);
    int startIndexHead = headCons.stream().min(Comparator.comparing(Constituent::getStartSpan)).get()
            .getStartSpan();
    int endIndexHead = headCons.stream().max(Comparator.comparing(Constituent::getEndSpan)).get().getEndSpan();

    Constituent c = new Constituent(rm.getType(), viewName, ta, startIndex, endIndex);
    c.addAttribute("startIndexHead", String.valueOf(startIndexHead));
    c.addAttribute("endIndexHead", String.valueOf(endIndexHead));
    return c;
}