Search in sources :

Example 6 with StatementEdit

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);
    }
}
Also used : TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) HashMap(java.util.HashMap) ReconEntityIdValue(org.openrefine.wikidata.schema.entityvalues.ReconEntityIdValue) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) ReconEntityIdValue(org.openrefine.wikidata.schema.entityvalues.ReconEntityIdValue) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) StatementEdit(org.openrefine.wikidata.updates.StatementEdit)

Example 7 with StatementEdit

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));
}
Also used : PropertyOnlyStatementMerger(org.openrefine.wikidata.schema.strategies.PropertyOnlyStatementMerger) StatementEdit(org.openrefine.wikidata.updates.StatementEdit) JacksonSerializationTest(org.openrefine.wikidata.testing.JacksonSerializationTest) Test(org.testng.annotations.Test)

Example 8 with StatementEdit

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

Example 9 with StatementEdit

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

Example 10 with StatementEdit

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

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