Search in sources :

Example 1 with QAWarning

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

the class QuantityScrutinizer method scrutinize.

@Override
public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
    if (!added) {
        return;
    }
    if (snak instanceof ValueSnak && ((ValueSnak) snak).getValue() instanceof QuantityValue && added) {
        PropertyIdValue pid = snak.getPropertyId();
        QuantityValue value = (QuantityValue) ((ValueSnak) snak).getValue();
        if (!_fetcher.getConstraintsByType(pid, noBoundsConstraintQid).isEmpty() && (value.getUpperBound() != null || value.getLowerBound() != null)) {
            QAWarning issue = new QAWarning(boundsDisallowedType, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
            issue.setProperty("property_entity", pid);
            issue.setProperty("example_value", value.getNumericValue().toString());
            issue.setProperty("example_item_entity", entityId);
            addIssue(issue);
        }
        if (!_fetcher.getConstraintsByType(pid, integerValuedConstraintQid).isEmpty() && value.getNumericValue().scale() > 0) {
            QAWarning issue = new QAWarning(integerConstraintType, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
            issue.setProperty("property_entity", pid);
            issue.setProperty("example_value", value.getNumericValue().toString());
            issue.setProperty("example_item_entity", entityId);
            addIssue(issue);
        }
        List<Statement> statementList = _fetcher.getConstraintsByType(pid, allowedUnitsConstraintQid);
        Set<ItemIdValue> allowedUnits = null;
        if (!statementList.isEmpty()) {
            AllowedUnitsConstraint allowedUnitsConstraint = new AllowedUnitsConstraint(statementList.get(0));
            allowedUnits = allowedUnitsConstraint.allowedUnits;
        }
        ItemIdValue currentUnit = null;
        if (value.getUnitItemId() != null) {
            currentUnit = value.getUnitItemId();
        }
        if (allowedUnits != null && !allowedUnits.contains(currentUnit)) {
            String issueType = currentUnit == null ? noUnitProvidedType : invalidUnitType;
            QAWarning issue = new QAWarning(issueType, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
            issue.setProperty("property_entity", pid);
            issue.setProperty("example_value", value.getNumericValue().toString());
            issue.setProperty("example_item_entity", entityId);
            if (currentUnit != null) {
                issue.setProperty("unit_entity", value.getUnitItemId());
            }
            addIssue(issue);
        }
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) QuantityValue(org.wikidata.wdtk.datamodel.interfaces.QuantityValue) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 2 with QAWarning

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

the class RestrictedValuesScrutinizer method scrutinize.

@Override
public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
    if (!added) {
        return;
    }
    PropertyIdValue pid = snak.getPropertyId();
    Value value = null;
    if (snak instanceof ValueSnak) {
        value = ((ValueSnak) snak).getValue();
    }
    List<Statement> allowedValueConstraintDefinitions = _fetcher.getConstraintsByType(pid, allowedValuesConstraintQid);
    List<Statement> disallowedValueConstraintDefinitions = _fetcher.getConstraintsByType(pid, disallowedValuesConstraintQid);
    Set<Value> allowedValues = null, disallowedValues = null;
    if (!allowedValueConstraintDefinitions.isEmpty()) {
        AllowedValueConstraint constraint = new AllowedValueConstraint(allowedValueConstraintDefinitions.get(0));
        allowedValues = constraint.allowedValues;
    }
    if (!disallowedValueConstraintDefinitions.isEmpty()) {
        DisallowedValueConstraint constraint = new DisallowedValueConstraint(disallowedValueConstraintDefinitions.get(0));
        disallowedValues = constraint.disallowedValues;
    }
    if ((allowedValues != null && !allowedValues.contains(value)) || (disallowedValues != null && disallowedValues.contains(value))) {
        QAWarning issue = new QAWarning(type, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
        issue.setProperty("property_entity", pid);
        issue.setProperty("example_value_entity", value);
        issue.setProperty("example_subject_entity", entityId);
        addIssue(issue);
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) Value(org.wikidata.wdtk.datamodel.interfaces.Value) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 3 with QAWarning

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

the class WhitespaceScrutinizer method emitWarning.

private void emitWarning(String type, String example) {
    QAWarning warning = new QAWarning(type, null, QAWarning.Severity.WARNING, 1);
    warning.setProperty("example_string", example);
    addIssue(warning);
}
Also used : QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 4 with QAWarning

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

the class CommonDescriptionScrutinizer method checkLabel.

// Description are expected to be more specific than labels.
protected void checkLabel(TermedStatementEntityEdit update, String descText, String lang) {
    Set<MonolingualTextValue> labels = update.getLabels();
    // merge
    labels.addAll(update.getLabelsIfNew());
    for (MonolingualTextValue label : labels) {
        String labelText = label.getText();
        if (labelText == null) {
            continue;
        }
        labelText = labelText.trim();
        if (labelText.equals(descText)) {
            QAWarning issue = new QAWarning(descIdenticalWithLabel, null, QAWarning.Severity.WARNING, 1);
            issue.setProperty("example_entity", update.getEntityId());
            issue.setProperty("description", descText);
            issue.setProperty("lang", lang);
            issue.setProperty("label_lang", label.getLanguageCode());
            addIssue(issue);
            break;
        }
    }
}
Also used : MonolingualTextValue(org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 5 with QAWarning

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

the class CommonDescriptionScrutinizer method checkLength.

// Descriptions are not full sentences, but small bits of information.
// In most cases, the proper length is between two and twelve words.
protected void checkLength(TermedStatementEntityEdit update, String descText, String lang) {
    final int maxLength = 250;
    if (descText.length() > maxLength) {
        QAWarning issue = new QAWarning(descTooLongType, null, QAWarning.Severity.CRITICAL, 1);
        issue.setProperty("example_entity", update.getEntityId());
        issue.setProperty("description", descText);
        issue.setProperty("lang", lang);
        issue.setProperty("length", descText.length());
        issue.setProperty("max_length", maxLength);
        addIssue(issue);
    }
}
Also used : 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