Example usage for edu.stanford.nlp.pipeline Annotation copy

List of usage examples for edu.stanford.nlp.pipeline Annotation copy

Introduction

In this page you can find the example usage for edu.stanford.nlp.pipeline Annotation copy.

Prototype

public Annotation copy() 

Source Link

Document

Copies the map, but not a deep copy.

Usage

From source file:org.ets.research.nlp.stanford_thrift.general.CoreNLPThriftUtil.java

License:Open Source License

public static Annotation getAnnotationFromTokens(List<String> tokens, Annotation existingAnnotation) {
    List<CoreMap> sentences = new ArrayList<CoreMap>();
    Annotation allSentences;/*w  w w  . jav  a2  s . c o  m*/

    String[] tokensArr = new String[tokens.size()];
    tokens.toArray(tokensArr);
    List<CoreLabel> sentenceTokens = Sentence.toCoreLabelList(tokensArr);
    String originalText = Sentence.listToString(tokens);

    CoreMap sentence = new Annotation(originalText);
    sentence.set(CharacterOffsetBeginAnnotation.class, 0);
    sentence.set(CharacterOffsetEndAnnotation.class,
            sentenceTokens.get(sentenceTokens.size() - 1).get(TextAnnotation.class).length());
    sentence.set(CoreAnnotations.TokensAnnotation.class, sentenceTokens);
    sentence.set(CoreAnnotations.TokenBeginAnnotation.class, 0);
    sentence.set(CoreAnnotations.TokenEndAnnotation.class, sentenceTokens.size());

    sentences.add(sentence);

    if (existingAnnotation != null) {
        sentences.addAll(existingAnnotation.get(CoreAnnotations.SentencesAnnotation.class));
        allSentences = existingAnnotation.copy();
        allSentences.set(CoreAnnotations.SentencesAnnotation.class, adjustCharacterOffsets(sentences, true));
    } else {
        allSentences = new Annotation(Sentence.listToString(tokens));
        allSentences.set(CoreAnnotations.SentencesAnnotation.class, adjustCharacterOffsets(sentences, true));
    }

    return allSentences;
}

From source file:org.ets.research.nlp.stanford_thrift.ner.StanfordNERThrift.java

License:Open Source License

public Annotation annotateForNamedEntities(Annotation annotation) {
    Annotation withNE = annotation.copy();
    ner.annotate(withNE);/*from w w w . j  a v a  2s.c  o  m*/
    return withNE;
}