Search in sources :

Example 21 with ValueSnak

use of org.wikidata.wdtk.datamodel.interfaces.ValueSnak in project OpenRefine by OpenRefine.

the class UseAsQualifierScrutinizer method scrutinize.

@Override
public void scrutinize(TermedStatementEntityEdit update) {
    for (Statement statement : update.getAddedStatements()) {
        PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId();
        Map<PropertyIdValue, List<Value>> qualifiersMap = new HashMap<>();
        List<SnakGroup> qualifiersList = statement.getClaim().getQualifiers();
        for (SnakGroup qualifier : qualifiersList) {
            PropertyIdValue qualifierPid = qualifier.getProperty();
            List<Value> itemList;
            for (Snak snak : qualifier.getSnaks()) {
                if (!(snak instanceof ValueSnak)) {
                    continue;
                }
                if (qualifiersMap.containsKey(qualifierPid)) {
                    itemList = qualifiersMap.get(qualifierPid);
                } else {
                    itemList = new ArrayList<>();
                }
                itemList.add(((ValueSnak) snak).getValue());
                qualifiersMap.put(qualifierPid, itemList);
            }
        }
        List<Statement> constraintDefinitions = _fetcher.getConstraintsByType(pid, oneOfQualifierValuePropertyQid);
        for (Statement constraintStatement : constraintDefinitions) {
            UseAsQualifierConstraint constraint = new UseAsQualifierConstraint(constraintStatement);
            if (qualifiersMap.containsKey(constraint.allowedQualifierPid)) {
                for (Value value : qualifiersMap.get(constraint.allowedQualifierPid)) {
                    if (!constraint.itemList.contains(value)) {
                        QAWarning issue = new QAWarning(type, pid.getId() + constraint.allowedQualifierPid.getId(), QAWarning.Severity.WARNING, 1);
                        issue.setProperty("statement_entity", pid);
                        issue.setProperty("qualifier_entity", constraint.allowedQualifierPid);
                        issue.setProperty("example_entity", update.getEntityId());
                        addIssue(issue);
                    }
                }
            }
        }
    }
}
Also used : Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) HashMap(java.util.HashMap) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Value(org.wikidata.wdtk.datamodel.interfaces.Value) ArrayList(java.util.ArrayList) List(java.util.List) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 22 with ValueSnak

use of org.wikidata.wdtk.datamodel.interfaces.ValueSnak in project OpenRefine by OpenRefine.

the class DistinctValuesScrutinizer method scrutinize.

@Override
public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) {
    if (!added) {
        // not scrutinizing removed statements
        return;
    }
    Snak mainSnak = statement.getClaim().getMainSnak();
    PropertyIdValue pid = mainSnak.getPropertyId();
    List<Statement> statementList = _fetcher.getConstraintsByType(pid, distinctValuesConstraintQid);
    if (!statementList.isEmpty() && mainSnak instanceof ValueSnak) {
        Value mainSnakValue = ((ValueSnak) mainSnak).getValue();
        Map<Value, EntityIdValue> seen = _seenValues.get(pid);
        if (seen == null) {
            seen = new HashMap<Value, EntityIdValue>();
            _seenValues.put(pid, seen);
        }
        if (seen.containsKey(mainSnakValue)) {
            EntityIdValue otherId = seen.get(mainSnakValue);
            QAWarning issue = new QAWarning(type, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
            issue.setProperty("property_entity", pid);
            issue.setProperty("item1_entity", entityId);
            issue.setProperty("item2_entity", otherId);
            addIssue(issue);
        } else {
            seen.put(mainSnakValue, entityId);
        }
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) 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) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) QAWarning(org.openrefine.wikidata.qa.QAWarning)

Example 23 with ValueSnak

use of org.wikidata.wdtk.datamodel.interfaces.ValueSnak 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 24 with ValueSnak

use of org.wikidata.wdtk.datamodel.interfaces.ValueSnak 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

ValueSnak (org.wikidata.wdtk.datamodel.interfaces.ValueSnak)24 Statement (org.wikidata.wdtk.datamodel.interfaces.Statement)20 ItemIdValue (org.wikidata.wdtk.datamodel.interfaces.ItemIdValue)16 ConstraintFetcher (org.openrefine.wikidata.qa.ConstraintFetcher)14 TermedStatementEntityEdit (org.openrefine.wikidata.updates.TermedStatementEntityEdit)14 TermedStatementEntityEditBuilder (org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder)14 Test (org.testng.annotations.Test)14 StatementImpl (org.wikidata.wdtk.datamodel.implementation.StatementImpl)14 Snak (org.wikidata.wdtk.datamodel.interfaces.Snak)14 SnakGroup (org.wikidata.wdtk.datamodel.interfaces.SnakGroup)10 QAWarning (org.openrefine.wikidata.qa.QAWarning)8 PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)8 Value (org.wikidata.wdtk.datamodel.interfaces.Value)7 NoValueSnak (org.wikidata.wdtk.datamodel.interfaces.NoValueSnak)6 HashMap (java.util.HashMap)3 EntityIdValue (org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 TimeValueImpl (org.wikidata.wdtk.datamodel.implementation.TimeValueImpl)2