CoreDocument document = new CoreDocument(text); CoreLabel token = document.tokens().get(10); System.out.println("Example: token"); System.out.println(token); String sentenceText = document.sentences().get(0).text(); System.out.println("Example: sentence"); System.out.println(sentenceText); CoreSentence sentence = document.sentences().get(1); document.sentences().get(4).relations(); System.out.println("Example: relation"); System.out.println(relations.get(0)); CoreEntityMention originalEntityMention = document.sentences().get(3).entityMentions().get(1); System.out.println("Example: original entity mention"); System.out.println(originalEntityMention); Map<Integer, CorefChain> corefChains = document.corefChains(); System.out.println("Example: coref chains for document"); System.out.println(corefChains); List<CoreQuote> quotes = document.quotes(); CoreQuote quote = quotes.get(0); System.out.println("Example: quote");
@Override public String toString() { return annotation().toString(); }
/** complete the wrapping process post annotation by a pipeline **/ public void wrapAnnotations() { // wrap all of the sentences if (this.annotationDocument.get(CoreAnnotations.SentencesAnnotation.class) != null) { wrapSentences(); // if there are entity mentions, build a document wide list if ( ! sentences.isEmpty() && sentences.get(0).entityMentions() != null) { buildDocumentEntityMentionsList(); } // if there are quotes, build a document wide list if (QuoteAnnotator.gatherQuotes(this.annotationDocument) != null) buildDocumentQuotesList(); } }
int lastSentenceIndex = this.quoteCoreMap.get(CoreAnnotations.SentenceEndAnnotation.class); for (int currSentIndex = firstSentenceIndex ; currSentIndex <= lastSentenceIndex ; currSentIndex++) { this.sentences.add(this.document.sentences().get(currSentIndex)); for (int speakerTokenIndex = firstSpeakerTokenIndex ; speakerTokenIndex <= lastSpeakerTokenIndex ; speakerTokenIndex++) { this.speakerTokens.get().add(this.document.tokens().get(speakerTokenIndex)); speakerTokens.get().size() - 1).get(CoreAnnotations.CharacterOffsetEndAnnotation.class); this.speakerCharOffsets = Optional.of(new Pair<>(speakerCharOffsetBegin, speakerCharOffsetEnd)); for (CoreEntityMention candidateEntityMention : this.document.entityMentions()) { Pair<Integer,Integer> entityMentionOffsets = candidateEntityMention.charOffsets(); if (entityMentionOffsets.equals(this.speakerCharOffsets.get())) { for (int canonicalSpeakerTokenIndex = firstCanonicalSpeakerTokenIndex ; canonicalSpeakerTokenIndex <= lastCanonicalSpeakerTokenIndex ; canonicalSpeakerTokenIndex++) { this.canonicalSpeakerTokens.get().add(this.document.tokens().get(canonicalSpeakerTokenIndex)); canonicalSpeakerTokens.get().size() - 1).get(CoreAnnotations.CharacterOffsetEndAnnotation.class); this.canonicalSpeakerCharOffsets = Optional.of(new Pair<>(canonicalSpeakerCharOffsetBegin, canonicalSpeakerCharOffsetEnd)); for (CoreEntityMention candidateEntityMention : this.document.entityMentions()) { Pair<Integer,Integer> entityMentionOffsets = candidateEntityMention.charOffsets(); if (entityMentionOffsets.equals(this.canonicalSpeakerCharOffsets.get())) {
public CoreDocument(Annotation annotation) { this.annotationDocument = annotation; wrapAnnotations(); }
/** return the canonical entity mention for this entity mention **/ public Optional<CoreEntityMention> canonicalEntityMention() { CoreDocument myDocument = sentence.document(); Optional<Integer> canonicalEntityMentionIndex = Optional.ofNullable(coreMap().get(CoreAnnotations.CanonicalEntityMentionIndexAnnotation.class)); return canonicalEntityMentionIndex.isPresent() ? Optional.of(sentence.document().entityMentions().get(canonicalEntityMentionIndex.get())) : Optional.empty(); }
/** * Read in a CoreDocument from this input stream. * * @param is The input stream to read a CoreDocument's annotation from * @return A pair with the CoreDocument and the input stream * @throws IOException * @throws ClassNotFoundException * @throws ClassCastException */ public Pair<CoreDocument, InputStream> readCoreDocument(InputStream is) throws IOException, ClassNotFoundException, ClassCastException { Pair<Annotation, InputStream> readPair = read(is); CoreDocument readCoreDocument = new CoreDocument(readPair.first()); return new Pair<CoreDocument, InputStream>(readCoreDocument, is); }
int lastSentenceIndex = this.quoteCoreMap.get(CoreAnnotations.SentenceEndAnnotation.class); for (int currSentIndex = firstSentenceIndex ; currSentIndex <= lastSentenceIndex ; currSentIndex++) { this.sentences.add(this.document.sentences().get(currSentIndex)); for (int speakerTokenIndex = firstSpeakerTokenIndex ; speakerTokenIndex <= lastSpeakerTokenIndex ; speakerTokenIndex++) { this.speakerTokens.get().add(this.document.tokens().get(speakerTokenIndex)); speakerTokens.get().size() - 1).get(CoreAnnotations.CharacterOffsetEndAnnotation.class); this.speakerCharOffsets = Optional.of(new Pair<>(speakerCharOffsetBegin, speakerCharOffsetEnd)); for (CoreEntityMention candidateEntityMention : this.document.entityMentions()) { Pair<Integer,Integer> entityMentionOffsets = candidateEntityMention.charOffsets(); if (entityMentionOffsets.equals(this.speakerCharOffsets.get())) { for (int canonicalSpeakerTokenIndex = firstCanonicalSpeakerTokenIndex ; canonicalSpeakerTokenIndex <= lastCanonicalSpeakerTokenIndex ; canonicalSpeakerTokenIndex++) { this.canonicalSpeakerTokens.get().add(this.document.tokens().get(canonicalSpeakerTokenIndex)); canonicalSpeakerTokens.get().size() - 1).get(CoreAnnotations.CharacterOffsetEndAnnotation.class); this.canonicalSpeakerCharOffsets = Optional.of(new Pair<>(canonicalSpeakerCharOffsetBegin, canonicalSpeakerCharOffsetEnd)); for (CoreEntityMention candidateEntityMention : this.document.entityMentions()) { Pair<Integer,Integer> entityMentionOffsets = candidateEntityMention.charOffsets(); if (entityMentionOffsets.equals(this.canonicalSpeakerCharOffsets.get())) {
/** Annotate the CoreDocument wrapper. **/ public void annotate(CoreDocument document) { // annotate the underlying Annotation this.annotate(document.annotationDocument); // wrap the sentences and entity mentions post annotation document.wrapAnnotations(); }
/** return the canonical entity mention for this entity mention **/ public Optional<CoreEntityMention> canonicalEntityMention() { CoreDocument myDocument = sentence.document(); Optional<Integer> canonicalEntityMentionIndex = Optional.ofNullable(coreMap().get(CoreAnnotations.CanonicalEntityMentionIndexAnnotation.class)); return canonicalEntityMentionIndex.isPresent() ? Optional.of(sentence.document().entityMentions().get(canonicalEntityMentionIndex.get())) : Optional.empty(); }
/** * Read in a CoreDocument from this input stream. * * @param is The input stream to read a CoreDocument's annotation from * @return A pair with the CoreDocument and the input stream * @throws IOException * @throws ClassNotFoundException * @throws ClassCastException */ public Pair<CoreDocument, InputStream> readCoreDocument(InputStream is) throws IOException, ClassNotFoundException, ClassCastException { Pair<Annotation, InputStream> readPair = read(is); CoreDocument readCoreDocument = new CoreDocument(readPair.first()); return new Pair<CoreDocument, InputStream>(readCoreDocument, is); }
/** complete the wrapping process post annotation by a pipeline **/ public void wrapAnnotations() { // wrap all of the sentences if (this.annotationDocument.get(CoreAnnotations.SentencesAnnotation.class) != null) { wrapSentences(); // if there are entity mentions, build a document wide list if ( ! sentences.isEmpty() && sentences.get(0).entityMentions() != null) { buildDocumentEntityMentionsList(); } // if there are quotes, build a document wide list if (QuoteAnnotator.gatherQuotes(this.annotationDocument) != null) buildDocumentQuotesList(); } }
/** * Append a CoreDocument to this output stream. * * @param document The CoreDocument to serialize (its internal annotation is serialized) * @param os The output stream to serialize to * @return The output stream which should be closed * @throws IOException */ public OutputStream writeCoreDocument(CoreDocument document, OutputStream os) throws IOException { Annotation wrappedAnnotation = document.annotation(); return write(wrappedAnnotation, os); }
public CoreDocument(Annotation annotation) { this.annotationDocument = annotation; wrapAnnotations(); }
@Override public String toString() { return annotation().toString(); }
/** Annotate the CoreDocument wrapper. **/ public void annotate(CoreDocument document) { // annotate the underlying Annotation this.annotate(document.annotationDocument); // wrap the sentences and entity mentions post annotation document.wrapAnnotations(); }
/** * Append a CoreDocument to this output stream. * * @param document The CoreDocument to serialize (its internal annotation is serialized) * @param os The output stream to serialize to * @return The output stream which should be closed * @throws IOException */ public OutputStream writeCoreDocument(CoreDocument document, OutputStream os) throws IOException { Annotation wrappedAnnotation = document.annotation(); return write(wrappedAnnotation, os); }