use of org.openrefine.wikidata.updates.TermedStatementEntityEdit in project OpenRefine by OpenRefine.
the class WikibaseAPIUpdateScheduler method schedule.
@Override
public List<TermedStatementEntityEdit> schedule(List<TermedStatementEntityEdit> updates) {
List<TermedStatementEntityEdit> result = new ArrayList<>();
pointerFreeUpdates = new UpdateSequence();
pointerFullUpdates = new UpdateSequence();
allPointers = new HashSet<>();
for (TermedStatementEntityEdit update : updates) {
splitUpdate(update);
}
// Part 1: add all the pointer free updates
result.addAll(pointerFreeUpdates.getUpdates());
// Part 1': add the remaining new entities that have not been touched
Set<EntityIdValue> unseenPointers = new HashSet<>(allPointers);
unseenPointers.removeAll(pointerFreeUpdates.getSubjects());
result.addAll(unseenPointers.stream().map(e -> new TermedStatementEntityEditBuilder(e).build()).collect(Collectors.toList()));
// Part 2: add all the pointer full updates
result.addAll(pointerFullUpdates.getUpdates());
return result;
}
use of org.openrefine.wikidata.updates.TermedStatementEntityEdit in project OpenRefine by OpenRefine.
the class WikibaseAPIUpdateScheduler method splitUpdate.
/**
* Splits an update into two parts
*
* @param update
*/
protected void splitUpdate(TermedStatementEntityEdit update) {
TermedStatementEntityEditBuilder pointerFreeBuilder = new TermedStatementEntityEditBuilder(update.getEntityId()).addLabels(update.getLabels(), true).addLabels(update.getLabelsIfNew(), false).addDescriptions(update.getDescriptions(), true).addDescriptions(update.getDescriptionsIfNew(), false).addAliases(update.getAliases());
TermedStatementEntityEditBuilder pointerFullBuilder = new TermedStatementEntityEditBuilder(update.getEntityId());
for (StatementEdit statement : update.getStatementEdits()) {
Set<ReconEntityIdValue> pointers = extractor.extractPointers(statement.getStatement());
if (pointers.isEmpty()) {
pointerFreeBuilder.addStatement(statement);
} else {
pointerFullBuilder.addStatement(statement);
}
allPointers.addAll(pointers);
}
if (update.isNew()) {
// If the update is new, we might need to split it
// in two (if it refers to any other new entity).
TermedStatementEntityEdit pointerFree = pointerFreeBuilder.build();
if (!pointerFree.isNull()) {
pointerFreeUpdates.add(pointerFree);
}
TermedStatementEntityEdit pointerFull = pointerFullBuilder.build();
if (!pointerFull.isEmpty()) {
pointerFullUpdates.add(pointerFull);
}
} else {
// Otherwise, we just make sure this edit is done after
// all entity creations.
pointerFullUpdates.add(update);
}
}
use of org.openrefine.wikidata.updates.TermedStatementEntityEdit in project OpenRefine by OpenRefine.
the class EnglishDescriptionScrutinizerTest method testGoodDesc.
@Test
public void testGoodDesc() {
String description = "good description";
TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(TestingData.newIdA).addDescription(Datamodel.makeMonolingualTextValue(description, "en"), true).build();
scrutinize(update);
assertNoWarningRaised();
}
use of org.openrefine.wikidata.updates.TermedStatementEntityEdit in project OpenRefine by OpenRefine.
the class EnglishDescriptionScrutinizerTest method testAwfulDesc.
@Test
public void testAwfulDesc() {
String description = "An awful description.";
TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(TestingData.newIdA).addDescription(Datamodel.makeMonolingualTextValue(description, "en"), true).addLabel(Datamodel.makeMonolingualTextValue(description, "en"), true).build();
scrutinize(update);
assertWarningsRaised(EnglishDescriptionScrutinizer.descEndsByPunctuationSign, EnglishDescriptionScrutinizer.descBeginWithUppercase, EnglishDescriptionScrutinizer.descBeginWithArticle);
}
use of org.openrefine.wikidata.updates.TermedStatementEntityEdit in project OpenRefine by OpenRefine.
the class EnglishDescriptionScrutinizerTest method testEndWithPunctuationSign.
@Test
public void testEndWithPunctuationSign() {
String description = "description with punctuationSign.";
TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(TestingData.newIdA).addDescription(Datamodel.makeMonolingualTextValue(description, "en"), false).build();
scrutinize(update);
assertWarningsRaised(EnglishDescriptionScrutinizer.descEndsByPunctuationSign);
}
Aggregations