Search in sources :

Example 16 with Tag

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

the class TagSetImportPanel method actionImport.

private void actionImport(AjaxRequestTarget aTarget, Form<Preferences> aForm) {
    List<FileUpload> uploadedFiles = fileUpload.getFileUploads();
    Project project = selectedProject.getObject();
    if (isEmpty(uploadedFiles)) {
        error("Please choose file with tagset before uploading");
        return;
    } else if (isNull(project.getId())) {
        error("Project not yet created, please save project details!");
        return;
    }
    if (aForm.getModelObject().format.equals(ExportedTagSetConstant.JSON_FORMAT)) {
        for (FileUpload tagFile : uploadedFiles) {
            InputStream tagInputStream;
            try {
                tagInputStream = tagFile.getInputStream();
                if (aForm.getModelObject().overwrite) {
                    JsonImportUtil.importTagSetFromJsonWithOverwrite(project, tagInputStream, annotationService);
                } else {
                    JsonImportUtil.importTagSetFromJson(project, tagInputStream, annotationService);
                }
            } catch (IOException e) {
                error("Error Importing TagSet " + ExceptionUtils.getRootCauseMessage(e));
            }
        }
    } else if (aForm.getModelObject().format.equals(ExportedTagSetConstant.TAB_FORMAT)) {
        for (FileUpload tagFile : uploadedFiles) {
            InputStream tagInputStream;
            try {
                tagInputStream = tagFile.getInputStream();
                String text = IOUtils.toString(tagInputStream, "UTF-8");
                Map<String, String> tabbedTagsetFromFile = ImportUtil.getTagSetFromFile(text);
                Set<String> listOfTagsFromFile = tabbedTagsetFromFile.keySet();
                int i = 0;
                String tagSetName = "";
                String tagSetDescription = "";
                String tagsetLanguage = "";
                de.tudarmstadt.ukp.clarin.webanno.model.TagSet tagSet = null;
                for (String key : listOfTagsFromFile) {
                    // description
                    if (i == 0) {
                        tagSetName = key;
                        tagSetDescription = tabbedTagsetFromFile.get(key);
                    } else // the second key is the tagset language
                    if (i == 1) {
                        tagsetLanguage = key;
                        // exist
                        if (annotationService.existsTagSet(tagSetName, project)) {
                            // If overwrite is enabled
                            if (aForm.getModelObject().overwrite) {
                                tagSet = annotationService.getTagSet(tagSetName, project);
                                annotationService.removeAllTags(tagSet);
                            } else {
                                tagSet = new TagSet();
                                tagSet.setName(JsonImportUtil.copyTagSetName(annotationService, tagSetName, project));
                            }
                        } else {
                            tagSet = new TagSet();
                            tagSet.setName(tagSetName);
                        }
                        tagSet.setDescription(tagSetDescription.replace("\\n", "\n"));
                        tagSet.setLanguage(tagsetLanguage);
                        tagSet.setProject(project);
                        annotationService.createTagSet(tagSet);
                    } else // otherwise it is a tag entry, add the tag
                    // to the tagset
                    {
                        Tag tag = new Tag();
                        tag.setDescription(tabbedTagsetFromFile.get(key).replace("\\n", "\n"));
                        tag.setName(key);
                        tag.setTagSet(tagSet);
                        annotationService.createTag(tag);
                    }
                    i++;
                }
            } catch (Exception e) {
                error("Error importing tag set: " + ExceptionUtils.getRootCauseMessage(e));
                LOG.error("Error importing tag set", e);
            }
        }
    }
    try {
        onImportComplete(aTarget);
    } catch (Exception e) {
        error("Error importing tag set: " + ExceptionUtils.getRootCauseMessage(e));
        LOG.error("Error importing tag set", e);
    }
}
Also used : TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Set(java.util.Set) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) Map(java.util.Map) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload)

Example 17 with Tag

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

the class ImportUtil method exportLayerDetails.

public static de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer exportLayerDetails(Map<AnnotationLayer, de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer> aLayerToExLayer, Map<AnnotationFeature, de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature> aFeatureToExFeature, AnnotationLayer aLayer, AnnotationSchemaService aAnnotationService) {
    de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer exLayer = new de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationLayer();
    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(aLayer.isLockToTokenOffset());
    exLayer.setMultipleTokens(aLayer.isMultipleTokens());
    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<de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature> exFeatures = new ArrayList<>();
    for (AnnotationFeature feature : aAnnotationService.listAnnotationFeature(aLayer)) {
        de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature exFeature = new de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationFeature();
        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());
        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 : ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) 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) 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) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)17 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)11 ExportedTag (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag)7 ArrayList (java.util.ArrayList)7 ExportedTagSet (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet)5 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)5 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)4 IOException (java.io.IOException)4 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)3 PossibleValue (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue)3 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)2 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)2 File (java.io.File)2 HashSet (java.util.HashSet)2 UIMAException (org.apache.uima.UIMAException)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 Options (com.googlecode.wicket.jquery.core.Options)1 TooltipBehavior (com.googlecode.wicket.jquery.ui.widget.tooltip.TooltipBehavior)1 ProjectType (de.tudarmstadt.ukp.clarin.webanno.api.ProjectType)1 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)1