AnnotatedText implements Serializable { @SuppressWarnings("unchecked") @Deprecated public ListAttribute<EntityMention> getEntityMentions() { if (!compatMentionsProcessed) { compatMentionsProcessed = true; List<EntityMention> entityMentionList = Lists.newArrayList(); ListAttribute<Entity> entities = getEntities(); if (entities != null) { downconvertEntities(entityMentionList, entities); } else { return null; } ListAttribute.Builder<EntityMention> cmListBuilder = new ListAttribute.Builder<>(EntityMention.class); for (EntityMention entityMention : entityMentionList) { cmListBuilder.add(entityMention); } if (entities.getExtendedProperties() != null) { for (Map.Entry<String, Object> me : entities.getExtendedProperties().entrySet()) { String key = me.getKey(); if (key.startsWith("mention.")) { cmListBuilder.extendedProperty(key.substring(8), me.getValue()); } } } compatMentions = cmListBuilder.build(); } return compatMentions; } AnnotatedText(CharSequence data,
                  Map<String, BaseAttribute> attributes,
                  Map<String, List<String>> documentMetadata,
                  /*
                   * This version is only here as a workaround for https://github.com/FasterXML/jackson-databind/issues/1118
                   * It would be better if it was only mentioned in the mixins. No data arrives here, it just
                   * allows the mixin to be matched with the existence of a version item in the json.
                   */
                  String version); CharSequence getData(); Map<String, List<String>> getDocumentMetadata(); Map<String, BaseAttribute> getAttributes(); @SuppressWarnings("unchecked") ListAttribute<Token> getTokens(); @SuppressWarnings("unchecked") ListAttribute<TranslatedTokens> getTranslatedTokens(); @SuppressWarnings("unchecked") ListAttribute<TranslatedData> getTranslatedData(); @SuppressWarnings("unchecked") ListAttribute<LanguageDetection> getLanguageDetectionRegions(); LanguageDetection getWholeTextLanguageDetection(); @SuppressWarnings("unchecked") @Deprecated ListAttribute<EntityMention> getEntityMentions(); @SuppressWarnings("unchecked") ListAttribute<Entity> getEntities(); @SuppressWarnings("unchecked") MapAttribute<LanguageCode, ListAttribute<SimilarTerm>> getSimilarTerms(); @SuppressWarnings("unchecked") ListAttribute<SimilarTerm> getSimilarTerms(LanguageCode languageCode); @SuppressWarnings("unchecked") ListAttribute<RelationshipMention> getRelationshipMentions(); @SuppressWarnings("unchecked") @Deprecated ListAttribute<ResolvedEntity> getResolvedEntities(); @SuppressWarnings("unchecked") ListAttribute<ScriptRegion> getScriptRegions(); @SuppressWarnings("unchecked") ListAttribute<Sentence> getSentences(); @SuppressWarnings("unchecked") ListAttribute<LayoutRegion> getLayoutRegions(); @SuppressWarnings("unchecked") ListAttribute<BaseNounPhrase> getBaseNounPhrases(); @SuppressWarnings("unchecked") ListAttribute<CategorizerResult> getCategorizerResults(); @SuppressWarnings("unchecked") ListAttribute<CategorizerResult> getSentimentResults(); @SuppressWarnings("unchecked") ListAttribute<Dependency> getDependencies(); @SuppressWarnings("unchecked") ListAttribute<CategorizerResult> getTopicResults(); Embeddings getEmbeddings(); @SuppressWarnings("unchecked") ListAttribute<Concept> getConcepts(); @SuppressWarnings("unchecked") ListAttribute<Keyphrase> getKeyphrases(); TransliterationResults getTransliteration(); @Override String toString();  }
@SuppressWarnings("deprecation") @Test public void corefChainCompat() throws Exception { AnnotatedText.Builder textBuilder = new AnnotatedText.Builder(); textBuilder.data("George went to Boston. Washington hated it."); ListAttribute.Builder<Entity> entityListBuilder = new ListAttribute.Builder<>(Entity.class); Entity.Builder entityBuilder = new Entity.Builder(); entityBuilder.type("PERSON"); entityBuilder.headMentionIndex(1); entityBuilder.mention(new Mention.Builder(0, 6).build()); entityBuilder.mention(new Mention.Builder(23, 33).build()); entityListBuilder.add(entityBuilder.build()); entityBuilder = new Entity.Builder(); entityBuilder.type("LOCATION"); entityBuilder.headMentionIndex(0); entityBuilder.mention(new Mention.Builder(15, 21).build()); entityListBuilder.add(entityBuilder.build()); textBuilder.entities(entityListBuilder.build()); AnnotatedText text = textBuilder.build(); List<EntityMention> mentions = text.getEntityMentions(); assertEquals(3, mentions.size()); EntityMention em = mentions.get(0); assertEquals("PERSON", em.getEntityType()); assertEquals(0, em.getStartOffset()); assertEquals(6, em.getEndOffset()); assertEquals(2, (int)em.getCoreferenceChainId()); em = mentions.get(1); assertEquals("LOCATION", em.getEntityType()); assertEquals(15, em.getStartOffset()); assertEquals(21, em.getEndOffset()); assertEquals(1, (int)em.getCoreferenceChainId()); em = mentions.get(2); assertEquals("PERSON", em.getEntityType()); assertEquals(23, em.getStartOffset()); assertEquals(33, em.getEndOffset()); assertEquals(2, (int)em.getCoreferenceChainId()); }
@Test public void testEntityMentionsWithoutChains() { String rawText = "Bill. George."; AnnotatedText.Builder builder = new AnnotatedText.Builder().data(rawText); int[] entities = {0, 1, 65536, 2, 3, 65536}; int[] tokenOffsets = {0, 3, 7, 13}; ListAttribute.Builder<EntityMention> emListBuilder = new ListAttribute.Builder<>(EntityMention.class); for (int i = 0; i < entities.length / 3; i++) { int startOffset = tokenOffsets[i * 2]; int endOffset = tokenOffsets[i * 2 + 1]; EntityMention.Builder emBuilder = new EntityMention.Builder(startOffset, endOffset, "PERSON"); emListBuilder.add(emBuilder.build()); } builder.entityMentions(emListBuilder.build()); AnnotatedText text = builder.build(); Integer chainForBill = text.getEntityMentions().get(0).getCoreferenceChainId(); Integer chainForGeorge = text.getEntityMentions().get(1).getCoreferenceChainId(); assertNull(chainForBill); assertNull(chainForGeorge); }