Update to Wikidata-Toolkit 0.10.0. Closes #2064.

This commit is contained in:
Antonin Delpeuch 2019-06-13 10:07:21 +01:00
parent 8d97c519d8
commit 8ae4c8fe94
8 changed files with 15 additions and 67 deletions

View File

@ -93,45 +93,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>
@ -163,12 +124,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.10.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.10.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>

View File

@ -211,6 +211,9 @@ public class EditBatchProcessor {
} catch (MediaWikiApiErrorException e) { } catch (MediaWikiApiErrorException e) {
e.printStackTrace(); e.printStackTrace();
Thread.sleep(5000); Thread.sleep(5000);
} catch (IOException e) {
e.printStackTrace();
Thread.sleep(5000);
} }
retries--; retries--;
} }

View File

@ -31,6 +31,7 @@ import org.openrefine.wikidata.updates.scheduler.QuickStatementsUpdateScheduler;
import org.wikidata.wdtk.datamodel.interfaces.DatatypeIdValue; 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 +51,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 +71,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

View File

@ -45,22 +45,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.getUnitItemId() != 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", value.getUnitItemId());
// 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

@ -122,11 +122,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)) {

View File

@ -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"));