/** * Returns the prediction used to generate the VID */ public Optional<AnnotationSuggestion> getPrediction(SourceDocument aDocument, int aBegin, int aEnd, String aLabel) { return predictions.values().stream() .filter(f -> f.getDocumentName().equals(aDocument.getName())) .filter(f -> f.getBegin() == aBegin && f.getEnd() == aEnd) .filter(f -> f.getLabel().equals(aLabel)) .max(Comparator.comparingInt(AnnotationSuggestion::getId)); }
/** * Returns the first prediction that matches recommendationId and recommenderId * in the given document. */ public Optional<AnnotationSuggestion> getPredictionByVID(SourceDocument aDocument, VID aVID) { return predictions.values().stream() .filter(f -> f.getDocumentName().equals(aDocument.getName())) .filter(f -> f.getId() == aVID.getSubId()) .filter(f -> f.getRecommenderId() == aVID.getId()) .findFirst(); }
private static boolean isAlreadyInCleanList(SuggestionGroup cleanRecommendationList, AnnotationSuggestion recommendationItem) { String source = recommendationItem.getRecommenderName(); String annotation = recommendationItem.getLabel(); String documentName = recommendationItem.getDocumentName(); for (AnnotationSuggestion existingRecommendation : cleanRecommendationList) { if ( existingRecommendation.getRecommenderName().equals(source) && existingRecommendation.getLabel().equals(annotation) && existingRecommendation.getDocumentName().equals(documentName) ) { return true; } } return false; }
private static boolean isAlreadyInCleanList(SuggestionGroup cleanRecommendationList, AnnotationSuggestion recommendationItem) { String source = recommendationItem.getRecommenderName(); String annotation = recommendationItem.getLabel(); String documentName = recommendationItem.getDocumentName(); for (AnnotationSuggestion existingRecommendation : cleanRecommendationList) { if ( existingRecommendation.getRecommenderName().equals(source) && existingRecommendation.getLabel().equals(annotation) && existingRecommendation.getDocumentName().equals(documentName) ) { return true; } } return false; }
private void setHighlight(AnnotationSuggestion aSuggestion) { if (protectHighlight) { LOG.trace("Active learning sidebar not updating protected highlights"); protectHighlight = false; return; } LOG.trace("Active learning sidebar set highlight suggestion: {}", aSuggestion); highlightVID = aSuggestion.getVID(); highlightSpan = new Offset(aSuggestion.getBegin(), aSuggestion.getEnd()); highlightDocumentName = aSuggestion.getDocumentName(); }
public SuggestionGroup(AnnotationSuggestion... aItems) { suggestions = new ArrayList<>(asList(aItems)); sorted = suggestions.size() < 2; if (!suggestions.isEmpty()) { offset = suggestions.get(0).getOffset(); feature = get(0).getFeature(); layerId = get(0).getLayerId(); documentName = get(0).getDocumentName(); } }
private void setHighlight(AnnotationSuggestion aSuggestion) { if (protectHighlight) { LOG.trace("Active learning sidebar not updating protected highlights"); protectHighlight = false; return; } LOG.trace("Active learning sidebar set highlight suggestion: {}", aSuggestion); highlightVID = aSuggestion.getVID(); highlightSpan = new Offset(aSuggestion.getBegin(), aSuggestion.getEnd()); highlightDocumentName = aSuggestion.getDocumentName(); }
/** * * @param aLayerId * @param aPredictions - list of sentences containing recommendations */ public void putPredictions(long aLayerId, List<AnnotationSuggestion> aPredictions) { aPredictions.forEach(prediction -> { if (prediction.getLabel() != null) { predictions.put(new ExtendedId(user.getUsername(), project.getId(), prediction.getDocumentName(), aLayerId, prediction.getOffset(), prediction.getRecommenderId(), prediction.getId(), -1), prediction); } }); }
private void actionJumpToSuggestion(AjaxRequestTarget aTarget) throws IOException { ActiveLearningUserState alState = alStateModel.getObject(); AnnotationSuggestion suggestion = alState.getSuggestion().get(); if (LOG.isDebugEnabled()) { LOG.debug("Active suggestion: {}", suggestion); Optional<AnnotationSuggestion> updatedSuggestion = getMatchingSuggestion( activeLearningService.getSuggestions(getModelObject().getUser(), alState.getLayer()), suggestion).stream().findFirst(); updatedSuggestion.ifPresent(s -> LOG.debug("Update suggestion: {}", s)); } actionShowSelectedDocument(aTarget, documentService.getSourceDocument(this.getModelObject().getProject(), suggestion.getDocumentName()), suggestion.getBegin(), suggestion.getEnd()); setHighlight(suggestion); }
representative.getBegin(), representative.getEnd(), aSuggestion.getBegin(), aSuggestion.getEnd()); Validate.isTrue(representative.getDocumentName().equals(aSuggestion.getDocumentName()), "All suggestions in a group must come from the same document: expected [%s] but got [%s]", representative.getDocumentName(), aSuggestion.getDocumentName()); Validate.isTrue(representative.getLayerId() == aSuggestion.getLayerId(), "All suggestions in a group must be on the same layer: expected [%d] but got [%d]", feature = aSuggestion.getFeature(); layerId = aSuggestion.getLayerId(); documentName = aSuggestion.getDocumentName();
private void actionJumpToSuggestion(AjaxRequestTarget aTarget) throws IOException { ActiveLearningUserState alState = alStateModel.getObject(); AnnotationSuggestion suggestion = alState.getSuggestion().get(); if (LOG.isDebugEnabled()) { LOG.debug("Active suggestion: {}", suggestion); Optional<AnnotationSuggestion> updatedSuggestion = getMatchingSuggestion( activeLearningService.getSuggestions(getModelObject().getUser(), alState.getLayer()), suggestion).stream().findFirst(); updatedSuggestion.ifPresent(s -> LOG.debug("Update suggestion: {}", s)); } actionShowSelectedDocument(aTarget, documentService.getSourceDocument(this.getModelObject().getProject(), suggestion.getDocumentName()), suggestion.getBegin(), suggestion.getEnd()); setHighlight(suggestion); }
private List<AnnotationSuggestion> getMatchingSuggestion(List<SuggestionGroup> aSuggestions, AnnotationSuggestion aSuggestion) { return getMatchingSuggestion(aSuggestions, aSuggestion.getDocumentName(), aSuggestion.getLayerId(), aSuggestion.getFeature(), aSuggestion.getBegin(), aSuggestion.getEnd(), aSuggestion.getLabel()); }
private List<AnnotationSuggestion> getMatchingSuggestion(List<SuggestionGroup> aSuggestions, AnnotationSuggestion aSuggestion) { return getMatchingSuggestion(aSuggestions, aSuggestion.getDocumentName(), aSuggestion.getLayerId(), aSuggestion.getFeature(), aSuggestion.getBegin(), aSuggestion.getEnd(), aSuggestion.getLabel()); }
@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; }
.filter(r -> r.getSourceDocument().getName().equals(s.getDocumentName()) && r.getOffsetCharacterBegin() == s.getBegin() && r.getOffsetCharacterEnd() == s.getEnd()
.filter(r -> r.getSourceDocument().getName().equals(s.getDocumentName()) && r.getOffsetCharacterBegin() == s.getBegin() && r.getOffsetCharacterEnd() == s.getEnd()
private void writeLearningRecordInDatabaseAndEventLog(AnnotationSuggestion aSuggestion, LearningRecordType aUserAction, String aAnnotationValue) { AnnotatorState state = ActiveLearningSidebar.this.getModelObject(); ActiveLearningUserState alState = alStateModel.getObject(); AnnotationFeature feat = annotationService.getFeature(aSuggestion.getFeature(), alState.getLayer()); SourceDocument sourceDoc = documentService.getSourceDocument(state.getProject(), aSuggestion.getDocumentName()); // Log the action to the learning record learningRecordService.logRecord(sourceDoc, state.getUser().getUsername(), aSuggestion, aAnnotationValue, alState.getLayer(), feat, aUserAction, LearningRecordChangeLocation.AL_SIDEBAR); // Send an application event that the suggestion has been rejected List<AnnotationSuggestion> alternativeSuggestions = recommendationService .getPredictions(state.getUser(), state.getProject()) .getPredictionsByTokenAndFeature(aSuggestion.getDocumentName(), alState.getLayer(), aSuggestion.getBegin(), aSuggestion.getEnd(), aSuggestion.getFeature()); applicationEventPublisherHolder.get() .publishEvent(new ActiveLearningRecommendationEvent(this, sourceDoc, aSuggestion, state.getUser().getUsername(), alState.getLayer(), aSuggestion.getFeature(), aUserAction, alternativeSuggestions)); }
private void writeLearningRecordInDatabaseAndEventLog(AnnotationSuggestion aSuggestion, LearningRecordType aUserAction, String aAnnotationValue) { AnnotatorState state = ActiveLearningSidebar.this.getModelObject(); ActiveLearningUserState alState = alStateModel.getObject(); AnnotationFeature feat = annotationService.getFeature(aSuggestion.getFeature(), alState.getLayer()); SourceDocument sourceDoc = documentService.getSourceDocument(state.getProject(), aSuggestion.getDocumentName()); // Log the action to the learning record learningRecordService.logRecord(sourceDoc, state.getUser().getUsername(), aSuggestion, aAnnotationValue, alState.getLayer(), feat, aUserAction, LearningRecordChangeLocation.AL_SIDEBAR); // Send an application event that the suggestion has been rejected List<AnnotationSuggestion> alternativeSuggestions = recommendationService .getPredictions(state.getUser(), state.getProject()) .getPredictionsByTokenAndFeature(aSuggestion.getDocumentName(), alState.getLayer(), aSuggestion.getBegin(), aSuggestion.getEnd(), aSuggestion.getFeature()); applicationEventPublisherHolder.get() .publishEvent(new ActiveLearningRecommendationEvent(this, sourceDoc, aSuggestion, state.getUser().getUsername(), alState.getLayer(), aSuggestion.getFeature(), aUserAction, alternativeSuggestions)); }
eventState.getSelectedAnnotationLayer(), rejectedRecommendation.getFeature(), REJECTED, model.getPredictionsByTokenAndFeature( rejectedRecommendation.getDocumentName(), eventState.getSelectedAnnotationLayer(), rejectedRecommendation.getBegin(),