use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class EnglishDescriptionScrutinizer method checkArticle.
// Descriptions should not normally begin with initial articles ("a", "an", "the").
protected void checkArticle(TermedStatementEntityEdit update, String descText) {
assert descText.length() > 0;
String firstWord = descText.split("\\s")[0].toLowerCase();
if ("a".equals(firstWord) || "an".equals(firstWord) || "the".equals(firstWord)) {
QAWarning issue = new QAWarning(descBeginWithArticle, null, QAWarning.Severity.WARNING, 1);
issue.setProperty("example_entity", update.getEntityId());
issue.setProperty("description", descText);
issue.setProperty("lang", LANG);
issue.setProperty("article", firstWord);
addIssue(issue);
}
}
use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class FormatScrutinizer method scrutinize.
@Override
public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
if (snak instanceof ValueSnak && ((ValueSnak) snak).getValue() instanceof StringValue) {
String value = ((StringValue) ((ValueSnak) snak).getValue()).getString();
PropertyIdValue pid = snak.getPropertyId();
Set<Pattern> patterns = getPattern(pid);
for (Pattern pattern : patterns) {
if (!pattern.matcher(value).matches()) {
if (added) {
QAWarning issue = new QAWarning(type, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
issue.setProperty("property_entity", pid);
issue.setProperty("regex", pattern.toString());
issue.setProperty("example_value", value);
issue.setProperty("example_item_entity", entityId);
addIssue(issue);
} else {
info("remove-statements-with-invalid-format");
}
}
}
}
}
use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class NewItemScrutinizer method scrutinize.
@Override
public void scrutinize(TermedStatementEntityEdit update) {
if (update.isNew()) {
info(newItemType);
if (update.getLabels().isEmpty() && update.getLabelsIfNew().isEmpty() && update.getAliases().isEmpty()) {
QAWarning issue = new QAWarning(noLabelType, null, QAWarning.Severity.CRITICAL, 1);
issue.setProperty("example_entity", update.getEntityId());
addIssue(issue);
}
if (update.getDescriptions().isEmpty() && update.getDescriptionsIfNew().isEmpty()) {
QAWarning issue = new QAWarning(noDescType, null, QAWarning.Severity.WARNING, 1);
issue.setProperty("example_entity", update.getEntityId());
addIssue(issue);
}
if (!update.getDeletedStatements().isEmpty()) {
QAWarning issue = new QAWarning(deletedStatementsType, null, QAWarning.Severity.WARNING, 1);
issue.setProperty("example_entity", update.getEntityId());
addIssue(issue);
}
// Try to find a "instance of" or "subclass of" claim
boolean typeFound = false;
for (Statement statement : update.getAddedStatements()) {
String pid = statement.getMainSnak().getPropertyId().getId();
if (manifest.getInstanceOfPid().equals(pid) || manifest.getSubclassOfPid().equals(pid)) {
typeFound = true;
break;
}
}
if (!typeFound) {
QAWarning issue = new QAWarning(noTypeType, null, QAWarning.Severity.WARNING, 1);
issue.setProperty("example_entity", update.getEntityId());
addIssue(issue);
}
}
}
use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class WbStatementExpr method evaluate.
public StatementEdit evaluate(ExpressionContext ctxt, EntityIdValue subject, PropertyIdValue propertyId) throws SkipSchemaExpressionException {
Snak mainSnak = null;
if (mainSnakValueExpr != null) {
Value mainSnakValue = mainSnakValueExpr.evaluate(ctxt);
mainSnak = Datamodel.makeValueSnak(propertyId, mainSnakValue);
} else {
// hack to make sure we have a non-null snak
mainSnak = Datamodel.makeNoValueSnak(propertyId);
}
// evaluate qualifiers
List<Snak> qualifiers = new ArrayList<Snak>(getQualifiers().size());
for (WbSnakExpr qExpr : getQualifiers()) {
try {
qualifiers.add(qExpr.evaluate(ctxt));
} catch (SkipSchemaExpressionException e) {
QAWarning warning = new QAWarning("ignored-qualifiers", null, QAWarning.Severity.INFO, 1);
warning.setProperty("example_entity", subject);
warning.setProperty("example_property_entity", mainSnak.getPropertyId());
ctxt.addWarning(warning);
}
}
List<SnakGroup> groupedQualifiers = groupSnaks(qualifiers);
Claim claim = Datamodel.makeClaim(subject, mainSnak, groupedQualifiers);
// evaluate references
List<Reference> references = new ArrayList<Reference>();
for (WbReferenceExpr rExpr : getReferences()) {
try {
references.add(rExpr.evaluate(ctxt));
} catch (SkipSchemaExpressionException e) {
QAWarning warning = new QAWarning("ignored-references", null, QAWarning.Severity.INFO, 1);
warning.setProperty("example_entity", subject);
warning.setProperty("example_property_entity", mainSnak.getPropertyId());
ctxt.addWarning(warning);
}
}
StatementRank rank = StatementRank.NORMAL;
return new StatementEdit(Datamodel.makeStatement(claim, references, rank, ""), merger, mode);
}
use of org.openrefine.wikidata.qa.QAWarning in project OpenRefine by OpenRefine.
the class UnsourcedScrutinizer method scrutinize.
@Override
public void scrutinize(TermedStatementEntityEdit update) {
for (Statement statement : update.getAddedStatements()) {
PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId();
List<Statement> constraintDefinitions = _fetcher.getConstraintsByType(pid, citationNeededConstraintQid);
List<Reference> referenceList = statement.getReferences();
if (referenceList.isEmpty()) {
if (!constraintDefinitions.isEmpty()) {
QAWarning issue = new QAWarning(constraintItemType, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
issue.setProperty("property_entity", pid);
issue.setProperty("example_entity", update.getEntityId());
addIssue(issue);
} else {
warning(generalType);
}
}
}
}
Aggregations