Skip to content

Commit

Permalink
Merge branch 'main' into refactoring/Upgrade-to-Spring-Boot-3
Browse files Browse the repository at this point in the history
  • Loading branch information
reckart authored Mar 2, 2024
2 parents e4fc794 + 8077d7d commit 8822a49
Show file tree
Hide file tree
Showing 83 changed files with 7,584 additions and 347 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@

import static org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription;
import static org.apache.uima.fit.util.CasUtil.getType;
import static org.apache.uima.fit.util.FSUtil.setFeature;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.apache.uima.cas.CAS;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.fit.util.CasUtil;
import org.apache.uima.fit.util.FSUtil;
import org.apache.uima.resource.metadata.TypeSystemDescription;
Expand Down Expand Up @@ -58,8 +54,7 @@ public static void clearCasMetadata(CAS aCas) throws IllegalStateException
return;
}

List<AnnotationFS> cmds = new ArrayList<>(
CasUtil.select(aCas, getType(aCas, CASMetadata.class)));
var cmds = aCas.select(CASMetadata.class).toList();
if (cmds.size() > 1) {
throw new IllegalStateException("CAS contains more than one CASMetadata instance");
}
Expand All @@ -82,41 +77,42 @@ public static void addOrUpdateCasMetadata(CAS aCas, long aTimeStamp, SourceDocum
return;
}

