@Test public void canCreateDocumentWithCoreferences() throws UIMAException { JCas jCas = JCasFactory.createJCas(); jCas.setDocumentText("John Smith was here. Then he went."); Sentence s1 = Annotations.createSentence(jCas, 0, 20); Sentence s2 = Annotations.createSentence(jCas, 21, 34); Person p1 = Annotations.createPerson(jCas, 0, 10, "John Smith"); Person p2 = Annotations.createPerson(jCas, 26, 28, "he"); Annotations.createReferenceTarget(jCas, p1, p2); OdinSentence sentence1 = mock(OdinSentence.class, "s1"); OdinSentence sentence2 = mock(OdinSentence.class, "s2"); CorefMention coref1 = new CorefMention(0, 0, p1.getBegin(), p1.getEnd(), 0); CorefMention coref2 = new CorefMention(1, 1, 5, 7, 0); when(sentenceFactory.create()).thenReturn(ImmutableList.of(sentence1, sentence2)); when(sentence1.getBaleenSentence()).thenReturn(s1); when(sentence2.getBaleenSentence()).thenReturn(s2); when(sentence1.corefMention(p1, 0)).thenReturn(coref1); when(sentence2.corefMention(p2, 0)).thenReturn(coref2); DocumentFactory documentFactory = new DocumentFactory(jCas, sentenceFactory); Document document = documentFactory.create(); assertEquals(2, document.sentences().length); Option<CorefChains> coreferenceChains = document.coreferenceChains(); assertTrue(coreferenceChains.isDefined()); CorefChains corefChains = coreferenceChains.get(); assertFalse(corefChains.isEmpty()); assertEquals(2, corefChains.rawMentions().size()); Option<Iterable<CorefMention>> option1 = corefChains.getChain(0, 0); assertTrue(option1.isDefined()); Iterator<CorefMention> iterator = option1.get().iterator(); assertEquals(coref2, iterator.next()); assertEquals(coref1, iterator.next()); assertFalse(iterator.hasNext()); }
public OdinDocument create() { OdinDocument document = new OdinDocument(sentenceFactory.create()); document.text_$eq(Some.apply(jCas.getDocumentText())); int chainId = 0; List<CorefMention> mentions = new ArrayList<>(); for (Entry<ReferenceTarget, Collection<Entity>> coref : referentMap.asMap().entrySet()) { for (Entity entity : coref.getValue()) { Collection<Sentence> collection = entityIndex.get(entity); if (!collection.isEmpty()) { OdinSentence sentence = document.findSentence(collection.iterator().next()); mentions.add(sentence.corefMention(entity, chainId)); } } chainId++; } CorefChains chains = CorefChains.apply(JavaConversions.iterableAsScalaIterable(mentions)); document.coreferenceChains_$eq(Option.apply(chains)); return document; }
DocumentFactory { public OdinDocument create() { OdinDocument document = new OdinDocument(sentenceFactory.create()); document.text_$eq(Some.apply(jCas.getDocumentText())); int chainId = 0; List<CorefMention> mentions = new ArrayList<>(); for (Entry<ReferenceTarget, Collection<Entity>> coref : referentMap.asMap().entrySet()) { for (Entity entity : coref.getValue()) { Collection<Sentence> collection = entityIndex.get(entity); if (!collection.isEmpty()) { OdinSentence sentence = document.findSentence(collection.iterator().next()); mentions.add(sentence.corefMention(entity, chainId)); } } chainId++; } CorefChains chains = CorefChains.apply(JavaConversions.iterableAsScalaIterable(mentions)); document.coreferenceChains_$eq(Option.apply(chains)); return document; } }
DocumentFactory { public OdinDocument create() { OdinDocument document = new OdinDocument(sentenceFactory.create()); document.text_$eq(Some.apply(jCas.getDocumentText())); int chainId = 0; List<CorefMention> mentions = new ArrayList<>(); for (Entry<ReferenceTarget, Collection<Entity>> coref : referentMap.asMap().entrySet()) { for (Entity entity : coref.getValue()) { Collection<Sentence> collection = entityIndex.get(entity); if (!collection.isEmpty()) { OdinSentence sentence = document.findSentence(collection.iterator().next()); mentions.add(sentence.corefMention(entity, chainId)); } } chainId++; } CorefChains chains = CorefChains.apply(JavaConversions.iterableAsScalaIterable(mentions)); document.coreferenceChains_$eq(Option.apply(chains)); return document; } DocumentFactory(JCas jCas);  DocumentFactory(JCas jCas, SentenceFactory sentenceFactory);  DocumentFactory(
      JCas jCas,
      Map<Entity, List<Sentence>> entityIndex,
      Multimap<ReferenceTarget, Entity> referentMap,
      SentenceFactory sentenceFactory); }
DocumentFactory { public OdinDocument create() { OdinDocument document = new OdinDocument(sentenceFactory.create()); document.text_$eq(Some.apply(jCas.getDocumentText())); int chainId = 0; List<CorefMention> mentions = new ArrayList<>(); for (Entry<ReferenceTarget, Collection<Entity>> coref : referentMap.asMap().entrySet()) { for (Entity entity : coref.getValue()) { Collection<Sentence> collection = entityIndex.get(entity); if (!collection.isEmpty()) { OdinSentence sentence = document.findSentence(collection.iterator().next()); mentions.add(sentence.corefMention(entity, chainId)); } } chainId++; } CorefChains chains = CorefChains.apply(JavaConversions.iterableAsScalaIterable(mentions)); document.coreferenceChains_$eq(Option.apply(chains)); return document; } DocumentFactory(JCas jCas);  DocumentFactory(JCas jCas, SentenceFactory sentenceFactory);  DocumentFactory(
      JCas jCas,
      Map<Entity, List<Sentence>> entityIndex,
      Multimap<ReferenceTarget, Entity> referentMap,
      SentenceFactory sentenceFactory); OdinDocument create(); }
DocumentFactory { public OdinDocument create() { OdinDocument document = new OdinDocument(sentenceFactory.create()); document.text_$eq(Some.apply(jCas.getDocumentText())); int chainId = 0; List<CorefMention> mentions = new ArrayList<>(); for (Entry<ReferenceTarget, Collection<Entity>> coref : referentMap.asMap().entrySet()) { for (Entity entity : coref.getValue()) { Collection<Sentence> collection = entityIndex.get(entity); if (!collection.isEmpty()) { OdinSentence sentence = document.findSentence(collection.iterator().next()); mentions.add(sentence.corefMention(entity, chainId)); } } chainId++; } CorefChains chains = CorefChains.apply(JavaConversions.iterableAsScalaIterable(mentions)); document.coreferenceChains_$eq(Option.apply(chains)); return document; } DocumentFactory(JCas jCas);  DocumentFactory(JCas jCas, SentenceFactory sentenceFactory);  DocumentFactory(
      JCas jCas,
      Map<Entity, List<Sentence>> entityIndex,
      Multimap<ReferenceTarget, Entity> referentMap,
      SentenceFactory sentenceFactory); OdinDocument create();  }