Map<Long, List<AnnotationSuggestion>> suggestionsByRecommenders = stream() .collect(groupingBy(AnnotationSuggestion::getRecommenderId));
private List<AnnotationSuggestion> getMatchingSuggestion(List<SuggestionGroup> aSuggestions, String aDocumentName, long aLayerId, String aFeature, int aBegin, int aEnd, String aLabel) { return aSuggestions.stream() .filter(group -> aDocumentName.equals(group.getDocumentName()) && aLayerId == group.getLayerId() && (aFeature == null || aFeature == group.getFeature()) && (aBegin == -1 || aBegin == group.getOffset().getBegin()) && (aEnd == -1 || aEnd == group.getOffset().getEnd())) .flatMap(group -> group.stream()) .filter(suggestion -> aLabel == null || aLabel.equals(suggestion.getLabel())) .collect(toList()); }
private List<AnnotationSuggestion> getMatchingSuggestion(List<SuggestionGroup> aSuggestions, String aDocumentName, long aLayerId, String aFeature, int aBegin, int aEnd, String aLabel) { return aSuggestions.stream() .filter(group -> aDocumentName.equals(group.getDocumentName()) && aLayerId == group.getLayerId() && (aFeature == null || aFeature == group.getFeature()) && (aBegin == -1 || aBegin == group.getOffset().getBegin()) && (aEnd == -1 || aEnd == group.getOffset().getEnd())) .flatMap(group -> group.stream()) .filter(suggestion -> aLabel == null || aLabel.equals(suggestion.getLabel())) .collect(toList()); }
Map<Long, List<AnnotationSuggestion>> predictionsByRecommenders = stream() .collect(groupingBy(AnnotationSuggestion::getRecommenderId));
private void actionClearSkippedRecommendations(AjaxRequestTarget aTarget, Form<Void> aForm) throws IOException { learningRecordService.deleteSkippedSuggestions(getModelObject().getUser(), alStateModel.getObject().getLayer()); ActiveLearningUserState alState = alStateModel.getObject(); // The history records caused suggestions to disappear. Since visibility is only fully // recalculated when new predictions come in, we need to update the visibility explicitly // here alState.getSuggestions().stream() .flatMap(group -> group.stream()) .forEach(suggestion -> suggestion.show(FLAG_SKIPPED)); refreshSuggestions(); moveToNextRecommendation(aTarget, false); aTarget.add(mainContainer); }
private void actionClearSkippedRecommendations(AjaxRequestTarget aTarget, Form<Void> aForm) throws IOException { learningRecordService.deleteSkippedSuggestions(getModelObject().getUser(), alStateModel.getObject().getLayer()); ActiveLearningUserState alState = alStateModel.getObject(); // The history records caused suggestions to disappear. Since visibility is only fully // recalculated when new predictions come in, we need to update the visibility explicitly // here alState.getSuggestions().stream() .flatMap(group -> group.stream()) .forEach(suggestion -> suggestion.show(FLAG_SKIPPED)); refreshSuggestions(); moveToNextRecommendation(aTarget, false); aTarget.add(mainContainer); }
@Override public boolean isSuggestionVisible(LearningRecord aRecord) { User user = userService.get(aRecord.getUser()); List<SuggestionGroup> suggestions = getSuggestions(user, aRecord.getLayer()); for (SuggestionGroup listOfAO : suggestions) { if (listOfAO.stream().anyMatch(suggestion -> suggestion.getDocumentName().equals(aRecord.getSourceDocument().getName()) && suggestion.getFeature().equals(aRecord.getAnnotationFeature().getName()) && suggestion.getLabel().equals(aRecord.getAnnotation()) && suggestion.getBegin() == aRecord.getOffsetCharacterBegin() && suggestion.getEnd() == aRecord.getOffsetCharacterEnd() && suggestion.isVisible()) ) { return true; } } return false; }
@Override public boolean isSuggestionVisible(LearningRecord aRecord) { User user = userService.get(aRecord.getUser()); List<SuggestionGroup> suggestions = getSuggestions(user, aRecord.getLayer()); for (SuggestionGroup listOfAO : suggestions) { if (listOfAO.stream().anyMatch(suggestion -> suggestion.getDocumentName().equals(aRecord.getSourceDocument().getName()) && suggestion.getFeature().equals(aRecord.getAnnotationFeature().getName()) && suggestion.getLabel().equals(aRecord.getAnnotation()) && suggestion.getBegin() == aRecord.getOffsetCharacterBegin() && suggestion.getEnd() == aRecord.getOffsetCharacterEnd() && suggestion.isVisible()) ) { return true; } } return false; }
AnnotationSuggestion canonicalRecommendation = suggestion.stream() .filter(p -> p.getLabel().equals(label)) .max(Comparator.comparingInt(AnnotationSuggestion::getId)).orElse(null);