Search in sources :

Example 1 with ExportedAnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer in project webanno by webanno.

the class ImportUtil method exportLayerDetails.

@Deprecated
public static ExportedAnnotationLayer exportLayerDetails(Map<AnnotationLayer, ExportedAnnotationLayer> aLayerToExLayer, Map<AnnotationFeature, ExportedAnnotationFeature> aFeatureToExFeature, AnnotationLayer aLayer, AnnotationSchemaService aAnnotationService) {
    ExportedAnnotationLayer exLayer = new ExportedAnnotationLayer();
    exLayer.setAllowStacking(aLayer.isAllowStacking());
    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());
    exLayer.setLinkedListBehavior(aLayer.isLinkedListBehavior());
    exLayer.setName(aLayer.getName());
    exLayer.setProjectName(aLayer.getProject().getName());
    exLayer.setType(aLayer.getType());
    exLayer.setUiName(aLayer.getUiName());
    if (aLayerToExLayer != null) {
        aLayerToExLayer.put(aLayer, exLayer);
    }
    List<ExportedAnnotationFeature> exFeatures = new ArrayList<>();
    for (AnnotationFeature feature : aAnnotationService.listAnnotationFeature(aLayer)) {
        ExportedAnnotationFeature exFeature = new ExportedAnnotationFeature();
        exFeature.setDescription(feature.getDescription());
        exFeature.setEnabled(feature.isEnabled());
        exFeature.setRemember(feature.isRemember());
        exFeature.setRequired(feature.isRequired());
        exFeature.setHideUnconstraintFeature(feature.isHideUnconstraintFeature());
        exFeature.setName(feature.getName());
        exFeature.setProjectName(feature.getProject().getName());
        exFeature.setType(feature.getType());
        exFeature.setUiName(feature.getUiName());
        exFeature.setVisible(feature.isVisible());
        exFeature.setMultiValueMode(feature.getMultiValueMode());
        exFeature.setLinkMode(feature.getLinkMode());
        exFeature.setLinkTypeName(feature.getLinkTypeName());
        exFeature.setLinkTypeRoleFeatureName(feature.getLinkTypeRoleFeatureName());
        exFeature.setLinkTypeTargetFeatureName(feature.getLinkTypeTargetFeatureName());
        exFeature.setTraits(feature.getTraits());
        if (feature.getTagset() != null) {
            TagSet tagSet = feature.getTagset();
            ExportedTagSet exTagSet = new ExportedTagSet();
            exTagSet.setDescription(tagSet.getDescription());
            exTagSet.setLanguage(tagSet.getLanguage());
            exTagSet.setName(tagSet.getName());
            exTagSet.setCreateTag(tagSet.isCreateTag());
            List<ExportedTag> exportedTags = new ArrayList<>();
            for (Tag tag : aAnnotationService.listTags(tagSet)) {
                ExportedTag exTag = new ExportedTag();
                exTag.setDescription(tag.getDescription());
                exTag.setName(tag.getName());
                exportedTags.add(exTag);
            }
            exTagSet.setTags(exportedTags);
            exFeature.setTagSet(exTagSet);
        }
        exFeatures.add(exFeature);
        if (aFeatureToExFeature != null) {
            aFeatureToExFeature.put(feature, exFeature);
        }
    }
    exLayer.setFeatures(exFeatures);
    return exLayer;
}
Also used : ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) ExportedTagSet(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) ExportedTagSet(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet) ArrayList(java.util.ArrayList) ExportedAnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeature) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag) ExportedAnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 2 with ExportedAnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer in project webanno by webanno.

the class LayerDetailForm method exportLayerJson.

