Search in sources :

Example 21 with PropertyIdValue

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

the class SnakUtils method groupSnaks.

/**
 * Groups snaks into a list of snak groups.
 * The order of the first snaks in each group is preserved.
 *
 * @param snaks
 * @return
 */
public static List<SnakGroup> groupSnaks(List<Snak> snaks) {
    Map<PropertyIdValue, List<Snak>> snakGroups = new HashMap<>();
    List<PropertyIdValue> propertyOrder = new ArrayList<PropertyIdValue>();
    for (Snak snak : snaks) {
        List<Snak> existingSnaks = snakGroups.get(snak.getPropertyId());
        if (existingSnaks == null) {
            existingSnaks = new ArrayList<Snak>();
            snakGroups.put(snak.getPropertyId(), existingSnaks);
            propertyOrder.add(snak.getPropertyId());
        }
        if (!existingSnaks.contains(snak)) {
            existingSnaks.add(snak);
        }
    }
    return propertyOrder.stream().map(pid -> Datamodel.makeSnakGroup(snakGroups.get(pid))).collect(Collectors.toList());
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) List(java.util.List) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) Map(java.util.Map) Datamodel(org.wikidata.wdtk.datamodel.helpers.Datamodel) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 22 with PropertyIdValue

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

the class SchemaPropertyExtractorTest method makePropertySet.

public Set<PropertyIdValue> makePropertySet(String... pids) {
    Set<PropertyIdValue> propertyIdValues = new HashSet<>();
    for (String pid : pids) {
        PropertyIdValue propertyIdValue = Datamodel.makeWikidataPropertyIdValue(pid);
        propertyIdValues.add(propertyIdValue);
    }
    return propertyIdValues;
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) HashSet(java.util.HashSet)

Example 23 with PropertyIdValue

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

the class WbStatementExpr method groupSnaks.

public static List<SnakGroup> groupSnaks(List<Snak> snaks) {
    Map<PropertyIdValue, List<Snak>> snakGroups = new HashMap<>();
    List<PropertyIdValue> propertyOrder = new ArrayList<PropertyIdValue>();
    for (Snak snak : snaks) {
        List<Snak> existingSnaks = snakGroups.get(snak.getPropertyId());
        if (existingSnaks == null) {
            existingSnaks = new ArrayList<Snak>();
            snakGroups.put(snak.getPropertyId(), existingSnaks);
            propertyOrder.add(snak.getPropertyId());
        }
        if (!existingSnaks.contains(snak)) {
            existingSnaks.add(snak);
        }
    }
    return propertyOrder.stream().map(pid -> Datamodel.makeSnakGroup(snakGroups.get(pid))).collect(Collectors.toList());
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StatementEditingMode(org.openrefine.wikidata.schema.strategies.StatementEditingMode) Map(java.util.Map) EntityIdValue(org.wikidata.wdtk.datamodel.interfaces.EntityIdValue) Claim(org.wikidata.wdtk.datamodel.interfaces.Claim) QAWarning(org.openrefine.wikidata.qa.QAWarning) Value(org.wikidata.wdtk.datamodel.interfaces.Value) SkipSchemaExpressionException(org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException) Reference(org.wikidata.wdtk.datamodel.interfaces.Reference) Validate(org.jsoup.helper.Validate) PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) StatementMerger(org.openrefine.wikidata.schema.strategies.StatementMerger) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) StatementRank(org.wikidata.wdtk.datamodel.interfaces.StatementRank) List(java.util.List) StatementEdit(org.openrefine.wikidata.updates.StatementEdit) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) PropertyOnlyStatementMerger(org.openrefine.wikidata.schema.strategies.PropertyOnlyStatementMerger) Datamodel(org.wikidata.wdtk.datamodel.helpers.Datamodel) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) Collections(java.util.Collections) JsonIgnoreProperties(com.fasterxml.jackson.annotation.JsonIgnoreProperties) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 24 with PropertyIdValue

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

the class ConflictsWithScrutinizer method scrutinize.

@Override
public void scrutinize(TermedStatementEntityEdit update) {
    Map<PropertyIdValue, Set<Value>> propertyIdValueValueMap = new HashMap<>();
    for (Statement statement : update.getAddedStatements()) {
        PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId();
        Value value = null;
        Snak mainSnak = statement.getClaim().getMainSnak();
        if (mainSnak instanceof ValueSnak) {
            value = ((ValueSnak) mainSnak).getValue();
        }
        Set<Value> values;
        if (value != null) {
            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> statementList = _fetcher.getConstraintsByType(propertyId, conflictsWithConstraintQid);
        for (Statement statement : statementList) {
            ConflictsWithConstraint constraint = new ConflictsWithConstraint(statement);
            PropertyIdValue conflictingPid = constraint.conflictingPid;
            List<Value> itemList = constraint.itemList;
            if (propertyIdValueValueMap.containsKey(conflictingPid) && raiseWarning(propertyIdValueValueMap, conflictingPid, itemList)) {
                QAWarning issue = new QAWarning(type, propertyId.getId() + conflictingPid.getId(), QAWarning.Severity.WARNING, 1);
                issue.setProperty("property_entity", propertyId);
                issue.setProperty("added_property_entity", conflictingPid);
                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 25 with PropertyIdValue

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

the class EntityTypeScrutinizer method scrutinize.

@Override
public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
    if (!added) {
        return;
    }
    PropertyIdValue pid = snak.getPropertyId();
    List<Statement> statementList = _fetcher.getConstraintsByType(pid, allowedEntityTypesQid);
    if (!statementList.isEmpty()) {
        List<SnakGroup> constraint = statementList.get(0).getClaim().getQualifiers();
        boolean isUsable = true;
        if (constraint != null) {
            isUsable = findValues(constraint, itemOfPropertyConstraint).contains(Datamodel.makeWikidataItemIdValue(wikibaseItemQid));
        }
        if (!isUsable) {
            QAWarning issue = new QAWarning(type, null, QAWarning.Severity.WARNING, 1);
            issue.setProperty("property_entity", pid);
            issue.setProperty("example_entity", entityId);
            addIssue(issue);
        }
    }
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) QAWarning(org.openrefine.wikidata.qa.QAWarning)

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