@Test final void resolveMentionOverlappingHappy4() { final AnnotatorConfig config1 = new AnnotatorConfig(); config1.setName("ann1"); config1.setFrom("CoNLL"); final AnnotatorConfig config2 = new AnnotatorConfig(); config2.setName("ann2"); config2.setFrom("CoNLL"); final Entity entity1 = Entity.builder().phrase("States").cleanPhrase("States").startOffset(7).endOffset(13).type("LOCATION").build(); final Entity entity2 = Entity.builder().phrase("United States of America").cleanPhrase("United States of America").startOffset(0).endOffset(24).type("LOCATION").build(); final Document doc1 = Document.builder().entities(Collections.singletonList(entity1)).text("United States of America").build(); final Document doc2 = Document.builder().entities(Collections.singletonList(entity2)).text("United States of America").build(); final Map<AnnotatorConfig, List<Entity>> documents = new HashMap<>(); documents.put(config1, doc1.getEntities()); documents.put(config2, doc2.getEntities()); final MentionOverlapResolutionRepository mergeMentionOverlapResolution = new MergeMentionOverlapResolution(); final List<Entity> newEntities = mergeMentionOverlapResolution.resolveMentionOverlapping(documents); Assertions.assertEquals(1, newEntities.size(), "Must be equals"); Assertions.assertEquals(0, newEntities.get(0).getStartOffset().intValue(), "Must be equals"); Assertions.assertEquals(24, newEntities.get(0).getEndOffset().intValue(), "Must be equals"); Assertions.assertTrue("LOCATIONfromCoNLL--ann2||LOCATIONfromCoNLL--ann1".equals(newEntities.get(0).getType()) || "LOCATIONfromCoNLL--ann1||LOCATIONfromCoNLL--ann2".equals(newEntities.get(0).getType()), "Must be equals"); Assertions.assertEquals("United States of America", newEntities.get(0).getPhrase(), "Must be equals"); Assertions.assertEquals("United States of America", newEntities.get(0).getCleanPhrase(), "Must be equals"); }
@Override public final List<Entity> resolveMentionOverlapping( final Map<AnnotatorConfig, List<Entity>> documents) { final List<Entity> finalEntities = new ArrayList<>(); for (final Map.Entry<AnnotatorConfig, List<Entity>> document : documents.entrySet()) { for (final Entity old : document.getValue()) { final List<Integer> overlapIndexes = this.overlappingIndex(finalEntities, old); if (overlapIndexes.isEmpty()) { if (!old.getType().isEmpty()) { old.setType( old.getType() + "from" + document.getKey().getFrom() + "--" + document.getKey().getName()); } finalEntities.add(old); } else { final Collection<Entity> newEntities = new ArrayList<>(); Entity newEntity = this.entityResolution(finalEntities.get(overlapIndexes.get(0)), old, document.getKey()); newEntities.add(newEntity); for (int i = 1;i < overlapIndexes.size();i++) { newEntity = this.entityResolution(finalEntities.get(overlapIndexes.get(i)), old, document.getKey()); newEntities.add(newEntity); } if (1 < newEntities.size()) { final StringBuilder newType = new StringBuilder(); for (final Entity entity : newEntities) { final String[] splitTypes = entity.getType().split("\\|\\|"); for (final String splitType : splitTypes) { if (!newType.toString().contains(splitType)) { newType.append(splitType); newType.append("||"); } } } newEntity.setType(newType.substring(0, newType.length() - 2)); } final Collection<Entity> entitiesToRemove = new ArrayList<>(); for (final Integer overlapIndexe : overlapIndexes) { entitiesToRemove.add(finalEntities.get(overlapIndexe)); } finalEntities.removeAll(entitiesToRemove); finalEntities.add(newEntity); } } } return finalEntities; }
MergeMentionOverlapResolution implements MentionOverlapResolutionRepository { @Override public final List<Entity> resolveMentionOverlapping( final Map<AnnotatorConfig, List<Entity>> documents) { final List<Entity> finalEntities = new ArrayList<>(); for (final Map.Entry<AnnotatorConfig, List<Entity>> document : documents.entrySet()) { for (final Entity old : document.getValue()) { final List<Integer> overlapIndexes = this.overlappingIndex(finalEntities, old); if (overlapIndexes.isEmpty()) { if (!old.getType().isEmpty()) { old.setType( old.getType() + "from" + document.getKey().getFrom() + "--" + document.getKey().getName()); } finalEntities.add(old); } else { final Collection<Entity> newEntities = new ArrayList<>(); Entity newEntity = this.entityResolution(finalEntities.get(overlapIndexes.get(0)), old, document.getKey()); newEntities.add(newEntity); for (int i = 1;i < overlapIndexes.size();i++) { newEntity = this.entityResolution(finalEntities.get(overlapIndexes.get(i)), old, document.getKey()); newEntities.add(newEntity); } if (1 < newEntities.size()) { final StringBuilder newType = new StringBuilder(); for (final Entity entity : newEntities) { final String[] splitTypes = entity.getType().split("\\|\\|"); for (final String splitType : splitTypes) { if (!newType.toString().contains(splitType)) { newType.append(splitType); newType.append("||"); } } } newEntity.setType(newType.substring(0, newType.length() - 2)); } final Collection<Entity> entitiesToRemove = new ArrayList<>(); for (final Integer overlapIndexe : overlapIndexes) { entitiesToRemove.add(finalEntities.get(overlapIndexe)); } finalEntities.removeAll(entitiesToRemove); finalEntities.add(newEntity); } } } return finalEntities; } }
MergeMentionOverlapResolution implements MentionOverlapResolutionRepository { @Override public final List<Entity> resolveMentionOverlapping( final Map<AnnotatorConfig, List<Entity>> documents) { final List<Entity> finalEntities = new ArrayList<>(); for (final Map.Entry<AnnotatorConfig, List<Entity>> document : documents.entrySet()) { for (final Entity old : document.getValue()) { final List<Integer> overlapIndexes = this.overlappingIndex(finalEntities, old); if (overlapIndexes.isEmpty()) { if (!old.getType().isEmpty()) { old.setType( old.getType() + "from" + document.getKey().getFrom() + "--" + document.getKey().getName()); } finalEntities.add(old); } else { final Collection<Entity> newEntities = new ArrayList<>(); Entity newEntity = this.entityResolution(finalEntities.get(overlapIndexes.get(0)), old, document.getKey()); newEntities.add(newEntity); for (int i = 1;i < overlapIndexes.size();i++) { newEntity = this.entityResolution(finalEntities.get(overlapIndexes.get(i)), old, document.getKey()); newEntities.add(newEntity); } if (1 < newEntities.size()) { final StringBuilder newType = new StringBuilder(); for (final Entity entity : newEntities) { final String[] splitTypes = entity.getType().split("\\|\\|"); for (final String splitType : splitTypes) { if (!newType.toString().contains(splitType)) { newType.append(splitType); newType.append("||"); } } } newEntity.setType(newType.substring(0, newType.length() - 2)); } final Collection<Entity> entitiesToRemove = new ArrayList<>(); for (final Integer overlapIndexe : overlapIndexes) { entitiesToRemove.add(finalEntities.get(overlapIndexe)); } finalEntities.removeAll(entitiesToRemove); finalEntities.add(newEntity); } } } return finalEntities; }  }
MergeMentionOverlapResolution implements MentionOverlapResolutionRepository { @Override public final List<Entity> resolveMentionOverlapping( final Map<AnnotatorConfig, List<Entity>> documents) { final List<Entity> finalEntities = new ArrayList<>(); for (final Map.Entry<AnnotatorConfig, List<Entity>> document : documents.entrySet()) { for (final Entity old : document.getValue()) { final List<Integer> overlapIndexes = this.overlappingIndex(finalEntities, old); if (overlapIndexes.isEmpty()) { if (!old.getType().isEmpty()) { old.setType( old.getType() + "from" + document.getKey().getFrom() + "--" + document.getKey().getName()); } finalEntities.add(old); } else { final Collection<Entity> newEntities = new ArrayList<>(); Entity newEntity = this.entityResolution(finalEntities.get(overlapIndexes.get(0)), old, document.getKey()); newEntities.add(newEntity); for (int i = 1;i < overlapIndexes.size();i++) { newEntity = this.entityResolution(finalEntities.get(overlapIndexes.get(i)), old, document.getKey()); newEntities.add(newEntity); } if (1 < newEntities.size()) { final StringBuilder newType = new StringBuilder(); for (final Entity entity : newEntities) { final String[] splitTypes = entity.getType().split("\\|\\|"); for (final String splitType : splitTypes) { if (!newType.toString().contains(splitType)) { newType.append(splitType); newType.append("||"); } } } newEntity.setType(newType.substring(0, newType.length() - 2)); } final Collection<Entity> entitiesToRemove = new ArrayList<>(); for (final Integer overlapIndexe : overlapIndexes) { entitiesToRemove.add(finalEntities.get(overlapIndexe)); } finalEntities.removeAll(entitiesToRemove); finalEntities.add(newEntity); } } } return finalEntities; }  @Override final List<Entity> resolveMentionOverlapping(
      final Map<AnnotatorConfig, List<Entity>> documents); }
