Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4140 - Simplify lazy detail lookup #4141

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.apache.wicket.util.string.StringValueConversionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.wicketstuff.urlfragment.UrlFragment;
import org.wicketstuff.urlfragment.UrlParametersReceivingBehavior;

Expand Down Expand Up @@ -423,7 +422,7 @@ public void actionValidateDocument(AjaxRequestTarget aTarget, CAS aCas)
* is refreshed based on the visibility preferences and based on the project to which the
* document being edited belongs.
*/
protected void loadPreferences() throws BeansException, IOException
protected void loadPreferences() throws IOException
{
AnnotatorState state = getModelObject();
userPreferenceService.loadPreferences(state, userRepository.getCurrentUsername());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import java.io.IOException;

import org.springframework.beans.BeansException;

import de.tudarmstadt.ukp.clarin.webanno.model.Mode;
import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotationPreference;
Expand All @@ -36,14 +34,10 @@ public interface UserPreferencesService
* The {@link AnnotatorState} that will be populated with preferences from the file
* @param aUsername
* The user for whom we need to read the preference (preferences are stored per user)
*
* @throws BeansException
* hum?
* @throws IOException
* hum?
*/
void loadPreferences(AnnotatorState aState, String aUsername)
throws BeansException, IOException;
void loadPreferences(AnnotatorState aState, String aUsername) throws IOException;

AnnotationPreference loadPreferences(Project aProject, String aUsername, Mode aMode)
throws IOException;
Expand Down
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
Loading