Skip to content

Commit

Permalink
#5317 - Display correction suggestions
Browse files Browse the repository at this point in the history
- Added "correction" flag to annotation suggestions
  • Loading branch information
reckart committed Mar 4, 2025
1 parent 7812d8c commit e218e77
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public abstract class AnnotationSuggestion
protected final String uiLabel;
protected final double score;
protected final String scoreExplanation;
protected final boolean correction;

private AutoAcceptMode autoAcceptMode;
private int hidingFlags = 0;
Expand All @@ -92,7 +93,7 @@ public abstract class AnnotationSuggestion
public AnnotationSuggestion(int aId, int aGeneration, int aAge, long aRecommenderId,
String aRecommenderName, long aLayerId, String aFeature, String aDocumentName,
String aLabel, String aUiLabel, double aScore, String aScoreExplanation,
AutoAcceptMode aAutoAcceptMode, int aHidingFlags)
AutoAcceptMode aAutoAcceptMode, int aHidingFlags, boolean aCorrection)
{
generation = aGeneration;
age = aAge;
Expand All @@ -108,6 +109,7 @@ public AnnotationSuggestion(int aId, int aGeneration, int aAge, long aRecommende
documentName = aDocumentName;
autoAcceptMode = aAutoAcceptMode != null ? aAutoAcceptMode : AutoAcceptMode.NEVER;
hidingFlags = aHidingFlags;
correction = aCorrection;
}

public int getId()
Expand Down Expand Up @@ -211,6 +213,16 @@ public boolean isVisible()
return hidingFlags == 0;
}

/**
* @return whether the suggestion is a correction suggestion for an existing annotation.
* Corrections should not be hidden for overlap with an existing annotation unless the
* label matches.
*/
public boolean isCorrection()
{
return correction;
}

public AutoAcceptMode getAutoAcceptMode()
{
return autoAcceptMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected ArcSuggestion_ImplBase(Builder<?, P> builder)
super(builder.id, builder.generation, builder.age, builder.recommenderId,
builder.recommenderName, builder.layerId, builder.feature, builder.documentName,
builder.label, builder.uiLabel, builder.score, builder.scoreExplanation,
builder.autoAcceptMode, builder.hidingFlags);
builder.autoAcceptMode, builder.hidingFlags, builder.correction);

this.position = builder.position;
}
Expand Down Expand Up @@ -114,6 +114,7 @@ public static abstract class Builder<T extends Builder<?, ?>, P extends ArcPosit
protected P position;
protected AutoAcceptMode autoAcceptMode;
protected int hidingFlags;
private boolean correction;

protected Builder()
{
Expand Down Expand Up @@ -229,6 +230,12 @@ public T withHidingFlags(int aFlags)
return (T) this;
}

public Builder withCorrection(boolean aCorrection)
{
this.correction = aCorrection;
return (T) this;
}

public abstract ArcSuggestion_ImplBase build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private MetadataSuggestion(Builder builder)
super(builder.id, builder.generation, builder.age, builder.recommenderId,
builder.recommenderName, builder.layerId, builder.feature, builder.documentName,
builder.label, builder.uiLabel, builder.score, builder.scoreExplanation,
builder.autoAcceptMode, builder.hidingFlags);
builder.autoAcceptMode, builder.hidingFlags, builder.correction);
}

@Override
Expand Down Expand Up @@ -99,6 +99,7 @@ public static final class Builder
private String scoreExplanation;
private AutoAcceptMode autoAcceptMode;
private int hidingFlags;
boolean correction;

private Builder()
{
Expand Down Expand Up @@ -208,6 +209,12 @@ public Builder withHidingFlags(int aFlags)
return this;
}

public Builder withCorrection(boolean aCorrection)
{
this.correction = aCorrection;
return this;
}

public MetadataSuggestion build()
{
return new MetadataSuggestion(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private SpanSuggestion(Builder builder)
super(builder.id, builder.generation, builder.age, builder.recommenderId,
builder.recommenderName, builder.layerId, builder.feature, builder.documentName,
builder.label, builder.uiLabel, builder.score, builder.scoreExplanation,
builder.autoAcceptMode, builder.hidingFlags);
builder.autoAcceptMode, builder.hidingFlags, builder.correction);

position = builder.position;
coveredText = builder.coveredText;
Expand Down Expand Up @@ -152,6 +152,7 @@ public static final class Builder
private String coveredText;
private AutoAcceptMode autoAcceptMode = AutoAcceptMode.NEVER;
private int hidingFlags;
private boolean correction;

private Builder()
{
Expand Down Expand Up @@ -279,6 +280,12 @@ public Builder withHidingFlags(int aFlags)
return this;
}

public Builder withCorrection(boolean aCorrection)
{
this.correction = aCorrection;
return this;
}

public SpanSuggestion build()
{
return new SpanSuggestion(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ public <T extends AnnotationSuggestion> void calculateSuggestionVisibility(Strin
// If any annotation at this position has a non-null label for this feature,
// then we hide the suggestion group
for (var annotationFS : groupedAnnotations.get(position)) {
var label = annotationFS.getFeatureValueAsString(feat);
if (annotationFS.getFeatureValueAsString(feat) != null) {
for (var suggestion : group) {
if (suggestion.isCorrection() && !suggestion.labelEquals(label)) {
continue;
}

suggestion.hide(FLAG_OVERLAP);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,23 +296,19 @@ private void hideSpanSuggestionsThatOverlapWithAnnotations(
var pair = oi.next();
var suggestionOffset = pair.getKey();
var annotationOffset = pair.getValue();

// Fetch the current suggestion and annotation
var group = suggestions.get(suggestionOffset);
for (var annotation : annotations.get(annotationOffset)) {
Iterable<Object> labelObjects;
var featureSupport = featureSupportRegistry.findExtension(feature).get();
var wrappedValue = featureSupport.getFeatureValue(feature, annotation);
var value = featureSupport.unwrapFeatureValue(feature, annotation.getCAS(),
wrappedValue);
if (value instanceof Iterable iterableValues) {
labelObjects = iterableValues;
}
else {
labelObjects = asList(value);
}

var labelObjects = value instanceof Iterable values ? values : asList(value);

for (var labelObject : labelObjects) {
var label = labelObject != null ? String.valueOf(labelObject) : null;
var label = Objects.toString(labelObject, null);

for (var suggestion : group) {
// The suggestion would just create an annotation and not set any
Expand Down Expand Up @@ -352,8 +348,10 @@ private void hideSpanSuggestionsThatOverlapWithAnnotations(
// Does the suggested label match the label of an existing annotation
// at the same position then we hide
if (label != null && label.equals(suggestion.getLabel()) && colocated) {
suggestion.hide(FLAG_OVERLAP);
hiddenForOverlap.add(suggestion);
if (!suggestion.isCorrection()) {
suggestion.hide(FLAG_OVERLAP);
hiddenForOverlap.add(suggestion);
}
continue;
}

Expand Down

0 comments on commit e218e77

Please sign in to comment.