@Test public void testFilterToSingle() { final Map<ReferenceTarget, Entity> map = ReferentUtils.filterToSingle(referentMap, l -> l.iterator().next()); assertEquals(chris.getType().getName(), map.get(chrisRT).getType().getName()); assertEquals(london.getType().getName(), map.get(londonRT).getType().getName()); }
public static <T> Map<ReferenceTarget, T> filterToSingle( Multimap<ReferenceTarget, T> referentMap, Function<Collection<T>, T> convert) { final Map<ReferenceTarget, T> singleMap = new HashMap<>(referentMap.size()); referentMap.asMap().entrySet().stream() .forEach( e -> { final T t = convert.apply(e.getValue()); if (t != null) { singleMap.put(e.getKey(), t); } }); return singleMap; }
ReferentUtils { public static <T> Map<ReferenceTarget, T> filterToSingle( Multimap<ReferenceTarget, T> referentMap, Function<Collection<T>, T> convert) { final Map<ReferenceTarget, T> singleMap = new HashMap<>(referentMap.size()); referentMap.asMap().entrySet().stream() .forEach( e -> { final T t = convert.apply(e.getValue()); if (t != null) { singleMap.put(e.getKey(), t); } }); return singleMap; } }
ReferentUtils { public static <T> Map<ReferenceTarget, T> filterToSingle( Multimap<ReferenceTarget, T> referentMap, Function<Collection<T>, T> convert) { final Map<ReferenceTarget, T> singleMap = new HashMap<>(referentMap.size()); referentMap.asMap().entrySet().stream() .forEach( e -> { final T t = convert.apply(e.getValue()); if (t != null) { singleMap.put(e.getKey(), t); } }); return singleMap; } private  ReferentUtils(); }
ReferentUtils { public static <T> Map<ReferenceTarget, T> filterToSingle( Multimap<ReferenceTarget, T> referentMap, Function<Collection<T>, T> convert) { final Map<ReferenceTarget, T> singleMap = new HashMap<>(referentMap.size()); referentMap.asMap().entrySet().stream() .forEach( e -> { final T t = convert.apply(e.getValue()); if (t != null) { singleMap.put(e.getKey(), t); } }); return singleMap; } private  ReferentUtils(); static Multimap<ReferenceTarget, T> createReferentMap(
      final JCas jCas, final Class<T> clazz); static Multimap<ReferenceTarget, T> createReferentMap(
      final JCas jCas, final Class<T> clazz, final boolean filterEmptyReference); static Multimap<ReferenceTarget, T> createReferentMap(
      final JCas jCas, final Collection<T> mentions, final boolean filterEmptyReference); static Map<ReferenceTarget, T> filterToSingle(
      Multimap<ReferenceTarget, T> referentMap, Function<Collection<T>, T> convert); static List<Base> getAllEntityOrReferentToEntity(
      JCas jCas, Map<ReferenceTarget, Entity> referentMap); @SuppressWarnings("unlikely-arg-type") static List<Base> getAllAndReferents(
      JCas jCas, Class<T> clazz, Map<ReferenceTarget, T> referentMap); static Stream<Base> streamReferent(
      JCas jCas, Map<ReferenceTarget, T> referentMap); static T getLongestSingle(Collection<T> list); static T singleViaCompare(Collection<T> list, Comparator<T> compare); static Set<Entity> replaceWithCoreferent(
      Collection<Entity> entities, Map<ReferenceTarget, Entity> referentMap); }
ReferentUtils { public static <T> Map<ReferenceTarget, T> filterToSingle( Multimap<ReferenceTarget, T> referentMap, Function<Collection<T>, T> convert) { final Map<ReferenceTarget, T> singleMap = new HashMap<>(referentMap.size()); referentMap.asMap().entrySet().stream() .forEach( e -> { final T t = convert.apply(e.getValue()); if (t != null) { singleMap.put(e.getKey(), t); } }); return singleMap; } private  ReferentUtils(); static Multimap<ReferenceTarget, T> createReferentMap(
      final JCas jCas, final Class<T> clazz); static Multimap<ReferenceTarget, T> createReferentMap(
      final JCas jCas, final Class<T> clazz, final boolean filterEmptyReference); static Multimap<ReferenceTarget, T> createReferentMap(
      final JCas jCas, final Collection<T> mentions, final boolean filterEmptyReference); static Map<ReferenceTarget, T> filterToSingle(
      Multimap<ReferenceTarget, T> referentMap, Function<Collection<T>, T> convert); static List<Base> getAllEntityOrReferentToEntity(
      JCas jCas, Map<ReferenceTarget, Entity> referentMap); @SuppressWarnings("unlikely-arg-type") static List<Base> getAllAndReferents(
      JCas jCas, Class<T> clazz, Map<ReferenceTarget, T> referentMap); static Stream<Base> streamReferent(
      JCas jCas, Map<ReferenceTarget, T> referentMap); static T getLongestSingle(Collection<T> list); static T singleViaCompare(Collection<T> list, Comparator<T> compare); static Set<Entity> replaceWithCoreferent(
      Collection<Entity> entities, Map<ReferenceTarget, Entity> referentMap); static final Predicate<? super Base> NOT_ENTITY_OR_REFERENT; static final Predicate<? super Base> ENTITY_OR_REFERENT; }