Simply the scrutinizer architecture

This commit is contained in:
Antonin Delpeuch 2018-01-10 10:56:25 +00:00
parent 132af25b4a
commit 1ea1377734
7 changed files with 25 additions and 26 deletions

View File

@ -1,5 +1,7 @@
package org.openrefine.wikidata.qa; package org.openrefine.wikidata.qa;
import java.util.Properties;
import org.openrefine.wikidata.utils.JacksonJsonizable; import org.openrefine.wikidata.utils.JacksonJsonizable;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
@ -30,17 +32,21 @@ public class QAWarning extends JacksonJsonizable implements Comparable<QAWarning
private Severity severity; private Severity severity;
// The number of times this issue was found // The number of times this issue was found
private int count; private int count;
// Other details about the warning, that can be displayed to the user
private Properties properties;
@JsonCreator @JsonCreator
public QAWarning( public QAWarning(
@JsonProperty("type") String type, @JsonProperty("type") String type,
@JsonProperty("bucket_id") String bucketId, @JsonProperty("bucket_id") String bucketId,
@JsonProperty("severity") Severity severity, @JsonProperty("severity") Severity severity,
@JsonProperty("count") int count) { @JsonProperty("count") int count,
@JsonProperty("properties") Properties properties) {
this.type = type; this.type = type;
this.bucketId = bucketId; this.bucketId = bucketId;
this.severity = severity; this.severity = severity;
this.count = count; this.count = count;
this.properties = properties;
} }
/** /**
@ -86,6 +92,11 @@ public class QAWarning extends JacksonJsonizable implements Comparable<QAWarning
public int getCount() { public int getCount() {
return count; return count;
} }
@JsonProperty("properties")
public Properties getProperties() {
return properties;
}
/** /**
* Warnings are sorted by decreasing severity. * Warnings are sorted by decreasing severity.

View File

@ -1,7 +1,9 @@
package org.openrefine.wikidata.qa.scrutinizers; package org.openrefine.wikidata.qa.scrutinizers;
import java.util.List; import java.util.List;
import java.util.Properties;
import org.openrefine.wikidata.qa.ConstraintFetcher;
import org.openrefine.wikidata.qa.QAWarning; import org.openrefine.wikidata.qa.QAWarning;
import org.openrefine.wikidata.qa.QAWarningStore; import org.openrefine.wikidata.qa.QAWarningStore;
import org.openrefine.wikidata.schema.ItemUpdate; import org.openrefine.wikidata.schema.ItemUpdate;
@ -13,10 +15,15 @@ import org.openrefine.wikidata.schema.ItemUpdate;
*/ */
public abstract class EditScrutinizer { public abstract class EditScrutinizer {
private QAWarningStore store; protected QAWarningStore _store;
protected ConstraintFetcher _fetcher;
public EditScrutinizer() {
_fetcher = new ConstraintFetcher();
}
public void setStore(QAWarningStore store) { public void setStore(QAWarningStore store) {
this.store = store; _store = store;
} }
/** /**
@ -30,7 +37,7 @@ public abstract class EditScrutinizer {
* @param warning * @param warning
*/ */
protected void info(String type) { protected void info(String type) {
store.addWarning(new QAWarning(type, null, QAWarning.Severity.INFO, 1)); _store.addWarning(new QAWarning(type, null, QAWarning.Severity.INFO, 1, new Properties()));
} }
/** /**
@ -38,7 +45,7 @@ public abstract class EditScrutinizer {
* @param warning * @param warning
*/ */
protected void warning(String type) { protected void warning(String type) {
store.addWarning(new QAWarning(type, null, QAWarning.Severity.WARNING, 1)); _store.addWarning(new QAWarning(type, null, QAWarning.Severity.WARNING, 1, new Properties()));
} }
/** /**
@ -46,7 +53,7 @@ public abstract class EditScrutinizer {
* @param warning * @param warning
*/ */
protected void important(String type) { protected void important(String type) {
store.addWarning(new QAWarning(type, null, QAWarning.Severity.IMPORTANT, 1)); _store.addWarning(new QAWarning(type, null, QAWarning.Severity.IMPORTANT, 1, new Properties()));
} }
/** /**
@ -54,6 +61,6 @@ public abstract class EditScrutinizer {
* @param warning * @param warning
*/ */
protected void critical(String type) { protected void critical(String type) {
store.addWarning(new QAWarning(type, null, QAWarning.Severity.CRITICAL, 1)); _store.addWarning(new QAWarning(type, null, QAWarning.Severity.CRITICAL, 1, new Properties()));
} }
} }

View File

