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);
}
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]));
}
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;
}
Aggregations