Skip to content

Commit

Permalink
#3758 - Display suggestion score in annotation sidebar
Browse files Browse the repository at this point in the history
- Allow passing the score through to the annotation editor frontend in the compact_v2 serialization
- Use that to display the score in the annotation sidebar
  • Loading branch information
reckart committed Jan 28, 2023
1 parent 243b154 commit a884ec9
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public abstract class VObject
private List<VLazyDetailQuery> lazyDetails = new ArrayList<>();
private String color;
private String label;
private double score;
private boolean actionButtons;

public VObject(AnnotationLayer aLayer, VID aVid, Map<String, String> aFeatures)
Expand Down Expand Up @@ -128,4 +129,14 @@ public void setActionButtons(boolean aActionButtons)
{
actionButtons = aActionButtons;
}

public double getScore()
{
return score;
}

public void setScore(double aScore)
{
score = aScore;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@

<!-- svelte-ignore a11y-click-events-have-key-events -->
{#if annotation.vid.toString().startsWith('rec:')}
{#if annotation.score}
<span class="text-muted small">{annotation.score}</span>
{/if}
<div class="btn-group" role="group">
<button type="button" class="btn btn-success py-0 px-1" on:click={handleAccept} title="Accept">
<i class="far fa-check-circle"></i>
Expand Down
4 changes: 4 additions & 0 deletions inception/inception-diam/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
</dependency>

<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,32 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

@JsonInclude(Include.NON_EMPTY)
public class CompactAnnotationAttributes
{
public static final String ATTR_LABEL = "l";
public static final String ATTR_COLOR = "c";
public static final String ATTR_COMMENTS = "cm";
public static final String ATTR_SCORE = "s";

private @JsonProperty(ATTR_LABEL) String labelText;
private @JsonProperty(ATTR_COLOR) String color;
private @JsonProperty(ATTR_COMMENTS) List<CompactComment> comments;
private @JsonProperty(ATTR_SCORE) double score;

@JsonInclude(Include.NON_DEFAULT)
@JsonSerialize(using = ScoreSerializer.class)
public double getScore()
{
return score;
}

public void setScore(double aScore)
{
score = aScore;
}

public void setLabelText(String aLabelText)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ private CompactRelation renderRelation(VArc varc)
CompactRelation carc = new CompactRelation(varc.getLayer(), varc.getVid(),
getArgument(varc.getSource(), varc.getTarget()), varc.getLabelHint(),
varc.getColorHint());
carc.getAttributes().setScore(varc.getScore());
return carc;
}

Expand All @@ -143,6 +144,7 @@ private CompactSpan renderSpan(RenderRequest aRequest, VSpan vspan)
cspan = new CompactSpan(vspan.getLayer(), vspan.getVid(), offsets, vspan.getLabelHint(),
vspan.getColorHint());
}
cspan.getAttributes().setScore(vspan.getScore());
return cspan;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Technische Universität Darmstadt under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The Technische Universität Darmstadt
* licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.tudarmstadt.ukp.inception.diam.model.compactv2;

import java.io.IOException;

import org.apache.commons.math3.util.Precision;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.NumberSerializers.Base;

public class ScoreSerializer
extends Base<Object>
{
private static final long serialVersionUID = -1140076942834412161L;

final static ScoreSerializer instance = new ScoreSerializer();

public ScoreSerializer()
{
super(Double.class, JsonParser.NumberType.DOUBLE, "number");
}

@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
gen.writeNumber(Precision.round((Double) value, 2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void thatSerializationWorks() throws Exception
vdoc.add(span1);
var span2 = new VSpan(spanLayer, new VID(2), new VRange(5, 7), Map.of(), "000000");
span2.setLabelHint("span2");
span2.setScore(10.3123d);
vdoc.add(span2);
var span3 = new VSpan(spanLayer, new VID(3), VRange.clippedRange(vdoc, 0, 100).get(),
Map.of(), "000000");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
} ], [ 1, "2", [ [ 5, 7 ] ], {
"l" : "span2",
"c" : "000000",
"cm" : [ [ "error", "E" ] ]
"cm" : [ [ "error", "E" ] ],
"s" : 10.31
} ], [ 1, "3", [ [ 0, 15 ] ], {
"l" : "span3",
"c" : "000000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export interface Annotation {
*/
label?: string

/**
* Score (optional)
*/
score?: number

/**
* Comments
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class Relation implements Annotation {
vid: VID
color?: string
label?: string
score?: number
comments?: Comment[]
arguments: Array<Argument>
}
1 change: 1 addition & 0 deletions inception/inception-js-api/src/main/ts/src/model/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Span implements Annotation {
offsets: Array<Offsets>
color?: string
label?: string
score?: number
comments?: Comment[]

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ export interface CompactAnnotationAttributes {
/**
* Label (optional)
*/
l: string;
l: string

/**
* Color (optional)
*/
c: string;
c: string

/**
* Comments (optional)
*/
cm: CompactComment[];
cm: CompactComment[]

/**
* Score (optional)
*/
s: number
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function unpackCompactRelation (doc: AnnotatedText, raw: CompactRelation)
cooked.arguments = raw[2].map(arg => unpackCompactArgument(doc, arg))
cooked.color = raw[3]?.c
cooked.label = raw[3]?.l
cooked.score = raw[3]?.s
cooked.comments = unpackCompactComments(doc, cooked, raw[3]?.cm)
return cooked
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function unpackCompactSpan (doc: AnnotatedText, raw: CompactSpan): Span {
cooked.offsets = raw[2]
cooked.color = raw[3]?.c
cooked.label = raw[3]?.l
cooked.score = raw[3]?.s
cooked.clippingFlags = raw[3]?.cl
cooked.comments = unpackCompactComments(doc, cooked, raw[3]?.cm)
return cooked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public void render(VDocument aVDoc, RenderRequest aRequest)

VArc arc = new VArc(layer, suggestion.getVID(), new VID(source), new VID(target),
"\uD83E\uDD16 " + suggestion.getUiLabel(), featureAnnotation, COLOR);
arc.setScore(suggestion.getScore());

List<VLazyDetailQuery> lazyDetails = featureSupport.getLazyDetails(feature,
suggestion.getLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public void render(VDocument vdoc, RenderRequest aRequest)
featureAnnotation.put(ao.getFeature(), annotation);

VSpan v = new VSpan(layer, vid, range.get(), featureAnnotation, COLOR);
v.setScore(ao.getScore());

v.setActionButtons(recommenderProperties.isActionButtonsEnabled());

Expand Down

0 comments on commit a884ec9

Please sign in to comment.