@ -4,7 +4,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.openrefine.wikidata.qa.ConstraintFetcher;
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
import org.wikidata.wdtk.datamodel.interfaces.Snak; import org.wikidata.wdtk.datamodel.interfaces.Snak;
@ -20,11 +19,9 @@ import org.wikidata.wdtk.datamodel.interfaces.StringValue;
public class FormatConstraintScrutinizer extends SnakScrutinizer { public class FormatConstraintScrutinizer extends SnakScrutinizer {
private Map<PropertyIdValue, Pattern> _patterns; private Map<PropertyIdValue, Pattern> _patterns;
private ConstraintFetcher _fetcher;
public FormatConstraintScrutinizer() { public FormatConstraintScrutinizer() {
_patterns = new HashMap<>(); _patterns = new HashMap<>();
_fetcher = new ConstraintFetcher();
} }
/** /**

View File

@ -6,7 +6,6 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.openrefine.wikidata.qa.ConstraintFetcher;
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
@ -22,12 +21,10 @@ import org.wikidata.wdtk.datamodel.interfaces.Value;
*/ */
public class InverseConstraintScrutinizer extends StatementScrutinizer { public class InverseConstraintScrutinizer extends StatementScrutinizer {
private ConstraintFetcher _fetcher;
private Map<PropertyIdValue, PropertyIdValue> _inverse; private Map<PropertyIdValue, PropertyIdValue> _inverse;
private Map<PropertyIdValue, Map<EntityIdValue, Set<EntityIdValue> >> _statements; private Map<PropertyIdValue, Map<EntityIdValue, Set<EntityIdValue> >> _statements;
public InverseConstraintScrutinizer() { public InverseConstraintScrutinizer() {
_fetcher = new ConstraintFetcher();
_inverse = new HashMap<>(); _inverse = new HashMap<>();
_statements = new HashMap<>(); _statements = new HashMap<>();
} }

View File

@ -6,7 +6,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.openrefine.wikidata.qa.ConstraintFetcher;
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.Statement;
@ -19,12 +18,10 @@ import org.wikidata.wdtk.datamodel.interfaces.Statement;
*/ */
public class QualifierCompatibilityScrutinizer extends StatementScrutinizer { public class QualifierCompatibilityScrutinizer extends StatementScrutinizer {
private ConstraintFetcher _fetcher;
private Map<PropertyIdValue, Set<PropertyIdValue>> _allowedQualifiers; private Map<PropertyIdValue, Set<PropertyIdValue>> _allowedQualifiers;
private Map<PropertyIdValue, Set<PropertyIdValue>> _mandatoryQualifiers; private Map<PropertyIdValue, Set<PropertyIdValue>> _mandatoryQualifiers;
public QualifierCompatibilityScrutinizer() { public QualifierCompatibilityScrutinizer() {
_fetcher = new ConstraintFetcher();
_allowedQualifiers = new HashMap<>(); _allowedQualifiers = new HashMap<>();
_mandatoryQualifiers = new HashMap<>(); _mandatoryQualifiers = new HashMap<>();
} }

View File

@ -6,7 +6,6 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.openrefine.wikidata.qa.ConstraintFetcher;
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
import org.wikidata.wdtk.datamodel.interfaces.Reference; import org.wikidata.wdtk.datamodel.interfaces.Reference;
@ -24,12 +23,10 @@ public class RestrictedPositionScrutinizer extends StatementScrutinizer {
private Map<PropertyIdValue, SnakPosition> _restrictedPids; private Map<PropertyIdValue, SnakPosition> _restrictedPids;
private Set<PropertyIdValue> _unrestrictedPids; private Set<PropertyIdValue> _unrestrictedPids;
private ConstraintFetcher _fetcher;
public RestrictedPositionScrutinizer() { public RestrictedPositionScrutinizer() {
_restrictedPids = new HashMap<>(); _restrictedPids = new HashMap<>();
_unrestrictedPids = new HashSet<>(); _unrestrictedPids = new HashSet<>();
_fetcher = new ConstraintFetcher();
} }
SnakPosition positionRestriction(PropertyIdValue pid) { SnakPosition positionRestriction(PropertyIdValue pid) {

View File

@ -3,7 +3,6 @@ package org.openrefine.wikidata.qa.scrutinizers;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.openrefine.wikidata.qa.ConstraintFetcher;
import org.openrefine.wikidata.schema.ItemUpdate; import org.openrefine.wikidata.schema.ItemUpdate;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.Statement;
@ -15,12 +14,6 @@ import org.wikidata.wdtk.datamodel.interfaces.Statement;
* *
*/ */
public class SingleValueScrutinizer extends ItemEditScrutinizer { public class SingleValueScrutinizer extends ItemEditScrutinizer {
private ConstraintFetcher _fetcher;
public SingleValueScrutinizer() {
_fetcher = new ConstraintFetcher();
}
@Override @Override
public void scrutinize(ItemUpdate update) { public void scrutinize(ItemUpdate update) {