From abc51235c6f0113d638083ee0671269898762888 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Wed, 10 Jan 2018 12:13:28 +0000 Subject: [PATCH] Add infrastructure to let scrutinizers report more details --- .../org/openrefine/wikidata/qa/QAWarning.java | 26 ++++++++++++++-- .../qa/scrutinizers/EditScrutinizer.java | 30 ++++++++++++------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/QAWarning.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/QAWarning.java index 7c9bc07d1..aec8aca5a 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/QAWarning.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/QAWarning.java @@ -1,5 +1,7 @@ package org.openrefine.wikidata.qa; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; import org.openrefine.wikidata.utils.JacksonJsonizable; @@ -33,7 +35,15 @@ public class QAWarning extends JacksonJsonizable implements Comparable properties; + + public QAWarning(String type, String bucketId, Severity severity, int count) { + this.type = type; + this.bucketId = bucketId; + this.severity = severity; + this.count = count; + this.properties = new HashMap(); + } @JsonCreator public QAWarning( @@ -41,7 +51,7 @@ public class QAWarning extends JacksonJsonizable implements Comparable properties) { this.type = type; this.bucketId = bucketId; this.severity = severity; @@ -73,6 +83,16 @@ public class QAWarning extends JacksonJsonizable implements Comparable getProperties() { return properties; } diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/EditScrutinizer.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/EditScrutinizer.java index e68fe7a82..da2245190 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/EditScrutinizer.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/EditScrutinizer.java @@ -1,10 +1,11 @@ package org.openrefine.wikidata.qa.scrutinizers; import java.util.List; -import java.util.Properties; +import java.util.Map; import org.openrefine.wikidata.qa.ConstraintFetcher; import org.openrefine.wikidata.qa.QAWarning; +import org.openrefine.wikidata.qa.QAWarning.Severity; import org.openrefine.wikidata.qa.QAWarningStore; import org.openrefine.wikidata.schema.ItemUpdate; @@ -31,36 +32,45 @@ public abstract class EditScrutinizer { * @param edit: the list of ItemUpdates to scrutinize */ public abstract void scrutinize(List edit); + + protected void addIssue(QAWarning warning) { + _store.addWarning(warning); + } + protected void addIssue(String type, String aggregationId, Severity severity, int count) { + addIssue(new QAWarning(type, aggregationId, severity, count)); + } + /** - * Helper to be used by subclasses to emit INFO warnings + * Helper to be used by subclasses to emit simple INFO warnings * @param warning */ protected void info(String type) { - _store.addWarning(new QAWarning(type, null, QAWarning.Severity.INFO, 1, new Properties())); + addIssue(type, null, QAWarning.Severity.INFO, 1); + } - + /** - * Helper to be used by subclasses to emit warnings + * Helper to be used by subclasses to emit simple warnings * @param warning */ protected void warning(String type) { - _store.addWarning(new QAWarning(type, null, QAWarning.Severity.WARNING, 1, new Properties())); + addIssue(type, null, QAWarning.Severity.WARNING, 1); } /** - * Helper to be used by subclasses to emit important warnings + * Helper to be used by subclasses to emit simple important warnings * @param warning */ protected void important(String type) { - _store.addWarning(new QAWarning(type, null, QAWarning.Severity.IMPORTANT, 1, new Properties())); + addIssue(type, null, QAWarning.Severity.IMPORTANT, 1); } /** - * Helper to be used by subclasses to emit critical warnings + * Helper to be used by subclasses to emit simple critical warnings * @param warning */ protected void critical(String type) { - _store.addWarning(new QAWarning(type, null, QAWarning.Severity.CRITICAL, 1, new Properties())); + addIssue(type, null, QAWarning.Severity.CRITICAL, 1); } }