Search in sources :

Example 11 with StatementEdit

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));
}
Also used : TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) StatementEdit(org.openrefine.wikidata.updates.StatementEdit) Test(org.testng.annotations.Test) WikidataRefineTest(org.openrefine.wikidata.testing.WikidataRefineTest)

Example 12 with StatementEdit

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));
}
Also used : TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) StatementEdit(org.openrefine.wikidata.updates.StatementEdit) Test(org.testng.annotations.Test) WikidataRefineTest(org.openrefine.wikidata.testing.WikidataRefineTest)

Example 13 with StatementEdit

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));
}
Also used : Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) Claim(org.wikidata.wdtk.datamodel.interfaces.Claim) StatementEdit(org.openrefine.wikidata.updates.StatementEdit) Test(org.testng.annotations.Test) WikidataRefineTest(org.openrefine.wikidata.testing.WikidataRefineTest)

Example 14 with StatementEdit

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));
}
Also used : Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) Reference(org.wikidata.wdtk.datamodel.interfaces.Reference) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) Claim(org.wikidata.wdtk.datamodel.interfaces.Claim) StatementEdit(org.openrefine.wikidata.updates.StatementEdit) Test(org.testng.annotations.Test) WikidataRefineTest(org.openrefine.wikidata.testing.WikidataRefineTest)

Example 15 with StatementEdit

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);
    }
}
Also used : TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) ReconEntityIdValue(org.openrefine.wikidata.schema.entityvalues.ReconEntityIdValue) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) StatementEdit(org.openrefine.wikidata.updates.StatementEdit)

Aggregations

StatementEdit (org.openrefine.wikidata.updates.StatementEdit)17 Test (org.testng.annotations.Test)10 TermedStatementEntityEdit (org.openrefine.wikidata.updates.TermedStatementEntityEdit)9 TermedStatementEntityEditBuilder (org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder)9 WikidataRefineTest (org.openrefine.wikidata.testing.WikidataRefineTest)6 Statement (org.wikidata.wdtk.datamodel.interfaces.Statement)6 Claim (org.wikidata.wdtk.datamodel.interfaces.Claim)5 PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)5 JacksonSerializationTest (org.openrefine.wikidata.testing.JacksonSerializationTest)4 EntityIdValue (org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)4 SkipSchemaExpressionException (org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException)3 Snak (org.wikidata.wdtk.datamodel.interfaces.Snak)3 SnakGroup (org.wikidata.wdtk.datamodel.interfaces.SnakGroup)3 ArrayList (java.util.ArrayList)2 ReconEntityIdValue (org.openrefine.wikidata.schema.entityvalues.ReconEntityIdValue)2 StatementGroupEdit (org.openrefine.wikidata.updates.StatementGroupEdit)2 Reference (org.wikidata.wdtk.datamodel.interfaces.Reference)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1