Merge pull request #1791 from OpenRefine/issue1701
Bump Wikidata-Toolkit to 0.9.0
This commit is contained in:
commit
96e3015882
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -95,45 +95,6 @@
|
|||||||
</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>
|
||||||
@ -165,12 +126,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-SNAPSHOT</version>
|
<version>0.9.0</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-SNAPSHOT</version>
|
<version>0.9.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- testing dependencies -->
|
<!-- testing dependencies -->
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
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;
|
||||||
@ -36,7 +38,6 @@ 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;
|
||||||
@ -45,10 +46,7 @@ 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;
|
||||||
|
@ -31,6 +31,7 @@ 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;
|
||||||
|
@ -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,12 +50,6 @@ 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()) {
|
||||||
@ -76,12 +70,10 @@ public class QSValuePrinter implements ValueVisitor<String> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(QuantityValue value) {
|
public String visit(QuantityValue value) {
|
||||||
String unitPrefix = "http://www.wikidata.org/entity/Q";
|
ItemIdValue unit = value.getUnitItemId();
|
||||||
String unitIri = value.getUnit();
|
|
||||||
String unitRepresentation = "", boundsRepresentation = "";
|
String unitRepresentation = "", boundsRepresentation = "";
|
||||||
if (!unitIri.isEmpty()) {
|
if (unit != null) {
|
||||||
if (!unitIri.startsWith(unitPrefix)) return null; // QuickStatements only accepts Qids as units
|
unitRepresentation = "U" + unit.getId().substring(1);
|
||||||
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
|
||||||
|
@ -38,11 +38,14 @@ 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;
|
||||||
@ -180,9 +183,16 @@ public class QuickStatementsExporter implements WriterExporter {
|
|||||||
if (reference) {
|
if (reference) {
|
||||||
pid = pid.replace('P', 'S');
|
pid = pid.replace('P', 'S');
|
||||||
}
|
}
|
||||||
Value val = s.getValue();
|
String valStr = "";
|
||||||
ValueVisitor<String> vv = new QSValuePrinter();
|
if (s instanceof ValueSnak) {
|
||||||
String valStr = val.accept(vv);
|
Value val = ((ValueSnak)s).getValue();
|
||||||
|
ValueVisitor<String> vv = new QSValuePrinter();
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ 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
|
||||||
@ -329,7 +330,11 @@ 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())
|
||||||
results.add(snak.getValue());
|
if (snak instanceof ValueSnak) {
|
||||||
|
results.add(((ValueSnak)snak).getValue());
|
||||||
|
} else {
|
||||||
|
results.add(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
|
@ -29,8 +29,10 @@ 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
|
||||||
@ -53,7 +55,11 @@ 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)) {
|
||||||
Value mainSnakValue = statement.getClaim().getMainSnak().getValue();
|
Snak mainSnak = statement.getClaim().getMainSnak();
|
||||||
|
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>();
|
||||||
|
@ -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.Snak;
|
import org.wikidata.wdtk.datamodel.interfaces.ValueSnak;
|
||||||
|
|
||||||
|
|
||||||
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(Snak snak, EntityIdValue entityId, boolean added) {
|
public void scrutinize(ValueSnak 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);
|
||||||
|
@ -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(Snak snak, EntityIdValue entityId, boolean added) {
|
public void scrutinize(ValueSnak 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();
|
||||||
|
@ -33,8 +33,10 @@ 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.
|
||||||
@ -81,7 +83,11 @@ public class InverseConstraintScrutinizer extends StatementScrutinizer {
|
|||||||
return; // TODO support for deleted statements
|
return; // TODO support for deleted statements
|
||||||
}
|
}
|
||||||
|
|
||||||
Value mainSnakValue = statement.getClaim().getMainSnak().getValue();
|
Snak mainSnak = statement.getClaim().getMainSnak();
|
||||||
|
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);
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
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.Snak;
|
import org.wikidata.wdtk.datamodel.interfaces.ValueSnak;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scrutinizer checking for units and bounds in quantities.
|
* Scrutinizer checking for units and bounds in quantities.
|
||||||
@ -25,7 +23,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(Snak snak, EntityIdValue entityId, boolean added) {
|
public void scrutinize(ValueSnak 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();
|
||||||
@ -45,22 +43,19 @@ public class QuantityScrutinizer extends SnakScrutinizer {
|
|||||||
addIssue(issue);
|
addIssue(issue);
|
||||||
}
|
}
|
||||||
Set<ItemIdValue> allowedUnits = _fetcher.allowedUnits(pid);
|
Set<ItemIdValue> allowedUnits = _fetcher.allowedUnits(pid);
|
||||||
String currentUnit = null;
|
ItemIdValue currentUnit = null;
|
||||||
if (value.getUnit() != null && !value.getUnit().equals("")) {
|
if (value.getUnit() != null) {
|
||||||
currentUnit = value.getUnit();
|
currentUnit = value.getUnitItemId();
|
||||||
}
|
}
|
||||||
if(allowedUnits != null &&
|
if(allowedUnits != null &&
|
||||||
!allowedUnits.stream().map(u -> u != null ? u.getIri() : null)
|
!allowedUnits.contains(currentUnit)) {
|
||||||
.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",
|
issue.setProperty("unit_entity", currentUnit);
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,11 @@ 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.Snak;
|
import org.wikidata.wdtk.datamodel.interfaces.SomeValueSnak;
|
||||||
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 {
|
||||||
@ -14,10 +16,23 @@ public class RestrictedValuesScrutinizer extends SnakScrutinizer {
|
|||||||
public static String type = "forbidden-value";
|
public static String type = "forbidden-value";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void scrutinize(Snak snak, EntityIdValue entityId, boolean added) {
|
public void scrutinize(ValueSnak 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)) ||
|
||||||
|
@ -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.Snak;
|
import org.wikidata.wdtk.datamodel.interfaces.ValueSnak;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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(Snak snak, EntityIdValue entityId, boolean added) {
|
public void scrutinize(ValueSnak 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);
|
||||||
|
@ -26,9 +26,12 @@ 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
|
||||||
@ -49,7 +52,45 @@ 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(Snak snak, EntityIdValue entityId, boolean added);
|
public abstract void scrutinize(ValueSnak 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) {
|
||||||
|
@ -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(Snak snak, EntityIdValue entityId, boolean added) {
|
public void scrutinize(ValueSnak snak, EntityIdValue entityId, boolean added) {
|
||||||
scrutinize(snak.getValue());
|
scrutinize(snak.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ 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;
|
||||||
|
@ -29,7 +29,6 @@ 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;
|
||||||
@ -40,6 +39,7 @@ 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,7 +101,9 @@ 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()));
|
||||||
result.addAll(extractPointers(snak.getValue()));
|
if (snak instanceof ValueSnak) {
|
||||||
|
result.addAll(extractPointers(((ValueSnak)snak).getValue()));
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,11 +124,6 @@ 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)) {
|
||||||
|
@ -33,7 +33,6 @@ 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> {
|
||||||
|
|
||||||
|
@ -52,8 +52,6 @@ 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;
|
||||||
|
@ -25,8 +25,6 @@ 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;
|
||||||
|
@ -66,7 +66,6 @@ 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"));
|
||||||
|
Loading…
Reference in New Issue
Block a user