use of org.wikidata.wdtk.datamodel.interfaces.Statement 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);
}
}
}
use of org.wikidata.wdtk.datamodel.interfaces.Statement 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);
}
}
}
}
Aggregations