Skip to content

Commit

Permalink
Merge pull request #5060 from inception-project/feature/5056-Ability-…
Browse files Browse the repository at this point in the history
…to-configure-additional-languages-for-knowledge-bases

#5056 - Ability to configure additional languages for knowledge bases
  • Loading branch information
reckart authored Sep 21, 2024
2 parents b1b689e + 7d05497 commit ed1d8b4
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.wicketstuff.kendo.ui.renderer.ChoiceRenderer;

import de.tudarmstadt.ukp.clarin.webanno.model.ReorderableTag;
import de.tudarmstadt.ukp.clarin.webanno.model.TagSet;
import de.tudarmstadt.ukp.inception.annotation.feature.misc.ConstraintsInUseIndicator;
import de.tudarmstadt.ukp.inception.annotation.feature.string.KendoChoiceDescriptionScriptReference;
import de.tudarmstadt.ukp.inception.annotation.feature.string.StringFeatureSupportProperties;
Expand Down Expand Up @@ -228,11 +227,11 @@ public FormComponent getFocusComponent()
private List<ReorderableTag> getChoices(final IModel<FeatureState> aFeatureStateModel,
String aInput)
{
String input = aInput != null ? aInput.trim() : "";
var input = aInput != null ? aInput.trim() : "";

FeatureState featureState = aFeatureStateModel.getObject();
TagSet tagset = featureState.getFeature().getTagset();
List<ReorderableTag> choices = new ArrayList<>();
var featureState = aFeatureStateModel.getObject();
var tagset = featureState.getFeature().getTagset();
var choices = new ArrayList<ReorderableTag>();

Collection<String> values;
if (featureState.getValue() instanceof Collection) {
Expand All @@ -254,37 +253,36 @@ private List<ReorderableTag> getChoices(final IModel<FeatureState> aFeatureState

// If the currently selected values contain any values not covered by the tagset,
// add virtual entries for them as well
for (String value : values) {
for (var value : values) {
if (!choices.stream().anyMatch(t -> t.getName().equals(value))) {
choices.add(new ReorderableTag(value, false));
}
}

if (!input.isEmpty()) {
// Move any entries that match the input case-insensitive to the top
List<ReorderableTag> inputMatchesInsensitive = choices.stream() //
var inputMatchesInsensitive = choices.stream() //
.filter(t -> t.getName().equalsIgnoreCase(input)) //
.collect(toList());
for (ReorderableTag t : inputMatchesInsensitive) {
for (var t : inputMatchesInsensitive) {
choices.remove(t);
choices.add(0, t);
}

// Move any entries that match the input case-sensitive to the top
List<ReorderableTag> inputMatchesSensitive = choices.stream() //
var inputMatchesSensitive = choices.stream() //
.filter(t -> t.getName().equals(input)) //
.collect(toList());
if (inputMatchesSensitive.isEmpty()) {
// If the input does not match any tagset entry, add a new virtual entry for
// the
// input so that we can select that and add it - this has no description.
// the input so that we can select that and add it - this has no description.
// If the input matches an existing entry, move it to the top.
if (tagset == null || tagset.isCreateTag()) {
choices.add(0, new ReorderableTag(input, false));
}
}
else {
for (ReorderableTag t : inputMatchesSensitive) {
for (var t : inputMatchesSensitive) {
choices.remove(t);
choices.add(0, t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public MultiValueStringFeatureTraitsEditor(String aId,

traits = CompoundPropertyModel.of(getFeatureSupport().readTraits(feature.getObject()));

Form<MultiValueStringFeatureTraits> form = new Form<MultiValueStringFeatureTraits>(MID_FORM,
traits)
var form = new Form<MultiValueStringFeatureTraits>(MID_FORM, traits)
{
private static final long serialVersionUID = -3109239605783291123L;

Expand All @@ -74,7 +73,7 @@ protected void onSubmit()
form.setOutputMarkupPlaceholderTag(true);
add(form);

DropDownChoice<TagSet> tagset = new DropDownChoice<>("tagset");
var tagset = new DropDownChoice<TagSet>("tagset");
tagset.setOutputMarkupPlaceholderTag(true);
tagset.setChoiceRenderer(new ChoiceRenderer<>("name"));
tagset.setNullValid(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public class ExportedKnowledgeBase
@JsonProperty("additional_matching_properties")
private List<String> additionalMatchingProperties;

@JsonProperty("additional_languages")
private List<String> additionalLanguages;

@JsonProperty("default_language")
private String defaultLanguage;

Expand Down Expand Up @@ -314,6 +317,16 @@ public List<String> getAdditionalMatchingProperties()
return additionalMatchingProperties;
}

public void setAdditionalLanguages(List<String> aAdditionalLanguages)
{
additionalLanguages = aAdditionalLanguages;
}

public List<String> getAdditionalLanguages()
{
return additionalLanguages;
}

public String getDefaultLanguage()
{
return defaultLanguage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void exportData(FullProjectExportRequest aRequest, ProjectExportTaskMonit
exportedKB.setRootConcepts(new ArrayList<>(kb.getRootConcepts()));
exportedKB.setAdditionalMatchingProperties(
new ArrayList<>(kb.getAdditionalMatchingProperties()));
exportedKB.setAdditionalLanguages(new ArrayList<>(kb.getAdditionalLanguages()));
exportedKB.setDefaultLanguage(kb.getDefaultLanguage());
exportedKB.setDefaultDatasetIri(
kb.getDefaultDatasetIri() != null ? kb.getDefaultDatasetIri() : null);
Expand Down Expand Up @@ -242,6 +243,13 @@ public void importData(ProjectImportRequest aRequest, Project aProject,
kb.setAdditionalMatchingProperties(new ArrayList<>());
}

if (exportedKB.getAdditionalLanguages() != null) {
kb.setAdditionalLanguages(exportedKB.getAdditionalLanguages());
}
else {
kb.setAdditionalLanguages(new ArrayList<>());
}

kb.setDefaultLanguage(exportedKB.getDefaultLanguage());
kb.setDefaultDatasetIri(
exportedKB.getDefaultDatasetIri() != null ? exportedKB.getDefaultDatasetIri() //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ public class KnowledgeBase
@Column
private String defaultLanguage;

@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "knowledgebase_add_languages")
@Column(name = "name")
private Set<String> additionalLanguages = new LinkedHashSet<>();

/**
* Limits the number of results that can be retrieved from a SPARQL query.
*/
Expand All @@ -223,39 +228,39 @@ public String getRepositoryId()
return repositoryId;
}

public void setRepositoryId(String repositoryId)
public void setRepositoryId(String aRepositoryId)
{
this.repositoryId = repositoryId;
repositoryId = aRepositoryId;
}

public Project getProject()
{
return project;
}

public void setProject(Project project)
public void setProject(Project aProject)
{
this.project = project;
project = aProject;
}

public String getName()
{
return name;
}

public void setName(String name)
public void setName(String aName)
{
this.name = name;
name = aName;
}

public RepositoryType getType()
{
return type;
}

public void setType(RepositoryType type)
public void setType(RepositoryType aType)
{
this.type = type;
type = aType;
}

public String getClassIri()
Expand Down Expand Up @@ -487,6 +492,16 @@ public void applyAdditionalMatchingProperties(KnowledgeBaseProfile aProfile)
}
}

public void applyAdditionalLanguages(KnowledgeBaseProfile aProfile)
{
if (aProfile.getAdditionalLanguages() == null) {
additionalLanguages = emptySet();
}
else {
additionalLanguages = new LinkedHashSet<>(aProfile.getAdditionalLanguages());
}
}

public String getDefaultDatasetIri()
{
return defaultDatasetIri;
Expand Down Expand Up @@ -517,6 +532,19 @@ public Set<String> getAdditionalMatchingProperties()
return additionalMatchingProperties;
}

public void setAdditionalLanguages(Collection<String> aAdditionalLanguages)
{
additionalLanguages = new LinkedHashSet<>();
if (aAdditionalLanguages != null) {
additionalLanguages.addAll(aAdditionalLanguages);
}
}

public Set<String> getAdditionalLanguages()
{
return additionalLanguages;
}

public boolean isUseFuzzy()
{
return useFuzzy;
Expand Down
Loading

0 comments on commit ed1d8b4

Please sign in to comment.