Add support for conditional label and term updates, for issue #2063.
This commit is contained in:
parent
203cf8c20e
commit
05839b1bbf
@ -142,8 +142,15 @@ public class EditBatchProcessor {
|
|||||||
} else {
|
} else {
|
||||||
// Existing item
|
// Existing item
|
||||||
ItemDocument currentDocument = (ItemDocument) currentDocs.get(update.getItemId().getId());
|
ItemDocument currentDocument = (ItemDocument) currentDocs.get(update.getItemId().getId());
|
||||||
editor.updateTermsStatements(currentDocument, update.getLabels().stream().collect(Collectors.toList()),
|
List<MonolingualTextValue> labels = update.getLabels().stream().collect(Collectors.toList());
|
||||||
update.getDescriptions().stream().collect(Collectors.toList()),
|
labels.addAll(update.getLabelsIfNew().stream()
|
||||||
|
.filter(label -> !currentDocument.getLabels().containsKey(label.getLanguageCode())).collect(Collectors.toList()));
|
||||||
|
List<MonolingualTextValue> descriptions = update.getDescriptions().stream().collect(Collectors.toList());
|
||||||
|
descriptions.addAll(update.getDescriptionsIfNew().stream()
|
||||||
|
.filter(desc -> !currentDocument.getDescriptions().containsKey(desc.getLanguageCode())).collect(Collectors.toList()));
|
||||||
|
editor.updateTermsStatements(currentDocument,
|
||||||
|
labels,
|
||||||
|
descriptions,
|
||||||
update.getAliases().stream().collect(Collectors.toList()),
|
update.getAliases().stream().collect(Collectors.toList()),
|
||||||
new ArrayList<MonolingualTextValue>(),
|
new ArrayList<MonolingualTextValue>(),
|
||||||
update.getAddedStatements().stream().collect(Collectors.toList()),
|
update.getAddedStatements().stream().collect(Collectors.toList()),
|
||||||
|
@ -90,13 +90,16 @@ public class ReconEntityRewriter extends DatamodelConverter {
|
|||||||
|
|
||||||
public ItemUpdate rewrite(ItemUpdate update) {
|
public ItemUpdate rewrite(ItemUpdate update) {
|
||||||
Set<MonolingualTextValue> labels = update.getLabels().stream().map(l -> copy(l)).collect(Collectors.toSet());
|
Set<MonolingualTextValue> labels = update.getLabels().stream().map(l -> copy(l)).collect(Collectors.toSet());
|
||||||
|
Set<MonolingualTextValue> labelsIfNew = update.getLabelsIfNew().stream().map(l -> copy(l)).collect(Collectors.toSet());
|
||||||
Set<MonolingualTextValue> descriptions = update.getDescriptions().stream().map(l -> copy(l))
|
Set<MonolingualTextValue> descriptions = update.getDescriptions().stream().map(l -> copy(l))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
Set<MonolingualTextValue> descriptionsIfNew = update.getDescriptionsIfNew().stream().map(l -> copy(l))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
Set<MonolingualTextValue> aliases = update.getAliases().stream().map(l -> copy(l)).collect(Collectors.toSet());
|
Set<MonolingualTextValue> aliases = update.getAliases().stream().map(l -> copy(l)).collect(Collectors.toSet());
|
||||||
List<Statement> addedStatements = update.getAddedStatements().stream().map(l -> copy(l))
|
List<Statement> addedStatements = update.getAddedStatements().stream().map(l -> copy(l))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
Set<Statement> deletedStatements = update.getDeletedStatements().stream().map(l -> copy(l))
|
Set<Statement> deletedStatements = update.getDeletedStatements().stream().map(l -> copy(l))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
return new ItemUpdate(update.getItemId(), addedStatements, deletedStatements, labels, descriptions, aliases);
|
return new ItemUpdate(update.getItemId(), addedStatements, deletedStatements, labels, labelsIfNew, descriptions, descriptionsIfNew, aliases);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,9 @@ public class QuickStatementsExporter implements WriterExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
translateNameDescr(qid, item.getLabels(), "L", item.getItemId(), writer);
|
translateNameDescr(qid, item.getLabels(), "L", item.getItemId(), writer);
|
||||||
|
translateNameDescr(qid, item.getLabelsIfNew(), "L", item.getItemId(), writer);
|
||||||
translateNameDescr(qid, item.getDescriptions(), "D", item.getItemId(), writer);
|
translateNameDescr(qid, item.getDescriptions(), "D", item.getItemId(), writer);
|
||||||
|
translateNameDescr(qid, item.getDescriptionsIfNew(), "D", item.getItemId(), writer);
|
||||||
translateNameDescr(qid, item.getAliases(), "A", item.getItemId(), writer);
|
translateNameDescr(qid, item.getAliases(), "A", item.getItemId(), writer);
|
||||||
|
|
||||||
for (Statement s : item.getAddedStatements()) {
|
for (Statement s : item.getAddedStatements()) {
|
||||||
|
@ -45,13 +45,13 @@ public class NewItemScrutinizer extends EditScrutinizer {
|
|||||||
if (update.isNew()) {
|
if (update.isNew()) {
|
||||||
info(newItemType);
|
info(newItemType);
|
||||||
|
|
||||||
if (update.getLabels().isEmpty() && update.getAliases().isEmpty()) {
|
if (update.getLabels().isEmpty() && update.getLabelsIfNew().isEmpty() && update.getAliases().isEmpty()) {
|
||||||
QAWarning issue = new QAWarning(noLabelType, null, QAWarning.Severity.CRITICAL, 1);
|
QAWarning issue = new QAWarning(noLabelType, null, QAWarning.Severity.CRITICAL, 1);
|
||||||
issue.setProperty("example_entity", update.getItemId());
|
issue.setProperty("example_entity", update.getItemId());
|
||||||
addIssue(issue);
|
addIssue(issue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update.getDescriptions().isEmpty()) {
|
if (update.getDescriptions().isEmpty() && update.getDescriptionsIfNew().isEmpty()) {
|
||||||
QAWarning issue = new QAWarning(noDescType, null, QAWarning.Severity.WARNING, 1);
|
QAWarning issue = new QAWarning(noDescType, null, QAWarning.Severity.WARNING, 1);
|
||||||
issue.setProperty("example_entity", update.getItemId());
|
issue.setProperty("example_entity", update.getItemId());
|
||||||
addIssue(issue);
|
addIssue(issue);
|
||||||
|
@ -43,15 +43,15 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class WbNameDescExpr {
|
public class WbNameDescExpr {
|
||||||
|
|
||||||
enum NameDescrType {
|
enum NameDescType {
|
||||||
LABEL, DESCRIPTION, ALIAS,
|
LABEL, LABEL_IF_NEW, DESCRIPTION, DESCRIPTION_IF_NEW, ALIAS,
|
||||||
}
|
}
|
||||||
|
|
||||||
private NameDescrType type;
|
private NameDescType type;
|
||||||
private WbMonolingualExpr value;
|
private WbMonolingualExpr value;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public WbNameDescExpr(@JsonProperty("name_type") NameDescrType type,
|
public WbNameDescExpr(@JsonProperty("name_type") NameDescType type,
|
||||||
@JsonProperty("value") WbMonolingualExpr value) {
|
@JsonProperty("value") WbMonolingualExpr value) {
|
||||||
Validate.notNull(type);
|
Validate.notNull(type);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -72,11 +72,17 @@ public class WbNameDescExpr {
|
|||||||
MonolingualTextValue val = getValue().evaluate(ctxt);
|
MonolingualTextValue val = getValue().evaluate(ctxt);
|
||||||
switch (getType()) {
|
switch (getType()) {
|
||||||
case LABEL:
|
case LABEL:
|
||||||
item.addLabel(val);
|
item.addLabel(val, true);
|
||||||
break;
|
break;
|
||||||
|
case LABEL_IF_NEW:
|
||||||
|
item.addLabel(val, false);
|
||||||
|
break;
|
||||||
case DESCRIPTION:
|
case DESCRIPTION:
|
||||||
item.addDescription(val);
|
item.addDescription(val, true);
|
||||||
break;
|
break;
|
||||||
|
case DESCRIPTION_IF_NEW:
|
||||||
|
item.addDescription(val, false);
|
||||||
|
break;
|
||||||
case ALIAS:
|
case ALIAS:
|
||||||
item.addAlias(val);
|
item.addAlias(val);
|
||||||
break;
|
break;
|
||||||
@ -87,7 +93,7 @@ public class WbNameDescExpr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty("name_type")
|
@JsonProperty("name_type")
|
||||||
public NameDescrType getType() {
|
public NameDescType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,9 @@ public class ItemUpdate {
|
|||||||
private final List<Statement> addedStatements;
|
private final List<Statement> addedStatements;
|
||||||
private final Set<Statement> deletedStatements;
|
private final Set<Statement> deletedStatements;
|
||||||
private final Map<String, MonolingualTextValue> labels;
|
private final Map<String, MonolingualTextValue> labels;
|
||||||
|
private final Map<String, MonolingualTextValue> labelsIfNew;
|
||||||
private final Map<String, MonolingualTextValue> descriptions;
|
private final Map<String, MonolingualTextValue> descriptions;
|
||||||
|
private final Map<String, MonolingualTextValue> descriptionsIfNew;
|
||||||
private final Map<String, List<MonolingualTextValue>> aliases;
|
private final Map<String, List<MonolingualTextValue>> aliases;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,9 +78,13 @@ public class ItemUpdate {
|
|||||||
* @param deletedStatements
|
* @param deletedStatements
|
||||||
* the statements to remove from the item
|
* the statements to remove from the item
|
||||||
* @param labels
|
* @param labels
|
||||||
* the labels to add on the item
|
* the labels to add on the item, overriding any existing one in that language
|
||||||
|
* @param labelsIfNew
|
||||||
|
* the labels to add on the item, only if no label for that language exists
|
||||||
* @param descriptions
|
* @param descriptions
|
||||||
* the descriptions to add on the item
|
* the descriptions to add on the item, overriding any existing one in that language
|
||||||
|
* @param descriptionsIfNew
|
||||||
|
* the descriptions to add on the item, only if no description for that language exists
|
||||||
* @param aliases
|
* @param aliases
|
||||||
* the aliases to add on the item. In theory their order should
|
* the aliases to add on the item. In theory their order should
|
||||||
* matter but in practice people rarely rely on the order of aliases
|
* matter but in practice people rarely rely on the order of aliases
|
||||||
@ -89,7 +95,9 @@ public class ItemUpdate {
|
|||||||
@JsonProperty("addedStatements") List<Statement> addedStatements,
|
@JsonProperty("addedStatements") List<Statement> addedStatements,
|
||||||
@JsonProperty("deletedStatements") Set<Statement> deletedStatements,
|
@JsonProperty("deletedStatements") Set<Statement> deletedStatements,
|
||||||
@JsonProperty("labels") Set<MonolingualTextValue> labels,
|
@JsonProperty("labels") Set<MonolingualTextValue> labels,
|
||||||
|
@JsonProperty("labelsIfNew") Set<MonolingualTextValue> labelsIfNew,
|
||||||
@JsonProperty("descriptions") Set<MonolingualTextValue> descriptions,
|
@JsonProperty("descriptions") Set<MonolingualTextValue> descriptions,
|
||||||
|
@JsonProperty("descriptionsIfNew") Set<MonolingualTextValue> descriptionsIfNew,
|
||||||
@JsonProperty("addedAliases") Set<MonolingualTextValue> aliases) {
|
@JsonProperty("addedAliases") Set<MonolingualTextValue> aliases) {
|
||||||
Validate.notNull(qid);
|
Validate.notNull(qid);
|
||||||
this.qid = qid;
|
this.qid = qid;
|
||||||
@ -101,8 +109,12 @@ public class ItemUpdate {
|
|||||||
deletedStatements = Collections.emptySet();
|
deletedStatements = Collections.emptySet();
|
||||||
}
|
}
|
||||||
this.deletedStatements = deletedStatements;
|
this.deletedStatements = deletedStatements;
|
||||||
this.labels = constructTermMap(labels != null ? labels : Collections.emptyList());
|
this.labels = new HashMap<>();
|
||||||
this.descriptions = constructTermMap(descriptions != null ? descriptions : Collections.emptyList());
|
this.labelsIfNew = new HashMap<>();
|
||||||
|
mergeSingleTermMaps(this.labels, this.labelsIfNew, labels, labelsIfNew);
|
||||||
|
this.descriptions = new HashMap<>();
|
||||||
|
this.descriptionsIfNew = new HashMap<>();
|
||||||
|
mergeSingleTermMaps(this.descriptions, this.descriptionsIfNew, descriptions, descriptionsIfNew);
|
||||||
this.aliases = constructTermListMap(aliases != null ? aliases : Collections.emptyList());
|
this.aliases = constructTermListMap(aliases != null ? aliases : Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +131,13 @@ public class ItemUpdate {
|
|||||||
* @param deletedStatements
|
* @param deletedStatements
|
||||||
* the statements to delete
|
* the statements to delete
|
||||||
* @param labels
|
* @param labels
|
||||||
* the labels to add
|
* the labels to add on the item, overriding any existing one in that language
|
||||||
|
* @param labelsIfNew
|
||||||
|
* the labels to add on the item, only if no label for that language exists
|
||||||
|
* @param descriptions
|
||||||
|
* the descriptions to add on the item, overriding any existing one in that language
|
||||||
|
* @param descriptionsIfNew
|
||||||
|
* the descriptions to add on the item, only if no description for that language exists
|
||||||
* @param descriptions
|
* @param descriptions
|
||||||
* the descriptions to add
|
* the descriptions to add
|
||||||
* @param aliases
|
* @param aliases
|
||||||
@ -130,13 +148,17 @@ public class ItemUpdate {
|
|||||||
List<Statement> addedStatements,
|
List<Statement> addedStatements,
|
||||||
Set<Statement> deletedStatements,
|
Set<Statement> deletedStatements,
|
||||||
Map<String, MonolingualTextValue> labels,
|
Map<String, MonolingualTextValue> labels,
|
||||||
|
Map<String, MonolingualTextValue> labelsIfNew,
|
||||||
Map<String, MonolingualTextValue> descriptions,
|
Map<String, MonolingualTextValue> descriptions,
|
||||||
|
Map<String, MonolingualTextValue> descriptionsIfNew,
|
||||||
Map<String, List<MonolingualTextValue>> aliases) {
|
Map<String, List<MonolingualTextValue>> aliases) {
|
||||||
this.qid = qid;
|
this.qid = qid;
|
||||||
this.addedStatements = addedStatements;
|
this.addedStatements = addedStatements;
|
||||||
this.deletedStatements = deletedStatements;
|
this.deletedStatements = deletedStatements;
|
||||||
this.labels = labels;
|
this.labels = labels;
|
||||||
|
this.labelsIfNew = labelsIfNew;
|
||||||
this.descriptions = descriptions;
|
this.descriptions = descriptions;
|
||||||
|
this.descriptionsIfNew = descriptionsIfNew;
|
||||||
this.aliases = aliases;
|
this.aliases = aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,20 +190,36 @@ public class ItemUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the list of updated labels
|
* @return the list of updated labels, overriding existing ones
|
||||||
*/
|
*/
|
||||||
@JsonProperty("labels")
|
@JsonProperty("labels")
|
||||||
public Set<MonolingualTextValue> getLabels() {
|
public Set<MonolingualTextValue> getLabels() {
|
||||||
return labels.values().stream().collect(Collectors.toSet());
|
return labels.values().stream().collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the list of updated labels, only added if new
|
||||||
|
*/
|
||||||
|
@JsonProperty("labelsIfNew")
|
||||||
|
public Set<MonolingualTextValue> getLabelsIfNew() {
|
||||||
|
return labelsIfNew.values().stream().collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the list of updated descriptions
|
* @return the list of updated descriptions, overriding existing ones
|
||||||
*/
|
*/
|
||||||
@JsonProperty("descriptions")
|
@JsonProperty("descriptions")
|
||||||
public Set<MonolingualTextValue> getDescriptions() {
|
public Set<MonolingualTextValue> getDescriptions() {
|
||||||
return descriptions.values().stream().collect(Collectors.toSet());
|
return descriptions.values().stream().collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the list of updated descriptions, only added if new
|
||||||
|
*/
|
||||||
|
@JsonProperty("descriptionsIfNew")
|
||||||
|
public Set<MonolingualTextValue> getDescriptionsIfNew() {
|
||||||
|
return descriptionsIfNew.values().stream().collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the list of updated aliases
|
* @return the list of updated aliases
|
||||||
@ -228,13 +266,11 @@ public class ItemUpdate {
|
|||||||
Set<Statement> newDeletedStatements = new HashSet<>(deletedStatements);
|
Set<Statement> newDeletedStatements = new HashSet<>(deletedStatements);
|
||||||
newDeletedStatements.addAll(other.getDeletedStatements());
|
newDeletedStatements.addAll(other.getDeletedStatements());
|
||||||
Map<String,MonolingualTextValue> newLabels = new HashMap<>(labels);
|
Map<String,MonolingualTextValue> newLabels = new HashMap<>(labels);
|
||||||
for(MonolingualTextValue otherLabel : other.getLabels()) {
|
Map<String,MonolingualTextValue> newLabelsIfNew = new HashMap<>(labelsIfNew);
|
||||||
newLabels.put(otherLabel.getLanguageCode(), otherLabel);
|
mergeSingleTermMaps(newLabels, newLabelsIfNew, other.getLabels(), other.getLabelsIfNew());
|
||||||
}
|
|
||||||
Map<String,MonolingualTextValue> newDescriptions = new HashMap<>(descriptions);
|
Map<String,MonolingualTextValue> newDescriptions = new HashMap<>(descriptions);
|
||||||
for(MonolingualTextValue otherDescription : other.getDescriptions()) {
|
Map<String,MonolingualTextValue> newDescriptionsIfNew = new HashMap<>(descriptionsIfNew);
|
||||||
newDescriptions.put(otherDescription.getLanguageCode(), otherDescription);
|
mergeSingleTermMaps(newDescriptions, newDescriptionsIfNew, other.getDescriptions(), other.getDescriptionsIfNew());
|
||||||
}
|
|
||||||
Map<String,List<MonolingualTextValue>> newAliases = new HashMap<>(aliases);
|
Map<String,List<MonolingualTextValue>> newAliases = new HashMap<>(aliases);
|
||||||
for(MonolingualTextValue alias : other.getAliases()) {
|
for(MonolingualTextValue alias : other.getAliases()) {
|
||||||
List<MonolingualTextValue> aliases = newAliases.get(alias.getLanguageCode());
|
List<MonolingualTextValue> aliases = newAliases.get(alias.getLanguageCode());
|
||||||
@ -246,8 +282,8 @@ public class ItemUpdate {
|
|||||||
aliases.add(alias);
|
aliases.add(alias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ItemUpdate(qid, newAddedStatements, newDeletedStatements, newLabels, newDescriptions, newAliases);
|
return new ItemUpdate(qid, newAddedStatements, newDeletedStatements, newLabels, newLabelsIfNew, newDescriptions, newDescriptionsIfNew, newAliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Group added statements in StatementGroups: useful if the item is new.
|
* Group added statements in StatementGroups: useful if the item is new.
|
||||||
@ -309,16 +345,20 @@ public class ItemUpdate {
|
|||||||
public ItemUpdate normalizeLabelsAndAliases() {
|
public ItemUpdate normalizeLabelsAndAliases() {
|
||||||
// Ensure that we are only adding aliases with labels
|
// Ensure that we are only adding aliases with labels
|
||||||
Set<MonolingualTextValue> filteredAliases = new HashSet<>();
|
Set<MonolingualTextValue> filteredAliases = new HashSet<>();
|
||||||
Map<String, MonolingualTextValue> newLabels = new HashMap<>(labels);
|
Map<String, MonolingualTextValue> newLabels = new HashMap<>(labelsIfNew);
|
||||||
|
newLabels.putAll(labels);
|
||||||
for (MonolingualTextValue alias : getAliases()) {
|
for (MonolingualTextValue alias : getAliases()) {
|
||||||
if (!labels.containsKey(alias.getLanguageCode())) {
|
if (!newLabels.containsKey(alias.getLanguageCode())) {
|
||||||
newLabels.put(alias.getLanguageCode(), alias);
|
newLabels.put(alias.getLanguageCode(), alias);
|
||||||
} else {
|
} else {
|
||||||
filteredAliases.add(alias);
|
filteredAliases.add(alias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Map<String, MonolingualTextValue> newDescriptions = new HashMap<>(descriptionsIfNew);
|
||||||
|
newDescriptions.putAll(descriptions);
|
||||||
return new ItemUpdate(qid, addedStatements, deletedStatements,
|
return new ItemUpdate(qid, addedStatements, deletedStatements,
|
||||||
newLabels, descriptions, constructTermListMap(filteredAliases));
|
newLabels, Collections.emptyMap(), newDescriptions, Collections.emptyMap(),
|
||||||
|
constructTermListMap(filteredAliases));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -372,9 +412,35 @@ public class ItemUpdate {
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String,MonolingualTextValue> constructTermMap(Collection<MonolingualTextValue> mltvs) {
|
/**
|
||||||
return mltvs.stream()
|
* Helper function to merge dictionaries of terms to override or provide.
|
||||||
.collect(Collectors.toMap(MonolingualTextValue::getLanguageCode, Function.identity()));
|
* @param currentTerms
|
||||||
|
* current map of terms to override
|
||||||
|
* @param currentTermsIfNew
|
||||||
|
* current map of terms to provide if not already there
|
||||||
|
* @param newTerms
|
||||||
|
* new terms to override
|
||||||
|
* @param newTermsIfNew
|
||||||
|
* new terms to provide if not already there
|
||||||
|
*/
|
||||||
|
private static void mergeSingleTermMaps(
|
||||||
|
Map<String,MonolingualTextValue> currentTerms,
|
||||||
|
Map<String,MonolingualTextValue> currentTermsIfNew,
|
||||||
|
Set<MonolingualTextValue> newTerms,
|
||||||
|
Set<MonolingualTextValue> newTermsIfNew) {
|
||||||
|
for(MonolingualTextValue otherLabel : newTerms) {
|
||||||
|
String languageCode = otherLabel.getLanguageCode();
|
||||||
|
currentTerms.put(languageCode, otherLabel);
|
||||||
|
if (currentTermsIfNew.containsKey(languageCode)) {
|
||||||
|
currentTermsIfNew.remove(languageCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MonolingualTextValue otherLabel : newTermsIfNew) {
|
||||||
|
String languageCode = otherLabel.getLanguageCode();
|
||||||
|
if (!currentTermsIfNew.containsKey(languageCode) && !currentTerms.containsKey(languageCode)) {
|
||||||
|
currentTermsIfNew.put(languageCode, otherLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String, List<MonolingualTextValue>> constructTermListMap(Collection<MonolingualTextValue> mltvs) {
|
protected Map<String, List<MonolingualTextValue>> constructTermListMap(Collection<MonolingualTextValue> mltvs) {
|
||||||
|
@ -45,7 +45,9 @@ public class ItemUpdateBuilder {
|
|||||||
private List<Statement> addedStatements;
|
private List<Statement> addedStatements;
|
||||||
private Set<Statement> deletedStatements;
|
private Set<Statement> deletedStatements;
|
||||||
private Set<MonolingualTextValue> labels;
|
private Set<MonolingualTextValue> labels;
|
||||||
|
private Set<MonolingualTextValue> labelsIfNew;
|
||||||
private Set<MonolingualTextValue> descriptions;
|
private Set<MonolingualTextValue> descriptions;
|
||||||
|
private Set<MonolingualTextValue> descriptionsIfNew;
|
||||||
private Set<MonolingualTextValue> aliases;
|
private Set<MonolingualTextValue> aliases;
|
||||||
private boolean built;
|
private boolean built;
|
||||||
|
|
||||||
@ -62,7 +64,9 @@ public class ItemUpdateBuilder {
|
|||||||
this.addedStatements = new ArrayList<>();
|
this.addedStatements = new ArrayList<>();
|
||||||
this.deletedStatements = new HashSet<Statement>();
|
this.deletedStatements = new HashSet<Statement>();
|
||||||
this.labels = new HashSet<MonolingualTextValue>();
|
this.labels = new HashSet<MonolingualTextValue>();
|
||||||
|
this.labelsIfNew = new HashSet<MonolingualTextValue>();
|
||||||
this.descriptions = new HashSet<MonolingualTextValue>();
|
this.descriptions = new HashSet<MonolingualTextValue>();
|
||||||
|
this.descriptionsIfNew = new HashSet<MonolingualTextValue>();
|
||||||
this.aliases = new HashSet<MonolingualTextValue>();
|
this.aliases = new HashSet<MonolingualTextValue>();
|
||||||
this.built = false;
|
this.built = false;
|
||||||
}
|
}
|
||||||
@ -118,54 +122,74 @@ public class ItemUpdateBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a label to the item. It will override any existing label in this
|
* Adds a label to the item.
|
||||||
* language.
|
|
||||||
*
|
*
|
||||||
* @param label
|
* @param label
|
||||||
* the label to add
|
* the label to add
|
||||||
|
* @param override
|
||||||
|
* whether the label should be added even if there is already a label in that language
|
||||||
*/
|
*/
|
||||||
public ItemUpdateBuilder addLabel(MonolingualTextValue label) {
|
public ItemUpdateBuilder addLabel(MonolingualTextValue label, boolean override) {
|
||||||
Validate.isTrue(!built, "ItemUpdate has already been built");
|
Validate.isTrue(!built, "ItemUpdate has already been built");
|
||||||
labels.add(label);
|
if (override) {
|
||||||
|
labels.add(label);
|
||||||
|
} else {
|
||||||
|
labelsIfNew.add(label);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a list of labels to the item. It will override any existing label in
|
* Adds a list of labels to the item.
|
||||||
* each language.
|
|
||||||
*
|
*
|
||||||
* @param labels
|
* @param labels
|
||||||
* the labels to add
|
* the labels to add
|
||||||
|
* @param override
|
||||||
|
* whether the label should be added even if there is already a label in that language
|
||||||
*/
|
*/
|
||||||
public ItemUpdateBuilder addLabels(Set<MonolingualTextValue> labels) {
|
public ItemUpdateBuilder addLabels(Set<MonolingualTextValue> labels, boolean override) {
|
||||||
Validate.isTrue(!built, "ItemUpdate has already been built");
|
Validate.isTrue(!built, "ItemUpdate has already been built");
|
||||||
this.labels.addAll(labels);
|
if (override) {
|
||||||
|
this.labels.addAll(labels);
|
||||||
|
} else {
|
||||||
|
labelsIfNew.addAll(labels);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a description to the item. It will override any existing description in
|
* Adds a description to the item.
|
||||||
* this language.
|
|
||||||
*
|
*
|
||||||
* @param description
|
* @param description
|
||||||
* the description to add
|
* the description to add
|
||||||
|
* @param override
|
||||||
|
* whether the description should be added even if there is already a description in that language
|
||||||
*/
|
*/
|
||||||
public ItemUpdateBuilder addDescription(MonolingualTextValue description) {
|
public ItemUpdateBuilder addDescription(MonolingualTextValue description, boolean override) {
|
||||||
Validate.isTrue(!built, "ItemUpdate has already been built");
|
Validate.isTrue(!built, "ItemUpdate has already been built");
|
||||||
descriptions.add(description);
|
if (override) {
|
||||||
|
descriptions.add(description);
|
||||||
|
} else {
|
||||||
|
descriptionsIfNew.add(description);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a list of descriptions to the item. It will override any existing
|
* Adds a list of descriptions to the item.
|
||||||
* description in each language.
|
|
||||||
*
|
*
|
||||||
* @param descriptions
|
* @param descriptions
|
||||||
* the descriptions to add
|
* the descriptions to add
|
||||||
|
* @param override
|
||||||
|
* whether the description should be added even if there is already a description in that language
|
||||||
*/
|
*/
|
||||||
public ItemUpdateBuilder addDescriptions(Set<MonolingualTextValue> descriptions) {
|
public ItemUpdateBuilder addDescriptions(Set<MonolingualTextValue> descriptions, boolean override) {
|
||||||
Validate.isTrue(!built, "ItemUpdate has already been built");
|
Validate.isTrue(!built, "ItemUpdate has already been built");
|
||||||
this.descriptions.addAll(descriptions);
|
if (override) {
|
||||||
|
this.descriptions.addAll(descriptions);
|
||||||
|
} else {
|
||||||
|
descriptionsIfNew.addAll(descriptions);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +226,7 @@ public class ItemUpdateBuilder {
|
|||||||
*/
|
*/
|
||||||
public ItemUpdate build() {
|
public ItemUpdate build() {
|
||||||
built = true;
|
built = true;
|
||||||
return new ItemUpdate(qid, addedStatements, deletedStatements, labels, descriptions, aliases);
|
return new ItemUpdate(qid, addedStatements, deletedStatements, labels, labelsIfNew, descriptions, descriptionsIfNew, aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,11 @@ public class QuickStatementsUpdateScheduler implements UpdateScheduler {
|
|||||||
protected void splitUpdate(ItemUpdate update)
|
protected void splitUpdate(ItemUpdate update)
|
||||||
throws ImpossibleSchedulingException {
|
throws ImpossibleSchedulingException {
|
||||||
ItemUpdateBuilder remainingUpdateBuilder = new ItemUpdateBuilder(update.getItemId())
|
ItemUpdateBuilder remainingUpdateBuilder = new ItemUpdateBuilder(update.getItemId())
|
||||||
.addLabels(update.getLabels()).addDescriptions(update.getDescriptions()).addAliases(update.getAliases())
|
.addLabels(update.getLabels(), true)
|
||||||
|
.addLabels(update.getLabelsIfNew(), false)
|
||||||
|
.addDescriptions(update.getDescriptions(), true)
|
||||||
|
.addDescriptions(update.getDescriptionsIfNew(), false)
|
||||||
|
.addAliases(update.getAliases())
|
||||||
.deleteStatements(update.getDeletedStatements());
|
.deleteStatements(update.getDeletedStatements());
|
||||||
Map<ItemIdValue, ItemUpdateBuilder> referencingUpdates = new HashMap<>();
|
Map<ItemIdValue, ItemUpdateBuilder> referencingUpdates = new HashMap<>();
|
||||||
|
|
||||||
|
@ -98,8 +98,12 @@ public class WikibaseAPIUpdateScheduler implements UpdateScheduler {
|
|||||||
* @param update
|
* @param update
|
||||||
*/
|
*/
|
||||||
protected void splitUpdate(ItemUpdate update) {
|
protected void splitUpdate(ItemUpdate update) {
|
||||||
ItemUpdateBuilder pointerFreeBuilder = new ItemUpdateBuilder(update.getItemId()).addLabels(update.getLabels())
|
ItemUpdateBuilder pointerFreeBuilder = new ItemUpdateBuilder(update.getItemId())
|
||||||
.addDescriptions(update.getDescriptions()).addAliases(update.getAliases())
|
.addLabels(update.getLabels(), true)
|
||||||
|
.addLabels(update.getLabelsIfNew(), false)
|
||||||
|
.addDescriptions(update.getDescriptions(), true)
|
||||||
|
.addDescriptions(update.getDescriptionsIfNew(), false)
|
||||||
|
.addAliases(update.getAliases())
|
||||||
.deleteStatements(update.getDeletedStatements());
|
.deleteStatements(update.getDeletedStatements());
|
||||||
ItemUpdateBuilder pointerFullBuilder = new ItemUpdateBuilder(update.getItemId());
|
ItemUpdateBuilder pointerFullBuilder = new ItemUpdateBuilder(update.getItemId());
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ public class EditBatchProcessorTest extends RefineTest {
|
|||||||
List<ItemIdValue> qids = ids.stream().map(e -> Datamodel.makeWikidataItemIdValue(e))
|
List<ItemIdValue> qids = ids.stream().map(e -> Datamodel.makeWikidataItemIdValue(e))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<ItemUpdate> batch = qids.stream()
|
List<ItemUpdate> batch = qids.stream()
|
||||||
.map(qid -> new ItemUpdateBuilder(qid).addDescription(description).build())
|
.map(qid -> new ItemUpdateBuilder(qid).addDescription(description, true).build())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
int batchSize = 50;
|
int batchSize = 50;
|
||||||
|
@ -73,15 +73,15 @@ public class ReconEntityRewriterTest {
|
|||||||
ItemUpdate update = new ItemUpdateBuilder(subject)
|
ItemUpdate update = new ItemUpdateBuilder(subject)
|
||||||
.addStatement(TestingData.generateStatement(subject, TestingData.newIdB))
|
.addStatement(TestingData.generateStatement(subject, TestingData.newIdB))
|
||||||
.deleteStatement(TestingData.generateStatement(subject, TestingData.existingId))
|
.deleteStatement(TestingData.generateStatement(subject, TestingData.existingId))
|
||||||
.addLabel(Datamodel.makeMonolingualTextValue("label", "de"))
|
.addLabel(Datamodel.makeMonolingualTextValue("label", "de"), true)
|
||||||
.addDescription(Datamodel.makeMonolingualTextValue("beschreibung", "de"))
|
.addDescription(Datamodel.makeMonolingualTextValue("beschreibung", "de"), false)
|
||||||
.addAlias(Datamodel.makeMonolingualTextValue("darstellung", "de")).build();
|
.addAlias(Datamodel.makeMonolingualTextValue("darstellung", "de")).build();
|
||||||
ItemUpdate rewritten = rewriter.rewrite(update);
|
ItemUpdate rewritten = rewriter.rewrite(update);
|
||||||
ItemUpdate expected = new ItemUpdateBuilder(subject)
|
ItemUpdate expected = new ItemUpdateBuilder(subject)
|
||||||
.addStatement(TestingData.generateStatement(subject, newlyCreated))
|
.addStatement(TestingData.generateStatement(subject, newlyCreated))
|
||||||
.deleteStatement(TestingData.generateStatement(subject, TestingData.existingId))
|
.deleteStatement(TestingData.generateStatement(subject, TestingData.existingId))
|
||||||
.addLabel(Datamodel.makeMonolingualTextValue("label", "de"))
|
.addLabel(Datamodel.makeMonolingualTextValue("label", "de"), true)
|
||||||
.addDescription(Datamodel.makeMonolingualTextValue("beschreibung", "de"))
|
.addDescription(Datamodel.makeMonolingualTextValue("beschreibung", "de"), false)
|
||||||
.addAlias(Datamodel.makeMonolingualTextValue("darstellung", "de")).build();
|
.addAlias(Datamodel.makeMonolingualTextValue("darstellung", "de")).build();
|
||||||
assertEquals(expected, rewritten);
|
assertEquals(expected, rewritten);
|
||||||
}
|
}
|
||||||
|
@ -91,9 +91,24 @@ public class QuickStatementsExporterTest extends RefineTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testNameDesc()
|
public void testNameDesc()
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
/**
|
||||||
|
* Adding labels and description without overriding is not supported by QS, so
|
||||||
|
* we fall back on adding them with overriding.
|
||||||
|
*/
|
||||||
|
ItemUpdate update = new ItemUpdateBuilder(qid1)
|
||||||
|
.addLabel(Datamodel.makeMonolingualTextValue("some label", "en"), true)
|
||||||
|
.addDescription(Datamodel.makeMonolingualTextValue("some description", "en"), true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertEquals("Q1377\tLen\t\"some label\"\n" + "Q1377\tDen\t\"some description\"\n", export(update));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOptionalNameDesc()
|
||||||
|
throws IOException {
|
||||||
ItemUpdate update = new ItemUpdateBuilder(newIdA)
|
ItemUpdate update = new ItemUpdateBuilder(newIdA)
|
||||||
.addLabel(Datamodel.makeMonolingualTextValue("my new item", "en"))
|
.addLabel(Datamodel.makeMonolingualTextValue("my new item", "en"), false)
|
||||||
.addDescription(Datamodel.makeMonolingualTextValue("isn't it awesome?", "en"))
|
.addDescription(Datamodel.makeMonolingualTextValue("isn't it awesome?", "en"), false)
|
||||||
.addAlias(Datamodel.makeMonolingualTextValue("fabitem", "en")).build();
|
.addAlias(Datamodel.makeMonolingualTextValue("fabitem", "en")).build();
|
||||||
|
|
||||||
assertEquals("CREATE\n" + "LAST\tLen\t\"my new item\"\n" + "LAST\tDen\t\"isn't it awesome?\"\n"
|
assertEquals("CREATE\n" + "LAST\tLen\t\"my new item\"\n" + "LAST\tDen\t\"isn't it awesome?\"\n"
|
||||||
|
@ -65,8 +65,8 @@ public class NewItemScrutinizerTest extends ScrutinizerTest {
|
|||||||
public void testGoodNewItem() {
|
public void testGoodNewItem() {
|
||||||
|
|
||||||
ItemUpdate update = new ItemUpdateBuilder(TestingData.newIdA)
|
ItemUpdate update = new ItemUpdateBuilder(TestingData.newIdA)
|
||||||
.addLabel(Datamodel.makeMonolingualTextValue("bonjour", "fr"))
|
.addLabel(Datamodel.makeMonolingualTextValue("bonjour", "fr"), false)
|
||||||
.addDescription(Datamodel.makeMonolingualTextValue("interesting item", "en")).addStatement(p31Statement)
|
.addDescription(Datamodel.makeMonolingualTextValue("interesting item", "en"), true).addStatement(p31Statement)
|
||||||
.build();
|
.build();
|
||||||
scrutinize(update);
|
scrutinize(update);
|
||||||
assertWarningsRaised(NewItemScrutinizer.newItemType);
|
assertWarningsRaised(NewItemScrutinizer.newItemType);
|
||||||
@ -75,8 +75,8 @@ public class NewItemScrutinizerTest extends ScrutinizerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testDeletedStatements() {
|
public void testDeletedStatements() {
|
||||||
ItemUpdate update = new ItemUpdateBuilder(TestingData.newIdA)
|
ItemUpdate update = new ItemUpdateBuilder(TestingData.newIdA)
|
||||||
.addLabel(Datamodel.makeMonolingualTextValue("bonjour", "fr"))
|
.addLabel(Datamodel.makeMonolingualTextValue("bonjour", "fr"), false)
|
||||||
.addDescription(Datamodel.makeMonolingualTextValue("interesting item", "en")).addStatement(p31Statement)
|
.addDescription(Datamodel.makeMonolingualTextValue("interesting item", "en"), true).addStatement(p31Statement)
|
||||||
.deleteStatement(TestingData.generateStatement(TestingData.newIdA, TestingData.matchedId)).build();
|
.deleteStatement(TestingData.generateStatement(TestingData.newIdA, TestingData.matchedId)).build();
|
||||||
scrutinize(update);
|
scrutinize(update);
|
||||||
assertWarningsRaised(NewItemScrutinizer.newItemType, NewItemScrutinizer.deletedStatementsType);
|
assertWarningsRaised(NewItemScrutinizer.newItemType, NewItemScrutinizer.deletedStatementsType);
|
||||||
|
@ -43,6 +43,6 @@ public abstract class ValueScrutinizerTest extends SnakScrutinizerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void scrutinizeLabel(MonolingualTextValue text) {
|
public void scrutinizeLabel(MonolingualTextValue text) {
|
||||||
scrutinize(new ItemUpdateBuilder(TestingData.existingId).addLabel(text).build());
|
scrutinize(new ItemUpdateBuilder(TestingData.existingId).addLabel(text, true).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class WbItemDocumentExprTest extends WbExpressionTest<ItemUpdate> {
|
|||||||
|
|
||||||
public WbItemDocumentExprTest() {
|
public WbItemDocumentExprTest() {
|
||||||
WbStatementGroupExprTest sgt = new WbStatementGroupExprTest();
|
WbStatementGroupExprTest sgt = new WbStatementGroupExprTest();
|
||||||
WbNameDescExpr nde = new WbNameDescExpr(WbNameDescExpr.NameDescrType.ALIAS,
|
WbNameDescExpr nde = new WbNameDescExpr(WbNameDescExpr.NameDescType.ALIAS,
|
||||||
new WbMonolingualExpr(new WbLanguageConstant("en", "English"), new WbStringVariable("column D")));
|
new WbMonolingualExpr(new WbLanguageConstant("en", "English"), new WbStringVariable("column D")));
|
||||||
WbItemVariable subjectExpr = new WbItemVariable("column E");
|
WbItemVariable subjectExpr = new WbItemVariable("column E");
|
||||||
expr = new WbItemDocumentExpr(subjectExpr, Collections.singletonList(nde), Collections.singletonList(sgt.expr));
|
expr = new WbItemDocumentExpr(subjectExpr, Collections.singletonList(nde), Collections.singletonList(sgt.expr));
|
||||||
|
@ -38,7 +38,7 @@ import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
|
|||||||
public class WbNameDescExprTest extends WbExpressionTest<MonolingualTextValue> {
|
public class WbNameDescExprTest extends WbExpressionTest<MonolingualTextValue> {
|
||||||
|
|
||||||
private ItemIdValue subject = Datamodel.makeWikidataItemIdValue("Q56");
|
private ItemIdValue subject = Datamodel.makeWikidataItemIdValue("Q56");
|
||||||
public WbNameDescExpr expr = new WbNameDescExpr(WbNameDescExpr.NameDescrType.ALIAS,
|
public WbNameDescExpr expr = new WbNameDescExpr(WbNameDescExpr.NameDescType.ALIAS,
|
||||||
new WbMonolingualExpr(new WbLanguageConstant("en", "English"), new WbStringVariable("column A")));
|
new WbMonolingualExpr(new WbLanguageConstant("en", "English"), new WbStringVariable("column A")));
|
||||||
|
|
||||||
public String jsonRepresentation = "{\"name_type\":\"ALIAS\",\"value\":{\"type\":\"wbmonolingualexpr\",\"language\":"
|
public String jsonRepresentation = "{\"name_type\":\"ALIAS\",\"value\":{\"type\":\"wbmonolingualexpr\",\"language\":"
|
||||||
@ -47,7 +47,7 @@ public class WbNameDescExprTest extends WbExpressionTest<MonolingualTextValue> {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContributeToLabel() {
|
public void testContributeToLabel() {
|
||||||
WbNameDescExpr labelExpr = new WbNameDescExpr(WbNameDescExpr.NameDescrType.LABEL,
|
WbNameDescExpr labelExpr = new WbNameDescExpr(WbNameDescExpr.NameDescType.LABEL,
|
||||||
TestingData.getTestMonolingualExpr("fr", "français", "le croissant magnifique"));
|
TestingData.getTestMonolingualExpr("fr", "français", "le croissant magnifique"));
|
||||||
ItemUpdateBuilder update = new ItemUpdateBuilder(subject);
|
ItemUpdateBuilder update = new ItemUpdateBuilder(subject);
|
||||||
labelExpr.contributeTo(update, ctxt);
|
labelExpr.contributeTo(update, ctxt);
|
||||||
@ -57,7 +57,7 @@ public class WbNameDescExprTest extends WbExpressionTest<MonolingualTextValue> {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContributeToDescription() {
|
public void testContributeToDescription() {
|
||||||
WbNameDescExpr descriptionExpr = new WbNameDescExpr(WbNameDescExpr.NameDescrType.DESCRIPTION,
|
WbNameDescExpr descriptionExpr = new WbNameDescExpr(WbNameDescExpr.NameDescType.DESCRIPTION,
|
||||||
TestingData.getTestMonolingualExpr("de", "Deutsch", "wunderschön"));
|
TestingData.getTestMonolingualExpr("de", "Deutsch", "wunderschön"));
|
||||||
ItemUpdateBuilder update = new ItemUpdateBuilder(subject);
|
ItemUpdateBuilder update = new ItemUpdateBuilder(subject);
|
||||||
descriptionExpr.contributeTo(update, ctxt);
|
descriptionExpr.contributeTo(update, ctxt);
|
||||||
@ -67,7 +67,7 @@ public class WbNameDescExprTest extends WbExpressionTest<MonolingualTextValue> {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContributeToAlias() {
|
public void testContributeToAlias() {
|
||||||
WbNameDescExpr aliasExpr = new WbNameDescExpr(WbNameDescExpr.NameDescrType.ALIAS,
|
WbNameDescExpr aliasExpr = new WbNameDescExpr(WbNameDescExpr.NameDescType.ALIAS,
|
||||||
TestingData.getTestMonolingualExpr("en", "English", "snack"));
|
TestingData.getTestMonolingualExpr("en", "English", "snack"));
|
||||||
ItemUpdateBuilder update = new ItemUpdateBuilder(subject);
|
ItemUpdateBuilder update = new ItemUpdateBuilder(subject);
|
||||||
aliasExpr.contributeTo(update, ctxt);
|
aliasExpr.contributeTo(update, ctxt);
|
||||||
@ -86,8 +86,8 @@ public class WbNameDescExprTest extends WbExpressionTest<MonolingualTextValue> {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetters() {
|
public void testGetters() {
|
||||||
WbMonolingualExpr monolingualExpr = TestingData.getTestMonolingualExpr("en", "English", "not sure what");
|
WbMonolingualExpr monolingualExpr = TestingData.getTestMonolingualExpr("en", "English", "not sure what");
|
||||||
WbNameDescExpr aliasExpr = new WbNameDescExpr(WbNameDescExpr.NameDescrType.ALIAS, monolingualExpr);
|
WbNameDescExpr aliasExpr = new WbNameDescExpr(WbNameDescExpr.NameDescType.ALIAS, monolingualExpr);
|
||||||
assertEquals(WbNameDescExpr.NameDescrType.ALIAS, aliasExpr.getType());
|
assertEquals(WbNameDescExpr.NameDescType.ALIAS, aliasExpr.getType());
|
||||||
assertEquals(monolingualExpr, aliasExpr.getValue());
|
assertEquals(monolingualExpr, aliasExpr.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ public class ItemUpdateTest {
|
|||||||
public void testGroupBySubject() {
|
public void testGroupBySubject() {
|
||||||
ItemUpdate updateA = new ItemUpdateBuilder(newSubject).addStatement(statement1).build();
|
ItemUpdate updateA = new ItemUpdateBuilder(newSubject).addStatement(statement1).build();
|
||||||
ItemUpdate updateB = new ItemUpdateBuilder(sameNewSubject).addStatement(statement2).build();
|
ItemUpdate updateB = new ItemUpdateBuilder(sameNewSubject).addStatement(statement2).build();
|
||||||
ItemUpdate updateC = new ItemUpdateBuilder(existingSubject).addLabel(label).build();
|
ItemUpdate updateC = new ItemUpdateBuilder(existingSubject).addLabel(label, true).build();
|
||||||
ItemUpdate updateD = new ItemUpdateBuilder(matchedSubject).build();
|
ItemUpdate updateD = new ItemUpdateBuilder(matchedSubject).build();
|
||||||
Map<EntityIdValue, ItemUpdate> grouped = ItemUpdate
|
Map<EntityIdValue, ItemUpdate> grouped = ItemUpdate
|
||||||
.groupBySubject(Arrays.asList(updateA, updateB, updateC, updateD));
|
.groupBySubject(Arrays.asList(updateA, updateB, updateC, updateD));
|
||||||
@ -148,12 +148,12 @@ public class ItemUpdateTest {
|
|||||||
public void testNormalizeTerms() {
|
public void testNormalizeTerms() {
|
||||||
MonolingualTextValue aliasEn = Datamodel.makeMonolingualTextValue("alias", "en");
|
MonolingualTextValue aliasEn = Datamodel.makeMonolingualTextValue("alias", "en");
|
||||||
MonolingualTextValue aliasFr = Datamodel.makeMonolingualTextValue("coucou", "fr");
|
MonolingualTextValue aliasFr = Datamodel.makeMonolingualTextValue("coucou", "fr");
|
||||||
ItemUpdate updateA = new ItemUpdateBuilder(newSubject).addLabel(label).addAlias(aliasEn).addAlias(aliasFr)
|
ItemUpdate updateA = new ItemUpdateBuilder(newSubject).addLabel(label, true).addAlias(aliasEn).addAlias(aliasFr)
|
||||||
.build();
|
.build();
|
||||||
assertFalse(updateA.isNull());
|
assertFalse(updateA.isNull());
|
||||||
ItemUpdate normalized = updateA.normalizeLabelsAndAliases();
|
ItemUpdate normalized = updateA.normalizeLabelsAndAliases();
|
||||||
ItemUpdate expectedUpdate = new ItemUpdateBuilder(newSubject).addLabel(label).addAlias(aliasEn)
|
ItemUpdate expectedUpdate = new ItemUpdateBuilder(newSubject).addLabel(label, true).addAlias(aliasEn)
|
||||||
.addLabel(aliasFr).build();
|
.addLabel(aliasFr, true).build();
|
||||||
assertEquals(expectedUpdate, normalized);
|
assertEquals(expectedUpdate, normalized);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,9 +161,87 @@ public class ItemUpdateTest {
|
|||||||
public void testMergeLabels() {
|
public void testMergeLabels() {
|
||||||
MonolingualTextValue label1 = Datamodel.makeMonolingualTextValue("first label", "en");
|
MonolingualTextValue label1 = Datamodel.makeMonolingualTextValue("first label", "en");
|
||||||
MonolingualTextValue label2 = Datamodel.makeMonolingualTextValue("second label", "en");
|
MonolingualTextValue label2 = Datamodel.makeMonolingualTextValue("second label", "en");
|
||||||
ItemUpdate update1 = new ItemUpdateBuilder(existingSubject).addLabel(label1).build();
|
ItemUpdate update1 = new ItemUpdateBuilder(existingSubject).addLabel(label1, true).build();
|
||||||
ItemUpdate update2 = new ItemUpdateBuilder(existingSubject).addLabel(label2).build();
|
ItemUpdate update2 = new ItemUpdateBuilder(existingSubject).addLabel(label2, true).build();
|
||||||
ItemUpdate merged = update1.merge(update2);
|
ItemUpdate merged = update1.merge(update2);
|
||||||
assertEquals(Collections.singleton(label2), merged.getLabels());
|
assertEquals(Collections.singleton(label2), merged.getLabels());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeLabelsIfNew() {
|
||||||
|
MonolingualTextValue label1 = Datamodel.makeMonolingualTextValue("first label", "en");
|
||||||
|
MonolingualTextValue label2 = Datamodel.makeMonolingualTextValue("second label", "en");
|
||||||
|
ItemUpdate update1 = new ItemUpdateBuilder(existingSubject).addLabel(label1, false).build();
|
||||||
|
ItemUpdate update2 = new ItemUpdateBuilder(existingSubject).addLabel(label2, false).build();
|
||||||
|
ItemUpdate merged = update1.merge(update2);
|
||||||
|
assertEquals(Collections.singleton(label1), merged.getLabelsIfNew());
|
||||||
|
assertEquals(Collections.emptySet(), merged.getLabels());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeLabelsIfNewOverriding() {
|
||||||
|
MonolingualTextValue label1 = Datamodel.makeMonolingualTextValue("first label", "en");
|
||||||
|
MonolingualTextValue label2 = Datamodel.makeMonolingualTextValue("second label", "en");
|
||||||
|
ItemUpdate update1 = new ItemUpdateBuilder(existingSubject).addLabel(label1, true).build();
|
||||||
|
ItemUpdate update2 = new ItemUpdateBuilder(existingSubject).addLabel(label2, false).build();
|
||||||
|
ItemUpdate merged = update1.merge(update2);
|
||||||
|
assertEquals(Collections.singleton(label1), merged.getLabels());
|
||||||
|
assertEquals(Collections.emptySet(), merged.getLabelsIfNew());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeLabelsIfNewOverriding2() {
|
||||||
|
MonolingualTextValue label1 = Datamodel.makeMonolingualTextValue("first label", "en");
|
||||||
|
MonolingualTextValue label2 = Datamodel.makeMonolingualTextValue("second label", "en");
|
||||||
|
ItemUpdate update1 = new ItemUpdateBuilder(existingSubject).addLabel(label1, false).build();
|
||||||
|
ItemUpdate update2 = new ItemUpdateBuilder(existingSubject).addLabel(label2, true).build();
|
||||||
|
ItemUpdate merged = update1.merge(update2);
|
||||||
|
assertEquals(Collections.singleton(label2), merged.getLabels());
|
||||||
|
assertEquals(Collections.emptySet(), merged.getLabelsIfNew());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeDescriptionsIfNew() {
|
||||||
|
MonolingualTextValue description1 = Datamodel.makeMonolingualTextValue("first description", "en");
|
||||||
|
MonolingualTextValue description2 = Datamodel.makeMonolingualTextValue("second description", "en");
|
||||||
|
ItemUpdate update1 = new ItemUpdateBuilder(existingSubject).addDescription(description1, false).build();
|
||||||
|
ItemUpdate update2 = new ItemUpdateBuilder(existingSubject).addDescription(description2, false).build();
|
||||||
|
ItemUpdate merged = update1.merge(update2);
|
||||||
|
assertEquals(Collections.singleton(description1), merged.getDescriptionsIfNew());
|
||||||
|
assertEquals(Collections.emptySet(), merged.getDescriptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeDescriptionsIfNewOverriding() {
|
||||||
|
MonolingualTextValue description1 = Datamodel.makeMonolingualTextValue("first description", "en");
|
||||||
|
MonolingualTextValue description2 = Datamodel.makeMonolingualTextValue("second description", "en");
|
||||||
|
ItemUpdate update1 = new ItemUpdateBuilder(existingSubject).addDescription(description1, true).build();
|
||||||
|
ItemUpdate update2 = new ItemUpdateBuilder(existingSubject).addDescription(description2, false).build();
|
||||||
|
ItemUpdate merged = update1.merge(update2);
|
||||||
|
assertEquals(Collections.singleton(description1), merged.getDescriptions());
|
||||||
|
assertEquals(Collections.emptySet(), merged.getDescriptionsIfNew());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeDescriptionsIfNewOverriding2() {
|
||||||
|
MonolingualTextValue description1 = Datamodel.makeMonolingualTextValue("first description", "en");
|
||||||
|
MonolingualTextValue description2 = Datamodel.makeMonolingualTextValue("second description", "en");
|
||||||
|
ItemUpdate update1 = new ItemUpdateBuilder(existingSubject).addDescription(description1, false).build();
|
||||||
|
ItemUpdate update2 = new ItemUpdateBuilder(existingSubject).addDescription(description2, true).build();
|
||||||
|
ItemUpdate merged = update1.merge(update2);
|
||||||
|
assertEquals(Collections.singleton(description2), merged.getDescriptions());
|
||||||
|
assertEquals(Collections.emptySet(), merged.getDescriptionsIfNew());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConstructOverridingLabels() {
|
||||||
|
MonolingualTextValue label1 = Datamodel.makeMonolingualTextValue("first label", "en");
|
||||||
|
MonolingualTextValue label2 = Datamodel.makeMonolingualTextValue("second label", "en");
|
||||||
|
ItemUpdate update = new ItemUpdateBuilder(existingSubject)
|
||||||
|
.addLabel(label1, false)
|
||||||
|
.addLabel(label2, true)
|
||||||
|
.build();
|
||||||
|
assertEquals(Collections.singleton(label2), update.getLabels());
|
||||||
|
assertEquals(Collections.emptySet(), update.getLabelsIfNew());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ public abstract class UpdateSchedulerTest {
|
|||||||
throws ImpossibleSchedulingException {
|
throws ImpossibleSchedulingException {
|
||||||
ItemUpdate update1 = new ItemUpdateBuilder(existingIdA).addStatement(sAtoB).build();
|
ItemUpdate update1 = new ItemUpdateBuilder(existingIdA).addStatement(sAtoB).build();
|
||||||
ItemUpdate update2 = new ItemUpdateBuilder(existingIdA)
|
ItemUpdate update2 = new ItemUpdateBuilder(existingIdA)
|
||||||
.addLabel(Datamodel.makeMonolingualTextValue("hello", "fr")).addStatement(sAtoB).build();
|
.addLabel(Datamodel.makeMonolingualTextValue("hello", "fr"), true).addStatement(sAtoB).build();
|
||||||
ItemUpdate merged = update1.merge(update2);
|
ItemUpdate merged = update1.merge(update2);
|
||||||
assertEquals(Collections.singletonList(merged), schedule(update1, update2));
|
assertEquals(Collections.singletonList(merged), schedule(update1, update2));
|
||||||
}
|
}
|
||||||
@ -95,9 +95,9 @@ public abstract class UpdateSchedulerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testMergeNew()
|
public void testMergeNew()
|
||||||
throws ImpossibleSchedulingException {
|
throws ImpossibleSchedulingException {
|
||||||
ItemUpdate update1 = new ItemUpdateBuilder(newIdA).addLabel(Datamodel.makeMonolingualTextValue("hello", "fr"))
|
ItemUpdate update1 = new ItemUpdateBuilder(newIdA).addLabel(Datamodel.makeMonolingualTextValue("hello", "fr"), true)
|
||||||
.addStatement(sNewAtoB).build();
|
.addStatement(sNewAtoB).build();
|
||||||
ItemUpdate update2 = new ItemUpdateBuilder(newIdA).addLabel(Datamodel.makeMonolingualTextValue("hello", "fr"))
|
ItemUpdate update2 = new ItemUpdateBuilder(newIdA).addLabel(Datamodel.makeMonolingualTextValue("hello", "fr"), true)
|
||||||
.build();
|
.build();
|
||||||
ItemUpdate merged = update1.merge(update2);
|
ItemUpdate merged = update1.merge(update2);
|
||||||
assertEquals(Collections.singletonList(merged), schedule(update1, update2));
|
assertEquals(Collections.singletonList(merged), schedule(update1, update2));
|
||||||
|
Loading…
Reference in New Issue
Block a user