Skip to content

Commit

Permalink
#4140 - Simplify lazy detail lookup
Browse files Browse the repository at this point in the history
- Remove getLazyDetails() methods that produced the queries
- Remove all classes related to the queries
- Make lookupLazyDetails produce all the details on the fly when asked for details for a given VID
  • Loading branch information
reckart committed Aug 5, 2023
1 parent 8bf9746 commit d78e812
Show file tree
Hide file tree
Showing 32 changed files with 275 additions and 681 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature;
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;
import de.tudarmstadt.ukp.inception.rendering.Renderer;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VObject;
import de.tudarmstadt.ukp.inception.schema.adapter.TypeAdapter;
import de.tudarmstadt.ukp.inception.schema.feature.FeatureSupportRegistry;
import de.tudarmstadt.ukp.inception.schema.layer.LayerSupportRegistry;
Expand Down Expand Up @@ -144,12 +143,6 @@ public <T> Optional<T> getTraits(AnnotationLayer aLayer, Class<T> aInterface)
return Optional.empty();
}

public void renderLazyDetails(AnnotationFS fs, VObject aVObject,
List<AnnotationFeature> aFeatures)
{
aVObject.addLazyDetails(getLazyDetails(fs, aFeatures));
}

public abstract List<AnnotationFS> selectAnnotationsInWindow(CAS aCas, int aWindowBegin,
int aWindowEnd);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package de.tudarmstadt.ukp.inception.annotation.feature.multistring;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.uima.cas.CAS.TYPE_NAME_STRING_ARRAY;

Expand Down Expand Up @@ -51,8 +49,6 @@
import de.tudarmstadt.ukp.inception.editor.action.AnnotationActionHandler;
import de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotatorState;
import de.tudarmstadt.ukp.inception.rendering.editorstate.FeatureState;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VID;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailQuery;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailResult;
import de.tudarmstadt.ukp.inception.schema.AnnotationSchemaService;
import de.tudarmstadt.ukp.inception.schema.adapter.IllegalFeatureValueException;
Expand Down Expand Up @@ -236,43 +232,26 @@ public String renderFeatureValue(AnnotationFeature aFeature, FeatureStructure aF
}

