Search in sources :

Example 56 with TermedStatementEntityEditBuilder

use of org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder 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 57 with TermedStatementEntityEditBuilder

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

Example 58 with TermedStatementEntityEditBuilder

use of org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder 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)

Example 59 with TermedStatementEntityEditBuilder

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

Example 60 with TermedStatementEntityEditBuilder

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

Aggregations

TermedStatementEntityEditBuilder (org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder)107 TermedStatementEntityEdit (org.openrefine.wikidata.updates.TermedStatementEntityEdit)102 Test (org.testng.annotations.Test)101 ItemIdValue (org.wikidata.wdtk.datamodel.interfaces.ItemIdValue)57 Statement (org.wikidata.wdtk.datamodel.interfaces.Statement)56 ConstraintFetcher (org.openrefine.wikidata.qa.ConstraintFetcher)52 Snak (org.wikidata.wdtk.datamodel.interfaces.Snak)49 StatementImpl (org.wikidata.wdtk.datamodel.implementation.StatementImpl)44 SnakGroup (org.wikidata.wdtk.datamodel.interfaces.SnakGroup)34 ValueSnak (org.wikidata.wdtk.datamodel.interfaces.ValueSnak)18 WikidataRefineTest (org.openrefine.wikidata.testing.WikidataRefineTest)13 ArrayList (java.util.ArrayList)11 StatementEdit (org.openrefine.wikidata.updates.StatementEdit)9 JacksonSerializationTest (org.openrefine.wikidata.testing.JacksonSerializationTest)7 NoValueSnak (org.wikidata.wdtk.datamodel.interfaces.NoValueSnak)5 ReconEntityIdValue (org.openrefine.wikidata.schema.entityvalues.ReconEntityIdValue)4 Claim (org.wikidata.wdtk.datamodel.interfaces.Claim)4 EntityIdValue (org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)4 ItemDocument (org.wikidata.wdtk.datamodel.interfaces.ItemDocument)3 Engine (com.google.refine.browsing.Engine)2