/** * Convert a CoreNLP Annotation object to a Document. * @param ann The CoreNLP Annotation object. */ @SuppressWarnings("Convert2streamapi") public Document(Properties props, Annotation ann) { this.defaultProps = props; StanfordCoreNLP.getDefaultAnnotatorPool(props, new AnnotatorImplementations()); // cache the annotator pool this.impl = new ProtobufAnnotationSerializer(false).toProtoBuilder(ann); List<CoreMap> sentences = ann.get(CoreAnnotations.SentencesAnnotation.class); this.sentences = new ArrayList<>(sentences.size()); for (CoreMap sentence : sentences) { this.sentences.add(new Sentence(this, this.serializer.toProtoBuilder(sentence), sentence.get(CoreAnnotations.TextAnnotation.class), this.defaultProps)); } }
/** * Create a Document object from a read Protocol Buffer. * @see edu.stanford.nlp.simple.Document#serialize() * @param proto The protocol buffer representing this document. */ @SuppressWarnings("Convert2streamapi") public Document(Properties props, CoreNLPProtos.Document proto) { this.defaultProps = props; StanfordCoreNLP.getDefaultAnnotatorPool(props, new AnnotatorImplementations()); // cache the annotator pool this.impl = proto.toBuilder(); if (proto.getSentenceCount() > 0) { this.sentences = new ArrayList<>(proto.getSentenceCount()); for (CoreNLPProtos.Sentence sentence : proto.getSentenceList()) { this.sentences.add(new Sentence(this, sentence.toBuilder(), this.defaultProps)); } } }
/** * Convert a CoreNLP Annotation object to a Document. * @param ann The CoreNLP Annotation object. */ @SuppressWarnings("Convert2streamapi") public Document(Properties props, Annotation ann) { this.defaultProps = props; StanfordCoreNLP.getDefaultAnnotatorPool(props, new AnnotatorImplementations()); // cache the annotator pool this.impl = new ProtobufAnnotationSerializer(false).toProtoBuilder(ann); List<CoreMap> sentences = ann.get(CoreAnnotations.SentencesAnnotation.class); this.sentences = new ArrayList<>(sentences.size()); for (CoreMap sentence : sentences) { this.sentences.add(new Sentence(this, this.serializer.toProtoBuilder(sentence), sentence.get(CoreAnnotations.TextAnnotation.class), this.defaultProps)); } }
AnnotatorPool pool = getDefaultAnnotatorPool(props);
/** * Create a Document object from a read Protocol Buffer. * @see edu.stanford.nlp.simple.Document#serialize() * @param proto The protocol buffer representing this document. */ @SuppressWarnings("Convert2streamapi") public Document(Properties props, CoreNLPProtos.Document proto) { this.defaultProps = props; StanfordCoreNLP.getDefaultAnnotatorPool(props, new AnnotatorImplementations()); // cache the annotator pool this.impl = proto.toBuilder(); if (proto.getSentenceCount() > 0) { this.sentences = new ArrayList<>(proto.getSentenceCount()); for (CoreNLPProtos.Sentence sentence : proto.getSentenceList()) { this.sentences.add(new Sentence(this, sentence.toBuilder(), this.defaultProps)); } } }
if(pool == null) { pool = getDefaultAnnotatorPool(props);