private IResourceStream exportLayerJson() {
    try {
        AnnotationLayer layer = getModelObject();
        List<ExportedAnnotationLayer> exLayers = new ArrayList<>();
        ExportedAnnotationLayer exMainLayer = ImportUtil.exportLayerDetails(null, null, layer, annotationService);
        exLayers.add(exMainLayer);
        // that, otherwise we would be missing it during re-import.
        if (layer.getAttachType() != null) {
            AnnotationLayer attachLayer = layer.getAttachType();
            ExportedAnnotationLayer exAttachLayer = ImportUtil.exportLayerDetails(null, null, attachLayer, annotationService);
            exMainLayer.setAttachType(new ExportedAnnotationLayerReference(exAttachLayer.getName()));
            exLayers.add(exAttachLayer);
        }
        return new InputStreamResourceStream(new ByteArrayInputStream(JSONUtil.toPrettyJsonString(exLayers).getBytes("UTF-8")));
    } catch (Exception e) {
        error("Unable to generate the JSON file: " + ExceptionUtils.getRootCauseMessage(e));
        ProjectLayersPanel.LOG.error("Unable to generate the JSON file", e);
        RequestCycle.get().find(IPartialPageRequestHandler.class).ifPresent(handler -> handler.addChildren(getPage(), IFeedback.class));
        return null;
    }
}
Also used : ExportedAnnotationLayerReference(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayerReference) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) Strings.escapeMarkup(org.apache.wicket.util.string.Strings.escapeMarkup) CasStorageService(de.tudarmstadt.ukp.clarin.webanno.api.CasStorageService) LambdaAjaxFormChoiceComponentUpdatingBehavior(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxFormChoiceComponentUpdatingBehavior) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) TextField(org.apache.wicket.markup.html.form.TextField) StringUtils(org.apache.commons.lang3.StringUtils) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) InputStreamResourceStream(de.tudarmstadt.ukp.clarin.webanno.support.wicket.InputStreamResourceStream) LambdaBehavior.visibleWhen(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.visibleWhen) ByteArrayInputStream(java.io.ByteArrayInputStream) LayerConfigurationChangedEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent) Arrays.asList(java.util.Arrays.asList) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Objects.isNull(java.util.Objects.isNull) LayerSupportRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupportRegistry) IModel(org.apache.wicket.model.IModel) LambdaModelAdapter(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaModelAdapter) Label(org.apache.wicket.markup.html.basic.Label) LambdaBehavior.enabledWhen(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.enabledWhen) Collections.emptyList(java.util.Collections.emptyList) LayerType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerType) Model(org.apache.wicket.model.Model) Component(org.apache.wicket.Component) LambdaAjaxButton(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxButton) BootstrapRadioChoice(de.agilecoders.wicket.core.markup.html.bootstrap.form.BootstrapRadioChoice) Collectors(java.util.stream.Collectors) IFeedback(org.apache.wicket.feedback.IFeedback) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) List(java.util.List) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) PropertyModel(org.apache.wicket.model.PropertyModel) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) FeatureSelectionForm(de.tudarmstadt.ukp.clarin.webanno.ui.project.layers.ProjectLayersPanel.FeatureSelectionForm) ApplicationEventPublisherHolder(de.tudarmstadt.ukp.clarin.webanno.support.spring.ApplicationEventPublisherHolder) IResourceStream(org.apache.wicket.util.resource.IResourceStream) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) Form(org.apache.wicket.markup.html.form.Form) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StringResourceModel(org.apache.wicket.model.StringResourceModel) EmptyPanel(org.apache.wicket.markup.html.panel.EmptyPanel) EnumChoiceRenderer(org.apache.wicket.markup.html.form.EnumChoiceRenderer) CheckBox(org.apache.wicket.markup.html.form.CheckBox) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) ArrayList(java.util.ArrayList) AnnotationSchemaService(de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) BootstrapSelect(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.select.BootstrapSelect) ChallengeResponseDialog(de.tudarmstadt.ukp.clarin.webanno.support.dialog.ChallengeResponseDialog) ChoiceRenderer(org.apache.wicket.markup.html.form.ChoiceRenderer) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) AjaxDownloadLink(de.tudarmstadt.ukp.clarin.webanno.support.wicket.AjaxDownloadLink) TextArea(org.apache.wicket.markup.html.form.TextArea) DocumentService(de.tudarmstadt.ukp.clarin.webanno.api.DocumentService) LayerExportMode(de.tudarmstadt.ukp.clarin.webanno.ui.project.layers.ProjectLayersPanel.LayerExportMode) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) RELATION_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.RELATION_TYPE) SPAN_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.SPAN_TYPE) LayerSupport(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupport) ImportUtil(de.tudarmstadt.ukp.clarin.webanno.export.ImportUtil) JSONUtil(de.tudarmstadt.ukp.clarin.webanno.support.JSONUtil) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) LambdaAjaxLink(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxLink) LambdaModel(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaModel) IPartialPageRequestHandler(org.apache.wicket.core.request.handler.IPartialPageRequestHandler) ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) InputStreamResourceStream(de.tudarmstadt.ukp.clarin.webanno.support.wicket.InputStreamResourceStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ExportedAnnotationLayerReference(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayerReference) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer)

