List of usage examples for edu.stanford.nlp.pipeline Annotation copy
public Annotation copy()
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; }