use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class WbItemVariable method fromCell.
@Override
public ItemIdValue fromCell(Cell cell, ExpressionContext ctxt) throws SkipSchemaExpressionException {
if (cell.recon != null && (Judgment.Matched.equals(cell.recon.judgment) || Judgment.New.equals(cell.recon.judgment))) {
if (cell.recon.identifierSpace == null || !cell.recon.identifierSpace.equals(ctxt.getBaseIRI())) {
QAWarning warning = new QAWarning("invalid-identifier-space", null, QAWarning.Severity.INFO, 1);
warning.setProperty("example_cell", cell.value.toString());
ctxt.addWarning(warning);
throw new SkipSchemaExpressionException();
}
return new ReconItemIdValue(cell.recon, cell.value.toString());
}
throw new SkipSchemaExpressionException();
}
use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class CalendarScrutinizer method scrutinize.
@Override
public void scrutinize(Value value) {
if (value instanceof TimeValue) {
TimeValue time = (TimeValue) value;
if (time.getPreferredCalendarModel().equals(earliestGregorian.getPreferredCalendarModel()) && time.getPrecision() >= 10 && (time.getYear() < earliestGregorian.getYear() || time.getYear() == earliestGregorian.getYear() && time.getMonth() < earliestGregorian.getMonth() || time.getYear() == earliestGregorian.getYear() && time.getMonth() == earliestGregorian.getMonth() && time.getDay() < earliestGregorian.getDay())) {
QAWarning warning = new QAWarning(earlyGregorianDateType, null, QAWarning.Severity.WARNING, 1);
warning.setProperty("example_year", Long.toString(time.getYear()));
addIssue(warning);
}
}
}
use of org.openrefine.wikidata.qa.QAWarning 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.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class DifferenceWithinRangeScrutinizer method scrutinize.
@Override
public void scrutinize(TermedStatementEntityEdit update) {
Map<PropertyIdValue, Value> propertyIdValueValueMap = new HashMap<>();
for (Statement statement : update.getAddedStatements()) {
Snak mainSnak = statement.getClaim().getMainSnak();
if (mainSnak instanceof ValueSnak) {
PropertyIdValue pid = mainSnak.getPropertyId();
Value value = ((ValueSnak) mainSnak).getValue();
propertyIdValueValueMap.put(pid, value);
}
}
for (PropertyIdValue propertyId : propertyIdValueValueMap.keySet()) {
List<Statement> statementList = _fetcher.getConstraintsByType(propertyId, differenceWithinRangeConstraintQid);
if (!statementList.isEmpty()) {
DifferenceWithinRangeConstraint constraint = new DifferenceWithinRangeConstraint(statementList.get(0));
PropertyIdValue lowerPropertyId = constraint.lowerPropertyIdValue;
QuantityValue minRangeValue = constraint.minRangeValue;
QuantityValue maxRangeValue = constraint.maxRangeValue;
if (propertyIdValueValueMap.containsKey(lowerPropertyId)) {
Value startingValue = propertyIdValueValueMap.get(lowerPropertyId);
Value endingValue = propertyIdValueValueMap.get(propertyId);
if (startingValue instanceof TimeValue && endingValue instanceof TimeValue) {
TimeValue lowerDate = (TimeValue) startingValue;
TimeValue upperDate = (TimeValue) endingValue;
long differenceInYears = upperDate.getYear() - lowerDate.getYear();
long differenceInMonths = upperDate.getMonth() - lowerDate.getMonth();
long differenceInDays = upperDate.getMonth() - lowerDate.getMonth();
if (minRangeValue != null && (differenceInYears < minRangeValue.getNumericValue().longValue() || differenceInYears == 0 && differenceInMonths < 0 || differenceInYears == 0 && differenceInMonths == 0 && differenceInDays < 0)) {
QAWarning issue = new QAWarning(type, propertyId.getId(), QAWarning.Severity.WARNING, 1);
issue.setProperty("source_entity", lowerPropertyId);
issue.setProperty("target_entity", propertyId);
issue.setProperty("min_value", minRangeValue.getNumericValue());
if (maxRangeValue != null) {
issue.setProperty("max_value", maxRangeValue.getNumericValue());
} else {
issue.setProperty("max_value", null);
}
issue.setProperty("example_entity", update.getEntityId());
addIssue(issue);
}
if (maxRangeValue != null && differenceInYears > maxRangeValue.getNumericValue().longValue()) {
QAWarning issue = new QAWarning(type, propertyId.getId(), QAWarning.Severity.WARNING, 1);
issue.setProperty("source_entity", lowerPropertyId);
issue.setProperty("target_entity", propertyId);
if (minRangeValue != null) {
issue.setProperty("min_value", minRangeValue.getNumericValue());
} else {
issue.setProperty("min_value", null);
}
issue.setProperty("max_value", maxRangeValue.getNumericValue());
issue.setProperty("example_entity", update.getEntityId());
addIssue(issue);
}
}
}
}
}
}
use of org.openrefine.wikidata.qa.QAWarning 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);
}
}
}
Aggregations