Skip to content

Commit

Permalink
#3474 - Tagset export dropdown disappears when selecting format
Browse files Browse the repository at this point in the history
- 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
reckart committed Dec 6, 2022
1 parent 562a31a commit b3b4dac
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.tudarmstadt.ukp.clarin.webanno.project.initializers;
package de.tudarmstadt.ukp.inception.export;

import java.io.IOException;
import java.io.InputStream;
Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,6 @@
*/
public class ExportedTagSetConstant
{
/**
* Export/import tagsets in JSON format
*/
public static final String JSON_FORMAT = "JSON";

/**
* Export/Import TagSets in TAB separated format where the first five lines are information
* about the tagsets such as tagsetname, tagsetdescrition and the remaining lines are tag with
* optional tag descriptions. The format looks like:<br>
*
* <pre>
* tagSetName TAGSETNAME
* tagSetDescription DESCRIPTION
* ...
* TAG1 &lt;optional&gt;TAG1Description
* ....
* </pre>
*/
public static final String TAB_FORMAT = "TAB-sep";

/**
* The key for the tagsetNAme
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package de.tudarmstadt.ukp.clarin.webanno.project.initializers;

import static de.tudarmstadt.ukp.clarin.webanno.project.initializers.JsonImportUtil.importTagSetFromJson;
import static de.tudarmstadt.ukp.inception.export.JsonImportUtil.importTagSetFromJson;

import java.io.IOException;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package de.tudarmstadt.ukp.clarin.webanno.project.initializers;

import static de.tudarmstadt.ukp.clarin.webanno.project.initializers.JsonImportUtil.importTagSetFromJson;
import static de.tudarmstadt.ukp.inception.export.JsonImportUtil.importTagSetFromJson;

import java.io.IOException;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package de.tudarmstadt.ukp.clarin.webanno.project.initializers;

import static de.tudarmstadt.ukp.clarin.webanno.project.initializers.JsonImportUtil.importTagSetFromJson;
import static de.tudarmstadt.ukp.inception.export.JsonImportUtil.importTagSetFromJson;

import java.io.IOException;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package de.tudarmstadt.ukp.clarin.webanno.project.initializers;

import static de.tudarmstadt.ukp.clarin.webanno.project.initializers.JsonImportUtil.importTagSetFromJson;
import static de.tudarmstadt.ukp.inception.export.JsonImportUtil.importTagSetFromJson;

import java.io.IOException;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package de.tudarmstadt.ukp.clarin.webanno.project.initializers;

import static de.tudarmstadt.ukp.clarin.webanno.project.initializers.JsonImportUtil.importTagSetFromJson;
import static de.tudarmstadt.ukp.inception.export.JsonImportUtil.importTagSetFromJson;

import java.io.IOException;
import java.util.Collections;
Expand Down
4 changes: 4 additions & 0 deletions inception/inception-ui-tagsets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,41 @@
<wicket:message key="tagset.details"/>
<div class="actions">
<span class="dropdown" aria-haspopup="true" aria-expanded="false">
<button class="btn btn-secondary btn-action dropdown-toggle flex-content" type="button" data-bs-toggle="dropdown">
<i class="fas fa-download"></i>&nbsp;
<button class="btn btn-secondary btn-action dropdown-toggle text-nowrap" type="button" data-bs-toggle="dropdown">
<i class="fas fa-download pe-1"/>
<wicket:message key="export"/>
</button>
<div class="dropdown-menu shadow-lg pt-0 pb-0" role="menu" style="min-width: 220px;">
<div class="container">
<div class="row form-row">
<div wicket:id="format" class="small"></div>
</div>
<div class="row form-row">
<button wicket:id="export" class="btn btn-sm btn-primary col-sm-12">
<i class="fas fa-download"></i>&nbsp;
<wicket:message key="export"/>
</button>
</div>
</div>
</div>
<ul class="dropdown-menu shadow-lg pt-0 pb-0" role="menu" style="min-width: 220px;">
<li>
<a wicket:id="exportTagsetAsJson" class="dropdown-item">
<wicket:message key="exportTagsetAsJson"/>
</a>
</li>
<li>
<a wicket:id="exportTagsetAsTabSeparated" class="dropdown-item">
<wicket:message key="exportTagsetAsTabSeparated"/>
</a>
</li>
</ul>
</span>
<button wicket:id="save" class="btn btn-primary">
<i class="fas fa-save"></i>&nbsp;
<button wicket:id="save" class="btn btn-primary text-nowrap">
<i class="fas fa-save pe-1"/>
<wicket:message key="save"/>
</button>
<button wicket:id="cancel" class="btn btn-secondary">
<i class="fas fa-times"></i>&nbsp;
<button wicket:id="cancel" class="btn btn-secondary text-nowrap">
<i class="fas fa-times pe-1"/>
<wicket:message key="cancel"/>
</button>
<span class="dropdown" aria-haspopup="true" aria-expanded="false">
<button class="btn btn-action dropdown-toggle flex-content" type="button" data-bs-toggle="dropdown">
<i class="fas fa-ellipsis-v"></i>
<i class="fas fa-ellipsis-v"/>
</button>
<ul class="dropdown-menu shadow-lg" role="menu" style="min-width: 220px;">
<li>
<button wicket:id="delete" class="dropdown-item" type="button">
<wicket:message key="delete"/>
<span class="float-end badge badge-pill bg-danger">
<i class="fas fa-trash"></i>
<i class="fas fa-trash"/>
</span>
</button>
</li>
Expand Down Expand Up @@ -98,7 +97,7 @@
<div class="form-check">
<input class="form-check-input" type="checkbox" wicket:id="createTag">
<label class="form-check-label" wicket:for="createTag">
Annotators may add new tags
<wicket:message key="allowTagCreation"/>
</label>
</div>
</div>
Expand Down
Loading

0 comments on commit b3b4dac

Please sign in to comment.