use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.
the class QuickStatementsExporterTest method testDeleteStatement.
@Test
public void testDeleteStatement() throws IOException {
TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(qid1).addStatement(new StatementEdit(TestingData.generateStatement(qid1, qid2), StatementMerger.FORMER_DEFAULT_STRATEGY, StatementEditingMode.DELETE)).build();
assertEquals("- Q1377\tP38\tQ865528\n", export(update));
}
use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.
the class QuickStatementsExporterTest method testImpossibleScheduling.
@Test
public void testImpossibleScheduling() throws IOException {
StatementEdit sNewAtoNewB = TestingData.generateStatementAddition(newIdA, newIdB);
TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(newIdA).addStatement(sNewAtoNewB).build();
assertEquals(QuickStatementsExporter.impossibleSchedulingErrorMessage, export(update));
}
use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.
the class QuickStatementsExporterTest method testQualifier.
@Test
public void testQualifier() throws IOException {
Statement baseStatement = TestingData.generateStatement(qid1, qid2);
Statement otherStatement = TestingData.generateStatement(qid2, qid1);
Snak qualifierSnak = otherStatement.getClaim().getMainSnak();
SnakGroup group = Datamodel.makeSnakGroup(Collections.singletonList(qualifierSnak));
Claim claim = Datamodel.makeClaim(qid1, baseStatement.getClaim().getMainSnak(), Collections.singletonList(group));
Statement statement = Datamodel.makeStatement(claim, Collections.emptyList(), StatementRank.NORMAL, "");
StatementEdit statementUpdate = new StatementEdit(statement, StatementMerger.FORMER_DEFAULT_STRATEGY, StatementEditingMode.ADD_OR_MERGE);
TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(qid1).addStatement(statementUpdate).build();
assertEquals("Q1377\tP38\tQ865528\tP38\tQ1377\n", export(update));
}
use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.
the class QuickStatementsExporterTest method testReferences.
/**
* issue #2320
*
* A statement with different references should be duplicated, but each with a different reference.
*/
@Test
public void testReferences() throws IOException {
Statement baseStatement = TestingData.generateStatement(qid1, qid2);
Statement otherStatement = TestingData.generateStatement(qid2, qid1);
Snak snak1 = baseStatement.getClaim().getMainSnak();
Snak snak2 = otherStatement.getClaim().getMainSnak();
SnakGroup group1 = Datamodel.makeSnakGroup(Collections.singletonList(snak1));
SnakGroup group2 = Datamodel.makeSnakGroup(Collections.singletonList(snak2));
Claim claim = Datamodel.makeClaim(qid1, baseStatement.getClaim().getMainSnak(), Collections.singletonList(group2));
Reference reference1 = Datamodel.makeReference(Collections.singletonList(group1));
Reference reference2 = Datamodel.makeReference(Collections.singletonList(group2));
Statement statement = Datamodel.makeStatement(claim, Arrays.asList(reference1, reference2), StatementRank.NORMAL, "");
StatementEdit statementUpdate = new StatementEdit(statement, StatementMerger.FORMER_DEFAULT_STRATEGY, StatementEditingMode.ADD_OR_MERGE);
TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(qid1).addStatement(statementUpdate).build();
assertEquals("Q1377\tP38\tQ865528\tP38\tQ1377\tS38\tQ865528\n" + "Q1377\tP38\tQ865528\tP38\tQ1377\tS38\tQ1377\n", export(update));
}
use of org.openrefine.wikidata.updates.StatementEdit 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);
}
}
Aggregations