@Test public void testCanCollectInformation() throws UIMAException { JCas jCas = JCasFactory.createJCas(); jCas.setDocumentText( "Sir John Major was Prime Minister of the United Kingdom. Major became Prime Minister after Thatcher resigned."); List<Sentence> s = Annotations.createSentences(jCas); Person j1 = Annotations.createPerson(jCas, 0, 14, "Sir John Major"); Person j2 = Annotations.createPerson(jCas, 59, 64, "Major"); ReferenceTarget jRT = Annotations.createReferenceTarget(jCas, j1, j2); JCasInformationCollector collector = new JCasInformationCollector(); Set<EntityInformation<Person>> entityInformations = collector.getEntityInformation(jCas, Person.class); assertEquals(1, entityInformations.size()); EntityInformation<Person> entityInformation = entityInformations.iterator().next(); assertEquals(jRT, entityInformation.getReferenceTarget()); assertTrue( CollectionUtils.isEqualCollection( ImmutableSet.of(j1, j2), entityInformation.getMentions())); assertTrue(CollectionUtils.isEqualCollection(s, entityInformation.getSentences())); }
@Override public <T extends Entity> Set<EntityInformation<T>> getEntityInformation( JCas jCas, Class<T> clazz) { Multimap<ReferenceTarget, T> map = ReferentUtils.createReferentMap(jCas, clazz); Map<T, List<Sentence>> index = JCasUtil.indexCovering(jCas, clazz, Sentence.class); Set<EntityInformation<T>> infos = new HashSet<>(); for (Map.Entry<ReferenceTarget, Collection<T>> entry : map.asMap().entrySet()) { Collection<Sentence> sentences = entry.getValue().stream().flatMap(m -> index.get(m).stream()).collect(Collectors.toSet()); infos.add(new EntityInformation<T>(entry.getKey(), entry.getValue(), sentences)); } return infos; }
JCasInformationCollector implements InformationCollector { @Override public <T extends Entity> Set<EntityInformation<T>> getEntityInformation( JCas jCas, Class<T> clazz) { Multimap<ReferenceTarget, T> map = ReferentUtils.createReferentMap(jCas, clazz); Map<T, List<Sentence>> index = JCasUtil.indexCovering(jCas, clazz, Sentence.class); Set<EntityInformation<T>> infos = new HashSet<>(); for (Map.Entry<ReferenceTarget, Collection<T>> entry : map.asMap().entrySet()) { Collection<Sentence> sentences = entry.getValue().stream().flatMap(m -> index.get(m).stream()).collect(Collectors.toSet()); infos.add(new EntityInformation<T>(entry.getKey(), entry.getValue(), sentences)); } return infos; } }
JCasInformationCollector implements InformationCollector { @Override public <T extends Entity> Set<EntityInformation<T>> getEntityInformation( JCas jCas, Class<T> clazz) { Multimap<ReferenceTarget, T> map = ReferentUtils.createReferentMap(jCas, clazz); Map<T, List<Sentence>> index = JCasUtil.indexCovering(jCas, clazz, Sentence.class); Set<EntityInformation<T>> infos = new HashSet<>(); for (Map.Entry<ReferenceTarget, Collection<T>> entry : map.asMap().entrySet()) { Collection<Sentence> sentences = entry.getValue().stream().flatMap(m -> index.get(m).stream()).collect(Collectors.toSet()); infos.add(new EntityInformation<T>(entry.getKey(), entry.getValue(), sentences)); } return infos; }  }
JCasInformationCollector implements InformationCollector { @Override public <T extends Entity> Set<EntityInformation<T>> getEntityInformation( JCas jCas, Class<T> clazz) { Multimap<ReferenceTarget, T> map = ReferentUtils.createReferentMap(jCas, clazz); Map<T, List<Sentence>> index = JCasUtil.indexCovering(jCas, clazz, Sentence.class); Set<EntityInformation<T>> infos = new HashSet<>(); for (Map.Entry<ReferenceTarget, Collection<T>> entry : map.asMap().entrySet()) { Collection<Sentence> sentences = entry.getValue().stream().flatMap(m -> index.get(m).stream()).collect(Collectors.toSet()); infos.add(new EntityInformation<T>(entry.getKey(), entry.getValue(), sentences)); } return infos; }  @Override Set<EntityInformation<T>> getEntityInformation(
      JCas jCas, Class<T> clazz); }
JCasInformationCollector implements InformationCollector { @Override public <T extends Entity> Set<EntityInformation<T>> getEntityInformation( JCas jCas, Class<T> clazz) { Multimap<ReferenceTarget, T> map = ReferentUtils.createReferentMap(jCas, clazz); Map<T, List<Sentence>> index = JCasUtil.indexCovering(jCas, clazz, Sentence.class); Set<EntityInformation<T>> infos = new HashSet<>(); for (Map.Entry<ReferenceTarget, Collection<T>> entry : map.asMap().entrySet()) { Collection<Sentence> sentences = entry.getValue().stream().flatMap(m -> index.get(m).stream()).collect(Collectors.toSet()); infos.add(new EntityInformation<T>(entry.getKey(), entry.getValue(), sentences)); } return infos; }  @Override Set<EntityInformation<T>> getEntityInformation(
      JCas jCas, Class<T> clazz);  }