Example usage for edu.stanford.nlp.ling CoreLabel CoreLabel

List of usage examples for edu.stanford.nlp.ling CoreLabel CoreLabel

Introduction

In this page you can find the example usage for edu.stanford.nlp.ling CoreLabel CoreLabel.

Prototype

@SuppressWarnings("unchecked")
public CoreLabel(Label label) 

Source Link

Document

Returns a new CoreLabel instance based on the contents of the given label.

Usage

From source file:ims.cs.corenlp.TokenAligner.java

License:Open Source License

/**
 * Splits a CoreNLP token based on a position. We split only the word form as we don't have sufficient information
 * to split the lemma./* w  ww. j  a  v  a  2 s. c  o  m*/
 * @param token
 * @param absPosition
 * @return
 */
private CoreLabel[] splitToken(CoreLabel token, int absPosition) {
    String word = token.word();
    String origText = token.originalText();

    // initialize parts
    CoreLabel[] splitting = new CoreLabel[2];
    splitting[0] = new CoreLabel(token);
    splitting[1] = new CoreLabel(token);

    // calculate split position
    int relPosition = absPosition - token.beginPosition();

    // cut up original text
    if (origText.length() >= relPosition) {
        String origText1 = origText.substring(0, relPosition);
        String origText2 = origText.substring(relPosition);

        splitting[0].setOriginalText(origText1);
        splitting[1].setOriginalText(origText2);
    }

    // cut up predicted text
    if (word.length() >= relPosition) {
        String word1 = word.substring(0, relPosition);
        String word2 = word.substring(relPosition);

        splitting[0].setWord(word1);
        splitting[1].setWord(word2);
    }

    // we could do the same with POS and lemma, but that would be complicated ...
    splitting[0].setEndPosition(absPosition); /* set a new end as we just shortened this token */
    splitting[1].setBeginPosition(absPosition); /* set a new position as we just shortened this token */

    // copy lemmas
    splitting[0].setLemma(token.lemma());
    splitting[1].setLemma(token.lemma());

    return splitting;
}