Example 3 with ExportedAnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer in project webanno by webanno.

the class LayerExporter method exportLayerDetails.

private ExportedAnnotationLayer exportLayerDetails(Map<AnnotationLayer, ExportedAnnotationLayer> aLayerToExLayer, Map<AnnotationFeature, ExportedAnnotationFeature> aFeatureToExFeature, AnnotationLayer aLayer) {
    ExportedAnnotationLayer exLayer = new ExportedAnnotationLayer();
    exLayer.setAllowStacking(aLayer.isAllowStacking());
    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());
    exLayer.setLinkedListBehavior(aLayer.isLinkedListBehavior());
    exLayer.setName(aLayer.getName());
    exLayer.setProjectName(aLayer.getProject().getName());
    exLayer.setType(aLayer.getType());
    exLayer.setUiName(aLayer.getUiName());
    exLayer.setTraits(aLayer.getTraits());
    if (aLayerToExLayer != null) {
        aLayerToExLayer.put(aLayer, exLayer);
    }
    // Export features
    List<ExportedAnnotationFeature> exFeatures = new ArrayList<>();
    for (AnnotationFeature feature : annotationService.listAnnotationFeature(aLayer)) {
        ExportedAnnotationFeature exFeature = exportFeatureDetails(feature);
        exFeatures.add(exFeature);
        if (aFeatureToExFeature != null) {
            aFeatureToExFeature.put(feature, exFeature);
        }
    }
    exLayer.setFeatures(exFeatures);
    return exLayer;
}
Also used : ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) ArrayList(java.util.ArrayList) ExportedAnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeature) ExportedAnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 4 with ExportedAnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer in project webanno by webanno.

the class LayerExporter method exportData.

@Override
public void exportData(ProjectExportRequest aRequest, ProjectExportTaskMonitor aMonitor, ExportedProject aExProject, File aStage) throws Exception {
    List<ExportedAnnotationLayer> exLayers = new ArrayList<>();
    // Store map of layer and its equivalent exLayer so that the attach type is attached later
    Map<AnnotationLayer, ExportedAnnotationLayer> layerToExLayers = new HashMap<>();
    // Store map of feature and its equivalent exFeature so that the attach feature is attached
    // later
    Map<AnnotationFeature, ExportedAnnotationFeature> featureToExFeatures = new HashMap<>();
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aRequest.getProject())) {
        exLayers.add(exportLayerDetails(layerToExLayers, featureToExFeatures, layer));
    }
    // add the attach-type and attach-feature to the exported layers and exported feature
    for (AnnotationLayer layer : layerToExLayers.keySet()) {
        if (layer.getAttachType() != null) {
            layerToExLayers.get(layer).setAttachType(new ExportedAnnotationLayerReference(layer.getAttachType().getName()));
        }
        if (layer.getAttachFeature() != null) {
            layerToExLayers.get(layer).setAttachFeature(new ExportedAnnotationFeatureReference(layer.getAttachFeature()));
        }
    }
    aExProject.setLayers(exLayers);
    LOG.info("Exported [{}] layers for project [{}]", exLayers.size(), aRequest.getProject().getName());
}
Also used : ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) HashMap(java.util.HashMap) ExportedAnnotationLayerReference(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayerReference) ArrayList(java.util.ArrayList) ExportedAnnotationFeatureReference(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeatureReference) ExportedAnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeature) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) ExportedAnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 5 with ExportedAnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer in project webanno by webanno.