@Override
public List<VLazyDetailQuery> getLazyDetails(AnnotationFeature aFeature, FeatureStructure aFs)
public List<VLazyDetailResult> lookupLazyDetails(AnnotationFeature aFeature, Object aValue)
{
Feature labelFeature = aFs.getType().getFeatureByBaseName(aFeature.getName());

if (labelFeature == null) {
return emptyList();
}

List<String> values = getFeatureValue(aFeature, aFs);
if (values == null || values.isEmpty()) {
return emptyList();
}

var details = new ArrayList<VLazyDetailQuery>();
for (String value : values) {
if (isNotBlank(value) && aFeature.getTagset() != null) {
details.add(new VLazyDetailQuery(aFeature.getName(), value));
var results = new ArrayList<VLazyDetailResult>();
if (aValue instanceof Iterable) {
var values = (Iterable<?>) aValue;
for (var v : values) {
if (v instanceof String) {
var value = (String) v;
var tag = schemaService.getTag(value, aFeature.getTagset());

if (tag.isEmpty()) {
results.add(new VLazyDetailResult(value, "Tag not in tagset"));
}

if (tag.map(t -> isNotBlank(t.getDescription())).orElse(false)) {
results.add(new VLazyDetailResult(value, tag.get().getDescription()));
}
}
}
}

return details;
}

@Override
public List<VLazyDetailResult> renderLazyDetails(CAS aCas, AnnotationFeature aFeature,
VID aParamId, String aQuery)
{
var tag = schemaService.getTag(aQuery, aFeature.getTagset());

if (tag.isEmpty()) {
return asList(new VLazyDetailResult(aQuery, "Tag not in tagset"));
}

if (tag.map(t -> isBlank(t.getDescription())).orElse(true)) {
return emptyList();
}

return asList(new VLazyDetailResult(aQuery, tag.get().getDescription()));
return results;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static de.tudarmstadt.ukp.inception.annotation.feature.string.StringFeatureTraits.EditorType.RADIOGROUP;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

import java.io.IOException;
import java.util.Collections;
Expand All @@ -44,8 +44,6 @@
import de.tudarmstadt.ukp.inception.editor.action.AnnotationActionHandler;
import de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotatorState;
import de.tudarmstadt.ukp.inception.rendering.editorstate.FeatureState;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VID;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailQuery;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailResult;
import de.tudarmstadt.ukp.inception.schema.AnnotationSchemaService;
import de.tudarmstadt.ukp.inception.schema.adapter.AnnotationException;
Expand Down Expand Up @@ -232,37 +230,20 @@ public boolean suppressAutoFocus(AnnotationFeature aFeature)
}

@Override
public List<VLazyDetailQuery> getLazyDetails(AnnotationFeature aFeature, String aLabel)
public List<VLazyDetailResult> lookupLazyDetails(AnnotationFeature aFeature, Object aValue)
{
if (isBlank(aLabel) || aFeature.getTagset() == null) {
return emptyList();
}

// Checking here if the tag has a description would be nicer because it would avoid
// rendering an emtpy section for every string feature in the popover... but it also
// induces a database request for every single string feature on every annotation which
// would slow things down quite a bit...
// Tag tag = schemaService.getTag(aLabel, aFeature.getTagset());
// if (tag == null || isBlank(tag.getDescription())) {
// return emptyList();
// }

return asList(new VLazyDetailQuery(aFeature.getName(), aLabel));
}

@Override
public List<VLazyDetailResult> renderLazyDetails(CAS aCas, AnnotationFeature aFeature,
VID aParamId, String aQuery)
{
var tag = schemaService.getTag(aQuery, aFeature.getTagset());
if (tag.isEmpty()) {
return asList(new VLazyDetailResult(aQuery, "Tag not in tagset"));
}
if (aValue instanceof String) {
var value = (String) aValue;
var tag = schemaService.getTag(value, aFeature.getTagset());
if (tag.isEmpty()) {
return asList(new VLazyDetailResult(value, "Tag not in tagset"));
}

if (tag.map(t -> isBlank(t.getDescription())).orElse(true)) {
return emptyList();
if (tag.map(t -> isNotBlank(t.getDescription())).orElse(false)) {
return asList(new VLazyDetailResult(value, tag.get().getDescription()));
}
}

return asList(new VLazyDetailResult(aQuery, tag.get().getDescription()));
return emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ public void render(CAS aCas, List<AnnotationFeature> aFeatures, VDocument aRespo
label);
annoToSpanIdx.put(linkFs, span);
aResponse.add(span);

renderLazyDetails(linkFs, span, aFeatures);
}

// Render arc (we do this on prevLinkFs because then we easily know that the current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import de.tudarmstadt.ukp.inception.rendering.vmodel.VCommentType;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VDocument;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VID;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailQuery;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailResult;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VObject;
import de.tudarmstadt.ukp.inception.schema.feature.FeatureSupportRegistry;
Expand Down Expand Up @@ -134,12 +133,6 @@ public void render(final CAS aCas, List<AnnotationFeature> aFeatures, VDocument

RelationAdapter typeAdapter = getTypeAdapter();

// Map<Integer, Set<Integer>> relationLinks = getRelationLinks(aCas, aWindowBegin,
// aWindowEnd);
//
// // if this is a governor for more than one dependent, avoid duplicate yield
// List<Integer> yieldDeps = new ArrayList<>();

// Index mapping annotations to the corresponding rendered arcs
Map<AnnotationFS, VArc> annoToArcIdx = new HashMap<>();

Expand All @@ -154,9 +147,6 @@ public void render(final CAS aCas, List<AnnotationFeature> aFeatures, VDocument
aResponse.add(arc);
annoToArcIdx.put(fs, (VArc) arc);

// renderYield(aResponse, fs, relationLinks, yieldDeps);

renderLazyDetails(fs, arc, aFeatures);
renderRequiredFeatureErrors(aFeatures, fs, aResponse);
}
}
Expand Down Expand Up @@ -261,28 +251,17 @@ public List<VObject> render(VDocument aVDocument, AnnotationFS aFS,
}

@Override
public List<VLazyDetailQuery> getLazyDetails(AnnotationFS aFs,
List<AnnotationFeature> aFeatures)
public List<VLazyDetailResult> lookupLazyDetails(CAS aCas, VID aVid, int aWindowBeginOffset,
int aWindowEndOffset)
{
List<VLazyDetailQuery> queries = super.getLazyDetails(aFs, aFeatures);

if (!queries.contains(VLazyDetailQuery.LAYER_LEVEL_QUERY)) {
queries.add(VLazyDetailQuery.LAYER_LEVEL_QUERY);
if (!checkTypeSystem(aCas)) {
return Collections.emptyList();
}

return queries;
}

@Override
public List<VLazyDetailResult> renderLazyDetails(CAS aCas, VID aVid, int windowBeginOffset,
int windowEndOffset)
{
checkTypeSystem(aCas);

// FIXME Should also handle relations that are only partially visible using
// selectAnnotationsInWindow()
Map<Integer, Set<Integer>> relationLinks = getRelationLinks(aCas, windowBeginOffset,
windowEndOffset);
Map<Integer, Set<Integer>> relationLinks = getRelationLinks(aCas, aWindowBeginOffset,
aWindowEndOffset);

// if this is a governor for more than one dependent, avoid duplicate yield
List<Integer> yieldDeps = new ArrayList<>();
Expand All @@ -291,8 +270,8 @@ public List<VLazyDetailResult> renderLazyDetails(CAS aCas, VID aVid, int windowB

Optional<String> yield = renderYield(fs, relationLinks, yieldDeps);

List<VLazyDetailResult> details = super.renderLazyDetails(aCas, aVid, windowBeginOffset,
windowEndOffset);
List<VLazyDetailResult> details = super.lookupLazyDetails(aCas, aVid, aWindowBeginOffset,
aWindowEndOffset);

if (yield.isPresent()) {
details.add(new VLazyDetailResult("Yield", yield.get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public void render(CAS aCas, List<AnnotationFeature> aFeatures, VDocument aRespo
if (vobj instanceof VSpan) {
annoToSpanIdx.put(fs, (VSpan) vobj);

renderLazyDetails(fs, vobj, aFeatures);
renderRequiredFeatureErrors(aFeatures, fs, aResponse);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ default void generateContextMenuItems(List<IMenuItem> aItems)
// Do nothing by default
}

default List<VLazyDetailResult> renderLazyDetails(SourceDocument aDocument, User aUser,
VID aVid, AnnotationFeature aFeature, String aQuery)
default List<VLazyDetailResult> lookupLazyDetails(SourceDocument aDocument, User aUser,
VID aVid, AnnotationFeature aFeature)
{
return Collections.emptyList();
}

<V> V getFeatureValue(SourceDocument aDocument, User aUser, CAS aCas, VID aVid,
AnnotationFeature aFeature)
throws IOException;

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
* Result for a lazy detail.
* <p>
* Some information is only to be shown when the user performs a particular "detail information"
* action, e.g. hovering the mouse over an annotation. This class represents the result which is
* returned by the server for a particular detail query.
* action, e.g. hovering the mouse over an annotation.
* </p>
*
* @see VLazyDetailQuery
*/
public class VLazyDetailResult
implements Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
package de.tudarmstadt.ukp.inception.rendering.vmodel;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;
Expand All @@ -35,7 +33,6 @@ public abstract class VObject
private final int equivalenceSet;

private VID vid;
private List<VLazyDetailQuery> lazyDetails = new ArrayList<>();
private String color;
private String label;
private double score;
Expand Down Expand Up @@ -80,26 +77,6 @@ public Map<String, String> getFeatures()
return features;
}

public List<VLazyDetailQuery> getLazyDetails()
{
return lazyDetails;
}

public void setLazyDetails(List<VLazyDetailQuery> aLazyDetails)
{
lazyDetails = aLazyDetails;
}

public void addLazyDetails(List<VLazyDetailQuery> aDetails)
{
lazyDetails.addAll(aDetails);
}

public void addLazyDetail(VLazyDetailQuery aDetail)
{
lazyDetails.add(aDetail);
}

public void setColorHint(String aColor)
{
color = aColor;
Expand Down
Loading

0 comments on commit d78e812

Please sign in to comment.