Search in sources :

Example 6 with SkipSchemaExpressionException

use of org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException in project OpenRefine by OpenRefine.

the class WbLanguageVariable method fromCell.

@Override
public String fromCell(Cell cell, ExpressionContext ctxt) throws SkipSchemaExpressionException {
    if (cell.value != null && !cell.value.toString().isEmpty()) {
        String code = cell.value.toString().trim();
        String mediaWikiApiEndpoint = ctxt.getMediaWikiApiEndpoint();
        String normalized = WbLanguageConstant.normalizeLanguageCode(code, mediaWikiApiEndpoint);
        if (normalized != null) {
            return normalized;
        } else {
            QAWarning issue = new QAWarning("ignored-language", null, QAWarning.Severity.WARNING, 1);
            issue.setProperty("example_value", cell.value.toString());
            ctxt.addWarning(issue);
        }
    }
    throw new SkipSchemaExpressionException();
}
Also used : SkipSchemaExpressionException(org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 7 with SkipSchemaExpressionException

use of org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException 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)7 QAWarning (org.openrefine.wikidata.qa.QAWarning)5 StatementEdit (org.openrefine.wikidata.updates.StatementEdit)3 EntityIdValue (org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)3 PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)3 ArrayList (java.util.ArrayList)2 ReconItemIdValue (org.openrefine.wikidata.schema.entityvalues.ReconItemIdValue)2 StatementGroupEdit (org.openrefine.wikidata.updates.StatementGroupEdit)2 ItemIdValue (org.wikidata.wdtk.datamodel.interfaces.ItemIdValue)2 BigDecimal (java.math.BigDecimal)1 ReconMediaInfoIdValue (org.openrefine.wikidata.schema.entityvalues.ReconMediaInfoIdValue)1 ReconPropertyIdValue (org.openrefine.wikidata.schema.entityvalues.ReconPropertyIdValue)1 TermedStatementEntityEditBuilder (org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder)1 Claim (org.wikidata.wdtk.datamodel.interfaces.Claim)1 MediaInfoIdValue (org.wikidata.wdtk.datamodel.interfaces.MediaInfoIdValue)1 Reference (org.wikidata.wdtk.datamodel.interfaces.Reference)1 Snak (org.wikidata.wdtk.datamodel.interfaces.Snak)1 SnakGroup (org.wikidata.wdtk.datamodel.interfaces.SnakGroup)1 StatementRank (org.wikidata.wdtk.datamodel.interfaces.StatementRank)1 StringValue (org.wikidata.wdtk.datamodel.interfaces.StringValue)1