Search in sources :

Example 16 with StatementEdit

use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.

the class QuickStatementsExporter method translateItem.

protected void translateItem(TermedStatementEntityEdit item, Writer writer) throws IOException {
    String qid = item.getEntityId().getId();
    if (item.isNew()) {
        writer.write("CREATE\n");
        qid = "LAST";
        item = item.normalizeLabelsAndAliases();
    }
    translateNameDescr(qid, item.getLabels(), "L", item.getEntityId(), writer);
    translateNameDescr(qid, item.getLabelsIfNew(), "L", item.getEntityId(), writer);
    translateNameDescr(qid, item.getDescriptions(), "D", item.getEntityId(), writer);
    translateNameDescr(qid, item.getDescriptionsIfNew(), "D", item.getEntityId(), writer);
    translateNameDescr(qid, item.getAliases(), "A", item.getEntityId(), writer);
    for (StatementEdit s : item.getStatementEdits()) {
        translateStatement(qid, s.getStatement(), s.getPropertyId().getId(), s.getMode() == StatementEditingMode.ADD_OR_MERGE, writer);
    }
}
Also used : StatementEdit(org.openrefine.wikidata.updates.StatementEdit)

Example 17 with StatementEdit

use of org.openrefine.wikidata.updates.StatementEdit in project OpenRefine by OpenRefine.

the class WbStatementGroupExpr method evaluate.

public StatementGroupEdit evaluate(ExpressionContext ctxt, EntityIdValue subject) throws SkipSchemaExpressionException {
    PropertyIdValue propertyId = propertyExpr.evaluate(ctxt);
    List<StatementEdit> statements = new ArrayList<>(statementExprs.size());
    for (WbStatementExpr expr : statementExprs) {
        try {
            statements.add(expr.evaluate(ctxt, subject, propertyId));
        } catch (SkipSchemaExpressionException e) {
            continue;
        }
    }
    if (!statements.isEmpty()) {
        return new StatementGroupEdit(statements);
    } else {
        throw new SkipSchemaExpressionException();
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) StatementGroupEdit(org.openrefine.wikidata.updates.StatementGroupEdit) SkipSchemaExpressionException(org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException) ArrayList(java.util.ArrayList) 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