Type casMetadataType = getType(aCas, CASMetadata.class);
var casMetadataType = getType(aCas, CASMetadata.class);
FeatureStructure cmd;
List<AnnotationFS> cmds = new ArrayList<>(CasUtil.select(aCas, casMetadataType));
var cmds = aCas.select(CASMetadata.class).toList();
if (cmds.size() > 1) {
throw new IOException("CAS contains more than one CASMetadata instance!");
}
else if (cmds.size() == 1) {

if (cmds.size() == 1) {
cmd = cmds.get(0);
}
else {
cmd = aCas.createAnnotation(casMetadataType, 0, 0);
}

if (cmd.getType().getFeatureByBaseName("username") != null) {
FSUtil.setFeature(cmd, "username", aUsername);
if (cmd.getType().getFeatureByBaseName(CASMetadata._FeatName_username) != null) {
setFeature(cmd, CASMetadata._FeatName_username, aUsername);
}

if (cmd.getType().getFeatureByBaseName("sourceDocumentId") != null) {
FSUtil.setFeature(cmd, "sourceDocumentId", aDocument.getId());
if (cmd.getType().getFeatureByBaseName(CASMetadata._FeatName_sourceDocumentId) != null) {
setFeature(cmd, CASMetadata._FeatName_sourceDocumentId, aDocument.getId());
}

if (cmd.getType().getFeatureByBaseName("sourceDocumentName") != null) {
FSUtil.setFeature(cmd, "sourceDocumentName", aDocument.getName());
if (cmd.getType().getFeatureByBaseName(CASMetadata._FeatName_sourceDocumentName) != null) {
setFeature(cmd, CASMetadata._FeatName_sourceDocumentName, aDocument.getName());
}

if (cmd.getType().getFeatureByBaseName("projectId") != null) {
FSUtil.setFeature(cmd, "projectId", aDocument.getProject().getId());
if (cmd.getType().getFeatureByBaseName(CASMetadata._FeatName_projectId) != null) {
setFeature(cmd, CASMetadata._FeatName_projectId, aDocument.getProject().getId());
}

if (cmd.getType().getFeatureByBaseName("projectName") != null) {
FSUtil.setFeature(cmd, "projectName", aDocument.getProject().getName());
if (cmd.getType().getFeatureByBaseName(CASMetadata._FeatName_projectName) != null) {
setFeature(cmd, CASMetadata._FeatName_projectName, aDocument.getProject().getName());
}

if (cmd.getType().getFeatureByBaseName("lastChangedOnDisk") != null) {
FSUtil.setFeature(cmd, "lastChangedOnDisk", aTimeStamp);
if (cmd.getType().getFeatureByBaseName(CASMetadata._FeatName_lastChangedOnDisk) != null) {
setFeature(cmd, CASMetadata._FeatName_lastChangedOnDisk, aTimeStamp);
LOG.trace("CAS [{}] for [{}]@[{}]({}): set lastChangedOnDisk: {}", aCas.hashCode(),
aUsername, aDocument.getName(), aDocument.getId(), aTimeStamp);
}
Expand All @@ -131,17 +127,18 @@ public static Optional<FeatureStructure> getCasMetadataFS(CAS aCas)

public static long getLastChanged(CAS aCas)
{
Type casMetadataType = getType(aCas, CASMetadata.class);
Feature feature = casMetadataType.getFeatureByBaseName("lastChangedOnDisk");
var casMetadataType = getType(aCas, CASMetadata.class);
var feature = casMetadataType.getFeatureByBaseName(CASMetadata._FeatName_lastChangedOnDisk);
return aCas.select(casMetadataType).map(cmd -> cmd.getLongValue(feature)).findFirst()
.orElse(-1l);
}

public static Optional<String> getUsername(CAS aCas)
{
try {
FeatureStructure fs = CasUtil.selectSingle(aCas, getType(aCas, CASMetadata.class));
return Optional.ofNullable(FSUtil.getFeature(fs, "username", String.class));
var fs = CasUtil.selectSingle(aCas, getType(aCas, CASMetadata.class));
return Optional.ofNullable(
FSUtil.getFeature(fs, CASMetadata._FeatName_username, String.class));
}
catch (IllegalArgumentException e) {
return Optional.empty();
Expand All @@ -151,8 +148,9 @@ public static Optional<String> getUsername(CAS aCas)
public static Optional<Long> getSourceDocumentId(CAS aCas)
{
try {
FeatureStructure fs = CasUtil.selectSingle(aCas, getType(aCas, CASMetadata.class));
return Optional.ofNullable(FSUtil.getFeature(fs, "sourceDocumentId", Long.class));
var fs = CasUtil.selectSingle(aCas, getType(aCas, CASMetadata.class));
return Optional.ofNullable(
FSUtil.getFeature(fs, CASMetadata._FeatName_sourceDocumentId, Long.class));
}
catch (IllegalArgumentException e) {
return Optional.empty();
Expand All @@ -162,8 +160,9 @@ public static Optional<Long> getSourceDocumentId(CAS aCas)
public static Optional<String> getSourceDocumentName(CAS aCas)
{
try {
FeatureStructure fs = CasUtil.selectSingle(aCas, getType(aCas, CASMetadata.class));
return Optional.ofNullable(FSUtil.getFeature(fs, "sourceDocumentName", String.class));
var fs = CasUtil.selectSingle(aCas, getType(aCas, CASMetadata.class));
return Optional.ofNullable(
FSUtil.getFeature(fs, CASMetadata._FeatName_sourceDocumentName, String.class));
}
catch (IllegalArgumentException e) {
return Optional.empty();
Expand All @@ -173,8 +172,9 @@ public static Optional<String> getSourceDocumentName(CAS aCas)
public static Optional<Long> getProjectId(CAS aCas)
{
try {
FeatureStructure fs = CasUtil.selectSingle(aCas, getType(aCas, CASMetadata.class));
return Optional.ofNullable(FSUtil.getFeature(fs, "projectId", Long.class));
var fs = CasUtil.selectSingle(aCas, getType(aCas, CASMetadata.class));
return Optional
.ofNullable(FSUtil.getFeature(fs, CASMetadata._FeatName_projectId, Long.class));
}
catch (IllegalArgumentException e) {
return Optional.empty();
Expand All @@ -184,8 +184,9 @@ public static Optional<Long> getProjectId(CAS aCas)
public static Optional<String> getProjectName(CAS aCas)
{
try {
FeatureStructure fs = CasUtil.selectSingle(aCas, getType(aCas, CASMetadata.class));
return Optional.ofNullable(FSUtil.getFeature(fs, "projectName", String.class));
var fs = CasUtil.selectSingle(aCas, getType(aCas, CASMetadata.class));
return Optional.ofNullable(
FSUtil.getFeature(fs, CASMetadata._FeatName_projectName, String.class));
}
catch (IllegalArgumentException e) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@

import java.lang.invoke.MethodHandles;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;

import org.apache.uima.cas.CAS;
import org.apache.uima.resource.metadata.TypeDescription;
import org.apache.uima.resource.metadata.TypeSystemDescription;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.validation.ValidationError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
Expand All @@ -55,6 +57,13 @@ public class ChainLayerSupport
extends LayerSupport_ImplBase<ChainAdapter, ChainLayerTraits>
implements InitializingBean
{
public static final String FEATURE_NAME_FIRST = "first";
public static final String FEATURE_NAME_NEXT = "next";
public static final String FEATURE_NAME_REFERENCE_RELATION = "referenceRelation";
public static final String FEATURE_NAME_REFERENCE = "referenceType";
private static final String TYPE_SUFFIX_LINK = "Link";
private static final String TYPE_SUFFIX_CHAIN = "Chain";

private final static Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -91,7 +100,7 @@ public void setBeanName(String aBeanName)
@Override
public void afterPropertiesSet() throws Exception
{
types = asList(new LayerType(TYPE, "Chain", layerSupportId));
types = asList(new LayerType(TYPE, TYPE_SUFFIX_CHAIN, layerSupportId));
}

@Override
Expand All @@ -110,35 +119,33 @@ public boolean accepts(AnnotationLayer aLayer)
public ChainAdapter createAdapter(AnnotationLayer aLayer,
Supplier<Collection<AnnotationFeature>> aFeatures)
{
ChainAdapter adapter = new ChainAdapter(getLayerSupportRegistry(), featureSupportRegistry,
eventPublisher, aLayer, aFeatures,
return new ChainAdapter(getLayerSupportRegistry(), featureSupportRegistry, eventPublisher,
aLayer, aFeatures,
layerBehaviorsRegistry.getLayerBehaviors(this, SpanLayerBehavior.class));

return adapter;
}

@Override
public void generateTypes(TypeSystemDescription aTsd, AnnotationLayer aLayer,
List<AnnotationFeature> aAllFeaturesInProject)
{
TypeDescription tdChains = aTsd.addType(aLayer.getName() + "Chain", aLayer.getDescription(),
var tdChain = aTsd.addType(aLayer.getName() + TYPE_SUFFIX_CHAIN, aLayer.getDescription(),
CAS.TYPE_NAME_ANNOTATION_BASE);
tdChains.addFeature("first", "", aLayer.getName() + "Link");
tdChain.addFeature(FEATURE_NAME_FIRST, "", aLayer.getName() + TYPE_SUFFIX_LINK);

// Custom features on chain layers are currently not supported
// generateFeatures(aTsd, tdChains, type);

TypeDescription tdLink = aTsd.addType(aLayer.getName() + "Link", "",
var tdLink = aTsd.addType(aLayer.getName() + TYPE_SUFFIX_LINK, "",
CAS.TYPE_NAME_ANNOTATION);
tdLink.addFeature("next", "", aLayer.getName() + "Link");
tdLink.addFeature("referenceType", "", CAS.TYPE_NAME_STRING);
tdLink.addFeature("referenceRelation", "", CAS.TYPE_NAME_STRING);
tdLink.addFeature(FEATURE_NAME_NEXT, "", aLayer.getName() + TYPE_SUFFIX_LINK);
tdLink.addFeature(FEATURE_NAME_REFERENCE, "", CAS.TYPE_NAME_STRING);
tdLink.addFeature(FEATURE_NAME_REFERENCE_RELATION, "", CAS.TYPE_NAME_STRING);
}

@Override
public List<String> getGeneratedTypeNames(AnnotationLayer aLayer)
{
return asList(aLayer.getName() + "Chain", aLayer.getName() + "Link");
return asList(aLayer.getName() + TYPE_SUFFIX_CHAIN, aLayer.getName() + TYPE_SUFFIX_LINK);
}

@Override
Expand All @@ -153,7 +160,7 @@ public Renderer createRenderer(AnnotationLayer aLayer,
@Override
public Panel createTraitsEditor(String aId, IModel<AnnotationLayer> aLayerModel)
{
AnnotationLayer layer = aLayerModel.getObject();
var layer = aLayerModel.getObject();

if (!accepts(layer)) {
throw unsupportedLayerTypeException(layer);
Expand All @@ -167,4 +174,18 @@ public ChainLayerTraits createTraits()
{
return new ChainLayerTraits();
}

@Override
public List<ValidationError> validateFeatureName(AnnotationFeature aFeature)
{
var name = aFeature.getName();

if (Set.of(FEATURE_NAME_FIRST, FEATURE_NAME_NEXT, FEATURE_NAME_REFERENCE,
FEATURE_NAME_REFERENCE_RELATION).contains(name)) {
return asList(new ValidationError("[" + name + "] is a reserved feature name on "
+ "chain layers. Please use a different name for the feature."));
}

return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
*/
package de.tudarmstadt.ukp.inception.annotation.layer.relation;

import static de.tudarmstadt.ukp.inception.support.WebAnnoConst.FEAT_REL_SOURCE;
import static de.tudarmstadt.ukp.inception.support.WebAnnoConst.FEAT_REL_TARGET;
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
import static org.apache.uima.cas.CAS.TYPE_NAME_ANNOTATION;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;

import org.apache.uima.resource.metadata.TypeDescription;
import org.apache.uima.resource.metadata.TypeSystemDescription;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.validation.ValidationError;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
Expand All @@ -54,6 +54,12 @@ public class RelationLayerSupport
extends LayerSupport_ImplBase<RelationAdapter, RelationLayerTraits>
implements InitializingBean
{
@SuppressWarnings("deprecation")
public static final String FEAT_REL_TARGET = WebAnnoConst.FEAT_REL_TARGET;

@SuppressWarnings("deprecation")
public static final String FEAT_REL_SOURCE = WebAnnoConst.FEAT_REL_SOURCE;

@SuppressWarnings("deprecation")
public static final String TYPE = WebAnnoConst.RELATION_TYPE;

Expand Down Expand Up @@ -157,4 +163,16 @@ public RelationLayerTraits createTraits()
{
return new RelationLayerTraits();
}

@Override
public List<ValidationError> validateFeatureName(AnnotationFeature aFeature)
{
var name = aFeature.getName();
if (name.equals(FEAT_REL_SOURCE) || name.equals(FEAT_REL_TARGET)) {
return asList(new ValidationError("[" + name + "] is a reserved feature name on "
+ "relation layers. Please use a different name for the feature."));
}

return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ public boolean accepts(AnnotationLayer aLayer)
public SpanAdapter createAdapter(AnnotationLayer aLayer,
Supplier<Collection<AnnotationFeature>> aFeatures)
{
var adapter = new SpanAdapter(getLayerSupportRegistry(), featureSupportRegistry,
eventPublisher, aLayer, aFeatures,
return new SpanAdapter(getLayerSupportRegistry(), featureSupportRegistry, eventPublisher,
aLayer, aFeatures,
layerBehaviorsRegistry.getLayerBehaviors(this, SpanLayerBehavior.class));

return adapter;
}

@Override
Expand Down Expand Up @@ -134,7 +132,7 @@ public SpanRenderer createRenderer(AnnotationLayer aLayer,
@Override
public Panel createTraitsEditor(String aId, IModel<AnnotationLayer> aLayerModel)
{
AnnotationLayer layer = aLayerModel.getObject();
var layer = aLayerModel.getObject();

if (!accepts(layer)) {
throw unsupportedLayerTypeException(layer);
Expand Down
Loading

0 comments on commit 8822a49

Please sign in to comment.