use of org.openrefine.wikidata.qa.QAWarning 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.openrefine.wikidata.qa.QAWarning 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);
}
}
}
}
use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class QualifierCompatibilityScrutinizer method scrutinize.
@Override
public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) {
if (!added) {
// not scrutinizing deleted statements
return;
}
PropertyIdValue statementProperty = statement.getClaim().getMainSnak().getPropertyId();
Set<PropertyIdValue> qualifiers = statement.getClaim().getQualifiers().stream().map(e -> e.getProperty()).collect(Collectors.toSet());
Set<PropertyIdValue> missingQualifiers = mandatoryQualifiers(statementProperty).stream().filter(p -> !qualifiers.contains(p)).collect(Collectors.toSet());
Set<PropertyIdValue> disallowedQualifiers = qualifiers.stream().filter(p -> !qualifierIsAllowed(statementProperty, p)).collect(Collectors.toSet());
for (PropertyIdValue missing : missingQualifiers) {
QAWarning issue = new QAWarning(missingMandatoryQualifiersType, statementProperty.getId() + "-" + missing.getId(), QAWarning.Severity.WARNING, 1);
issue.setProperty("statement_property_entity", statementProperty);
issue.setProperty("missing_property_entity", missing);
issue.setProperty("example_item_entity", entityId);
addIssue(issue);
}
for (PropertyIdValue disallowed : disallowedQualifiers) {
QAWarning issue = new QAWarning(disallowedQualifiersType, statementProperty.getId() + "-" + disallowed.getId(), QAWarning.Severity.WARNING, 1);
issue.setProperty("statement_property_entity", statementProperty);
issue.setProperty("disallowed_property_entity", disallowed);
issue.setProperty("example_item_entity", entityId);
addIssue(issue);
}
}
use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class WbQuantityExpr method evaluate.
@Override
public QuantityValue evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
StringValue amount = getAmountExpr().evaluate(ctxt);
// we know the amount is nonnull, nonempty here
BigDecimal parsedAmount = null;
BigDecimal lowerBound = null;
BigDecimal upperBound = null;
String originalAmount = amount.getString().toUpperCase();
try {
parsedAmount = new BigDecimal(originalAmount);
if (originalAmount.contains("E")) {
// engineering notation: we derive the precision from
// the expression (feature!)
BigDecimal uncertainty = new BigDecimal("0.5").scaleByPowerOfTen(-parsedAmount.scale());
lowerBound = new BigDecimal(parsedAmount.subtract(uncertainty).toPlainString());
upperBound = new BigDecimal(parsedAmount.add(uncertainty).toPlainString());
}
// workaround for https://github.com/Wikidata/Wikidata-Toolkit/issues/341
parsedAmount = new BigDecimal(parsedAmount.toPlainString());
} catch (NumberFormatException e) {
if (!originalAmount.isEmpty()) {
QAWarning issue = new QAWarning("ignored-amount", null, QAWarning.Severity.WARNING, 1);
issue.setProperty("example_value", originalAmount);
ctxt.addWarning(issue);
}
throw new SkipSchemaExpressionException();
}
if (getUnitExpr() != null) {
ItemIdValue unit = getUnitExpr().evaluate(ctxt);
return Datamodel.makeQuantityValue(parsedAmount, lowerBound, upperBound, unit);
}
return Datamodel.makeQuantityValue(parsedAmount, lowerBound, upperBound);
}
use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class EnglishDescriptionScrutinizer method checkPunctuationSign.
// Description are not sentences, so the punctuation sign at the end should be avoided.
protected void checkPunctuationSign(TermedStatementEntityEdit update, String descText) {
assert descText.length() > 0;
final String punctuationSigns = ".?!;:,'\"";
char last = descText.charAt(descText.length() - 1);
if (punctuationSigns.indexOf(last) != -1) {
QAWarning issue = new QAWarning(descEndsByPunctuationSign, null, QAWarning.Severity.WARNING, 1);
issue.setProperty("example_entity", update.getEntityId());
issue.setProperty("description", descText);
issue.setProperty("lang", LANG);
issue.setProperty("punctuation_sign", last);
addIssue(issue);
}
}
Aggregations