MergeMentionOverlapResolution implements MentionOverlapResolutionRepository { @Override public final List<Entity> resolveMentionOverlapping( final Map<AnnotatorConfig, List<Entity>> documents) { final List<Entity> finalEntities = new ArrayList<>(); for (final Map.Entry<AnnotatorConfig, List<Entity>> document : documents.entrySet()) { for (final Entity old : document.getValue()) { final List<Integer> overlapIndexes = this.overlappingIndex(finalEntities, old); if (overlapIndexes.isEmpty()) { if (!old.getType().isEmpty()) { old.setType( old.getType() + "from" + document.getKey().getFrom() + "--" + document.getKey().getName()); } finalEntities.add(old); } else { final Collection<Entity> newEntities = new ArrayList<>(); Entity newEntity = this.entityResolution(finalEntities.get(overlapIndexes.get(0)), old, document.getKey()); newEntities.add(newEntity); for (int i = 1;i < overlapIndexes.size();i++) { newEntity = this.entityResolution(finalEntities.get(overlapIndexes.get(i)), old, document.getKey()); newEntities.add(newEntity); } if (1 < newEntities.size()) { final StringBuilder newType = new StringBuilder(); for (final Entity entity : newEntities) { final String[] splitTypes = entity.getType().split("\\|\\|"); for (final String splitType : splitTypes) { if (!newType.toString().contains(splitType)) { newType.append(splitType); newType.append("||"); } } } newEntity.setType(newType.substring(0, newType.length() - 2)); } final Collection<Entity> entitiesToRemove = new ArrayList<>(); for (final Integer overlapIndexe : overlapIndexes) { entitiesToRemove.add(finalEntities.get(overlapIndexe)); } finalEntities.removeAll(entitiesToRemove); finalEntities.add(newEntity); } } } return finalEntities; }  @Override final List<Entity> resolveMentionOverlapping(
      final Map<AnnotatorConfig, List<Entity>> documents);  }