use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet in project webanno by webanno.
the class JsonImportUtil method createTagSet.
public static TagSet createTagSet(Project project, ExportedTagSet importedTagSet, AnnotationSchemaService aAnnotationService) throws IOException {
String importedTagSetName = importedTagSet.getName();
if (aAnnotationService.existsTagSet(importedTagSetName, project)) {
// aAnnotationService.removeTagSet(aAnnotationService.getTagSet(
// importedTagSet.getName(), project));
// Rename Imported TagSet instead of deleting the old one.
importedTagSetName = copyTagSetName(aAnnotationService, importedTagSetName, project);
}
TagSet newTagSet = new TagSet();
newTagSet.setDescription(importedTagSet.getDescription());
newTagSet.setName(importedTagSetName);
newTagSet.setLanguage(importedTagSet.getLanguage());
newTagSet.setProject(project);
newTagSet.setCreateTag(importedTagSet.isCreateTag());
aAnnotationService.createTagSet(newTagSet);
for (ExportedTag tag : importedTagSet.getTags()) {
Tag newTag = new Tag();
newTag.setDescription(tag.getDescription());
newTag.setName(tag.getName());
newTag.setTagSet(newTagSet);
aAnnotationService.createTag(newTag);
}
return newTagSet;
}
use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet in project webanno by webanno.
the class JsonImportUtil method importTagSetFromJson.
public static TagSet importTagSetFromJson(Project project, InputStream tagInputStream, AnnotationSchemaService aAnnotationService) throws IOException {
String text = IOUtils.toString(tagInputStream, "UTF-8");
ExportedTagSet importedTagSet = JSONUtil.getJsonConverter().getObjectMapper().readValue(text, ExportedTagSet.class);
return createTagSet(project, importedTagSet, aAnnotationService);
}
use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet 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.ExportedTagSet 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.ExportedTagSet 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