@Test public void testGetSeparateAnnotationGroups() { EntityAnnotation annot1 = new EntityAnnotation(mockEntity, 0, 4); EntityAnnotation annot2 = new EntityAnnotation(mockEntity2, 5, 10); annotationList.add(annot1); annotationList.add(annot2); EntityAnnotationGroup expected1 = new EntityAnnotationGroup(); expected1.add(annot2); EntityAnnotationGroup expected2 = new EntityAnnotationGroup(); expected2.add(annot1); assertThat(EntityProcessorImpl.getAnnotationGroups(annotationList, false), contains(expected1, expected2)); }
static List<EntityAnnotationGroup> getAnnotationGroups(List<EntityAnnotation> annotationList, boolean longestOnly) { List<EntityAnnotationGroup> groups = new ArrayList<>(); Collections.sort(annotationList, Collections.reverseOrder()); PeekingIterator<EntityAnnotation> iter = Iterators.peekingIterator(annotationList.iterator()); while (iter.hasNext()) { EntityAnnotationGroup group = new EntityAnnotationGroup(); group.add(iter.next()); Set<Entity> entitiesInGroup = new HashSet<>(); while (iter.hasNext() && group.intersects(iter.peek())) { if (!entitiesInGroup.contains(iter.peek().getToken())) { entitiesInGroup.add(iter.peek().getToken()); group.add(iter.next()); } else { iter.next(); } } if (longestOnly) { Iterator<EntityAnnotation> groupIter = group.iterator(); int longest = group.peek().length(); while (groupIter.hasNext()) { EntityAnnotation annot = groupIter.next(); if (annot.length() < longest) { groupIter.remove(); } } } groups.add(group); } return groups; }
EntityProcessorImpl implements EntityProcessor { static List<EntityAnnotationGroup> getAnnotationGroups(List<EntityAnnotation> annotationList, boolean longestOnly) { List<EntityAnnotationGroup> groups = new ArrayList<>(); Collections.sort(annotationList, Collections.reverseOrder()); PeekingIterator<EntityAnnotation> iter = Iterators.peekingIterator(annotationList.iterator()); while (iter.hasNext()) { EntityAnnotationGroup group = new EntityAnnotationGroup(); group.add(iter.next()); Set<Entity> entitiesInGroup = new HashSet<>(); while (iter.hasNext() && group.intersects(iter.peek())) { if (!entitiesInGroup.contains(iter.peek().getToken())) { entitiesInGroup.add(iter.peek().getToken()); group.add(iter.next()); } else { iter.next(); } } if (longestOnly) { Iterator<EntityAnnotation> groupIter = group.iterator(); int longest = group.peek().length(); while (groupIter.hasNext()) { EntityAnnotation annot = groupIter.next(); if (annot.length() < longest) { groupIter.remove(); } } } groups.add(group); } return groups; } }
EntityProcessorImpl implements EntityProcessor { static List<EntityAnnotationGroup> getAnnotationGroups(List<EntityAnnotation> annotationList, boolean longestOnly) { List<EntityAnnotationGroup> groups = new ArrayList<>(); Collections.sort(annotationList, Collections.reverseOrder()); PeekingIterator<EntityAnnotation> iter = Iterators.peekingIterator(annotationList.iterator()); while (iter.hasNext()) { EntityAnnotationGroup group = new EntityAnnotationGroup(); group.add(iter.next()); Set<Entity> entitiesInGroup = new HashSet<>(); while (iter.hasNext() && group.intersects(iter.peek())) { if (!entitiesInGroup.contains(iter.peek().getToken())) { entitiesInGroup.add(iter.peek().getToken()); group.add(iter.next()); } else { iter.next(); } } if (longestOnly) { Iterator<EntityAnnotation> groupIter = group.iterator(); int longest = group.peek().length(); while (groupIter.hasNext()) { EntityAnnotation annot = groupIter.next(); if (annot.length() < longest) { groupIter.remove(); } } } groups.add(group); } return groups; } @Inject protected  EntityProcessorImpl(EntityRecognizer recognizer); }
EntityProcessorImpl implements EntityProcessor { static List<EntityAnnotationGroup> getAnnotationGroups(List<EntityAnnotation> annotationList, boolean longestOnly) { List<EntityAnnotationGroup> groups = new ArrayList<>(); Collections.sort(annotationList, Collections.reverseOrder()); PeekingIterator<EntityAnnotation> iter = Iterators.peekingIterator(annotationList.iterator()); while (iter.hasNext()) { EntityAnnotationGroup group = new EntityAnnotationGroup(); group.add(iter.next()); Set<Entity> entitiesInGroup = new HashSet<>(); while (iter.hasNext() && group.intersects(iter.peek())) { if (!entitiesInGroup.contains(iter.peek().getToken())) { entitiesInGroup.add(iter.peek().getToken()); group.add(iter.next()); } else { iter.next(); } } if (longestOnly) { Iterator<EntityAnnotation> groupIter = group.iterator(); int longest = group.peek().length(); while (groupIter.hasNext()) { EntityAnnotation annot = groupIter.next(); if (annot.length() < longest) { groupIter.remove(); } } } groups.add(group); } return groups; } @Inject protected  EntityProcessorImpl(EntityRecognizer recognizer); @Override List<EntityAnnotation> annotateEntities(EntityFormatConfiguration config); }
EntityProcessorImpl implements EntityProcessor { static List<EntityAnnotationGroup> getAnnotationGroups(List<EntityAnnotation> annotationList, boolean longestOnly) { List<EntityAnnotationGroup> groups = new ArrayList<>(); Collections.sort(annotationList, Collections.reverseOrder()); PeekingIterator<EntityAnnotation> iter = Iterators.peekingIterator(annotationList.iterator()); while (iter.hasNext()) { EntityAnnotationGroup group = new EntityAnnotationGroup(); group.add(iter.next()); Set<Entity> entitiesInGroup = new HashSet<>(); while (iter.hasNext() && group.intersects(iter.peek())) { if (!entitiesInGroup.contains(iter.peek().getToken())) { entitiesInGroup.add(iter.peek().getToken()); group.add(iter.next()); } else { iter.next(); } } if (longestOnly) { Iterator<EntityAnnotation> groupIter = group.iterator(); int longest = group.peek().length(); while (groupIter.hasNext()) { EntityAnnotation annot = groupIter.next(); if (annot.length() < longest) { groupIter.remove(); } } } groups.add(group); } return groups; } @Inject protected  EntityProcessorImpl(EntityRecognizer recognizer); @Override List<EntityAnnotation> annotateEntities(EntityFormatConfiguration config);  }