use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.
the class QuickStatementsUpdateScheduler method splitUpdate.
/**
* Separates out the statements which refer to new entities from the rest of the
* update. The resulting updates are stored in {@link referencingUpdates} and
* {@link updatesWithoutReferences}.
*
* @param update
* @throws ImpossibleSchedulingException
* if two new entity ids are referred to in the same statement
*/
protected void splitUpdate(TermedStatementEntityEdit update) throws ImpossibleSchedulingException {
TermedStatementEntityEditBuilder remainingUpdateBuilder = new TermedStatementEntityEditBuilder(update.getEntityId()).addLabels(update.getLabels(), true).addLabels(update.getLabelsIfNew(), false).addDescriptions(update.getDescriptions(), true).addDescriptions(update.getDescriptionsIfNew(), false).addAliases(update.getAliases());
Map<EntityIdValue, TermedStatementEntityEditBuilder> referencingUpdates = new HashMap<>();
for (StatementEdit statement : update.getStatementEdits()) {
Set<ReconEntityIdValue> pointers = extractor.extractPointers(statement.getStatement());
if (pointers.isEmpty()) {
remainingUpdateBuilder.addStatement(statement);
} else if (pointers.size() == 1 && !update.isNew()) {
EntityIdValue pointer = pointers.stream().findFirst().get();
TermedStatementEntityEditBuilder referencingBuilder = referencingUpdates.get(pointer);
if (referencingBuilder == null) {
referencingBuilder = new TermedStatementEntityEditBuilder(update.getEntityId());
}
referencingBuilder.addStatement(statement);
referencingUpdates.put(pointer, referencingBuilder);
} else if (pointers.size() == 1 && pointers.stream().findFirst().get().equals(update.getEntityId())) {
remainingUpdateBuilder.addStatement(statement);
} else {
throw new ImpossibleSchedulingException();
}
}
// Add the update that is not referring to anything to the schedule
TermedStatementEntityEdit pointerFree = remainingUpdateBuilder.build();
if (!pointerFree.isNull()) {
pointerFreeUpdates.add(pointerFree);
}
// Add the other updates to the map
for (Entry<EntityIdValue, TermedStatementEntityEditBuilder> entry : referencingUpdates.entrySet()) {
TermedStatementEntityEdit pointerUpdate = entry.getValue().build();
UpdateSequence pointerUpdatesForKey = pointerUpdates.get(entry.getKey());
if (pointerUpdatesForKey == null) {
pointerUpdatesForKey = new UpdateSequence();
}
pointerUpdatesForKey.add(pointerUpdate);
pointerUpdates.put(entry.getKey(), pointerUpdatesForKey);
}
}
use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.
the class WbStatementExprTest method testDeleteAllStatements.
@Test
public void testDeleteAllStatements() {
setRow(recon("Q3434"), "2010-07-23", "3.898,4.389");
evaluatesTo(new StatementEdit(Datamodel.makeStatement(Datamodel.makeClaim(subject, Datamodel.makeNoValueSnak(property), Collections.emptyList()), Collections.emptyList(), StatementRank.NORMAL, ""), new PropertyOnlyStatementMerger(), StatementEditingMode.DELETE), new Wrapper(statementDeleteExpr));
}
use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.
the class WbStatementExprTest method testEvaluateWithoutQualifierAndReference.
@Test
public void testEvaluateWithoutQualifierAndReference() {
setRow("invalid", "2010-invalid", "3.898,4.389");
evaluatesTo(new StatementEdit(Datamodel.makeStatement(Datamodel.makeClaim(subject, mainsnak, Collections.emptyList()), Collections.emptyList(), StatementRank.NORMAL, ""), StatementMerger.FORMER_DEFAULT_STRATEGY, StatementEditingMode.ADD_OR_MERGE), new Wrapper(statementExpr));
}
use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.
the class WbStatementExprTest method testEvaluateWithoutQualifier.
@Test
public void testEvaluateWithoutQualifier() {
setRow(recon("Q3434"), "2010-invalid", "3.898,4.389");
evaluatesTo(new StatementEdit(Datamodel.makeStatement(Datamodel.makeClaim(subject, mainsnak, Collections.emptyList()), Collections.singletonList(reference), StatementRank.NORMAL, ""), StatementMerger.FORMER_DEFAULT_STRATEGY, StatementEditingMode.ADD_OR_MERGE), new Wrapper(statementExpr));
}
use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.
the class WbStatementExprTest method testEvaluateWithoutReference.
@Test
public void testEvaluateWithoutReference() {
setRow("not reconciled", "2010-07-23", "3.898,4.389");
Statement statement = Datamodel.makeStatement(fullClaim, Collections.emptyList(), StatementRank.NORMAL, "");
evaluatesTo(new StatementEdit(statement, StatementMerger.FORMER_DEFAULT_STRATEGY, StatementEditingMode.ADD_OR_MERGE), new Wrapper(statementExpr));
}
Aggregations