Skip to content

Commit

Permalink
#2696 - Document-level recommendations
Browse files Browse the repository at this point in the history
- Added extraction code for document-level suggestions
  • Loading branch information
reckart committed Dec 7, 2023
1 parent 2fc5ec3 commit 57a30a2
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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(RelationSuggestion.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);
Expand Down Expand Up @@ -246,6 +271,10 @@ static List<AnnotationSuggestion> 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() + "]");
Expand Down

0 comments on commit 57a30a2

Please sign in to comment.