Revert "Bump Wikidata-Toolkit to 0.9.0"

This reverts commit 44bbdcc83d.
This commit is contained in:
Antonin Delpeuch 2018-11-01 22:27:42 +00:00
parent 922a9e7c43
commit 04ed08c2c5
25 changed files with 101 additions and 121 deletions

View File

@ -95,6 +95,45 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-wdtk-datamodel</id>
<phase>process-resources</phase>
<configuration>
<file>${basedir}/lib-local/wdtk-datamodel-0.9.0-SNAPSHOT-jar-with-dependencies.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>org.wikidata.wdtk</groupId>
<artifactId>wdtk-datamodel</artifactId>
<version>0.9.0-SNAPSHOT</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
<execution>
<id>install-wdtk-wikibaseapi</id>
<phase>process-resources</phase>
<configuration>
<file>${basedir}/lib-local/wdtk-wikibaseapi-0.9.0-SNAPSHOT.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>org.wikidata.wdtk</groupId>
<artifactId>wdtk-wikibaseapi</artifactId>
<version>0.9.0-SNAPSHOT</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId> <artifactId>maven-clean-plugin</artifactId>
@ -126,12 +165,12 @@
<dependency> <dependency>
<groupId>org.wikidata.wdtk</groupId> <groupId>org.wikidata.wdtk</groupId>
<artifactId>wdtk-wikibaseapi</artifactId> <artifactId>wdtk-wikibaseapi</artifactId>
<version>0.9.0</version> <version>0.9.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.wikidata.wdtk</groupId> <groupId>org.wikidata.wdtk</groupId>
<artifactId>wdtk-datamodel</artifactId> <artifactId>wdtk-datamodel</artifactId>
<version>0.9.0</version> <version>0.9.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>

View File

@ -24,8 +24,6 @@
package org.openrefine.wikidata.commands; package org.openrefine.wikidata.commands;
import static org.openrefine.wikidata.commands.CommandUtilities.respondError;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.List; import java.util.List;
@ -38,6 +36,7 @@ import javax.servlet.http.HttpServletResponse;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter; import org.json.JSONWriter;
import org.openrefine.wikidata.qa.EditInspector; import org.openrefine.wikidata.qa.EditInspector;
import org.openrefine.wikidata.qa.QAWarning; 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.ItemUpdate;
import org.openrefine.wikidata.updates.scheduler.WikibaseAPIUpdateScheduler; import org.openrefine.wikidata.updates.scheduler.WikibaseAPIUpdateScheduler;
import static org.openrefine.wikidata.commands.CommandUtilities.respondError;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.refine.browsing.Engine; import com.google.refine.browsing.Engine;
import com.google.refine.commands.Command; import com.google.refine.commands.Command;
import com.google.refine.model.Project; import com.google.refine.model.Project;

View File

@ -31,7 +31,6 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.wikidata.wdtk.wikibaseapi.ApiConnection; import org.wikidata.wdtk.wikibaseapi.ApiConnection;
import org.wikidata.wdtk.wikibaseapi.BasicApiConnection;
import org.wikidata.wdtk.wikibaseapi.LoginFailedException; import org.wikidata.wdtk.wikibaseapi.LoginFailedException;
import com.google.refine.ProjectManager; import com.google.refine.ProjectManager;

View File

