-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3474 - Tagset export dropdown disappears when selecting format
- Clicking on a format directly downloads the tagset - selection via a radio-group is no longer necessary - Importing a tagset auto-detects the format - choosing a format is no longer necessary - Improve layout of various buttons - Extract more code from UI layer to service / utils
- Loading branch information
Showing
16 changed files
with
254 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...ion-export/src/main/java/de/tudarmstadt/ukp/inception/export/TagsetImportExportUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Licensed to the Technische Universität Darmstadt under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The Technische Universität Darmstadt | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.tudarmstadt.ukp.inception.export; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
|
||
import de.tudarmstadt.ukp.clarin.webanno.model.Project; | ||
import de.tudarmstadt.ukp.clarin.webanno.model.Tag; | ||
import de.tudarmstadt.ukp.clarin.webanno.model.TagSet; | ||
import de.tudarmstadt.ukp.inception.schema.AnnotationSchemaService; | ||
|
||
public class TagsetImportExportUtils | ||
{ | ||
public static TagSet importTagsetFromTabSeparated(AnnotationSchemaService annotationService, | ||
Project project, InputStream aInputStream, boolean aOverwrite) | ||
throws IOException | ||
{ | ||
String text = IOUtils.toString(aInputStream, UTF_8); | ||
Map<String, String> tabbedTagsetFromFile = LayerImportExportUtils.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) { | ||
// the first key is the tagset name and its | ||
// description | ||
if (i == 0) { | ||
tagSetName = key; | ||
tagSetDescription = tabbedTagsetFromFile.get(key); | ||
} | ||
// the second key is the tagset language | ||
else if (i == 1) { | ||
tagsetLanguage = key; | ||
// remove and replace the tagset if it | ||
// exist | ||
if (annotationService.existsTagSet(tagSetName, project)) { | ||
// If overwrite is enabled | ||
if (aOverwrite) { | ||
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); | ||
} | ||
// otherwise it is a tag entry, add the tag to the tagset | ||
else { | ||
Tag tag = new Tag(); | ||
tag.setName(key); | ||
tag.setDescription(tabbedTagsetFromFile.get(key).replace("\\n", "\n")); | ||
tag.setRank(i); | ||
tag.setTagSet(tagSet); | ||
annotationService.createTag(tag); | ||
} | ||
i++; | ||
} | ||
|
||
return tagSet; | ||
} | ||
|
||
public static TagSet importTagsetFromJson(AnnotationSchemaService annotationService, | ||
Project project, InputStream aInputStream, boolean aOverwrite) | ||
throws IOException | ||
{ | ||
if (aOverwrite) { | ||
return JsonImportUtil.importTagSetFromJsonWithOverwrite(project, aInputStream, | ||
annotationService); | ||
} | ||
else { | ||
return JsonImportUtil.importTagSetFromJson(project, aInputStream, annotationService); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.