Search in sources :

Example 6 with QAWarning

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

the class InverseConstraintScrutinizer method batchIsFinished.

@Override
public void batchIsFinished() {
    // For each pair of inverse properties (in each direction)
    for (Entry<PropertyIdValue, PropertyIdValue> propertyPair : _inverse.entrySet()) {
        // Get the statements made for the first
        PropertyIdValue ourProperty = propertyPair.getKey();
        for (Entry<EntityIdValue, Set<EntityIdValue>> itemLinks : _statements.get(ourProperty).entrySet()) {
            // For each outgoing link
            for (EntityIdValue idValue : itemLinks.getValue()) {
                // Check that they are in the statements made for the second
                PropertyIdValue missingProperty = propertyPair.getValue();
                Set<EntityIdValue> reciprocalLinks = _statements.get(missingProperty).get(idValue);
                if (reciprocalLinks == null || !reciprocalLinks.contains(itemLinks.getKey())) {
                    QAWarning issue = new QAWarning(type, ourProperty.getId(), QAWarning.Severity.IMPORTANT, 1);
                    issue.setProperty("added_property_entity", ourProperty);
                    issue.setProperty("inverse_property_entity", missingProperty);
                    issue.setProperty("source_entity", itemLinks.getKey());
                    issue.setProperty("target_entity", idValue);
                    addIssue(issue);
                }
            }
        }
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Set(java.util.Set) HashSet(java.util.HashSet) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 7 with QAWarning

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

the class MultiValueScrutinizer method scrutinize.

@Override
public void scrutinize(TermedStatementEntityEdit update) {
    Map<PropertyIdValue, Integer> propertyCount = new HashMap<>();
    for (Statement statement : update.getAddedStatements()) {
        PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId();
        List<Statement> statementList = _fetcher.getConstraintsByType(pid, multiValueConstraintQid);
        if (propertyCount.containsKey(pid)) {
            propertyCount.put(pid, propertyCount.get(pid) + 1);
        } else if (!statementList.isEmpty()) {
            propertyCount.put(pid, 1);
        }
    }
    if (update.isNew()) {
        for (PropertyIdValue pid : propertyCount.keySet()) {
            if (propertyCount.get(pid) == 1) {
                QAWarning issue = new QAWarning(new_type, pid.getId(), QAWarning.Severity.WARNING, 1);
                issue.setProperty("property_entity", pid);
                issue.setProperty("example_entity", update.getEntityId());
                addIssue(issue);
            }
        }
    } else {
        for (PropertyIdValue pid : propertyCount.keySet()) {
            if (propertyCount.get(pid) == 1) {
                QAWarning issue = new QAWarning(existing_type, pid.getId(), QAWarning.Severity.INFO, 1);
                issue.setProperty("property_entity", pid);
                issue.setProperty("example_entity", update.getEntityId());
                addIssue(issue);
            }
        }
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) HashMap(java.util.HashMap) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 8 with QAWarning

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

the class QualifierCompatibilityScrutinizer method scrutinize.

@Override
public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) {
    if (!added) {
        // not scrutinizing deleted statements
        return;
    }
    PropertyIdValue statementProperty = statement.getClaim().getMainSnak().getPropertyId();
    Set<PropertyIdValue> qualifiers = statement.getClaim().getQualifiers().stream().map(e -> e.getProperty()).collect(Collectors.toSet());
    Set<PropertyIdValue> missingQualifiers = mandatoryQualifiers(statementProperty).stream().filter(p -> !qualifiers.contains(p)).collect(Collectors.toSet());
    Set<PropertyIdValue> disallowedQualifiers = qualifiers.stream().filter(p -> !qualifierIsAllowed(statementProperty, p)).collect(Collectors.toSet());
    for (PropertyIdValue missing : missingQualifiers) {
        QAWarning issue = new QAWarning(missingMandatoryQualifiersType, statementProperty.getId() + "-" + missing.getId(), QAWarning.Severity.WARNING, 1);
        issue.setProperty("statement_property_entity", statementProperty);
        issue.setProperty("missing_property_entity", missing);
        issue.setProperty("example_item_entity", entityId);
        addIssue(issue);
    }
    for (PropertyIdValue disallowed : disallowedQualifiers) {
        QAWarning issue = new QAWarning(disallowedQualifiersType, statementProperty.getId() + "-" + disallowed.getId(), QAWarning.Severity.WARNING, 1);
        issue.setProperty("statement_property_entity", statementProperty);
        issue.setProperty("disallowed_property_entity", disallowed);
        issue.setProperty("example_item_entity", entityId);
        addIssue(issue);
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) HashSet(java.util.HashSet) List(java.util.List) Map(java.util.Map) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) Set(java.util.Set) HashMap(java.util.HashMap) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) Collectors(java.util.stream.Collectors) QAWarning(org.openrefine.wikidata.qa.QAWarning) Value(org.wikidata.wdtk.datamodel.interfaces.Value) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 9 with QAWarning

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

the class WbQuantityExpr method evaluate.

@Override
public QuantityValue evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
    StringValue amount = getAmountExpr().evaluate(ctxt);
    // we know the amount is nonnull, nonempty here
    BigDecimal parsedAmount = null;
    BigDecimal lowerBound = null;
    BigDecimal upperBound = null;
    String originalAmount = amount.getString().toUpperCase();
    try {
        parsedAmount = new BigDecimal(originalAmount);
        if (originalAmount.contains("E")) {
            // engineering notation: we derive the precision from
            // the expression (feature!)
            BigDecimal uncertainty = new BigDecimal("0.5").scaleByPowerOfTen(-parsedAmount.scale());
            lowerBound = new BigDecimal(parsedAmount.subtract(uncertainty).toPlainString());
            upperBound = new BigDecimal(parsedAmount.add(uncertainty).toPlainString());
        }
        // workaround for https://github.com/Wikidata/Wikidata-Toolkit/issues/341
        parsedAmount = new BigDecimal(parsedAmount.toPlainString());
    } catch (NumberFormatException e) {
        if (!originalAmount.isEmpty()) {
            QAWarning issue = new QAWarning("ignored-amount", null, QAWarning.Severity.WARNING, 1);
            issue.setProperty("example_value", originalAmount);
            ctxt.addWarning(issue);
        }
        throw new SkipSchemaExpressionException();
    }
    if (getUnitExpr() != null) {
        ItemIdValue unit = getUnitExpr().evaluate(ctxt);
        return Datamodel.makeQuantityValue(parsedAmount, lowerBound, upperBound, unit);
    }
    return Datamodel.makeQuantityValue(parsedAmount, lowerBound, upperBound);
}
Also used : ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) SkipSchemaExpressionException(org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException) StringValue(org.wikidata.wdtk.datamodel.interfaces.StringValue) QAWarning(org.openrefine.wikidata.qa.QAWarning) BigDecimal(java.math.BigDecimal)

Example 10 with QAWarning

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

the class EnglishDescriptionScrutinizer method checkPunctuationSign.

// Description are not sentences, so the punctuation sign at the end should be avoided.
protected void checkPunctuationSign(TermedStatementEntityEdit update, String descText) {
    assert descText.length() > 0;
    final String punctuationSigns = ".?!;:,'\"";
    char last = descText.charAt(descText.length() - 1);
    if (punctuationSigns.indexOf(last) != -1) {
        QAWarning issue = new QAWarning(descEndsByPunctuationSign, null, QAWarning.Severity.WARNING, 1);
        issue.setProperty("example_entity", update.getEntityId());
        issue.setProperty("description", descText);
        issue.setProperty("lang", LANG);
        issue.setProperty("punctuation_sign", last);
        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