@Test public void testFilterToTopLevelAnnotations() { final Collection<WordToken> select = JCasUtil.select(jCas, WordToken.class); final List<WordToken> topLevel = AnnotationUtils.filterToTopLevelAnnotations(select); Assert.assertEquals(3, topLevel.size()); Assert.assertEquals("0123456789", topLevel.get(0).getCoveredText()); Assert.assertEquals("abcde", topLevel.get(1).getCoveredText()); Assert.assertEquals("fghij", topLevel.get(2).getCoveredText()); }
public static <T extends Annotation> List<T> filterToTopLevelAnnotations( final Collection<T> annotations) { final List<T> topLevel = new LinkedList<>(); for (final T a : annotations) { boolean covered = false; for (final T b : annotations) { if (!a.equals(b) && b.getBegin() <= a.getBegin() && a.getEnd() <= b.getEnd()) { covered = true; break; } } if (!covered) { topLevel.add(a); } } return topLevel; }
AnnotationUtils { public static <T extends Annotation> List<T> filterToTopLevelAnnotations( final Collection<T> annotations) { final List<T> topLevel = new LinkedList<>(); for (final T a : annotations) { boolean covered = false; for (final T b : annotations) { if (!a.equals(b) && b.getBegin() <= a.getBegin() && a.getEnd() <= b.getEnd()) { covered = true; break; } } if (!covered) { topLevel.add(a); } } return topLevel; } }
AnnotationUtils { public static <T extends Annotation> List<T> filterToTopLevelAnnotations( final Collection<T> annotations) { final List<T> topLevel = new LinkedList<>(); for (final T a : annotations) { boolean covered = false; for (final T b : annotations) { if (!a.equals(b) && b.getBegin() <= a.getBegin() && a.getEnd() <= b.getEnd()) { covered = true; break; } } if (!covered) { topLevel.add(a); } } return topLevel; } private  AnnotationUtils(); }
AnnotationUtils { public static <T extends Annotation> List<T> filterToTopLevelAnnotations( final Collection<T> annotations) { final List<T> topLevel = new LinkedList<>(); for (final T a : annotations) { boolean covered = false; for (final T b : annotations) { if (!a.equals(b) && b.getBegin() <= a.getBegin() && a.getEnd() <= b.getEnd()) { covered = true; break; } } if (!covered) { topLevel.add(a); } } return topLevel; } private  AnnotationUtils(); static Optional<T> getSingleCovered(
      final Class<T> clazz, final Annotation annotation); static List<T> filterToTopLevelAnnotations(
      final Collection<T> annotations); static boolean isInBetween(
      final Annotation between, final Annotation source, final Annotation target); static boolean isCovering(final Annotation covering, final Annotation covered); }
AnnotationUtils { public static <T extends Annotation> List<T> filterToTopLevelAnnotations( final Collection<T> annotations) { final List<T> topLevel = new LinkedList<>(); for (final T a : annotations) { boolean covered = false; for (final T b : annotations) { if (!a.equals(b) && b.getBegin() <= a.getBegin() && a.getEnd() <= b.getEnd()) { covered = true; break; } } if (!covered) { topLevel.add(a); } } return topLevel; } private  AnnotationUtils(); static Optional<T> getSingleCovered(
      final Class<T> clazz, final Annotation annotation); static List<T> filterToTopLevelAnnotations(
      final Collection<T> annotations); static boolean isInBetween(
      final Annotation between, final Annotation source, final Annotation target); static boolean isCovering(final Annotation covering, final Annotation covered);  }