diff --git a/inception/inception-layer-docmetadata/src/main/java/de/tudarmstadt/ukp/inception/ui/core/docanno/recommendation/MetadataSuggestionSupport.java b/inception/inception-layer-docmetadata/src/main/java/de/tudarmstadt/ukp/inception/ui/core/docanno/recommendation/MetadataSuggestionSupport.java index 5b7e3c490dd..da8bfc176c1 100644 --- a/inception/inception-layer-docmetadata/src/main/java/de/tudarmstadt/ukp/inception/ui/core/docanno/recommendation/MetadataSuggestionSupport.java +++ b/inception/inception-layer-docmetadata/src/main/java/de/tudarmstadt/ukp/inception/ui/core/docanno/recommendation/MetadataSuggestionSupport.java @@ -19,8 +19,6 @@ import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_ALL; import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_OVERLAP; -import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_TRANSIENT_REJECTED; -import static de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordUserAction.REJECTED; import java.lang.invoke.MethodHandles; import java.util.ArrayList; @@ -29,7 +27,6 @@ import java.util.Objects; import java.util.Optional; -import org.apache.commons.lang3.NotImplementedException; import org.apache.uima.cas.AnnotationBaseFS; import org.apache.uima.cas.CAS; import org.apache.uima.cas.Feature; @@ -45,7 +42,6 @@ import de.tudarmstadt.ukp.inception.recommendation.api.RecommendationService; import de.tudarmstadt.ukp.inception.recommendation.api.SuggestionRenderer; import de.tudarmstadt.ukp.inception.recommendation.api.SuggestionSupport_ImplBase; -import de.tudarmstadt.ukp.inception.recommendation.api.event.RecommendationRejectedEvent; import de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion; import de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecord; import de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordChangeLocation; @@ -135,37 +131,6 @@ else if (candidates.isEmpty() || !aAdapter.getTraits(DocumentMetadataLayerTraits return annotation; } - @Override - public void rejectSuggestion(String aSessionOwner, SourceDocument aDocument, String aDataOwner, - AnnotationSuggestion aSuggestion, LearningRecordChangeLocation aAction) - throws AnnotationException - { - var suggestion = (MetadataSuggestion) aSuggestion; - - // Hide the suggestion. This is faster than having to recalculate the visibility status - // for the entire document or even for the part visible on screen. - suggestion.hide(FLAG_TRANSIENT_REJECTED); - - var recommender = recommendationService.getRecommender(suggestion); - var feature = recommender.getFeature(); - // Log the action to the learning record - var record = toLearningRecord(aDocument, aDataOwner, aSuggestion, feature, REJECTED, - aAction); - learningRecordService.logRecord(aSessionOwner, aDocument, record); - - // Send an application event that the suggestion has been rejected - applicationEventPublisher.publishEvent(new RecommendationRejectedEvent(this, aDocument, - aDataOwner, feature, suggestion.getLabel())); - } - - @Override - public void skipSuggestion(String aSessionOwner, SourceDocument aDocument, String aDataOwner, - AnnotationSuggestion aSuggestion, LearningRecordChangeLocation aAction) - throws AnnotationException - { - throw new NotImplementedException("Not yet implemented"); - } - @Override public void calculateSuggestionVisibility(String aSessionOwner, SourceDocument aDocument, CAS aCas, String aDataOwner, AnnotationLayer aLayer, diff --git a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/SuggestionSupport.java b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/SuggestionSupport.java index 26aa7ed1e34..f6b4bbe6661 100644 --- a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/SuggestionSupport.java +++ b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/SuggestionSupport.java @@ -86,7 +86,7 @@ AnnotationBaseFS acceptSuggestion(String aSessionOwner, SourceDocument aDocument * if there was a problem rejecting the annotation. */ void rejectSuggestion(String aSessionOwner, SourceDocument aDocument, String aDataOwner, - AnnotationSuggestion aSuggestion, LearningRecordChangeLocation aAction) + AnnotationSuggestion aSuggestion, LearningRecordChangeLocation aLocation) throws AnnotationException; /** diff --git a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/SuggestionSupport_ImplBase.java b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/SuggestionSupport_ImplBase.java index f5899453d57..e2d15fa3480 100644 --- a/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/SuggestionSupport_ImplBase.java +++ b/inception/inception-recommendation-api/src/main/java/de/tudarmstadt/ukp/inception/recommendation/api/SuggestionSupport_ImplBase.java @@ -17,9 +17,13 @@ */ package de.tudarmstadt.ukp.inception.recommendation.api; +import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_SKIPPED; import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_TRANSIENT_ACCEPTED; import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_TRANSIENT_CORRECTED; +import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_TRANSIENT_REJECTED; import static de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordUserAction.ACCEPTED; +import static de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordUserAction.REJECTED; +import static de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordUserAction.SKIPPED; import org.apache.uima.cas.AnnotationBaseFS; import org.apache.uima.cas.CAS; @@ -32,10 +36,12 @@ import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature; import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument; import de.tudarmstadt.ukp.inception.recommendation.api.event.RecommendationAcceptedEvent; +import de.tudarmstadt.ukp.inception.recommendation.api.event.RecommendationRejectedEvent; import de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion; import de.tudarmstadt.ukp.inception.recommendation.api.model.AutoAcceptMode; import de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordChangeLocation; import de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordUserAction; +import de.tudarmstadt.ukp.inception.recommendation.api.model.SpanSuggestion; import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService; import de.tudarmstadt.ukp.inception.schema.api.adapter.AnnotationException; import de.tudarmstadt.ukp.inception.schema.api.adapter.TypeAdapter; @@ -125,4 +131,46 @@ public static String[] getPredictedLabels(FeatureStructure predictedFS, return new String[] { predictedFS.getFeatureValueAsString(predictedFeature) }; } + + @Override + public void rejectSuggestion(String aSessionOwner, SourceDocument aDocument, String aDataOwner, + AnnotationSuggestion aSuggestion, LearningRecordChangeLocation aLocation) + throws AnnotationException + { + var suggestion = (SpanSuggestion) aSuggestion; + + // Hide the suggestion. This is faster than having to recalculate the visibility status + // for the entire document or even for the part visible on screen. + suggestion.hide(FLAG_TRANSIENT_REJECTED); + + var recommender = recommendationService.getRecommender(suggestion); + var feature = recommender.getFeature(); + // Log the action to the learning record + var record = toLearningRecord(aDocument, aDataOwner, aSuggestion, feature, REJECTED, + aLocation); + learningRecordService.logRecord(aSessionOwner, record); + + // Send an application event that the suggestion has been rejected + applicationEventPublisher.publishEvent(new RecommendationRejectedEvent(this, aDocument, + aDataOwner, suggestion.getBegin(), suggestion.getEnd(), suggestion.getCoveredText(), + feature, suggestion.getLabel())); + } + + @Override + public void skipSuggestion(String aSessionOwner, SourceDocument aDocument, String aDataOwner, + AnnotationSuggestion aSuggestion, LearningRecordChangeLocation aLocation) + throws AnnotationException + { + // Hide the suggestion. This is faster than having to recalculate the visibility status + // for the entire document or even for the part visible on screen. + aSuggestion.hide(FLAG_SKIPPED); + + var recommender = recommendationService.getRecommender(aSuggestion); + var feature = recommender.getFeature(); + + // Log the action to the learning record + var record = toLearningRecord(aDocument, aDataOwner, aSuggestion, feature, SKIPPED, + aLocation); + learningRecordService.logRecord(aSessionOwner, record); + } } diff --git a/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/relation/RelationSuggestionSupport.java b/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/relation/RelationSuggestionSupport.java index 23abea7b499..1bad84ab702 100644 --- a/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/relation/RelationSuggestionSupport.java +++ b/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/relation/RelationSuggestionSupport.java @@ -18,8 +18,6 @@ package de.tudarmstadt.ukp.inception.recommendation.relation; import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_OVERLAP; -import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_SKIPPED; -import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_TRANSIENT_REJECTED; import static de.tudarmstadt.ukp.inception.support.WebAnnoConst.FEAT_REL_SOURCE; import static de.tudarmstadt.ukp.inception.support.WebAnnoConst.FEAT_REL_TARGET; import static java.util.stream.Collectors.toList; @@ -206,33 +204,6 @@ else if (candidates.size() > 1) { return annotation; } - @Override - public void rejectSuggestion(String aSessionOwner, SourceDocument aDocument, String aDataOwner, - AnnotationSuggestion aSuggestion, LearningRecordChangeLocation aAction) - { - // Hide the suggestion. This is faster than having to recalculate the visibility status - // for - // the entire document or even for the part visible on screen. - aSuggestion.hide(FLAG_TRANSIENT_REJECTED); - - // TODO: See span recommendation support... - - } - - @Override - public void skipSuggestion(String aSessionOwner, SourceDocument aDocument, String aDataOwner, - AnnotationSuggestion aSuggestion, LearningRecordChangeLocation aAction) - throws AnnotationException - { - // Hide the suggestion. This is faster than having to recalculate the visibility status - // for - // the entire document or even for the part visible on screen. - aSuggestion.hide(FLAG_SKIPPED); - - // TODO: Log rejection - // TODO: Publish rejection event - } - @Override public void calculateSuggestionVisibility(String aSessionOwner, SourceDocument aDocument, CAS aCas, String aUser, AnnotationLayer aLayer, diff --git a/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/span/SpanSuggestionSupport.java b/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/span/SpanSuggestionSupport.java index 5b63143ed69..c0ffb1fb3ac 100644 --- a/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/span/SpanSuggestionSupport.java +++ b/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/span/SpanSuggestionSupport.java @@ -18,10 +18,6 @@ package de.tudarmstadt.ukp.inception.recommendation.span; import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_OVERLAP; -import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_SKIPPED; -import static de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion.FLAG_TRANSIENT_REJECTED; -import static de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordUserAction.REJECTED; -import static de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordUserAction.SKIPPED; import static java.lang.Math.max; import static java.lang.Math.min; import static java.util.Comparator.comparingInt; @@ -67,7 +63,6 @@ import de.tudarmstadt.ukp.inception.recommendation.api.RecommendationService; import de.tudarmstadt.ukp.inception.recommendation.api.SuggestionRenderer; import de.tudarmstadt.ukp.inception.recommendation.api.SuggestionSupport_ImplBase; -import de.tudarmstadt.ukp.inception.recommendation.api.event.RecommendationRejectedEvent; import de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion; import de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecord; import de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordChangeLocation; @@ -174,48 +169,6 @@ else if (candidates.isEmpty() || aAdapter.getLayer().isAllowStacking()) { return annotation; } - @Override - public void rejectSuggestion(String aSessionOwner, SourceDocument aDocument, String aDataOwner, - AnnotationSuggestion aSuggestion, LearningRecordChangeLocation aLocation) - { - var suggestion = (SpanSuggestion) aSuggestion; - - // Hide the suggestion. This is faster than having to recalculate the visibility status - // for the entire document or even for the part visible on screen. - suggestion.hide(FLAG_TRANSIENT_REJECTED); - - var recommender = recommendationService.getRecommender(suggestion); - var feature = recommender.getFeature(); - // Log the action to the learning record - var record = toLearningRecord(aDocument, aDataOwner, aSuggestion, feature, REJECTED, - aLocation); - learningRecordService.logRecord(aSessionOwner, record); - - // Send an application event that the suggestion has been rejected - applicationEventPublisher.publishEvent(new RecommendationRejectedEvent(this, aDocument, - aDataOwner, suggestion.getBegin(), suggestion.getEnd(), suggestion.getCoveredText(), - feature, suggestion.getLabel())); - - } - - @Override - public void skipSuggestion(String aSessionOwner, SourceDocument aDocument, String aDataOwner, - AnnotationSuggestion aSuggestion, LearningRecordChangeLocation aLocation) - throws AnnotationException - { - // Hide the suggestion. This is faster than having to recalculate the visibility status - // for the entire document or even for the part visible on screen. - aSuggestion.hide(FLAG_SKIPPED); - - var recommender = recommendationService.getRecommender(aSuggestion); - var feature = recommender.getFeature(); - - // Log the action to the learning record - var record = toLearningRecord(aDocument, aDataOwner, aSuggestion, feature, SKIPPED, - aLocation); - learningRecordService.logRecord(aSessionOwner, record); - } - @Override public void calculateSuggestionVisibility(String aSessionOwner, SourceDocument aDocument, CAS aCas, String aDataOwner, AnnotationLayer aLayer,