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(); } }
/** * TODO #176 use the document Id once it it available in the CAS * Returns a list of predictions for a given token that matches the given layer and * the annotation feature in the given document * * @param aDocumentName the given document name * @param aLayer the given layer * @param aBegin the offset character begin * @param aEnd the offset character end * @param aFeature the given annotation feature name * @return */ public List<AnnotationSuggestion> getPredictionsByTokenAndFeature(String aDocumentName, AnnotationLayer aLayer, int aBegin, int aEnd, String aFeature) { return predictions.entrySet().stream() .filter(f -> f.getKey().getDocumentName().equals(aDocumentName)) .filter(f -> f.getKey().getLayerId() == aLayer.getId()) .filter(f -> f.getKey().getOffset().getBeginCharacter() == aBegin) .filter(f -> f.getKey().getOffset().getEndCharacter() == aEnd) .filter(f -> f.getValue().getFeature().equals(aFeature)) .map(Map.Entry::getValue) .collect(Collectors.toList()); } }
public GroupKey(AnnotationSuggestion aSuggestion) { super(); begin = aSuggestion.getBegin(); end = aSuggestion.getEnd(); feature = aSuggestion.getFeature(); layerId = aSuggestion.getLayerId(); }
"All suggestions in a group must be on the same layer: expected [%d] but got [%d]", representative.getLayerId(), aSuggestion.getLayerId()); Validate.isTrue(representative.getFeature().equals(aSuggestion.getFeature()), "All suggestions in a group must be for the same feature: expected [%s] but got [%s]", representative.getFeature(), aSuggestion.getFeature()); feature = aSuggestion.getFeature(); layerId = aSuggestion.getLayerId(); documentName = aSuggestion.getDocumentName();
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 String formatLabel(AnnotationSuggestion aCurrentRecommendation) { AnnotationFeature feat = annotationService.getFeature(aCurrentRecommendation.getFeature(), alStateModel.getObject().getLayer()); FeatureSupport<?> featureSupport = featureSupportRegistry.getFeatureSupport(feat); String labelValue = featureSupport.renderFeatureValue(feat, aCurrentRecommendation.getLabel()); return labelValue; }
private String formatLabel(AnnotationSuggestion aCurrentRecommendation) { AnnotationFeature feat = annotationService.getFeature(aCurrentRecommendation.getFeature(), alStateModel.getObject().getLayer()); FeatureSupport<?> featureSupport = featureSupportRegistry.getFeatureSupport(feat); String labelValue = featureSupport.renderFeatureValue(feat, aCurrentRecommendation.getLabel()); return labelValue; }
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; }
AnnotationFeature feat = annotationService.getFeature(aCurrentRecommendation.getFeature(), alState.getLayer()); FeatureSupport<?> featureSupport = featureSupportRegistry.getFeatureSupport(feat); aCurrentRecommendation.getDocumentName(), alState.getLayer(), aCurrentRecommendation.getBegin(), aCurrentRecommendation.getEnd(), aCurrentRecommendation.getFeature());
AnnotationFeature feat = annotationService.getFeature(aCurrentRecommendation.getFeature(), alState.getLayer()); FeatureSupport<?> featureSupport = featureSupportRegistry.getFeatureSupport(feat); aCurrentRecommendation.getDocumentName(), alState.getLayer(), aCurrentRecommendation.getBegin(), aCurrentRecommendation.getEnd(), aCurrentRecommendation.getFeature());
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)); }
/** * Listens to the user setting a feature on an annotation in the main annotation editor. Mind * that we do not need to listen to the creation of annotations since they have no effect on * the active learning sidebar as long as they have no features set. */ @OnEvent public void onFeatureValueUpdated(FeatureValueUpdatedEvent aEvent) { AnnotatorState state = getModelObject(); ActiveLearningUserState alState = alStateModel.getObject(); // If the user creates a new annotation at the site of the suggestion that is currently // offered to the user, then the AL should move on to the next available suggestion if ( alState.isSessionActive() && (!alState.getSuggestion().isPresent() || ( aEvent.getUser().equals(state.getUser().getUsername()) && aEvent.getDocument().equals(state.getDocument()) && aEvent.getFeature().getLayer().equals(alState.getLayer()) && aEvent.getFeature().getName().equals(alState.getSuggestion().get().getFeature()))) ) { reactToAnnotationsBeingCreatedOrDeleted(aEvent.getRequestTarget(), aEvent.getFeature().getLayer()); } }
new ActiveLearningRecommendationEvent(this, eventState.getDocument(), acceptedSuggestion, state.getUser().getUsername(), eventState.getSelectedAnnotationLayer(), acceptedSuggestion.getFeature(), ACCEPTED, model.getPredictionsByTokenAndFeature( acceptedSuggestion.getDocumentName(), acceptedSuggestion.getBegin(), acceptedSuggestion.getEnd(), acceptedSuggestion.getFeature()))); acceptedSuggestion.getOffset().equals(suggestion.getOffset()) && vid.getLayerId() == suggestion.getLayerId() && acceptedSuggestion.getFeature().equals(suggestion.getFeature()) ) { moveToNextRecommendation(aEvent.getTarget(), false);
/** * Listens to the user setting a feature on an annotation in the main annotation editor. Mind * that we do not need to listen to the creation of annotations since they have no effect on * the active learning sidebar as long as they have no features set. */ @OnEvent public void onFeatureValueUpdated(FeatureValueUpdatedEvent aEvent) { AnnotatorState state = getModelObject(); ActiveLearningUserState alState = alStateModel.getObject(); // If the user creates a new annotation at the site of the suggestion that is currently // offered to the user, then the AL should move on to the next available suggestion if ( alState.isSessionActive() && (!alState.getSuggestion().isPresent() || ( aEvent.getUser().equals(state.getUser().getUsername()) && aEvent.getDocument().equals(state.getDocument()) && aEvent.getFeature().getLayer().equals(alState.getLayer()) && aEvent.getFeature().getName().equals(alState.getSuggestion().get().getFeature()))) ) { reactToAnnotationsBeingCreatedOrDeleted(aEvent.getRequestTarget(), aEvent.getFeature().getLayer()); } }
new ActiveLearningRecommendationEvent(this, eventState.getDocument(), rejectedRecommendation, annotatorState.getUser().getUsername(), eventState.getSelectedAnnotationLayer(), rejectedRecommendation.getFeature(), REJECTED, model.getPredictionsByTokenAndFeature( rejectedRecommendation.getDocumentName(), rejectedRecommendation.getBegin(), rejectedRecommendation.getEnd(), rejectedRecommendation.getFeature())));
new ActiveLearningRecommendationEvent(this, eventState.getDocument(), rejectedRecommendation, annotatorState.getUser().getUsername(), eventState.getSelectedAnnotationLayer(), rejectedRecommendation.getFeature(), REJECTED, model.getPredictionsByTokenAndFeature( rejectedRecommendation.getDocumentName(), rejectedRecommendation.getBegin(), rejectedRecommendation.getEnd(), rejectedRecommendation.getFeature())));
AnnotationFeature feature = annotationService.getFeature(suggestion.getFeature(), layer); int address = recommendationService.upsertFeature(annotationService, aState.getDocument(), aState.getUser().getUsername(), aJCas, layer, feature, suggestion.getLabel(),