Improve support for terms in schema

This commit is contained in:
Antonin Delpeuch 2018-01-02 18:39:12 +01:00
parent 5e99e0d2e3
commit f6eceefd8e
5 changed files with 49 additions and 17 deletions

View File

@ -301,6 +301,7 @@ SchemaAlignmentDialog._addNameDesc = function(item, json) {
.attr('value', 'ALIAS')
.text('Alias')
.appendTo(type_input);
type_input.val(type);
var toolbar = $('<div></div>').addClass('wbs-toolbar').appendTo(namedesc);
$('<img src="images/close.png" />').attr('alt', 'remove name/description').click(function() {
@ -317,10 +318,10 @@ SchemaAlignmentDialog._nameDescToJSON = function (namedesc) {
var type = namedesc.find('select').first().val();
var value = namedesc.find('.wbs-namedesc-value').first().data("jsonValue");
return {
type: "wbnamedescexpr",
type: "wbnamedescexpr",
name_type: type,
value: value,
}
};
}
@ -551,7 +552,7 @@ SchemaAlignmentDialog._getPropertyType = function(pid, callback) {
props: "datatype",
},
dataType: "jsonp",
success: function(data) {
success: function(data) {
callback(data.entities[pid].datatype);
}});
}
@ -884,7 +885,7 @@ $.suggest("langsuggest", {
success: function(data) {
self.response(self.convertResults(data));
},
dataType: "jsonp",
dataType: "jsonp",
};
$.ajax(ajax_options);
},

View File

@ -76,6 +76,7 @@ public class QuickStatementsExporter implements WriterExporter {
if (item.getItemId().getId() == "Q0") {
writer.write("CREATE\n");
qid = "LAST";
item.normalizeLabelsAndAliases();
}
translateNameDescr(qid, item.getLabels(), "L", item.getItemId(), writer);

View File

@ -156,4 +156,28 @@ public class ItemUpdate {
}
return map;
}
/**
* This should only be used when creating a new item.
* This ensures that we never add an alias without adding
* a label in the same language.
*/
public void normalizeLabelsAndAliases() {
// Ensure that we are only adding aliases with labels
List<String> labelLanguages = new ArrayList<String>();
for(MonolingualTextValue label : labels) {
labelLanguages.add(label.getLanguageCode());
}
List<MonolingualTextValue> filteredAliases = new ArrayList<>();
for(MonolingualTextValue alias : aliases) {
if(!labelLanguages.contains(alias.getLanguageCode())) {
labelLanguages.add(alias.getLanguageCode());
labels.add(alias);
} else {
filteredAliases.add(alias);
}
}
aliases = filteredAliases;
}
}

View File

@ -23,8 +23,10 @@ public abstract class WbLanguageExpr extends BiJsonizable {
String type = obj.getString(jsonTypeKey);
if (WbLanguageConstant.jsonType.equals(type)) {
return WbLanguageConstant.fromJSON(obj);
} else if (WbLanguageVariable.jsonType.equals(type)) {
return WbLanguageVariable.fromJSON(obj);
} else {
throw new JSONException("unknown type for WbLocationExpr");
throw new JSONException("unknown type for WbLanguageExpr");
}
}
}

View File

@ -35,18 +35,22 @@ public class WbNameDescExpr extends BiJsonizable {
_value.write(writer, options);
}
public void contributeTo(ItemUpdate item, ExpressionContext ctxt) throws SkipStatementException {
MonolingualTextValue val = _value.evaluate(ctxt);
switch (_type) {
case LABEL:
item.addLabel(val);
break;
case DESCRIPTION:
item.addDescription(val);
break;
case ALIAS:
item.addAlias(val);
break;
public void contributeTo(ItemUpdate item, ExpressionContext ctxt) {
try {
MonolingualTextValue val = _value.evaluate(ctxt);
switch (_type) {
case LABEL:
item.addLabel(val);
break;
case DESCRIPTION:
item.addDescription(val);
break;
case ALIAS:
item.addAlias(val);
break;
}
} catch (SkipStatementException e) {
return;
}
}