use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class RestrictedPositionScrutinizer method scrutinize.
public void scrutinize(Snak snak, EntityIdValue entityId, SnakPosition position, boolean added) {
if (!positionAllowed(snak.getPropertyId(), position)) {
String positionStr = position.toString().toLowerCase();
QAWarning issue = new QAWarning("property-found-in-" + positionStr, snak.getPropertyId().getId(), QAWarning.Severity.IMPORTANT, 1);
issue.setProperty("property_entity", snak.getPropertyId());
addIssue(issue);
}
}
use of org.openrefine.wikidata.qa.QAWarning 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.openrefine.wikidata.qa.QAWarning 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.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class WbEntityVariable method fromCell.
@Override
public EntityIdValue fromCell(Cell cell, ExpressionContext ctxt) throws SkipSchemaExpressionException {
if (cell.recon != null && (Judgment.Matched.equals(cell.recon.judgment) || Judgment.New.equals(cell.recon.judgment))) {
if (Judgment.New.equals(cell.recon.judgment)) {
return new ReconItemIdValue(cell.recon, cell.value.toString());
}
EntityIdValue entityIdValue = EntityIdValueImpl.fromId(cell.recon.match.id, cell.recon.identifierSpace);
EntityIdValue reconEntityIdValue = null;
String entityType = null;
if (entityIdValue instanceof ItemIdValue) {
reconEntityIdValue = new ReconItemIdValue(cell.recon, cell.value.toString());
entityType = "item";
} else if (entityIdValue instanceof MediaInfoIdValue) {
reconEntityIdValue = new ReconMediaInfoIdValue(cell.recon, cell.value.toString());
entityType = "mediainfo";
} else if (entityIdValue instanceof PropertyIdValue) {
reconEntityIdValue = new ReconPropertyIdValue(cell.recon, cell.value.toString());
entityType = "property";
}
if (reconEntityIdValue == null) {
throw new SkipSchemaExpressionException();
}
if (cell.recon.identifierSpace == null || !cell.recon.identifierSpace.equals(ctxt.getBaseIRIForEntityType(entityType))) {
QAWarning warning = new QAWarning("invalid-identifier-space", null, QAWarning.Severity.INFO, 1);
warning.setProperty("example_cell", cell.value.toString());
warning.setProperty("expected_site_iri", ctxt.getBaseIRIForEntityType(entityType));
ctxt.addWarning(warning);
throw new SkipSchemaExpressionException();
}
return reconEntityIdValue;
}
throw new SkipSchemaExpressionException();
}
use of org.openrefine.wikidata.qa.QAWarning 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);
}
}
}
Aggregations