the class LayerExporter method importLayers.

/**
 * Create a {@link TagSet} for the imported project,
 *
 * @param aProject
 *            a project.
 * @param aExProject
 *            the settings.
 * @throws IOException
 *             if an I/O error occurs.
 */
private void importLayers(Project aProject, ExportedProject aExProject) throws IOException {
    // Round 1: layers and features
    for (ExportedAnnotationLayer exLayer : aExProject.getLayers()) {
        if (annotationService.existsLayer(exLayer.getName(), exLayer.getType(), aProject)) {
            AnnotationLayer layer = annotationService.findLayer(aProject, exLayer.getName());
            importLayer(layer, exLayer, aProject);
            for (ExportedAnnotationFeature exfeature : exLayer.getFeatures()) {
                if (annotationService.existsFeature(exfeature.getName(), layer)) {
                    AnnotationFeature feature = annotationService.getFeature(exfeature.getName(), layer);
                    importFeature(feature, exfeature, aProject);
                    continue;
                }
                AnnotationFeature feature = new AnnotationFeature();
                feature.setLayer(layer);
                importFeature(feature, exfeature, aProject);
            }
        } else {
            AnnotationLayer layer = new AnnotationLayer();
            importLayer(layer, exLayer, aProject);
            for (ExportedAnnotationFeature exfeature : exLayer.getFeatures()) {
                AnnotationFeature feature = new AnnotationFeature();
                feature.setLayer(layer);
                importFeature(feature, exfeature, aProject);
            }
        }
    }
    // Round 2: attach-layers, attach-features
    for (ExportedAnnotationLayer exLayer : aExProject.getLayers()) {
        if (exLayer.getAttachType() != null) {
            AnnotationLayer layer = annotationService.findLayer(aProject, exLayer.getName());
            AnnotationLayer attachLayer = annotationService.findLayer(aProject, exLayer.getAttachType().getName());
            layer.setAttachType(attachLayer);
            if (exLayer.getAttachFeature() != null) {
                AnnotationFeature attachFeature = annotationService.getFeature(exLayer.getAttachFeature().getName(), attachLayer);
                layer.setAttachFeature(attachFeature);
            }
            annotationService.createOrUpdateLayer(layer);
        }
    }
}
Also used : ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) ExportedAnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeature) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ExportedAnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer) ExportedAnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

ExportedAnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayer)5 ExportedAnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeature)4 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)4 ArrayList (java.util.ArrayList)4 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)3 ExportedAnnotationLayerReference (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationLayerReference)2 BootstrapRadioChoice (de.agilecoders.wicket.core.markup.html.bootstrap.form.BootstrapRadioChoice)1 BootstrapSelect (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.select.BootstrapSelect)1 AnnotationSchemaService (de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService)1 CasStorageService (de.tudarmstadt.ukp.clarin.webanno.api.CasStorageService)1 DocumentService (de.tudarmstadt.ukp.clarin.webanno.api.DocumentService)1 RELATION_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.RELATION_TYPE)1 SPAN_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.SPAN_TYPE)1 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)1 LayerSupport (de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupport)1 LayerSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupportRegistry)1 LayerType (de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerType)1 LayerConfigurationChangedEvent (de.tudarmstadt.ukp.clarin.webanno.api.event.LayerConfigurationChangedEvent)1 ImportUtil (de.tudarmstadt.ukp.clarin.webanno.export.ImportUtil)1 ExportedAnnotationFeatureReference (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationFeatureReference)1