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