Search in sources :

Example 1 with CoreAnnotations

use of edu.stanford.nlp.ling.CoreAnnotations in project CoreNLP by stanfordnlp.

the class IOBUtils method createDatum.

/**
   * Create a datum from a string. The CoreAnnotations must correspond to those used by
   * SequenceClassifier. The following annotations are copied from the provided
   * CoreLabel cl, if present:
   *    DomainAnnotation
   * startOffset and endOffset will be added to the {@link CharacterOffsetBeginAnnotation} of
   * the {@link CoreLabel} cl to give the {@link CharacterOffsetBeginAnnotation} and
   * {@link CharacterOffsetEndAnnotation} of the resulting datum.
   */
private static CoreLabel createDatum(CoreLabel cl, String token, String label, int startOffset, int endOffset) {
    CoreLabel newTok = new CoreLabel();
    newTok.set(CoreAnnotations.TextAnnotation.class, token);
    newTok.set(CoreAnnotations.CharAnnotation.class, token);
    newTok.set(CoreAnnotations.AnswerAnnotation.class, label);
    newTok.set(CoreAnnotations.GoldAnswerAnnotation.class, label);
    newTok.set(CoreAnnotations.CharacterOffsetBeginAnnotation.class, cl.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class) + startOffset);
    newTok.set(CoreAnnotations.CharacterOffsetEndAnnotation.class, cl.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class) + endOffset);
    if (cl != null && cl.containsKey(CoreAnnotations.DomainAnnotation.class))
        newTok.set(CoreAnnotations.DomainAnnotation.class, cl.get(CoreAnnotations.DomainAnnotation.class));
    return newTok;
}
Also used : CoreLabel(edu.stanford.nlp.ling.CoreLabel) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations)

Aggregations

CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)1 CoreLabel (edu.stanford.nlp.ling.CoreLabel)1