diff --git a/extensions/wikidata/lib-local-src/wdtk-datamodel-0.9.0-SNAPSHOT-sources.jar b/extensions/wikidata/lib-local-src/wdtk-datamodel-0.9.0-SNAPSHOT-sources.jar new file mode 100644 index 000000000..975097035 Binary files /dev/null and b/extensions/wikidata/lib-local-src/wdtk-datamodel-0.9.0-SNAPSHOT-sources.jar differ diff --git a/extensions/wikidata/lib-local-src/wdtk-wikibaseapi-0.9.0-SNAPSHOT-sources.jar b/extensions/wikidata/lib-local-src/wdtk-wikibaseapi-0.9.0-SNAPSHOT-sources.jar new file mode 100644 index 000000000..bfb4c41f8 Binary files /dev/null and b/extensions/wikidata/lib-local-src/wdtk-wikibaseapi-0.9.0-SNAPSHOT-sources.jar differ diff --git a/extensions/wikidata/lib-local/wdtk-datamodel-0.9.0-SNAPSHOT-jar-with-dependencies.jar b/extensions/wikidata/lib-local/wdtk-datamodel-0.9.0-SNAPSHOT-jar-with-dependencies.jar new file mode 100644 index 000000000..4cefe5a59 Binary files /dev/null and b/extensions/wikidata/lib-local/wdtk-datamodel-0.9.0-SNAPSHOT-jar-with-dependencies.jar differ diff --git a/extensions/wikidata/lib-local/wdtk-wikibaseapi-0.9.0-SNAPSHOT.jar b/extensions/wikidata/lib-local/wdtk-wikibaseapi-0.9.0-SNAPSHOT.jar new file mode 100644 index 000000000..fb099272b Binary files /dev/null and b/extensions/wikidata/lib-local/wdtk-wikibaseapi-0.9.0-SNAPSHOT.jar differ diff --git a/extensions/wikidata/pom.xml b/extensions/wikidata/pom.xml index a366d1dfb..fef9dd644 100644 --- a/extensions/wikidata/pom.xml +++ b/extensions/wikidata/pom.xml @@ -95,6 +95,45 @@ + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 + + + install-wdtk-datamodel + process-resources + + ${basedir}/lib-local/wdtk-datamodel-0.9.0-SNAPSHOT-jar-with-dependencies.jar + default + org.wikidata.wdtk + wdtk-datamodel + 0.9.0-SNAPSHOT + jar + true + + + install-file + + + + install-wdtk-wikibaseapi + process-resources + + ${basedir}/lib-local/wdtk-wikibaseapi-0.9.0-SNAPSHOT.jar + default + org.wikidata.wdtk + wdtk-wikibaseapi + 0.9.0-SNAPSHOT + jar + true + + + install-file + + + + org.apache.maven.plugins maven-clean-plugin @@ -126,12 +165,12 @@ org.wikidata.wdtk wdtk-wikibaseapi - 0.9.0 + 0.9.0-SNAPSHOT org.wikidata.wdtk wdtk-datamodel - 0.9.0 + 0.9.0-SNAPSHOT org.slf4j diff --git a/extensions/wikidata/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommand.java b/extensions/wikidata/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommand.java index eb3749133..28ed72400 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommand.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommand.java @@ -24,8 +24,6 @@ package org.openrefine.wikidata.commands; -import static org.openrefine.wikidata.commands.CommandUtilities.respondError; - import java.io.IOException; import java.io.StringWriter; import java.util.List; @@ -38,6 +36,7 @@ import javax.servlet.http.HttpServletResponse; import org.json.JSONArray; import org.json.JSONException; +import org.json.JSONObject; import org.json.JSONWriter; import org.openrefine.wikidata.qa.EditInspector; import org.openrefine.wikidata.qa.QAWarning; @@ -46,7 +45,10 @@ import org.openrefine.wikidata.schema.WikibaseSchema; import org.openrefine.wikidata.updates.ItemUpdate; import org.openrefine.wikidata.updates.scheduler.WikibaseAPIUpdateScheduler; +import static org.openrefine.wikidata.commands.CommandUtilities.respondError; + import com.fasterxml.jackson.databind.ObjectMapper; + import com.google.refine.browsing.Engine; import com.google.refine.commands.Command; import com.google.refine.model.Project; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/editing/ConnectionManager.java b/extensions/wikidata/src/org/openrefine/wikidata/editing/ConnectionManager.java index 203b9e5c3..f631be707 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/editing/ConnectionManager.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/editing/ConnectionManager.java @@ -31,7 +31,6 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.wikidata.wdtk.wikibaseapi.ApiConnection; -import org.wikidata.wdtk.wikibaseapi.BasicApiConnection; import org.wikidata.wdtk.wikibaseapi.LoginFailedException; import com.google.refine.ProjectManager; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/exporters/QSValuePrinter.java b/extensions/wikidata/src/org/openrefine/wikidata/exporters/QSValuePrinter.java index eb8ed04cd..4a4153f57 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/exporters/QSValuePrinter.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/exporters/QSValuePrinter.java @@ -28,9 +28,9 @@ import java.util.Locale; import org.openrefine.wikidata.schema.entityvalues.ReconEntityIdValue; import org.openrefine.wikidata.updates.scheduler.QuickStatementsUpdateScheduler; +import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue; -import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue; import org.wikidata.wdtk.datamodel.interfaces.QuantityValue; import org.wikidata.wdtk.datamodel.interfaces.StringValue; @@ -50,6 +50,12 @@ import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor; */ public class QSValuePrinter implements ValueVisitor { + @Override + public String visit(DatatypeIdValue value) { + // impossible case (this is actually a bug in WDTK, DatatypeIdValue should not subclass Value) + throw new IllegalArgumentException(); + } + @Override public String visit(EntityIdValue value) { if (ReconEntityIdValue.class.isInstance(value) && ((ReconEntityIdValue) value).isNew()) { @@ -70,10 +76,12 @@ public class QSValuePrinter implements ValueVisitor { @Override public String visit(QuantityValue value) { - ItemIdValue unit = value.getUnitItemId(); + String unitPrefix = "http://www.wikidata.org/entity/Q"; + String unitIri = value.getUnit(); String unitRepresentation = "", boundsRepresentation = ""; - if (unit != null) { - unitRepresentation = "U" + unit.getId().substring(1); + if (!unitIri.isEmpty()) { + if (!unitIri.startsWith(unitPrefix)) return null; // QuickStatements only accepts Qids as units + unitRepresentation = "U" + unitIri.substring(unitPrefix.length()); } if (value.getLowerBound() != null) { // bounds are always null at the same time so we know they are both not null diff --git a/extensions/wikidata/src/org/openrefine/wikidata/exporters/QuickStatementsExporter.java b/extensions/wikidata/src/org/openrefine/wikidata/exporters/QuickStatementsExporter.java index 0b1e9b291..6bc650bf8 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/exporters/QuickStatementsExporter.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/exporters/QuickStatementsExporter.java @@ -38,14 +38,11 @@ import org.slf4j.LoggerFactory; import org.wikidata.wdtk.datamodel.interfaces.Claim; import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue; -import org.wikidata.wdtk.datamodel.interfaces.NoValueSnak; import org.wikidata.wdtk.datamodel.interfaces.Reference; import org.wikidata.wdtk.datamodel.interfaces.Snak; import org.wikidata.wdtk.datamodel.interfaces.SnakGroup; -import org.wikidata.wdtk.datamodel.interfaces.SomeValueSnak; import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.Value; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor; import com.google.refine.browsing.Engine; @@ -183,16 +180,9 @@ public class QuickStatementsExporter implements WriterExporter { if (reference) { pid = pid.replace('P', 'S'); } - String valStr = ""; - if (s instanceof ValueSnak) { - Value val = ((ValueSnak)s).getValue(); - ValueVisitor vv = new QSValuePrinter(); - valStr = val.accept(vv); - } else if (s instanceof NoValueSnak) { - valStr = "novalue"; - } else if (s instanceof SomeValueSnak) { - valStr = "somevalue"; - } + Value val = s.getValue(); + ValueVisitor vv = new QSValuePrinter(); + String valStr = val.accept(vv); if (valStr != null) { writer.write("\t" + pid + "\t" + valStr); } diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/WikidataConstraintFetcher.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/WikidataConstraintFetcher.java index 3b218af18..cbe2aebc7 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/WikidataConstraintFetcher.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/WikidataConstraintFetcher.java @@ -42,7 +42,6 @@ import org.wikidata.wdtk.datamodel.interfaces.StatementGroup; import org.wikidata.wdtk.datamodel.interfaces.StatementRank; import org.wikidata.wdtk.datamodel.interfaces.StringValue; import org.wikidata.wdtk.datamodel.interfaces.Value; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; /** * This class provides an abstraction over the way constraint definitions are @@ -330,11 +329,7 @@ public class WikidataConstraintFetcher implements ConstraintFetcher { for (SnakGroup group : groups) { if (group.getProperty().getId().equals(pid)) { for (Snak snak : group.getSnaks()) - if (snak instanceof ValueSnak) { - results.add(((ValueSnak)snak).getValue()); - } else { - results.add(null); - } + results.add(snak.getValue()); } } return results; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/DistinctValuesScrutinizer.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/DistinctValuesScrutinizer.java index 6a6aabba3..03a5761d1 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/DistinctValuesScrutinizer.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/DistinctValuesScrutinizer.java @@ -29,10 +29,8 @@ import java.util.Map; import org.openrefine.wikidata.qa.QAWarning; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; -import org.wikidata.wdtk.datamodel.interfaces.Snak; import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.Value; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; /** * A scrutinizer that checks for properties using the same value on different @@ -55,11 +53,7 @@ public class DistinctValuesScrutinizer extends StatementScrutinizer { public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) { PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId(); if (_fetcher.hasDistinctValues(pid)) { - Snak mainSnak = statement.getClaim().getMainSnak(); - if(!(mainSnak instanceof ValueSnak)) { - return; - } - Value mainSnakValue = ((ValueSnak)mainSnak).getValue(); + Value mainSnakValue = statement.getClaim().getMainSnak().getValue(); Map seen = _seenValues.get(pid); if (seen == null) { seen = new HashMap(); diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/EntityTypeScrutinizer.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/EntityTypeScrutinizer.java index fbcfd8d82..af822dc28 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/EntityTypeScrutinizer.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/EntityTypeScrutinizer.java @@ -3,7 +3,7 @@ package org.openrefine.wikidata.qa.scrutinizers; import org.openrefine.wikidata.qa.QAWarning; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; +import org.wikidata.wdtk.datamodel.interfaces.Snak; public class EntityTypeScrutinizer extends SnakScrutinizer { @@ -11,7 +11,7 @@ public class EntityTypeScrutinizer extends SnakScrutinizer { public final static String type = "invalid-entity-type"; @Override - public void scrutinize(ValueSnak snak, EntityIdValue entityId, boolean added) { + public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) { PropertyIdValue pid = snak.getPropertyId(); if(!_fetcher.usableOnItems(pid)) { QAWarning issue = new QAWarning(type, null, QAWarning.Severity.WARNING, 1); diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/FormatScrutinizer.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/FormatScrutinizer.java index 05997d227..c61b90a06 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/FormatScrutinizer.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/FormatScrutinizer.java @@ -30,8 +30,8 @@ import java.util.regex.Pattern; import org.openrefine.wikidata.qa.QAWarning; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; +import org.wikidata.wdtk.datamodel.interfaces.Snak; import org.wikidata.wdtk.datamodel.interfaces.StringValue; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; /** * A scrutinizer that detects incorrect formats in text values (mostly @@ -73,7 +73,7 @@ public class FormatScrutinizer extends SnakScrutinizer { } @Override - public void scrutinize(ValueSnak snak, EntityIdValue entityId, boolean added) { + public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) { if (StringValue.class.isInstance(snak.getValue())) { String value = ((StringValue) snak.getValue()).getString(); PropertyIdValue pid = snak.getPropertyId(); diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/InverseConstraintScrutinizer.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/InverseConstraintScrutinizer.java index 87aab1d67..88bc2c3ae 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/InverseConstraintScrutinizer.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/InverseConstraintScrutinizer.java @@ -33,10 +33,8 @@ import org.openrefine.wikidata.qa.QAWarning; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; -import org.wikidata.wdtk.datamodel.interfaces.Snak; import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.Value; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; /** * A scrutinizer that checks for missing inverse statements in edit batches. @@ -83,11 +81,7 @@ public class InverseConstraintScrutinizer extends StatementScrutinizer { return; // TODO support for deleted statements } - Snak mainSnak = statement.getClaim().getMainSnak(); - if(! (mainSnak instanceof ValueSnak)) { - return; - } - Value mainSnakValue = ((ValueSnak)mainSnak).getValue(); + Value mainSnakValue = statement.getClaim().getMainSnak().getValue(); if (ItemIdValue.class.isInstance(mainSnakValue)) { PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId(); PropertyIdValue inversePid = getInverseConstraint(pid); diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/QuantityScrutinizer.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/QuantityScrutinizer.java index a2d9cf866..ea711fe56 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/QuantityScrutinizer.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/QuantityScrutinizer.java @@ -1,13 +1,15 @@ package org.openrefine.wikidata.qa.scrutinizers; import java.util.Set; +import java.util.stream.Collectors; import org.openrefine.wikidata.qa.QAWarning; +import org.wikidata.wdtk.datamodel.helpers.Datamodel; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; import org.wikidata.wdtk.datamodel.interfaces.QuantityValue; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; +import org.wikidata.wdtk.datamodel.interfaces.Snak; /** * Scrutinizer checking for units and bounds in quantities. @@ -23,7 +25,7 @@ public class QuantityScrutinizer extends SnakScrutinizer { public static final String noUnitProvidedType = "no-unit-provided"; @Override - public void scrutinize(ValueSnak snak, EntityIdValue entityId, boolean added) { + public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) { if (QuantityValue.class.isInstance(snak.getValue()) && added) { PropertyIdValue pid = snak.getPropertyId(); QuantityValue value = (QuantityValue)snak.getValue(); @@ -43,19 +45,22 @@ public class QuantityScrutinizer extends SnakScrutinizer { addIssue(issue); } Set allowedUnits = _fetcher.allowedUnits(pid); - ItemIdValue currentUnit = null; - if (value.getUnit() != null) { - currentUnit = value.getUnitItemId(); + String currentUnit = null; + if (value.getUnit() != null && !value.getUnit().equals("")) { + currentUnit = value.getUnit(); } if(allowedUnits != null && - !allowedUnits.contains(currentUnit)) { + !allowedUnits.stream().map(u -> u != null ? u.getIri() : null) + .collect(Collectors.toSet()).contains(currentUnit)) { String issueType = currentUnit == null ? noUnitProvidedType : invalidUnitType; QAWarning issue = new QAWarning(issueType, pid.getId(), QAWarning.Severity.IMPORTANT, 1); issue.setProperty("property_entity", pid); issue.setProperty("example_value", value.getNumericValue().toString()); issue.setProperty("example_item_entity", entityId); if (currentUnit != null) { - issue.setProperty("unit_entity", currentUnit); + issue.setProperty("unit_entity", + // this is a hack but it will not be needed anymore in the upcoming version of Wikidata-Toolkit + Datamodel.makeWikidataItemIdValue(currentUnit.substring(currentUnit.indexOf("Q")))); } addIssue(issue); } diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/RestrictedValuesScrutinizer.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/RestrictedValuesScrutinizer.java index 2726d6ca5..5aed7b8b4 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/RestrictedValuesScrutinizer.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/RestrictedValuesScrutinizer.java @@ -4,11 +4,9 @@ import java.util.Set; import org.openrefine.wikidata.qa.QAWarning; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; -import org.wikidata.wdtk.datamodel.interfaces.NoValueSnak; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; -import org.wikidata.wdtk.datamodel.interfaces.SomeValueSnak; +import org.wikidata.wdtk.datamodel.interfaces.Snak; import org.wikidata.wdtk.datamodel.interfaces.Value; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; public class RestrictedValuesScrutinizer extends SnakScrutinizer { @@ -16,23 +14,10 @@ public class RestrictedValuesScrutinizer extends SnakScrutinizer { public static String type = "forbidden-value"; @Override - public void scrutinize(ValueSnak snak, EntityIdValue entityId, boolean added) { + public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) { PropertyIdValue pid = snak.getPropertyId(); Value value = snak.getValue(); - scrutinizeValue(value, pid, entityId, added); - } - - @Override - public void scrutinize(SomeValueSnak snak, EntityIdValue entityId, boolean added) { - scrutinizeValue(null, snak.getPropertyId(), entityId, added); - } - - @Override - public void scrutinize(NoValueSnak snak, EntityIdValue entityId, boolean added) { - scrutinizeValue(null, snak.getPropertyId(), entityId, added); - } - - public void scrutinizeValue(Value value, PropertyIdValue pid, EntityIdValue entityId, boolean added) { + Set allowedValues = _fetcher.allowedValues(pid); Set disallowedValues = _fetcher.disallowedValues(pid); if((allowedValues != null && !allowedValues.contains(value)) || diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/SelfReferentialScrutinizer.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/SelfReferentialScrutinizer.java index c130fd239..c23f0606e 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/SelfReferentialScrutinizer.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/SelfReferentialScrutinizer.java @@ -25,7 +25,7 @@ package org.openrefine.wikidata.qa.scrutinizers; import org.openrefine.wikidata.qa.QAWarning; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; +import org.wikidata.wdtk.datamodel.interfaces.Snak; /** * A scrutinizer that checks for self-referential statements. These statements @@ -39,7 +39,7 @@ public class SelfReferentialScrutinizer extends SnakScrutinizer { public static final String type = "self-referential-statements"; @Override - public void scrutinize(ValueSnak snak, EntityIdValue entityId, boolean added) { + public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) { if (entityId.equals(snak.getValue())) { QAWarning issue = new QAWarning(type, null, QAWarning.Severity.WARNING, 1); issue.setProperty("example_entity", entityId); diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/SnakScrutinizer.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/SnakScrutinizer.java index 42f08e2c6..7e7e3afe7 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/SnakScrutinizer.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/SnakScrutinizer.java @@ -26,12 +26,9 @@ package org.openrefine.wikidata.qa.scrutinizers; import java.util.Iterator; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; -import org.wikidata.wdtk.datamodel.interfaces.NoValueSnak; import org.wikidata.wdtk.datamodel.interfaces.Reference; import org.wikidata.wdtk.datamodel.interfaces.Snak; -import org.wikidata.wdtk.datamodel.interfaces.SomeValueSnak; import org.wikidata.wdtk.datamodel.interfaces.Statement; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; /** * A scrutinizer that inspects snaks individually, no matter whether they appear @@ -52,46 +49,8 @@ public abstract class SnakScrutinizer extends StatementScrutinizer { * @param added: * whether this snak is going to be added or deleted */ - public abstract void scrutinize(ValueSnak snak, EntityIdValue entityId, boolean added); + public abstract void scrutinize(Snak snak, EntityIdValue entityId, boolean added); - /** - * Scrutinizes a novalue snak - * - * @param snak: - * the snak to inspect - * @param entityId: - * the item on which it is going to (dis)appear - * @param added: - * whether this snak is going to be added or deleted - */ - public void scrutinize(NoValueSnak snak, EntityIdValue entityId, boolean added) { - - } - - /** - * Scrutinizes a somevalue snak - * - * @param snak: - * the snak to inspect - * @param entityId: - * the item on which it is going to (dis)appear - * @param added: - * whether this snak is going to be added or deleted - */ - public void scrutinize(SomeValueSnak snak, EntityIdValue entityId, boolean added) { - - } - - public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) { - if(snak instanceof ValueSnak) { - scrutinize((ValueSnak)snak, entityId, added); - } else if(snak instanceof NoValueSnak) { - scrutinize((NoValueSnak)snak, entityId, added); - } else if(snak instanceof SomeValueSnak) { - scrutinize((SomeValueSnak)snak, entityId, added); - } - } - @Override public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) { // Main snak diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/ValueScrutinizer.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/ValueScrutinizer.java index 2d10b065f..1a70302a9 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/ValueScrutinizer.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/scrutinizers/ValueScrutinizer.java @@ -26,8 +26,8 @@ package org.openrefine.wikidata.qa.scrutinizers; import org.openrefine.wikidata.updates.ItemUpdate; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue; +import org.wikidata.wdtk.datamodel.interfaces.Snak; import org.wikidata.wdtk.datamodel.interfaces.Value; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; /** * A scrutinizer that inspects the values of snaks and terms @@ -55,7 +55,7 @@ public abstract class ValueScrutinizer extends SnakScrutinizer { public abstract void scrutinize(Value value); @Override - public void scrutinize(ValueSnak snak, EntityIdValue entityId, boolean added) { + public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) { scrutinize(snak.getValue()); } diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbSnakExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbSnakExpr.java index 61d8c4ac4..a9b33b952 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbSnakExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbSnakExpr.java @@ -26,6 +26,7 @@ package org.openrefine.wikidata.schema; import org.jsoup.helper.Validate; import org.openrefine.wikidata.schema.entityvalues.FullyPropertySerializingValueSnak; import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException; +import org.wikidata.wdtk.datamodel.helpers.Datamodel; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; import org.wikidata.wdtk.datamodel.interfaces.Snak; import org.wikidata.wdtk.datamodel.interfaces.Value; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/updates/scheduler/PointerExtractor.java b/extensions/wikidata/src/org/openrefine/wikidata/updates/scheduler/PointerExtractor.java index 2b66150a6..7fac7b09e 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/updates/scheduler/PointerExtractor.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/updates/scheduler/PointerExtractor.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Set; import org.openrefine.wikidata.schema.entityvalues.ReconItemIdValue; +import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue; import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue; @@ -39,7 +40,6 @@ import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.StringValue; import org.wikidata.wdtk.datamodel.interfaces.TimeValue; import org.wikidata.wdtk.datamodel.interfaces.Value; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor; /** @@ -101,9 +101,7 @@ public class PointerExtractor implements ValueVisitor> { public Set extractPointers(Snak snak) { Set result = new HashSet<>(); result.addAll(extractPointers(snak.getPropertyId())); - if (snak instanceof ValueSnak) { - result.addAll(extractPointers(((ValueSnak)snak).getValue())); - } + result.addAll(extractPointers(snak.getValue())); return result; } @@ -124,6 +122,11 @@ public class PointerExtractor implements ValueVisitor> { return pointers; } + @Override + public Set visit(DatatypeIdValue value) { + return null; + } + @Override public Set visit(EntityIdValue value) { if (ReconItemIdValue.class.isInstance(value)) { diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbQuantityExprTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbQuantityExprTest.java index 97676504c..79485cbc3 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbQuantityExprTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WbQuantityExprTest.java @@ -33,6 +33,7 @@ import org.wikidata.wdtk.datamodel.helpers.Datamodel; import org.wikidata.wdtk.datamodel.interfaces.QuantityValue; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; public class WbQuantityExprTest extends WbExpressionTest { diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java index fb0839699..72bd2d941 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java @@ -52,6 +52,8 @@ import org.wikidata.wdtk.datamodel.interfaces.StatementRank; import org.wikidata.wdtk.datamodel.interfaces.StringValue; import org.wikidata.wdtk.datamodel.interfaces.TimeValue; +import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; + import com.google.refine.browsing.Engine; import com.google.refine.browsing.EngineConfig; import com.google.refine.model.Project; diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/testing/TestingData.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/testing/TestingData.java index 7e58362dd..efa25756f 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/testing/TestingData.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/testing/TestingData.java @@ -25,6 +25,8 @@ package org.openrefine.wikidata.testing; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Collections; import org.apache.commons.io.IOUtils; diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/updates/scheduler/PointerExtractorTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/updates/scheduler/PointerExtractorTest.java index 5671c173e..6bab3955a 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/updates/scheduler/PointerExtractorTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/updates/scheduler/PointerExtractorTest.java @@ -66,6 +66,7 @@ public class PointerExtractorTest { @Test public void testExtractDatavalues() { + assertEmpty(Datamodel.makeDatatypeIdValue("string")); assertEmpty(Datamodel.makeGlobeCoordinatesValue(1.34, 2.354, 0.1, GlobeCoordinatesValue.GLOBE_EARTH)); assertEmpty(Datamodel.makeStringValue("est")); assertEmpty(Datamodel.makeMonolingualTextValue("srtu", "en"));