use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.
the class QuantityScrutinizer method scrutinize.
@Override
public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
if (!added) {
return;
}
if (snak instanceof ValueSnak && ((ValueSnak) snak).getValue() instanceof QuantityValue && added) {
PropertyIdValue pid = snak.getPropertyId();
QuantityValue value = (QuantityValue) ((ValueSnak) snak).getValue();
if (!_fetcher.getConstraintsByType(pid, noBoundsConstraintQid).isEmpty() && (value.getUpperBound() != null || value.getLowerBound() != null)) {
QAWarning issue = new QAWarning(boundsDisallowedType, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
issue.setProperty("property_entity", pid);
issue.setProperty("example_value", value.getNumericValue().toString());
issue.setProperty("example_item_entity", entityId);
addIssue(issue);
}
if (!_fetcher.getConstraintsByType(pid, integerValuedConstraintQid).isEmpty() && value.getNumericValue().scale() > 0) {
QAWarning issue = new QAWarning(integerConstraintType, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
issue.setProperty("property_entity", pid);
issue.setProperty("example_value", value.getNumericValue().toString());
issue.setProperty("example_item_entity", entityId);
addIssue(issue);
}
List<Statement> statementList = _fetcher.getConstraintsByType(pid, allowedUnitsConstraintQid);
Set<ItemIdValue> allowedUnits = null;
if (!statementList.isEmpty()) {
AllowedUnitsConstraint allowedUnitsConstraint = new AllowedUnitsConstraint(statementList.get(0));
allowedUnits = allowedUnitsConstraint.allowedUnits;
}
ItemIdValue currentUnit = null;
if (value.getUnitItemId() != null) {
currentUnit = value.getUnitItemId();
}
if (allowedUnits != null && !allowedUnits.contains(currentUnit)) {
String issueType = currentUnit == null ? noUnitProvidedType : invalidUnitType;
QAWarning issue = new QAWarning(issueType, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
issue.setProperty("property_entity", pid);
issue.setProperty("example_value", value.getNumericValue().toString());
issue.setProperty("example_item_entity", entityId);
if (currentUnit != null) {
issue.setProperty("unit_entity", value.getUnitItemId());
}
addIssue(issue);
}
}
}
use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.
the class RestrictedValuesScrutinizer method scrutinize.
@Override
public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
if (!added) {
return;
}
PropertyIdValue pid = snak.getPropertyId();
Value value = null;
if (snak instanceof ValueSnak) {
value = ((ValueSnak) snak).getValue();
}
List<Statement> allowedValueConstraintDefinitions = _fetcher.getConstraintsByType(pid, allowedValuesConstraintQid);
List<Statement> disallowedValueConstraintDefinitions = _fetcher.getConstraintsByType(pid, disallowedValuesConstraintQid);
Set<Value> allowedValues = null, disallowedValues = null;
if (!allowedValueConstraintDefinitions.isEmpty()) {
AllowedValueConstraint constraint = new AllowedValueConstraint(allowedValueConstraintDefinitions.get(0));
allowedValues = constraint.allowedValues;
}
if (!disallowedValueConstraintDefinitions.isEmpty()) {
DisallowedValueConstraint constraint = new DisallowedValueConstraint(disallowedValueConstraintDefinitions.get(0));
disallowedValues = constraint.disallowedValues;
}
if ((allowedValues != null && !allowedValues.contains(value)) || (disallowedValues != null && disallowedValues.contains(value))) {
QAWarning issue = new QAWarning(type, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
issue.setProperty("property_entity", pid);
issue.setProperty("example_value_entity", value);
issue.setProperty("example_subject_entity", entityId);
addIssue(issue);
}
}
use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.
the class ConstraintFetcher method getConstraintStatements.
/**
* Gets all the constraint statements for a given property
*
* @param pid
* the id of the property to retrieve the constraints for
* @return the list of constraint statements
*/
private List<Statement> getConstraintStatements(PropertyIdValue pid) {
PropertyDocument doc = (PropertyDocument) entityCache.get(pid);
StatementGroup group = doc.findStatementGroup(wikibaseConstraintPid);
if (group != null) {
return group.getStatements().stream().filter(s -> s.getValue() != null && s.getValue() instanceof EntityIdValue).collect(Collectors.toList());
} else {
return Collections.emptyList();
}
}
use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.
the class InverseConstraintScrutinizer method batchIsFinished.
@Override
public void batchIsFinished() {
// For each pair of inverse properties (in each direction)
for (Entry<PropertyIdValue, PropertyIdValue> propertyPair : _inverse.entrySet()) {
// Get the statements made for the first
PropertyIdValue ourProperty = propertyPair.getKey();
for (Entry<EntityIdValue, Set<EntityIdValue>> itemLinks : _statements.get(ourProperty).entrySet()) {
// For each outgoing link
for (EntityIdValue idValue : itemLinks.getValue()) {
// Check that they are in the statements made for the second
PropertyIdValue missingProperty = propertyPair.getValue();
Set<EntityIdValue> reciprocalLinks = _statements.get(missingProperty).get(idValue);
if (reciprocalLinks == null || !reciprocalLinks.contains(itemLinks.getKey())) {
QAWarning issue = new QAWarning(type, ourProperty.getId(), QAWarning.Severity.IMPORTANT, 1);
issue.setProperty("added_property_entity", ourProperty);
issue.setProperty("inverse_property_entity", missingProperty);
issue.setProperty("source_entity", itemLinks.getKey());
issue.setProperty("target_entity", idValue);
addIssue(issue);
}
}
}
}
}
use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.
the class MultiValueScrutinizer method scrutinize.
@Override
public void scrutinize(TermedStatementEntityEdit update) {
Map<PropertyIdValue, Integer> propertyCount = new HashMap<>();
for (Statement statement : update.getAddedStatements()) {
PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId();
List<Statement> statementList = _fetcher.getConstraintsByType(pid, multiValueConstraintQid);
if (propertyCount.containsKey(pid)) {
propertyCount.put(pid, propertyCount.get(pid) + 1);
} else if (!statementList.isEmpty()) {
propertyCount.put(pid, 1);
}
}
if (update.isNew()) {
for (PropertyIdValue pid : propertyCount.keySet()) {
if (propertyCount.get(pid) == 1) {
QAWarning issue = new QAWarning(new_type, pid.getId(), QAWarning.Severity.WARNING, 1);
issue.setProperty("property_entity", pid);
issue.setProperty("example_entity", update.getEntityId());
addIssue(issue);
}
}
} else {
for (PropertyIdValue pid : propertyCount.keySet()) {
if (propertyCount.get(pid) == 1) {
QAWarning issue = new QAWarning(existing_type, pid.getId(), QAWarning.Severity.INFO, 1);
issue.setProperty("property_entity", pid);
issue.setProperty("example_entity", update.getEntityId());
addIssue(issue);
}
}
}
}
Aggregations