Search in sources :

Example 6 with ExportedTag

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

the class TagSetEditorPanel method export.

private FileResourceStream export() {
    File exportFile = null;
    if (exportFormat.getObject().equals(ExportedTagSetConstant.JSON_FORMAT)) {
        try {
            exportFile = File.createTempFile("exportedtagsets", ".json");
        } catch (IOException e1) {
            error("Unable to create temporary File!!");
            return null;
        }
        if (isNull(selectedTagSet.getObject().getId())) {
            error("Project not yet created. Please save project details first!");
        } else {
            TagSet tagSet = selectedTagSet.getObject();
            ExportedTagSet exTagSet = new ExportedTagSet();
            exTagSet.setDescription(tagSet.getDescription());
            exTagSet.setLanguage(tagSet.getLanguage());
            exTagSet.setName(tagSet.getName());
            List<ExportedTag> exportedTags = new ArrayList<>();
            for (Tag tag : annotationSchemaService.listTags(tagSet)) {
                ExportedTag exportedTag = new ExportedTag();
                exportedTag.setDescription(tag.getDescription());
                exportedTag.setName(tag.getName());
                exportedTags.add(exportedTag);
            }
            exTagSet.setTags(exportedTags);
            try {
                JSONUtil.generatePrettyJson(exTagSet, exportFile);
            } catch (IOException e) {
                error("File Path not found or No permision to save the file!");
            }
            info("TagSets successfully exported to :" + exportFile.getAbsolutePath());
        }
    } else if (exportFormat.getObject().equals(ExportedTagSetConstant.TAB_FORMAT)) {
        TagSet tagSet = selectedTagSet.getObject();
        try {
            exportFile = File.createTempFile("exportedtagsets", ".txt");
        } catch (IOException e1) {
            error("Unable to create temporary File!!");
        }
        OutputStream os;
        OutputStreamWriter osw;
        BufferedWriter bw;
        try {
            String tagSetDescription = tagSet.getDescription() == null ? "" : tagSet.getDescription();
            os = new FileOutputStream(exportFile);
            osw = new OutputStreamWriter(os, "UTF-8");
            bw = new BufferedWriter(osw);
            bw.write(tagSet.getName() + "\t" + tagSetDescription.replace("\n", "\\n") + "\n");
            bw.write(tagSet.getLanguage() + "\t" + " \n");
            for (Tag tag : annotationSchemaService.listTags(tagSet)) {
                String tagDescription = tag.getDescription() == null ? "" : tag.getDescription();
                bw.write(tag.getName() + "\t" + tagDescription.replace("\n", "\\n") + "\n");
            }
            bw.flush();
            bw.close();
        } catch (FileNotFoundException e) {
            error("The file for export not found " + ExceptionUtils.getRootCauseMessage(e));
        } catch (UnsupportedEncodingException e) {
            error("Unsupported encoding " + ExceptionUtils.getRootCauseMessage(e));
        } catch (IOException e) {
            error(ExceptionUtils.getRootCause(e));
        }
    }
    return new FileResourceStream(exportFile);
}
Also used : FileResourceStream(org.apache.wicket.util.resource.FileResourceStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) 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) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) File(java.io.File) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag)

Example 7 with ExportedTag

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

the class ImportUtil method createV0TagSet.

/**
 * Import tagsets from projects prior to WebAnno 2.0.
 */
private static void createV0TagSet(Project aProject, List<ExportedTagSet> importedTagSets, AnnotationSchemaService aAnnotationService, User user) throws IOException {
    List<String> posTags = new ArrayList<>();
    List<String> depTags = new ArrayList<>();
    List<String> neTags = new ArrayList<>();
    List<String> posTagDescriptions = new ArrayList<>();
    List<String> depTagDescriptions = new ArrayList<>();
    List<String> neTagDescriptions = new ArrayList<>();
    List<String> corefTypeTags = new ArrayList<>();
    List<String> corefRelTags = new ArrayList<>();
    for (ExportedTagSet tagSet : importedTagSets) {
        switch(tagSet.getTypeName()) {
            case WebAnnoConst.POS:
                for (ExportedTag tag : tagSet.getTags()) {
                    posTags.add(tag.getName());
                    posTagDescriptions.add(tag.getDescription());
                }
                break;
            case WebAnnoConst.DEPENDENCY:
                for (ExportedTag tag : tagSet.getTags()) {
                    depTags.add(tag.getName());
                    depTagDescriptions.add(tag.getDescription());
                }
                break;
            case WebAnnoConst.NAMEDENTITY:
                for (ExportedTag tag : tagSet.getTags()) {
                    neTags.add(tag.getName());
                    neTagDescriptions.add(tag.getDescription());
                }
                break;
            case WebAnnoConst.COREFRELTYPE:
                for (ExportedTag tag : tagSet.getTags()) {
                    corefTypeTags.add(tag.getName());
                }
                break;
            case WebAnnoConst.COREFERENCE:
                for (ExportedTag tag : tagSet.getTags()) {
                    corefRelTags.add(tag.getName());
                }
                break;
        }
    }
    new LegacyProjectInitializer(aAnnotationService).initialize(aProject, posTags.toArray(new String[0]), posTagDescriptions.toArray(new String[0]), depTags.toArray(new String[0]), depTagDescriptions.toArray(new String[0]), neTags.toArray(new String[0]), neTagDescriptions.toArray(new String[0]), corefTypeTags.toArray(new String[0]), corefRelTags.toArray(new String[0]));
}
Also used : ExportedTagSet(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet) ArrayList(java.util.ArrayList) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag)

Example 8 with ExportedTag

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag 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

ExportedTag (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag)8 Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)7 ExportedTagSet (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet)6 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)6 ArrayList (java.util.ArrayList)4 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)2 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)2 MiraTemplate (de.tudarmstadt.ukp.clarin.webanno.automation.model.MiraTemplate)1 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.export.model.AnnotationDocument)1 ProjectPermission (de.tudarmstadt.ukp.clarin.webanno.export.model.ProjectPermission)1 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.export.model.SourceDocument)1 Mode (de.tudarmstadt.ukp.clarin.webanno.model.Mode)1 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)1 TrainingDocument (de.tudarmstadt.ukp.clarin.webanno.model.TrainingDocument)1 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1