Search in sources :

Example 26 with QAWarning

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

the class EnglishDescriptionScrutinizer method checkUppercase.

// Descriptions begin with a lowercase letter except when uppercase would normally be required or expected.
protected void checkUppercase(TermedStatementEntityEdit update, String descText) {
    assert descText.length() > 0;
    char first = descText.charAt(0);
    if ('A' <= first && first <= 'Z') {
        QAWarning issue = new QAWarning(descBeginWithUppercase, null, QAWarning.Severity.INFO, 1);
        issue.setProperty("example_entity", update.getEntityId());
        issue.setProperty("description", descText);
        issue.setProperty("lang", LANG);
        issue.setProperty("uppercase_letter", first);
        addIssue(issue);
    }
}
Also used : QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 27 with QAWarning

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

the class ItemRequiresScrutinizer method scrutinize.

@Override
public void scrutinize(TermedStatementEntityEdit update) {
    Map<PropertyIdValue, Set<Value>> propertyIdValueValueMap = new HashMap<>();
    for (Statement statement : update.getAddedStatements()) {
        Snak mainSnak = statement.getClaim().getMainSnak();
        PropertyIdValue pid = mainSnak.getPropertyId();
        Set<Value> values;
        if (mainSnak instanceof ValueSnak) {
            Value value = ((ValueSnak) mainSnak).getValue();
            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> constraintDefinitions = _fetcher.getConstraintsByType(propertyId, itemRequiresConstraintQid);
        for (Statement statement : constraintDefinitions) {
            ItemRequiresConstraint constraint = new ItemRequiresConstraint(statement);
            PropertyIdValue itemRequiresPid = constraint.itemRequiresPid;
            List<Value> itemList = constraint.itemList;
            if (!propertyIdValueValueMap.containsKey(itemRequiresPid)) {
                QAWarning issue = new QAWarning(update.isNew() ? newItemRequirePropertyType : existingItemRequirePropertyType, propertyId.getId() + itemRequiresPid.getId(), update.isNew() ? QAWarning.Severity.WARNING : QAWarning.Severity.INFO, 1);
                issue.setProperty("property_entity", propertyId);
                issue.setProperty("added_property_entity", itemRequiresPid);
                issue.setProperty("example_entity", update.getEntityId());
                addIssue(issue);
            } else if (raiseWarning(propertyIdValueValueMap, itemRequiresPid, itemList)) {
                QAWarning issue = new QAWarning(update.isNew() ? newItemRequireValuesType : existingItemRequireValuesType, propertyId.getId() + itemRequiresPid.getId(), update.isNew() ? QAWarning.Severity.WARNING : QAWarning.Severity.INFO, 1);
                issue.setProperty("property_entity", propertyId);
                issue.setProperty("added_property_entity", itemRequiresPid);
                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 28 with QAWarning

use of org.openrefine.wikidata.qa.QAWarning 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 29 with QAWarning

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

the class SelfReferentialScrutinizer method scrutinize.

@Override
public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
    if (!added) {
        return;
    }
    if (snak instanceof ValueSnak && entityId.equals(((ValueSnak) snak).getValue())) {
        QAWarning issue = new QAWarning(type, null, QAWarning.Severity.WARNING, 1);
        issue.setProperty("example_entity", entityId);
        addIssue(issue);
    }
}
Also used : ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) 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