diff --git a/inception/inception-export/pom.xml b/inception/inception-export/pom.xml index 17acbdd558e..2cf07d59896 100644 --- a/inception/inception-export/pom.xml +++ b/inception/inception-export/pom.xml @@ -15,7 +15,9 @@ See the License for the specific language governing permissions and limitations under the License. --> - + 4.0.0 de.tudarmstadt.ukp.inception.app @@ -78,7 +80,7 @@ org.apache.uima uimafit-core - + org.apache.commons commons-lang3 @@ -91,7 +93,7 @@ it.unimi.dsi fastutil - + org.springframework spring-core @@ -112,7 +114,7 @@ org.springframework.boot spring-boot - + org.dkpro.core dkpro-core-api-metadata-asl @@ -121,18 +123,22 @@ org.dkpro.core dkpro-core-api-segmentation-asl - + + org.dkpro.core + dkpro-core-api-lexmorph-asl + + org.slf4j slf4j-api - + com.fasterxml.jackson.core jackson-databind - - + + de.tudarmstadt.ukp.inception.app diff --git a/inception/inception-export/src/main/java/de/tudarmstadt/ukp/inception/export/LayerImportExportUtils.java b/inception/inception-export/src/main/java/de/tudarmstadt/ukp/inception/export/LayerImportExportUtils.java index 2f76eec785d..c9ad5a6f181 100644 --- a/inception/inception-export/src/main/java/de/tudarmstadt/ukp/inception/export/LayerImportExportUtils.java +++ b/inception/inception-export/src/main/java/de/tudarmstadt/ukp/inception/export/LayerImportExportUtils.java @@ -19,13 +19,15 @@ import static de.tudarmstadt.ukp.clarin.webanno.model.OverlapMode.ANY_OVERLAP; import static de.tudarmstadt.ukp.clarin.webanno.model.OverlapMode.OVERLAP_ONLY; +import static de.tudarmstadt.ukp.clarin.webanno.support.WebAnnoConst.CHAIN_TYPE; +import static de.tudarmstadt.ukp.clarin.webanno.support.WebAnnoConst.COREFERENCE_RELATION_FEATURE; +import static de.tudarmstadt.ukp.clarin.webanno.support.WebAnnoConst.COREFERENCE_TYPE_FEATURE; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import java.util.StringTokenizer; @@ -46,7 +48,9 @@ import de.tudarmstadt.ukp.clarin.webanno.model.ValidationMode; import de.tudarmstadt.ukp.clarin.webanno.security.model.User; import de.tudarmstadt.ukp.clarin.webanno.support.JSONUtil; -import de.tudarmstadt.ukp.clarin.webanno.support.WebAnnoConst; +import de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.morph.MorphologicalFeatures; +import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma; +import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token; import de.tudarmstadt.ukp.inception.schema.AnnotationSchemaService; /** @@ -158,6 +162,7 @@ private static void setLayer(AnnotationSchemaService aAnnotationService, Annotat aLayer.setName(aExLayer.getName()); aLayer.setProject(aProject); aLayer.setType(aExLayer.getType()); + aLayer.setTraits(aExLayer.getTraits()); aAnnotationService.createOrUpdateLayer(aLayer); } @@ -167,28 +172,27 @@ public static AnnotationLayer importLayerFile(AnnotationSchemaService annotation { String text = IOUtils.toString(aIS, "UTF-8"); - ExportedAnnotationLayer[] exLayers = JSONUtil.getObjectMapper().readValue(text, - ExportedAnnotationLayer[].class); + var exLayers = JSONUtil.getObjectMapper().readValue(text, ExportedAnnotationLayer[].class); // First import the layers but without setting the attach-layers/features Map exLayersMap = new HashMap<>(); Map layersMap = new HashMap<>(); - for (ExportedAnnotationLayer exLayer : exLayers) { - AnnotationLayer layer = createLayer(annotationService, project, exLayer); + for (var exLayer : exLayers) { + var layer = createLayer(annotationService, project, exLayer); layersMap.put(layer.getName(), layer); exLayersMap.put(layer.getName(), exLayer); } // Second fill in the attach-layer and attach-feature information - for (AnnotationLayer layer : layersMap.values()) { - ExportedAnnotationLayer exLayer = exLayersMap.get(layer.getName()); + for (var layer : layersMap.values()) { + var exLayer = exLayersMap.get(layer.getName()); if (exLayer.getAttachType() != null) { layer.setAttachType(layersMap.get(exLayer.getAttachType().getName())); } if (exLayer.getAttachFeature() != null) { - AnnotationLayer attachLayer = annotationService.findLayer(project, + var attachLayer = annotationService.findLayer(project, exLayer.getAttachType().getName()); - AnnotationFeature attachFeature = annotationService + var attachFeature = annotationService .getFeature(exLayer.getAttachFeature().getName(), attachLayer); layer.setAttachFeature(attachFeature); } @@ -213,8 +217,8 @@ private static AnnotationLayer createLayer(AnnotationSchemaService annotationSer setLayer(annotationService, layer, aExLayer, project); } - for (ExportedAnnotationFeature exfeature : aExLayer.getFeatures()) { - ExportedTagSet exTagset = exfeature.getTagSet(); + for (var exfeature : aExLayer.getFeatures()) { + var exTagset = exfeature.getTagSet(); TagSet tagSet = null; if (exTagset != null && annotationService.existsTagSet(exTagset.getName(), project)) { tagSet = annotationService.getTagSet(exTagset.getName(), project); @@ -231,7 +235,7 @@ else if (exTagset != null) { setFeature(annotationService, feature, exfeature, project); continue; } - AnnotationFeature feature = new AnnotationFeature(); + var feature = new AnnotationFeature(); feature.setLayer(layer); feature.setTagset(tagSet); setFeature(annotationService, feature, exfeature, project); @@ -249,16 +253,21 @@ private static void setFeature(AnnotationSchemaService aAnnotationService, aFeature.setVisible(aExFeature.isVisible()); aFeature.setUiName(aExFeature.getUiName()); aFeature.setProject(aProject); - aFeature.setLayer(aFeature.getLayer()); - boolean isItChainedLayer = aFeature.getLayer().getType().equals(WebAnnoConst.CHAIN_TYPE); - if (isItChainedLayer && (aExFeature.getName().equals(WebAnnoConst.COREFERENCE_TYPE_FEATURE) - || aExFeature.getName().equals(WebAnnoConst.COREFERENCE_RELATION_FEATURE))) { + aFeature.setName(aExFeature.getName()); + boolean isItChainedLayer = CHAIN_TYPE.equals(aFeature.getLayer().getType()); + if (isItChainedLayer && (COREFERENCE_TYPE_FEATURE.equals(aExFeature.getName()) + || COREFERENCE_RELATION_FEATURE.equals(aExFeature.getName()))) { aFeature.setType(CAS.TYPE_NAME_STRING); } + else if (Token._TypeName.equals(aFeature.getLayer().getName()) + && Token._FeatName_morph.equals(aExFeature.getName()) + && Lemma._TypeName.equals(aExFeature.getType())) { + // See https://github.com/inception-project/inception/issues/3080 + aFeature.setType(MorphologicalFeatures._TypeName); + } else { aFeature.setType(aExFeature.getType()); } - aFeature.setName(aExFeature.getName()); aFeature.setRemember(aExFeature.isRemember()); aFeature.setRequired(aExFeature.isRequired()); aFeature.setHideUnconstraintFeature(aExFeature.isHideUnconstraintFeature()); @@ -268,7 +277,8 @@ private static void setFeature(AnnotationSchemaService aAnnotationService, aFeature.setLinkTypeRoleFeatureName(aExFeature.getLinkTypeRoleFeatureName()); aFeature.setLinkTypeTargetFeatureName(aExFeature.getLinkTypeTargetFeatureName()); aFeature.setTraits(aExFeature.getTraits()); - + aFeature.setCuratable(aExFeature.isCuratable()); + aFeature.setRank(aExFeature.getRank()); aAnnotationService.createFeature(aFeature); } @@ -278,15 +288,15 @@ public static ExportedAnnotationLayer exportLayerDetails( Map aFeatureToExFeature, AnnotationLayer aLayer, AnnotationSchemaService aAnnotationService) { - ExportedAnnotationLayer exLayer = new ExportedAnnotationLayer(); + var exLayer = new ExportedAnnotationLayer(); exLayer.setAllowStacking(aLayer.isAllowStacking()); + exLayer.setLockToTokenOffset(AnchoringMode.SINGLE_TOKEN.equals(aLayer.getAnchoringMode())); + exLayer.setMultipleTokens(AnchoringMode.TOKENS.equals(aLayer.getAnchoringMode())); exLayer.setBuiltIn(aLayer.isBuiltIn()); exLayer.setReadonly(aLayer.isReadonly()); exLayer.setCrossSentence(aLayer.isCrossSentence()); exLayer.setDescription(aLayer.getDescription()); exLayer.setEnabled(aLayer.isEnabled()); - exLayer.setLockToTokenOffset(AnchoringMode.SINGLE_TOKEN.equals(aLayer.getAnchoringMode())); - exLayer.setMultipleTokens(AnchoringMode.TOKENS.equals(aLayer.getAnchoringMode())); exLayer.setOverlapMode(aLayer.getOverlapMode()); exLayer.setAnchoringMode(aLayer.getAnchoringMode()); exLayer.setValidationMode(aLayer.getValidationMode()); @@ -295,14 +305,15 @@ public static ExportedAnnotationLayer exportLayerDetails( exLayer.setProjectName(aLayer.getProject().getName()); exLayer.setType(aLayer.getType()); exLayer.setUiName(aLayer.getUiName()); + exLayer.setTraits(aLayer.getTraits()); if (aLayerToExLayer != null) { aLayerToExLayer.put(aLayer, exLayer); } - List exFeatures = new ArrayList<>(); - for (AnnotationFeature feature : aAnnotationService.listAnnotationFeature(aLayer)) { - ExportedAnnotationFeature exFeature = new ExportedAnnotationFeature(); + var exFeatures = new ArrayList(); + for (var feature : aAnnotationService.listAnnotationFeature(aLayer)) { + var exFeature = new ExportedAnnotationFeature(); exFeature.setDescription(feature.getDescription()); exFeature.setEnabled(feature.isEnabled()); exFeature.setRemember(feature.isRemember()); @@ -319,18 +330,20 @@ public static ExportedAnnotationLayer exportLayerDetails( exFeature.setLinkTypeRoleFeatureName(feature.getLinkTypeRoleFeatureName()); exFeature.setLinkTypeTargetFeatureName(feature.getLinkTypeTargetFeatureName()); exFeature.setTraits(feature.getTraits()); + exFeature.setCuratable(feature.isCuratable()); + exFeature.setRank(feature.getRank()); if (feature.getTagset() != null) { - TagSet tagSet = feature.getTagset(); - ExportedTagSet exTagSet = new ExportedTagSet(); + var tagSet = feature.getTagset(); + var exTagSet = new ExportedTagSet(); exTagSet.setDescription(tagSet.getDescription()); exTagSet.setLanguage(tagSet.getLanguage()); exTagSet.setName(tagSet.getName()); exTagSet.setCreateTag(tagSet.isCreateTag()); - List exportedTags = new ArrayList<>(); - for (Tag tag : aAnnotationService.listTags(tagSet)) { - ExportedTag exTag = new ExportedTag(); + var exportedTags = new ArrayList(); + for (var tag : aAnnotationService.listTags(tagSet)) { + var exTag = new ExportedTag(); exTag.setDescription(tag.getDescription()); exTag.setName(tag.getName()); exportedTags.add(exTag); @@ -343,6 +356,7 @@ public static ExportedAnnotationLayer exportLayerDetails( aFeatureToExFeature.put(feature, exFeature); } } + exLayer.setFeatures(exFeatures); return exLayer; }