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