Reorganize scrutinizers to simplify the methods
This commit is contained in:
parent
2795a54ea2
commit
b5f2085038
@ -39,14 +39,6 @@ public class SaveWikibaseSchemaOperation extends AbstractOperation {
|
||||
|
||||
static public AbstractOperation reconstruct(Project project, JSONObject obj)
|
||||
throws Exception {
|
||||
System.out.println("Attempting to reconstruct save op");
|
||||
try {
|
||||
System.out.println(WikibaseSchema.reconstruct(obj.getJSONObject("schema")).toString());
|
||||
} catch(Exception e) {
|
||||
System.out.println("Failed to reconstruct");
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("SUCCESS");
|
||||
return new SaveWikibaseSchemaOperation(WikibaseSchema.reconstruct(obj
|
||||
.getJSONObject("schema")));
|
||||
}
|
||||
|
@ -13,7 +13,21 @@ public abstract class ItemEditScrutinizer extends EditScrutinizer {
|
||||
scrutinize(update);
|
||||
}
|
||||
}
|
||||
batchIsFinished();
|
||||
}
|
||||
|
||||
public abstract void scrutinize(ItemUpdate update);
|
||||
/**
|
||||
* Method to be overridden by subclasses to scrutinize
|
||||
* an individual item update.
|
||||
* @param update
|
||||
*/
|
||||
public abstract void scrutinize(ItemUpdate update);
|
||||
|
||||
/**
|
||||
* Method to be overridden by subclasses to emit warnings
|
||||
* once a batch has been completely analyzed.
|
||||
*/
|
||||
public void batchIsFinished() {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class NewItemScrutinizer extends ItemEditScrutinizer {
|
||||
info("new-item-created");
|
||||
|
||||
if (update.getLabels().isEmpty() && update.getAliases().isEmpty()) {
|
||||
important("new-item-without-labels-or-aliases");
|
||||
critical("new-item-without-labels-or-aliases");
|
||||
}
|
||||
|
||||
if (update.getDescriptions().isEmpty()) {
|
||||
|
@ -2,52 +2,33 @@ package org.openrefine.wikidata.qa.scrutinizers;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Reference;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Snak;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Statement;
|
||||
|
||||
public abstract class SnakScrutinizer extends StatementScrutinizer {
|
||||
|
||||
public abstract void scrutinizeAdded(Snak snak);
|
||||
|
||||
public abstract void scrutinizeDeleted(Snak snak);
|
||||
public abstract void scrutinize(Snak snak, boolean added);
|
||||
|
||||
@Override
|
||||
public void scrutinizeAdded(Statement statement) {
|
||||
public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) {
|
||||
// Main snak
|
||||
scrutinizeAdded(statement.getClaim().getMainSnak());
|
||||
scrutinize(statement.getClaim().getMainSnak(), added);
|
||||
|
||||
// Qualifiers
|
||||
scrutinizeSnakSet(statement.getClaim().getAllQualifiers(), true);
|
||||
scrutinizeSnakSet(statement.getClaim().getAllQualifiers(), added);
|
||||
|
||||
// References
|
||||
for(Reference ref : statement.getReferences()) {
|
||||
scrutinizeSnakSet(ref.getAllSnaks(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrutinizeDeleted(Statement statement) {
|
||||
// Main snak
|
||||
scrutinizeDeleted(statement.getClaim().getMainSnak());
|
||||
|
||||
// Qualifiers
|
||||
scrutinizeSnakSet(statement.getClaim().getAllQualifiers(), false);
|
||||
|
||||
// References
|
||||
for(Reference ref : statement.getReferences()) {
|
||||
scrutinizeSnakSet(ref.getAllSnaks(), false);
|
||||
scrutinizeSnakSet(ref.getAllSnaks(), added);
|
||||
}
|
||||
}
|
||||
|
||||
private void scrutinizeSnakSet(Iterator<Snak> snaks, boolean add) {
|
||||
private void scrutinizeSnakSet(Iterator<Snak> snaks, boolean added) {
|
||||
while(snaks.hasNext()) {
|
||||
Snak snak = snaks.next();
|
||||
if (add) {
|
||||
scrutinizeAdded(snak);
|
||||
} else {
|
||||
scrutinizeDeleted(snak);
|
||||
}
|
||||
scrutinize(snak, added);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,28 @@
|
||||
package org.openrefine.wikidata.qa.scrutinizers;
|
||||
|
||||
import org.openrefine.wikidata.schema.ItemUpdate;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Statement;
|
||||
|
||||
public abstract class StatementScrutinizer extends ItemEditScrutinizer {
|
||||
|
||||
@Override
|
||||
public void scrutinize(ItemUpdate update) {
|
||||
EntityIdValue currentEntityId = update.getItemId();
|
||||
for(Statement statement : update.getAddedStatements()) {
|
||||
scrutinizeAdded(statement);
|
||||
scrutinize(statement, currentEntityId, true);
|
||||
}
|
||||
for (Statement statement : update.getDeletedStatements()) {
|
||||
scrutinize(statement, currentEntityId, false);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void scrutinizeAdded(Statement statement);
|
||||
|
||||
public abstract void scrutinizeDeleted(Statement statement);
|
||||
/**
|
||||
* The method that should be overridden by subclasses, implementing
|
||||
* the checks on one statement
|
||||
* @param statement: the statement to scrutinize
|
||||
* @param entityId: the id of the entity on which this statement is made or removed
|
||||
* @param added: whether this statement was added or deleted
|
||||
*/
|
||||
public abstract void scrutinize(Statement statement, EntityIdValue entityId, boolean added);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user