Skip to content

Commit

Permalink
Merge branch 'main' into refactoring/4977-Clean-up-Knowledge-Base-UI-…
Browse files Browse the repository at this point in the history
…code

* main: (42 commits)
  #5047 - Clean up layer detail UI a bit
  #4949 - Showing the start and end points of relations in left side bar
  No issue: Minor cleaning up
  #5043 - Ability to specify token breaking zones when calling tokenizer
  [maven-release-plugin] prepare for next development iteration
  [maven-release-plugin] prepare release inception-34.0-beta-6
  #5009 - Better handling of stacked annotations with link features in curation
  #5009 - Better handling of stacked annotations with link features in curation
  [maven-release-plugin] prepare for next development iteration
  [maven-release-plugin] prepare release inception-34.0-beta-6
  [maven-release-plugin] prepare for next development iteration
  [maven-release-plugin] prepare release inception-33.6
  #5040 - Improve feature form tab navigation
  #5037 - Show fraction of annotators that chose a certain label in curation sidebar mode
  #5035 - NBSPs should not be treated as tokens
  #5031 - ChatGPT recommender fails because format is not a supported parameter
  #5029 - Duplicate lines on the about page
  #5027 - Add more CSP configurations
  #4753 - Entity linker should skip already linked concepts
  #5007 - Lazy details on suggestions for multi-value concept features fail rendering
  ...
  • Loading branch information
reckart committed Sep 8, 2024
2 parents 5042880 + ccd189e commit 3eec32b
Show file tree
Hide file tree
Showing 422 changed files with 81,256 additions and 59,473 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

- name: Cache Maven repository
id: maven-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ env.CACHE_DATE }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
import java.util.Optional;

import org.apache.uima.cas.CAS;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.fit.util.CasUtil;
import org.apache.wicket.Component;
Expand Down Expand Up @@ -992,10 +990,11 @@ private void actionSelectHistoryItem(AjaxRequestTarget aTarget, LearningRecord a

private Optional<AnnotationFS> getMatchingAnnotation(CAS aCas, LearningRecord aRecord)
{
Type type = CasUtil.getType(aCas, alStateModel.getObject().getLayer().getName());
Feature feature = type.getFeatureByBaseName(aRecord.getAnnotationFeature().getName());
var type = CasUtil.getType(aCas, alStateModel.getObject().getLayer().getName());
var feature = type.getFeatureByBaseName(aRecord.getAnnotationFeature().getName());
return selectAt(aCas, type, aRecord.getOffsetBegin(), aRecord.getOffsetEnd()).stream()
.filter(fs -> aRecord.getAnnotation().equals(fs.getFeatureValueAsString(feature)))
.filter(fs -> Objects.equals(aRecord.getAnnotation(),
fs.getFeatureValueAsString(feature)))
.findFirst();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,31 @@ public boolean equals(final Object other)
return false;
}
CasKey castOther = (CasKey) other;
return new EqualsBuilder().append(projectId, castOther.projectId)
.append(documentId, castOther.documentId).append(userId, castOther.userId)
return new EqualsBuilder() //
.append(projectId, castOther.projectId) //
.append(documentId, castOther.documentId) //
.append(userId, castOther.userId) //
.isEquals();
}

@Override
public int hashCode()
{
return new HashCodeBuilder().append(projectId).append(documentId).append(userId)
return new HashCodeBuilder() //
.append(projectId) //
.append(documentId) //
.append(userId) //
.toHashCode();
}

@Override
public String toString()
{
return new ToStringBuilder(this, ToStringStyle.NO_CLASS_NAME_STYLE).append("p", projectId)
.append("d", documentId).append("u", userId).toString();
return new ToStringBuilder(this, ToStringStyle.NO_CLASS_NAME_STYLE) //
.append("p", projectId) //
.append("d", documentId) //
.append("u", userId) //
.toString();
}

