Search in sources :

Example 1 with StatementGroupEdit

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

the class WbEntityDocumentExpr method evaluate.

@Override
public TermedStatementEntityEdit evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
    EntityIdValue subjectId = getSubject().evaluate(ctxt);
    TermedStatementEntityEditBuilder update = new TermedStatementEntityEditBuilder(subjectId);
    for (WbStatementGroupExpr expr : getStatementGroups()) {
        try {
            StatementGroupEdit statementGroupUpdate = expr.evaluate(ctxt, subjectId);
            // TODO also store statement groups in TermedStatementEntityUpdate?
            for (StatementEdit s : statementGroupUpdate.getStatementEdits()) {
                update.addStatement(s);
            }
        } catch (SkipSchemaExpressionException e) {
            continue;
        }
    }
    for (WbNameDescExpr expr : getNameDescs()) {
        expr.contributeTo(update, ctxt);
    }
    return update.build();
}
Also used : TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) StatementGroupEdit(org.openrefine.wikidata.updates.StatementGroupEdit) SkipSchemaExpressionException(org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) StatementEdit(org.openrefine.wikidata.updates.StatementEdit)

Example 2 with StatementGroupEdit

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

SkipSchemaExpressionException (org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException)2 StatementEdit (org.openrefine.wikidata.updates.StatementEdit)2 StatementGroupEdit (org.openrefine.wikidata.updates.StatementGroupEdit)2 ArrayList (java.util.ArrayList)1 TermedStatementEntityEditBuilder (org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder)1 EntityIdValue (org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)1 PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)1