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);
}
}
}
}
}
}
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);
}
}
}
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);
}
}
}
}
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);
}
}
Aggregations