Skip to content

Commit

Permalink
#4139 - Reusable popover component for annotation editors
Browse files Browse the repository at this point in the history
- Send sentence VID to brat
- Use the new popover also for the sentence IDs in the brat editor
- Clean up listeners in popover component
- Add loading indicator to popover component
  • Loading branch information
reckart committed Oct 23, 2023
1 parent 003250e commit 474871c
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence;
import de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotatorState;
import de.tudarmstadt.ukp.inception.rendering.paging.Unit;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VID;

public class SentenceOrientedPagingStrategy
extends PagingStrategy_ImplBase
Expand Down Expand Up @@ -78,7 +79,8 @@ private Unit toUnit(int aIndex, AnnotationFS aSentence)
catch (IllegalArgumentException e) {
// Ignore if there is no "id" feature on the sentence
}
return new Unit(sentId, aIndex, aSentence.getBegin(), aSentence.getEnd());
return new Unit(VID.of(aSentence), sentId, aIndex, aSentence.getBegin(),
aSentence.getEnd());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import de.tudarmstadt.ukp.inception.rendering.vmodel.VID;

public class Unit
implements Serializable
{
Expand All @@ -32,6 +34,7 @@ public class Unit
private final int index;
private final int begin;
private final int end;
private final VID vid;
private final String id;

/**
Expand All @@ -44,7 +47,7 @@ public class Unit
*/
public Unit(int aIndex, int aBegin, int aEnd)
{
this(null, aIndex, aBegin, aEnd);
this(null, null, aIndex, aBegin, aEnd);
}

/**
Expand All @@ -58,8 +61,9 @@ public Unit(int aIndex, int aBegin, int aEnd)
* @param aEnd
* end character offset
*/
public Unit(@Nullable String aId, int aIndex, int aBegin, int aEnd)
public Unit(@Nullable VID aVid, @Nullable String aId, int aIndex, int aBegin, int aEnd)
{
vid = aVid;
id = aId;
index = aIndex;
begin = aBegin;
Expand Down Expand Up @@ -87,6 +91,11 @@ public String getId()
return id;
}

public VID getVid()
{
return vid;
}

@Override
public String toString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ private void renderComments(GetDocumentResponse aResponse, VDocument aVDoc,
}

int index = sentenceIndexes.get(fs);
aResponse.addComment(new SentenceComment(index, type, vcomment.getComment()));
aResponse.addComment(
new SentenceComment(VID.of(fs), index, type, vcomment.getComment()));
}
else {
aResponse.addComment(
Expand Down Expand Up @@ -312,8 +313,8 @@ private void renderBratRowsFromUnits(GetDocumentResponse aResponse, RenderReques
// If there is a sentence ID, then make it accessible to the user via a sentence-level
// comment.
if (isNotBlank(unit.getId())) {
aResponse.addComment(new SentenceComment(unitNum, Comment.ANNOTATOR_NOTES,
String.format("Sentence ID: %s", unit.getId())));
aResponse.addComment(new SentenceComment(unit.getVid(), unitNum,
Comment.ANNOTATOR_NOTES, String.format("Sentence ID: %s", unit.getId())));
}

unitNum++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import de.tudarmstadt.ukp.inception.rendering.vmodel.VID;
import de.tudarmstadt.ukp.inception.support.json.BeanAsArraySerializer;

/**
Expand All @@ -39,13 +40,23 @@ public SentenceComment()
// Nothing to do
}

public SentenceComment(int aSentenceIndex, String aCommentType, String aComment)
public SentenceComment(VID aVid, int aSentenceIndex, String aCommentType, String aComment)
{
anchor = new Object[] { "sent", aSentenceIndex };
anchor = new Object[] { "sent", aSentenceIndex, aVid };
commentType = aCommentType;
comment = aComment;
}

public int getVid()
{
return (int) anchor[0];
}

public void getVid(VID aVid)
{
anchor[2] = aVid;
}

public int getSentenceIndex()
{
return (int) anchor[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type AnnotationCommentDto = [
]

export type SentenceCommentDto = [
anchor: ['sent', number],
anchor: ['sent', number, VID],
commentType: CommentType,
comment: string
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { VID } from "@inception-project/inception-js-api"

/*
* ## INCEpTION ##
* Licensed to the Technische Universität Darmstadt under one
Expand Down Expand Up @@ -38,6 +40,7 @@
* SOFTWARE.
*/
export class Comment {
id: VID = undefined
text: string = undefined
type: string = undefined

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,12 @@ export class Visualizer {
if (comment[0] instanceof Array && comment[0][0] === 'sent') {
// sentence comment
const sent = comment[0][1]
const id = comment[0][2]
let text = comment[2]
if (docData.sentComment[sent]) {
text = docData.sentComment[sent].text + '<br/>' + text
}
docData.sentComment[sent] = { type: comment[1], text }
docData.sentComment[sent] = { id, type: comment[1], text }
continue
}

Expand Down Expand Up @@ -3739,6 +3740,14 @@ export class Visualizer {
if (id) {
const comment = this.data.sentComment[id]
if (comment) {
if (evt.target) {
const fakeSpan = new Span()
fakeSpan.vid = comment.id
fakeSpan.document = { text: this.data.text }
fakeSpan.layer = { id: 0, name: Util.spanDisplayForm(this.entityTypes, comment.type) }
evt.target.dispatchEvent(new AnnotationOverEvent(fakeSpan, evt.originalEvent))
}

this.dispatcher.post('displaySentComment', [evt, comment.text, comment.type])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class VisualizerUI {
.on('dataReady', this, this.rememberData)
// .on('displaySpanComment', this, this.displaySpanComment)
// .on('displayArcComment', this, this.displayArcComment)
.on('displaySentComment', this, this.displaySentComment)
// .on('displaySentComment', this, this.displaySentComment)
.on('hideComment', this, this.hideComment)
.on('resize', this, this.onResize)
.on('spanAndAttributeTypesLoaded', this, this.spanAndAttributeTypesLoaded)
Expand Down
9 changes: 4 additions & 5 deletions inception/inception-diam/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@
<groupId>org.apache.uima</groupId>
<artifactId>uimaj-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimafit-core</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down Expand Up @@ -200,11 +204,6 @@
<version>0.4.0</version>
</dependency>

<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimafit-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,23 @@
import java.util.List;

import org.apache.uima.cas.CAS;
import org.apache.uima.fit.util.FSUtil;
import org.apache.wicket.request.IRequestParameters;
import org.apache.wicket.util.string.StringValue;

import com.nimbusds.oauth2.sdk.util.StringUtils;

import de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasProvider;
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature;
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;
import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument;
import de.tudarmstadt.ukp.clarin.webanno.security.model.User;
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence;
import de.tudarmstadt.ukp.inception.diam.editor.config.DiamAutoConfig;
import de.tudarmstadt.ukp.inception.editor.AnnotationEditorExtensionRegistry;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VID;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetail;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailGroup;
import de.tudarmstadt.ukp.inception.schema.AnnotationSchemaService;
import de.tudarmstadt.ukp.inception.schema.adapter.AnnotationException;
Expand Down Expand Up @@ -82,29 +87,51 @@ public List<LazyDetailGroup> lookupLazyDetails(IRequestParameters request, VID a
}

var cas = aCas.get();
var layer = findLayer(aVid, cas, layerParam, aDocument.getProject());

var detailGroups = new ArrayList<VLazyDetailGroup>();
if (isSentence(cas, aVid)) {
var fs = selectFsByAddr(cas, aVid.getId());
var id = FSUtil.getFeature(fs, Sentence._FeatName_id, String.class);
if (StringUtils.isNotBlank(id)) {
var group = new VLazyDetailGroup();
group.addDetail(new VLazyDetail(Sentence._FeatName_id, id));
detailGroups.add(group);
}
}
else {
var layer = findLayer(aVid, cas, layerParam, aDocument.getProject());

lookupLayerLevelDetails(aVid, cas, windowBeginOffset, windowEndOffset, layer)
.forEach(detailGroups::add);

for (var feature : annotationService.listAnnotationFeature(layer)) {
lookupExtensionLevelDetails(aVid, aDocument, cas, aUser, feature)
lookupLayerLevelDetails(aVid, cas, windowBeginOffset, windowEndOffset, layer)
.forEach(detailGroups::add);

// FIXME: We would like to get feature-level lazy details for the annotation label
// provided by the extension or said otherwise, we want to e.g. get KB details for a
// concept
// feature suggestion... this worked when we used the "query", but now is broken!
lookupFeatureLevelDetail(aVid, cas, feature).forEach(detailGroups::add);
for (var feature : annotationService.listAnnotationFeature(layer)) {
lookupExtensionLevelDetails(aVid, aDocument, cas, aUser, feature)
.forEach(detailGroups::add);

// FIXME: We would like to get feature-level lazy details for the annotation label
// provided by the extension or said otherwise, we want to e.g. get KB details for a
// concept feature suggestion... this worked when we used the "query", but now is
// broken!
lookupFeatureLevelDetail(aVid, cas, feature).forEach(detailGroups::add);
}
}

return detailGroups.stream() //
.map(this::toExternalForm) //
.collect(toList());
}

private boolean isSentence(CAS aCas, VID aVid)
{
if (aVid.isSynthetic()) {
return false;
}

var fs = selectFsByAddr(aCas, aVid.getId());
return Sentence._TypeName.equals(fs.getType().getName());

}

private LazyDetailGroup toExternalForm(VLazyDetailGroup aGroup)
{
var extGroup = new LazyDetailGroup(aGroup.getTitle());
Expand Down
Loading

0 comments on commit 474871c

Please sign in to comment.