From 6db8d1fa140e62602d8b41dba708fb9be94c5420 Mon Sep 17 00:00:00 2001 From: Richard Eckart de Castilho Date: Thu, 7 Dec 2023 20:56:22 +0100 Subject: [PATCH] #2696 - Document-level recommendations - Added extraction code for document-level suggestions --- .../service/SuggestionExtraction.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/service/SuggestionExtraction.java b/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/service/SuggestionExtraction.java index 2dadc39f17c..85c14af2d3e 100644 --- a/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/service/SuggestionExtraction.java +++ b/inception/inception-recommendation/src/main/java/de/tudarmstadt/ukp/inception/recommendation/service/SuggestionExtraction.java @@ -55,12 +55,14 @@ import de.tudarmstadt.ukp.inception.annotation.layer.span.SpanLayerSupport; 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.MetadataSuggestion; import de.tudarmstadt.ukp.inception.recommendation.api.model.Offset; import de.tudarmstadt.ukp.inception.recommendation.api.model.Recommender; import de.tudarmstadt.ukp.inception.recommendation.api.model.RelationPosition; import de.tudarmstadt.ukp.inception.recommendation.api.model.RelationSuggestion; import de.tudarmstadt.ukp.inception.recommendation.api.model.SpanSuggestion; import de.tudarmstadt.ukp.inception.schema.api.adapter.AnnotationComparisonUtils; +import de.tudarmstadt.ukp.inception.ui.core.docanno.layer.DocumentMetadataLayerSupport; public class SuggestionExtraction { @@ -152,6 +154,29 @@ private static String[] getPredictedLabels(FeatureStructure predictedFS, return new String[] { predictedFS.getFeatureValueAsString(predictedFeature) }; } + private static void extractDocumentMetadataSuggestion(ExtractionContext ctx, TOP predictedFS) + { + var autoAcceptMode = getAutoAcceptMode(predictedFS, ctx.modeFeature); + var labels = getPredictedLabels(predictedFS, ctx.labelFeature, ctx.isMultiLabels); + var score = predictedFS.getDoubleValue(ctx.scoreFeature); + var scoreExplanation = predictedFS.getStringValue(ctx.scoreExplanationFeature); + + for (var label : labels) { + var suggestion = MetadataSuggestion.builder() // + .withId(MetadataSuggestion.NEW_ID) // + .withGeneration(ctx.generation) // + .withRecommender(ctx.recommender) // + .withDocumentName(ctx.document.getName()) // + .withLabel(label) // + .withUiLabel(label) // + .withScore(score) // + .withScoreExplanation(scoreExplanation) // + .withAutoAcceptMode(autoAcceptMode) // + .build(); + ctx.result.add(suggestion); + } + } + static void extractRelationSuggestion(ExtractionContext ctx, TOP predictedFS) { var autoAcceptMode = getAutoAcceptMode(predictedFS, ctx.modeFeature); @@ -246,6 +271,10 @@ static List extractSuggestions(int aGeneration, CAS aOrigi extractRelationSuggestion(ctx, predictedFS); break; } + case DocumentMetadataLayerSupport.TYPE: { + extractDocumentMetadataSuggestion(ctx, predictedFS); + break; + } default: throw new IllegalStateException( "Unsupported layer type [" + ctx.layer.getType() + "]");