public static CasKey matchingAllFromProject(Project aProject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ protected void validateRequiredFeatures(AjaxRequestTarget aTarget, CAS aCas,
var constraints = getModelObject().getConstraints();

// Check each feature structure of this layer
var layerType = aAdapter.getAnnotationType(editorCas);
var layerType = aAdapter.getAnnotationType(editorCas).get();
var annotationFsType = editorCas.getAnnotationType();
try (var fses = editorCas.select(layerType)) {
for (var fs : fses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
import org.springframework.core.annotation.Order;

import de.tudarmstadt.ukp.clarin.webanno.api.annotation.config.AnnotationAutoConfiguration;
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;
import de.tudarmstadt.ukp.inception.rendering.pipeline.RenderStep;
import de.tudarmstadt.ukp.inception.rendering.request.RenderRequest;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VDocument;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VObject;

/**
* <p>
Expand All @@ -49,8 +47,8 @@ public String getId()
@Override
public void render(VDocument aVDoc, RenderRequest aRequest)
{
for (AnnotationLayer layer : aVDoc.getAnnotationLayers()) {
for (VObject vobj : aVDoc.objects(layer.getId())) {
for (var layer : aVDoc.getAnnotationLayers()) {
for (var vobj : aVDoc.objects(layer.getId())) {
if (vobj.getLabelHint() != null) {
// Label hint was already set earlier - do not overwrite it!
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
*/
package de.tudarmstadt.ukp.inception.annotation.feature.bool;

import static java.lang.Boolean.FALSE;
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;

import java.util.List;

import org.apache.uima.cas.CAS;
import org.apache.uima.cas.FeatureStructure;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.model.IModel;

Expand Down Expand Up @@ -105,4 +107,11 @@ public String renderFeatureValue(AnnotationFeature aFeature, String aLabel)
return "-" + aFeature.getUiName();
}
}

@SuppressWarnings("unchecked")
@Override
public <V> V getDefaultFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS)
{
return (V) FALSE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

import static de.tudarmstadt.ukp.clarin.webanno.model.LinkMode.WITH_ROLE;
import static de.tudarmstadt.ukp.clarin.webanno.model.MultiValueMode.ARRAY;
import static org.apache.commons.collections4.CollectionUtils.disjunction;
import static org.apache.uima.cas.CAS.TYPE_NAME_FS_ARRAY;
import static org.apache.uima.cas.CAS.TYPE_NAME_STRING;
import static org.apache.uima.cas.CAS.TYPE_NAME_TOP;

import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.apache.commons.text.WordUtils;
Expand Down Expand Up @@ -59,6 +61,7 @@
import de.tudarmstadt.ukp.inception.schema.api.feature.FeatureSupport;
import de.tudarmstadt.ukp.inception.schema.api.feature.FeatureType;
import de.tudarmstadt.ukp.inception.schema.api.feature.LinkWithRoleModel;
import de.tudarmstadt.ukp.inception.schema.api.feature.MaterializedLink;
import de.tudarmstadt.ukp.inception.support.uima.ICasUtil;

/**
Expand Down Expand Up @@ -207,14 +210,16 @@ public void generateFeature(TypeSystemDescription aTSD, TypeDescription aTD,
public List<LinkWithRoleModel> getFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS)
{
var linkFeature = aFS.getType().getFeatureByBaseName(aFeature.getName());

if (linkFeature == null) {
wrapFeatureValue(aFeature, aFS.getCAS(), null);
}

return wrapFeatureValue(aFeature, aFS.getCAS(), aFS.getFeatureValue(linkFeature));
}

@SuppressWarnings("unchecked")
@Override
public <V> V getDefaultFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS)
{
return (V) Collections.emptyList();
}

@Override
public void setFeatureValue(CAS aCas, AnnotationFeature aFeature, int aAddress, Object aValue)
throws AnnotationException
Expand Down Expand Up @@ -309,4 +314,26 @@ public String renderFeatureValue(AnnotationFeature aFeature, String aLabel)
// Never render link feature labels
return null;
}

@Override
public boolean isCopyOnCurationMerge(AnnotationFeature aFeature)
{
// Links count as separate positions and should be merged separately
return false;
}

@Override
public boolean isFeatureValueEqual(AnnotationFeature aFeature, FeatureStructure aFS1,
FeatureStructure aFS2)
{
List<LinkWithRoleModel> links1 = getFeatureValue(aFeature, aFS1);
var matLinks1 = links1.stream()
.map(link -> MaterializedLink.toMaterializedLink(aFS1, aFeature, link)).toList();

List<LinkWithRoleModel> links2 = getFeatureValue(aFeature, aFS2);
var matLinks2 = links2.stream()
.map(link -> MaterializedLink.toMaterializedLink(aFS2, aFeature, link)).toList();

return disjunction(matLinks1, matLinks2).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ public boolean accepts(AnnotationFeature aFeature)
&& CAS.TYPE_NAME_STRING_ARRAY.equals(aFeature.getType());
}

@SuppressWarnings("unchecked")
@Override
public <V> V getDefaultFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS)
{
return (V) Collections.emptyList();
}

@SuppressWarnings("unchecked")
@Override
public List<String> unwrapFeatureValue(AnnotationFeature aFeature, CAS aCAS, Object aValue)
Expand Down Expand Up @@ -307,4 +314,27 @@ public List<VLazyDetailGroup> lookupLazyDetails(AnnotationFeature aFeature, Obje
}
return asList(results);
}

@Override
public <V> V getFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS)
{
Object value;

var f = aFS.getType().getFeatureByBaseName(aFeature.getName());

if (f == null) {
value = null;
}
else if (f.getRange().isPrimitive()) {
value = FSUtil.getFeature(aFS, aFeature.getName(), Object.class);
}
else if (FSUtil.isMultiValuedFeature(aFS, f)) {
value = FSUtil.getFeature(aFS, aFeature.getName(), List.class);
}
else {
value = FSUtil.getFeature(aFS, aFeature.getName(), FeatureStructure.class);
}

return (V) wrapFeatureValue(aFeature, aFS.getCAS(), value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.stream.IntStream;

import org.apache.uima.cas.CAS;
import org.apache.uima.cas.FeatureStructure;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
Expand Down Expand Up @@ -137,4 +138,15 @@ public NumberFeatureTraits createDefaultTraits()
{
return new NumberFeatureTraits();
}

@SuppressWarnings("unchecked")
@Override
public <V> V getDefaultFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS)
{
return switch (aFeature.getType()) {
case CAS.TYPE_NAME_INTEGER -> (V) (Object) 0;
case CAS.TYPE_NAME_FLOAT -> (V) (Object) 0.0f;
default -> throw unsupportedFeatureTypeException(aFeature);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,10 @@ public List<VLazyDetailGroup> lookupLazyDetails(AnnotationFeature aFeature, Obje

return emptyList();
}

@Override
public <V> V getDefaultFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS)
{
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ public final boolean isFeatureValueValid(AnnotationFeature aFeature, FeatureStru
return featureSupport.isFeatureValueValid(aFeature, aFS);
}

@Override
public final boolean isFeatureValueEqual(AnnotationFeature aFeature, FeatureStructure aFS1,
FeatureStructure aFS2)
{
var featureSupport = featureSupportRegistry.findExtension(aFeature).orElseThrow();

return featureSupport.isFeatureValueEqual(aFeature, aFS1, aFS2);
}

@Override
public final void setFeatureValue(SourceDocument aDocument, String aUsername, CAS aCas,
int aAddress, AnnotationFeature aFeature, Object aValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static de.tudarmstadt.ukp.inception.support.uima.WebAnnoCasUtil.isSame;
import static java.lang.System.currentTimeMillis;
import static java.util.Collections.emptyList;
import static org.apache.uima.cas.text.AnnotationPredicates.colocated;

import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
Expand Down Expand Up @@ -566,4 +567,32 @@ public Selection selectLink(AnnotationFS aAnno)
selection.selectArc(new VID(aAnno, 1, VID.NONE, VID.NONE), aAnno, getNextLink(aAnno));
return selection;
}

@Override
public boolean isSamePosition(FeatureStructure aFS1, FeatureStructure aFS2)
{
if (aFS1 == null || aFS2 == null) {
return false;
}

if (!aFS1.getType().getName().equals(getAnnotationTypeName())) {
throw new IllegalArgumentException("Expected [" + getAnnotationTypeName()
+ "] but got [" + aFS1.getType().getName() + "]");
}

if (!aFS2.getType().getName().equals(getAnnotationTypeName())) {
throw new IllegalArgumentException("Expected [" + getAnnotationTypeName()
+ "] but got [" + aFS2.getType().getName() + "]");
}

if (aFS1 instanceof AnnotationFS ann1 && aFS2 instanceof AnnotationFS ann2) {
if (aFS1 == aFS2) {
return true;
}

return colocated(ann1, ann2);
}

throw new IllegalArgumentException("Feature structures need to be annotations");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void render(RenderRequest aRequest, List<AnnotationFeature> aFeatures,
var nextLinkFs = (AnnotationFS) linkFs.getFeatureValue(linkNext);

// Is link after window? If yes, we can skip the rest of the chain
if (linkFs.getBegin() >= windowBegin) {
if (linkFs.getBegin() >= windowEnd) {
break; // Go to next chain
}

Expand Down
Loading

0 comments on commit 3eec32b

Please sign in to comment.