Search in sources :

Example 16 with QAWarning

use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.

the class WbItemVariable method fromCell.

@Override
public ItemIdValue fromCell(Cell cell, ExpressionContext ctxt) throws SkipSchemaExpressionException {
    if (cell.recon != null && (Judgment.Matched.equals(cell.recon.judgment) || Judgment.New.equals(cell.recon.judgment))) {
        if (cell.recon.identifierSpace == null || !cell.recon.identifierSpace.equals(ctxt.getBaseIRI())) {
            QAWarning warning = new QAWarning("invalid-identifier-space", null, QAWarning.Severity.INFO, 1);
            warning.setProperty("example_cell", cell.value.toString());
            ctxt.addWarning(warning);
            throw new SkipSchemaExpressionException();
        }
        return new ReconItemIdValue(cell.recon, cell.value.toString());
    }
    throw new SkipSchemaExpressionException();
}
Also used : ReconItemIdValue(org.openrefine.wikidata.schema.entityvalues.ReconItemIdValue) SkipSchemaExpressionException(org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 17 with QAWarning

use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.

the class CalendarScrutinizer method scrutinize.

@Override
public void scrutinize(Value value) {
    if (value instanceof TimeValue) {
        TimeValue time = (TimeValue) value;
        if (time.getPreferredCalendarModel().equals(earliestGregorian.getPreferredCalendarModel()) && time.getPrecision() >= 10 && (time.getYear() < earliestGregorian.getYear() || time.getYear() == earliestGregorian.getYear() && time.getMonth() < earliestGregorian.getMonth() || time.getYear() == earliestGregorian.getYear() && time.getMonth() == earliestGregorian.getMonth() && time.getDay() < earliestGregorian.getDay())) {
            QAWarning warning = new QAWarning(earlyGregorianDateType, null, QAWarning.Severity.WARNING, 1);
            warning.setProperty("example_year", Long.toString(time.getYear()));
            addIssue(warning);
        }
    }
}
Also used : QAWarning(org.openrefine.wikidata.qa.QAWarning) TimeValue(org.wikidata.wdtk.datamodel.interfaces.TimeValue)

Example 18 with QAWarning

use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.

the class ConflictsWithScrutinizer method scrutinize.

@Override
public void scrutinize(TermedStatementEntityEdit update) {
    Map<PropertyIdValue, Set<Value>> propertyIdValueValueMap = new HashMap<>();
    for (Statement statement : update.getAddedStatements()) {
        PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId();
        Value value = null;
        Snak mainSnak = statement.getClaim().getMainSnak();
        if (mainSnak instanceof ValueSnak) {
            value = ((ValueSnak) mainSnak).getValue();
        }
        Set<Value> values;
        if (value != null) {
            if (propertyIdValueValueMap.containsKey(pid)) {
                values = propertyIdValueValueMap.get(pid);
            } else {
                values = new HashSet<>();
            }
            values.add(value);
            propertyIdValueValueMap.put(pid, values);
        }
    }
    for (PropertyIdValue propertyId : propertyIdValueValueMap.keySet()) {
        List<Statement> statementList = _fetcher.getConstraintsByType(propertyId, conflictsWithConstraintQid);
        for (Statement statement : statementList) {
            ConflictsWithConstraint constraint = new ConflictsWithConstraint(statement);
            PropertyIdValue conflictingPid = constraint.conflictingPid;
            List<Value> itemList = constraint.itemList;
            if (propertyIdValueValueMap.containsKey(conflictingPid) && raiseWarning(propertyIdValueValueMap, conflictingPid, itemList)) {
                QAWarning issue = new QAWarning(type, propertyId.getId() + conflictingPid.getId(), QAWarning.Severity.WARNING, 1);
                issue.setProperty("property_entity", propertyId);
                issue.setProperty("added_property_entity", conflictingPid);
                issue.setProperty("example_entity", update.getEntityId());
                addIssue(issue);
            }
        }
    }
}
Also used : Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Value(org.wikidata.wdtk.datamodel.interfaces.Value) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 19 with QAWarning

use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.

the class DifferenceWithinRangeScrutinizer method scrutinize.

@Override
public void scrutinize(TermedStatementEntityEdit update) {
    Map<PropertyIdValue, Value> propertyIdValueValueMap = new HashMap<>();
    for (Statement statement : update.getAddedStatements()) {
        Snak mainSnak = statement.getClaim().getMainSnak();
        if (mainSnak instanceof ValueSnak) {
            PropertyIdValue pid = mainSnak.getPropertyId();
            Value value = ((ValueSnak) mainSnak).getValue();
            propertyIdValueValueMap.put(pid, value);
        }
    }
    for (PropertyIdValue propertyId : propertyIdValueValueMap.keySet()) {
        List<Statement> statementList = _fetcher.getConstraintsByType(propertyId, differenceWithinRangeConstraintQid);
        if (!statementList.isEmpty()) {
            DifferenceWithinRangeConstraint constraint = new DifferenceWithinRangeConstraint(statementList.get(0));
            PropertyIdValue lowerPropertyId = constraint.lowerPropertyIdValue;
            QuantityValue minRangeValue = constraint.minRangeValue;
            QuantityValue maxRangeValue = constraint.maxRangeValue;
            if (propertyIdValueValueMap.containsKey(lowerPropertyId)) {
                Value startingValue = propertyIdValueValueMap.get(lowerPropertyId);
                Value endingValue = propertyIdValueValueMap.get(propertyId);
                if (startingValue instanceof TimeValue && endingValue instanceof TimeValue) {
                    TimeValue lowerDate = (TimeValue) startingValue;
                    TimeValue upperDate = (TimeValue) endingValue;
                    long differenceInYears = upperDate.getYear() - lowerDate.getYear();
                    long differenceInMonths = upperDate.getMonth() - lowerDate.getMonth();
                    long differenceInDays = upperDate.getMonth() - lowerDate.getMonth();
                    if (minRangeValue != null && (differenceInYears < minRangeValue.getNumericValue().longValue() || differenceInYears == 0 && differenceInMonths < 0 || differenceInYears == 0 && differenceInMonths == 0 && differenceInDays < 0)) {
                        QAWarning issue = new QAWarning(type, propertyId.getId(), QAWarning.Severity.WARNING, 1);
                        issue.setProperty("source_entity", lowerPropertyId);
                        issue.setProperty("target_entity", propertyId);
                        issue.setProperty("min_value", minRangeValue.getNumericValue());
                        if (maxRangeValue != null) {
                            issue.setProperty("max_value", maxRangeValue.getNumericValue());
                        } else {
                            issue.setProperty("max_value", null);
                        }
                        issue.setProperty("example_entity", update.getEntityId());
                        addIssue(issue);
                    }
                    if (maxRangeValue != null && differenceInYears > maxRangeValue.getNumericValue().longValue()) {
                        QAWarning issue = new QAWarning(type, propertyId.getId(), QAWarning.Severity.WARNING, 1);
                        issue.setProperty("source_entity", lowerPropertyId);
                        issue.setProperty("target_entity", propertyId);
                        if (minRangeValue != null) {
                            issue.setProperty("min_value", minRangeValue.getNumericValue());
                        } else {
                            issue.setProperty("min_value", null);
                        }
                        issue.setProperty("max_value", maxRangeValue.getNumericValue());
                        issue.setProperty("example_entity", update.getEntityId());
                        addIssue(issue);
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 20 with QAWarning

use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.

the class EntityTypeScrutinizer method scrutinize.

@Override
public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
    if (!added) {
        return;
    }
    PropertyIdValue pid = snak.getPropertyId();
    List<Statement> statementList = _fetcher.getConstraintsByType(pid, allowedEntityTypesQid);
    if (!statementList.isEmpty()) {
        List<SnakGroup> constraint = statementList.get(0).getClaim().getQualifiers();
        boolean isUsable = true;
        if (constraint != null) {
            isUsable = findValues(constraint, itemOfPropertyConstraint).contains(Datamodel.makeWikidataItemIdValue(wikibaseItemQid));
        }
        if (!isUsable) {
            QAWarning issue = new QAWarning(type, null, QAWarning.Severity.WARNING, 1);
            issue.setProperty("property_entity", pid);
            issue.setProperty("example_entity", entityId);
            addIssue(issue);
        }
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Aggregations

QAWarning (org.openrefine.wikidata.qa.QAWarning)29 PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)15 Statement (org.wikidata.wdtk.datamodel.interfaces.Statement)12 ValueSnak (org.wikidata.wdtk.datamodel.interfaces.ValueSnak)8 Value (org.wikidata.wdtk.datamodel.interfaces.Value)7 HashMap (java.util.HashMap)6 EntityIdValue (org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)6 HashSet (java.util.HashSet)5 SkipSchemaExpressionException (org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException)5 Snak (org.wikidata.wdtk.datamodel.interfaces.Snak)5 Set (java.util.Set)4 SnakGroup (org.wikidata.wdtk.datamodel.interfaces.SnakGroup)4 ItemIdValue (org.wikidata.wdtk.datamodel.interfaces.ItemIdValue)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ReconItemIdValue (org.openrefine.wikidata.schema.entityvalues.ReconItemIdValue)2 Reference (org.wikidata.wdtk.datamodel.interfaces.Reference)2 StringValue (org.wikidata.wdtk.datamodel.interfaces.StringValue)2 BigDecimal (java.math.BigDecimal)1 Map (java.util.Map)1