Search in sources :

Example 26 with PropertyIdValue

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

the class InverseConstraintScrutinizer method scrutinize.

@Override
public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) {
    if (!added) {
        // TODO support for deleted statements
        return;
    }
    Snak mainSnak = statement.getClaim().getMainSnak();
    if (!(mainSnak instanceof ValueSnak)) {
        return;
    }
    Value mainSnakValue = ((ValueSnak) mainSnak).getValue();
    if (mainSnakValue instanceof ItemIdValue) {
        PropertyIdValue pid = mainSnak.getPropertyId();
        PropertyIdValue inversePid = getInverseConstraint(pid);
        if (inversePid != null) {
            EntityIdValue targetEntityId = (EntityIdValue) mainSnakValue;
            Set<EntityIdValue> currentValues = _statements.get(pid).get(entityId);
            if (currentValues == null) {
                currentValues = new HashSet<EntityIdValue>();
                _statements.get(pid).put(entityId, currentValues);
            }
            currentValues.add(targetEntityId);
        }
    }
}
Also used : ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) ValueSnak(org.wikidata.wdtk.datamodel.interfaces.ValueSnak) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) 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)

Example 27 with PropertyIdValue

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

the class InverseConstraintScrutinizer method getInverseConstraint.

protected PropertyIdValue getInverseConstraint(PropertyIdValue pid) {
    if (_inverse.containsKey(pid)) {
        return _inverse.get(pid);
    } else {
        PropertyIdValue inversePid = null;
        List<Statement> statementList = _fetcher.getConstraintsByType(pid, inverseConstraintQid);
        if (!statementList.isEmpty()) {
            InverseConstraint constraint = new InverseConstraint(statementList.get(0));
            inversePid = constraint.propertyParameterValue;
        }
        if (inversePid == null && !_fetcher.getConstraintsByType(pid, symmetricConstraintQid).isEmpty()) {
            inversePid = pid;
        }
        _inverse.put(pid, inversePid);
        _statements.put(pid, new HashMap<EntityIdValue, Set<EntityIdValue>>());
        // the inverse constraints are consistent on Wikidata.
        if (inversePid != null && !_inverse.containsKey(inversePid)) {
            _inverse.put(inversePid, pid);
            _statements.put(inversePid, new HashMap<EntityIdValue, Set<EntityIdValue>>());
        }
        return inversePid;
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Set(java.util.Set) HashSet(java.util.HashSet) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)

Example 28 with PropertyIdValue

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

the class SingleValueScrutinizer method scrutinize.

@Override
public void scrutinize(TermedStatementEntityEdit update) {
    Set<PropertyIdValue> seenSingleProperties = new HashSet<>();
    for (Statement statement : update.getAddedStatements()) {
        PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId();
        List<Statement> constraintStatementList1 = _fetcher.getConstraintsByType(pid, singleValueConstraintQid);
        List<Statement> constraintStatementList2 = _fetcher.getConstraintsByType(pid, singleBestValueConstraintQid);
        if (seenSingleProperties.contains(pid)) {
            QAWarning issue = new QAWarning(type, pid.getId(), QAWarning.Severity.WARNING, 1);
            issue.setProperty("property_entity", pid);
            issue.setProperty("example_entity", update.getEntityId());
            addIssue(issue);
        } else if (!constraintStatementList1.isEmpty() || !constraintStatementList2.isEmpty()) {
            seenSingleProperties.add(pid);
        }
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) QAWarning(org.openrefine.wikidata.qa.QAWarning) HashSet(java.util.HashSet)

Example 29 with PropertyIdValue

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

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

the class WbEntityVariable method fromCell.

@Override
public EntityIdValue fromCell(Cell cell, ExpressionContext ctxt) throws SkipSchemaExpressionException {
    if (cell.recon != null && (Judgment.Matched.equals(cell.recon.judgment) || Judgment.New.equals(cell.recon.judgment))) {
        if (Judgment.New.equals(cell.recon.judgment)) {
            return new ReconItemIdValue(cell.recon, cell.value.toString());
        }
        EntityIdValue entityIdValue = EntityIdValueImpl.fromId(cell.recon.match.id, cell.recon.identifierSpace);
        EntityIdValue reconEntityIdValue = null;
        String entityType = null;
        if (entityIdValue instanceof ItemIdValue) {
            reconEntityIdValue = new ReconItemIdValue(cell.recon, cell.value.toString());
            entityType = "item";
        } else if (entityIdValue instanceof MediaInfoIdValue) {
            reconEntityIdValue = new ReconMediaInfoIdValue(cell.recon, cell.value.toString());
            entityType = "mediainfo";
        } else if (entityIdValue instanceof PropertyIdValue) {
            reconEntityIdValue = new ReconPropertyIdValue(cell.recon, cell.value.toString());
            entityType = "property";
        }
        if (reconEntityIdValue == null) {
            throw new SkipSchemaExpressionException();
        }
        if (cell.recon.identifierSpace == null || !cell.recon.identifierSpace.equals(ctxt.getBaseIRIForEntityType(entityType))) {
            QAWarning warning = new QAWarning("invalid-identifier-space", null, QAWarning.Severity.INFO, 1);
            warning.setProperty("example_cell", cell.value.toString());
            warning.setProperty("expected_site_iri", ctxt.getBaseIRIForEntityType(entityType));
            ctxt.addWarning(warning);
            throw new SkipSchemaExpressionException();
        }
        return reconEntityIdValue;
    }
    throw new SkipSchemaExpressionException();
}
Also used : ReconItemIdValue(org.openrefine.wikidata.schema.entityvalues.ReconItemIdValue) ItemIdValue(org.wikidata.wdtk.datamodel.interfaces.ItemIdValue) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) ReconPropertyIdValue(org.openrefine.wikidata.schema.entityvalues.ReconPropertyIdValue) ReconItemIdValue(org.openrefine.wikidata.schema.entityvalues.ReconItemIdValue) ReconMediaInfoIdValue(org.openrefine.wikidata.schema.entityvalues.ReconMediaInfoIdValue) MediaInfoIdValue(org.wikidata.wdtk.datamodel.interfaces.MediaInfoIdValue) SkipSchemaExpressionException(org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) ReconPropertyIdValue(org.openrefine.wikidata.schema.entityvalues.ReconPropertyIdValue) QAWarning(org.openrefine.wikidata.qa.QAWarning) ReconMediaInfoIdValue(org.openrefine.wikidata.schema.entityvalues.ReconMediaInfoIdValue)

Aggregations

PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)36 Statement (org.wikidata.wdtk.datamodel.interfaces.Statement)17 QAWarning (org.openrefine.wikidata.qa.QAWarning)16 Snak (org.wikidata.wdtk.datamodel.interfaces.Snak)12 EntityIdValue (org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)11 Value (org.wikidata.wdtk.datamodel.interfaces.Value)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 SnakGroup (org.wikidata.wdtk.datamodel.interfaces.SnakGroup)9 ValueSnak (org.wikidata.wdtk.datamodel.interfaces.ValueSnak)9 List (java.util.List)8 Set (java.util.Set)6 Claim (org.wikidata.wdtk.datamodel.interfaces.Claim)6 Reference (org.wikidata.wdtk.datamodel.interfaces.Reference)6 Collectors (java.util.stream.Collectors)5 StatementEdit (org.openrefine.wikidata.updates.StatementEdit)5 Test (org.testng.annotations.Test)5 SkipSchemaExpressionException (org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException)4 TermedStatementEntityEdit (org.openrefine.wikidata.updates.TermedStatementEntityEdit)4