@ -28,9 +28,9 @@ import java.util.Locale;
import org.openrefine.wikidata.schema.entityvalues.ReconEntityIdValue; import org.openrefine.wikidata.schema.entityvalues.ReconEntityIdValue;
import org.openrefine.wikidata.updates.scheduler.QuickStatementsUpdateScheduler; 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.EntityIdValue;
import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue; 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.MonolingualTextValue;
import org.wikidata.wdtk.datamodel.interfaces.QuantityValue; import org.wikidata.wdtk.datamodel.interfaces.QuantityValue;
import org.wikidata.wdtk.datamodel.interfaces.StringValue; import org.wikidata.wdtk.datamodel.interfaces.StringValue;
@ -50,6 +50,12 @@ import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor;
*/ */
public class QSValuePrinter implements ValueVisitor<String> { public class QSValuePrinter implements ValueVisitor<String> {
@Override
public String visit(DatatypeIdValue value) {
// impossible case (this is actually a bug in WDTK, DatatypeIdValue should not subclass Value)
throw new IllegalArgumentException();
}
@Override @Override
public String visit(EntityIdValue value) { public String visit(EntityIdValue value) {
if (ReconEntityIdValue.class.isInstance(value) && ((ReconEntityIdValue) value).isNew()) { if (ReconEntityIdValue.class.isInstance(value) && ((ReconEntityIdValue) value).isNew()) {
@ -70,10 +76,12 @@ public class QSValuePrinter implements ValueVisitor<String> {
@Override @Override
public String visit(QuantityValue value) { public String visit(QuantityValue value) {
ItemIdValue unit = value.getUnitItemId(); String unitPrefix = "http://www.wikidata.org/entity/Q";
String unitIri = value.getUnit();
String unitRepresentation = "", boundsRepresentation = ""; String unitRepresentation = "", boundsRepresentation = "";
if (unit != null) { if (!unitIri.isEmpty()) {
unitRepresentation = "U" + unit.getId().substring(1); if (!unitIri.startsWith(unitPrefix)) return null; // QuickStatements only accepts Qids as units
unitRepresentation = "U" + unitIri.substring(unitPrefix.length());
} }
if (value.getLowerBound() != null) { if (value.getLowerBound() != null) {
// bounds are always null at the same time so we know they are both not null // bounds are always null at the same time so we know they are both not null

View File

@ -38,14 +38,11 @@ import org.slf4j.LoggerFactory;
import org.wikidata.wdtk.datamodel.interfaces.Claim; import org.wikidata.wdtk.datamodel.interfaces.Claim;
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue; 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.Reference;
import org.wikidata.wdtk.datamodel.interfaces.Snak; import org.wikidata.wdtk.datamodel.interfaces.Snak;
import org.wikidata.wdtk.datamodel.interfaces.SnakGroup; 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.Statement;
import org.wikidata.wdtk.datamodel.interfaces.Value; import org.wikidata.wdtk.datamodel.interfaces.Value;
import org.wikidata.wdtk.datamodel.interfaces.ValueSnak;
import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor; import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor;
import com.google.refine.browsing.Engine; import com.google.refine.browsing.Engine;
@ -183,16 +180,9 @@ public class QuickStatementsExporter implements WriterExporter {
if (reference) { if (reference) {
pid = pid.replace('P', 'S'); pid = pid.replace('P', 'S');
} }
String valStr = ""; Value val = s.getValue();
if (s instanceof ValueSnak) {
Value val = ((ValueSnak)s).getValue();
ValueVisitor<String> vv = new QSValuePrinter(); ValueVisitor<String> vv = new QSValuePrinter();
valStr = val.accept(vv); String valStr = val.accept(vv);
} else if (s instanceof NoValueSnak) {
valStr = "novalue";
} else if (s instanceof SomeValueSnak) {
valStr = "somevalue";
}
if (valStr != null) { if (valStr != null) {
writer.write("\t" + pid + "\t" + valStr); writer.write("\t" + pid + "\t" + valStr);
} }

View File

@ -42,7 +42,6 @@ import org.wikidata.wdtk.datamodel.interfaces.StatementGroup;
import org.wikidata.wdtk.datamodel.interfaces.StatementRank; import org.wikidata.wdtk.datamodel.interfaces.StatementRank;
import org.wikidata.wdtk.datamodel.interfaces.StringValue; import org.wikidata.wdtk.datamodel.interfaces.StringValue;
import org.wikidata.wdtk.datamodel.interfaces.Value; 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 * This class provides an abstraction over the way constraint definitions are
@ -330,11 +329,7 @@ public class WikidataConstraintFetcher implements ConstraintFetcher {
for (SnakGroup group : groups) { for (SnakGroup group : groups) {
if (group.getProperty().getId().equals(pid)) { if (group.getProperty().getId().equals(pid)) {
for (Snak snak : group.getSnaks()) for (Snak snak : group.getSnaks())
if (snak instanceof ValueSnak) { results.add(snak.getValue());
results.add(((ValueSnak)snak).getValue());
} else {
results.add(null);
}
} }
} }
return results; return results;

View File

@ -29,10 +29,8 @@ import java.util.Map;
import org.openrefine.wikidata.qa.QAWarning; import org.openrefine.wikidata.qa.QAWarning;
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.Statement; import org.wikidata.wdtk.datamodel.interfaces.Statement;
import org.wikidata.wdtk.datamodel.interfaces.Value; 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 * 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) { public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) {
PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId(); PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId();
if (_fetcher.hasDistinctValues(pid)) { if (_fetcher.hasDistinctValues(pid)) {
Snak mainSnak = statement.getClaim().getMainSnak(); Value mainSnakValue = statement.getClaim().getMainSnak().getValue();
if(!(mainSnak instanceof ValueSnak)) {
return;
}
Value mainSnakValue = ((ValueSnak)mainSnak).getValue();
Map<Value, EntityIdValue> seen = _seenValues.get(pid); Map<Value, EntityIdValue> seen = _seenValues.get(pid);
if (seen == null) { if (seen == null) {
seen = new HashMap<Value, EntityIdValue>(); seen = new HashMap<Value, EntityIdValue>();

View File

@ -3,7 +3,7 @@ package org.openrefine.wikidata.qa.scrutinizers;
import org.openrefine.wikidata.qa.QAWarning; import org.openrefine.wikidata.qa.QAWarning;
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.ValueSnak; import org.wikidata.wdtk.datamodel.interfaces.Snak;
public class EntityTypeScrutinizer extends SnakScrutinizer { public class EntityTypeScrutinizer extends SnakScrutinizer {
@ -11,7 +11,7 @@ public class EntityTypeScrutinizer extends SnakScrutinizer {
public final static String type = "invalid-entity-type"; public final static String type = "invalid-entity-type";
@Override @Override
public void scrutinize(ValueSnak snak, EntityIdValue entityId, boolean added) { public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
PropertyIdValue pid = snak.getPropertyId(); PropertyIdValue pid = snak.getPropertyId();
if(!_fetcher.usableOnItems(pid)) { if(!_fetcher.usableOnItems(pid)) {
QAWarning issue = new QAWarning(type, null, QAWarning.Severity.WARNING, 1); QAWarning issue = new QAWarning(type, null, QAWarning.Severity.WARNING, 1);

View File

@ -30,8 +30,8 @@ import java.util.regex.Pattern;
import org.openrefine.wikidata.qa.QAWarning; import org.openrefine.wikidata.qa.QAWarning;
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.StringValue; import org.wikidata.wdtk.datamodel.interfaces.StringValue;
import org.wikidata.wdtk.datamodel.interfaces.ValueSnak;
/** /**
* A scrutinizer that detects incorrect formats in text values (mostly * A scrutinizer that detects incorrect formats in text values (mostly
@ -73,7 +73,7 @@ public class FormatScrutinizer extends SnakScrutinizer {
} }
@Override @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())) { if (StringValue.class.isInstance(snak.getValue())) {
String value = ((StringValue) snak.getValue()).getString(); String value = ((StringValue) snak.getValue()).getString();
PropertyIdValue pid = snak.getPropertyId(); PropertyIdValue pid = snak.getPropertyId();

View File

@ -33,10 +33,8 @@ import org.openrefine.wikidata.qa.QAWarning;
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;
import org.wikidata.wdtk.datamodel.interfaces.Snak;
import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.Statement;
import org.wikidata.wdtk.datamodel.interfaces.Value; 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. * 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 return; // TODO support for deleted statements
} }
Snak mainSnak = statement.getClaim().getMainSnak(); Value mainSnakValue = statement.getClaim().getMainSnak().getValue();
if(! (mainSnak instanceof ValueSnak)) {
return;
}
Value mainSnakValue = ((ValueSnak)mainSnak).getValue();
if (ItemIdValue.class.isInstance(mainSnakValue)) { if (ItemIdValue.class.isInstance(mainSnakValue)) {
PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId(); PropertyIdValue pid = statement.getClaim().getMainSnak().getPropertyId();
PropertyIdValue inversePid = getInverseConstraint(pid); PropertyIdValue inversePid = getInverseConstraint(pid);

View File

@ -1,13 +1,15 @@
package org.openrefine.wikidata.qa.scrutinizers; package org.openrefine.wikidata.qa.scrutinizers;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import org.openrefine.wikidata.qa.QAWarning; 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.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;
import org.wikidata.wdtk.datamodel.interfaces.QuantityValue; 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. * 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"; public static final String noUnitProvidedType = "no-unit-provided";
@Override @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) { if (QuantityValue.class.isInstance(snak.getValue()) && added) {
PropertyIdValue pid = snak.getPropertyId(); PropertyIdValue pid = snak.getPropertyId();
QuantityValue value = (QuantityValue)snak.getValue(); QuantityValue value = (QuantityValue)snak.getValue();
@ -43,19 +45,22 @@ public class QuantityScrutinizer extends SnakScrutinizer {
addIssue(issue); addIssue(issue);
} }
Set<ItemIdValue> allowedUnits = _fetcher.allowedUnits(pid); Set<ItemIdValue> allowedUnits = _fetcher.allowedUnits(pid);
ItemIdValue currentUnit = null; String currentUnit = null;
if (value.getUnit() != null) { if (value.getUnit() != null && !value.getUnit().equals("")) {
currentUnit = value.getUnitItemId(); currentUnit = value.getUnit();
} }
if(allowedUnits != null && 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; String issueType = currentUnit == null ? noUnitProvidedType : invalidUnitType;
QAWarning issue = new QAWarning(issueType, pid.getId(), QAWarning.Severity.IMPORTANT, 1); QAWarning issue = new QAWarning(issueType, pid.getId(), QAWarning.Severity.IMPORTANT, 1);
issue.setProperty("property_entity", pid); issue.setProperty("property_entity", pid);
issue.setProperty("example_value", value.getNumericValue().toString()); issue.setProperty("example_value", value.getNumericValue().toString());
issue.setProperty("example_item_entity", entityId); issue.setProperty("example_item_entity", entityId);
if (currentUnit != null) { 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); addIssue(issue);
} }

View File

@ -4,11 +4,9 @@ import java.util.Set;
import org.openrefine.wikidata.qa.QAWarning; import org.openrefine.wikidata.qa.QAWarning;
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; 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.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.Value;
import org.wikidata.wdtk.datamodel.interfaces.ValueSnak;
public class RestrictedValuesScrutinizer extends SnakScrutinizer { public class RestrictedValuesScrutinizer extends SnakScrutinizer {
@ -16,23 +14,10 @@ public class RestrictedValuesScrutinizer extends SnakScrutinizer {
public static String type = "forbidden-value"; public static String type = "forbidden-value";
@Override @Override
public void scrutinize(ValueSnak snak, EntityIdValue entityId, boolean added) { public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
PropertyIdValue pid = snak.getPropertyId(); PropertyIdValue pid = snak.getPropertyId();
Value value = snak.getValue(); 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<Value> allowedValues = _fetcher.allowedValues(pid); Set<Value> allowedValues = _fetcher.allowedValues(pid);
Set<Value> disallowedValues = _fetcher.disallowedValues(pid); Set<Value> disallowedValues = _fetcher.disallowedValues(pid);
if((allowedValues != null && !allowedValues.contains(value)) || if((allowedValues != null && !allowedValues.contains(value)) ||

View File

@ -25,7 +25,7 @@ package org.openrefine.wikidata.qa.scrutinizers;
import org.openrefine.wikidata.qa.QAWarning; import org.openrefine.wikidata.qa.QAWarning;
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; 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 * 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"; public static final String type = "self-referential-statements";
@Override @Override
public void scrutinize(ValueSnak snak, EntityIdValue entityId, boolean added) { public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
if (entityId.equals(snak.getValue())) { if (entityId.equals(snak.getValue())) {
QAWarning issue = new QAWarning(type, null, QAWarning.Severity.WARNING, 1); QAWarning issue = new QAWarning(type, null, QAWarning.Severity.WARNING, 1);
issue.setProperty("example_entity", entityId); issue.setProperty("example_entity", entityId);

View File

@ -26,12 +26,9 @@ package org.openrefine.wikidata.qa.scrutinizers;
import java.util.Iterator; import java.util.Iterator;
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; 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.Reference;
import org.wikidata.wdtk.datamodel.interfaces.Snak; 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.Statement;
import org.wikidata.wdtk.datamodel.interfaces.ValueSnak;
/** /**
* A scrutinizer that inspects snaks individually, no matter whether they appear * A scrutinizer that inspects snaks individually, no matter whether they appear
@ -52,45 +49,7 @@ public abstract class SnakScrutinizer extends StatementScrutinizer {
* @param added: * @param added:
* whether this snak is going to be added or deleted * 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 @Override
public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) { public void scrutinize(Statement statement, EntityIdValue entityId, boolean added) {

View File

@ -26,8 +26,8 @@ package org.openrefine.wikidata.qa.scrutinizers;
import org.openrefine.wikidata.updates.ItemUpdate; import org.openrefine.wikidata.updates.ItemUpdate;
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue; 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.Value;
import org.wikidata.wdtk.datamodel.interfaces.ValueSnak;
/** /**
* A scrutinizer that inspects the values of snaks and terms * 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); public abstract void scrutinize(Value value);
@Override @Override
public void scrutinize(ValueSnak snak, EntityIdValue entityId, boolean added) { public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
scrutinize(snak.getValue()); scrutinize(snak.getValue());
} }

View File

@ -26,6 +26,7 @@ package org.openrefine.wikidata.schema;
import org.jsoup.helper.Validate; import org.jsoup.helper.Validate;
import org.openrefine.wikidata.schema.entityvalues.FullyPropertySerializingValueSnak; import org.openrefine.wikidata.schema.entityvalues.FullyPropertySerializingValueSnak;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException; 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.PropertyIdValue;
import org.wikidata.wdtk.datamodel.interfaces.Snak; import org.wikidata.wdtk.datamodel.interfaces.Snak;
import org.wikidata.wdtk.datamodel.interfaces.Value; import org.wikidata.wdtk.datamodel.interfaces.Value;

View File

@ -29,6 +29,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import org.openrefine.wikidata.schema.entityvalues.ReconItemIdValue; 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.EntityIdValue;
import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue; import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue;
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue; 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.StringValue;
import org.wikidata.wdtk.datamodel.interfaces.TimeValue; import org.wikidata.wdtk.datamodel.interfaces.TimeValue;
import org.wikidata.wdtk.datamodel.interfaces.Value; import org.wikidata.wdtk.datamodel.interfaces.Value;
import org.wikidata.wdtk.datamodel.interfaces.ValueSnak;
import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor; import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor;
/** /**
@ -101,9 +101,7 @@ public class PointerExtractor implements ValueVisitor<Set<ReconItemIdValue>> {
public Set<ReconItemIdValue> extractPointers(Snak snak) { public Set<ReconItemIdValue> extractPointers(Snak snak) {
Set<ReconItemIdValue> result = new HashSet<>(); Set<ReconItemIdValue> result = new HashSet<>();
result.addAll(extractPointers(snak.getPropertyId())); result.addAll(extractPointers(snak.getPropertyId()));
if (snak instanceof ValueSnak) { result.addAll(extractPointers(snak.getValue()));
result.addAll(extractPointers(((ValueSnak)snak).getValue()));
}
return result; return result;
} }
@ -124,6 +122,11 @@ public class PointerExtractor implements ValueVisitor<Set<ReconItemIdValue>> {
return pointers; return pointers;
} }
@Override
public Set<ReconItemIdValue> visit(DatatypeIdValue value) {
return null;
}
@Override @Override
public Set<ReconItemIdValue> visit(EntityIdValue value) { public Set<ReconItemIdValue> visit(EntityIdValue value) {
if (ReconItemIdValue.class.isInstance(value)) { if (ReconItemIdValue.class.isInstance(value)) {

View File

@ -33,6 +33,7 @@ import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.QuantityValue; import org.wikidata.wdtk.datamodel.interfaces.QuantityValue;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class WbQuantityExprTest extends WbExpressionTest<QuantityValue> { public class WbQuantityExprTest extends WbExpressionTest<QuantityValue> {

View File

@ -52,6 +52,8 @@ import org.wikidata.wdtk.datamodel.interfaces.StatementRank;
import org.wikidata.wdtk.datamodel.interfaces.StringValue; import org.wikidata.wdtk.datamodel.interfaces.StringValue;
import org.wikidata.wdtk.datamodel.interfaces.TimeValue; 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.Engine;
import com.google.refine.browsing.EngineConfig; import com.google.refine.browsing.EngineConfig;
import com.google.refine.model.Project; import com.google.refine.model.Project;

View File

@ -25,6 +25,8 @@ package org.openrefine.wikidata.testing;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collections; import java.util.Collections;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;

View File

@ -66,6 +66,7 @@ public class PointerExtractorTest {
@Test @Test
public void testExtractDatavalues() { public void testExtractDatavalues() {
assertEmpty(Datamodel.makeDatatypeIdValue("string"));
assertEmpty(Datamodel.makeGlobeCoordinatesValue(1.34, 2.354, 0.1, GlobeCoordinatesValue.GLOBE_EARTH)); assertEmpty(Datamodel.makeGlobeCoordinatesValue(1.34, 2.354, 0.1, GlobeCoordinatesValue.GLOBE_EARTH));
assertEmpty(Datamodel.makeStringValue("est")); assertEmpty(Datamodel.makeStringValue("est"));
assertEmpty(Datamodel.makeMonolingualTextValue("srtu", "en")); assertEmpty(Datamodel.makeMonolingualTextValue("srtu", "en"));