Commit 6089a4eb authored by Florian Schäfer's avatar Florian Schäfer

Rename CheckEntityExistsResult → WbgetentitiesResult

parent 6c4ff3d9
......@@ -38,7 +38,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.wikipedia.api.ApiQueryClient;
import org.wikipedia.api.wikidata_action.WikidataActionApiQuery;
import org.wikipedia.api.wikidata_action.json.CheckEntityExistsResult;
import org.wikipedia.api.wikidata_action.json.WbgetentitiesResult;
import org.wikipedia.data.WikidataEntry;
import org.wikipedia.data.WikipediaEntry;
import org.wikipedia.tools.ListUtil;
......@@ -295,7 +295,7 @@ public final class WikipediaApp {
.getEntities().values()
.stream()
.filter(it -> RegexUtil.isValidQId(it.getId()) && it.getSitelinks().size() >= 1)
.collect(Collectors.toMap(it -> it.getSitelinks().iterator().next().getTitle(), CheckEntityExistsResult.Entity::getId));
.collect(Collectors.toMap(it -> it.getSitelinks().iterator().next().getTitle(), WbgetentitiesResult.Entity::getId));
} catch (IOException ex) {
throw new RuntimeException(ex);
}
......
......@@ -8,7 +8,7 @@ import org.openstreetmap.josm.tools.Utils;
import org.wikipedia.api.ApiQuery;
import org.wikipedia.api.ApiUrl;
import org.wikipedia.api.SerializationSchema;
import org.wikipedia.api.wikidata_action.json.CheckEntityExistsResult;
import org.wikipedia.api.wikidata_action.json.WbgetentitiesResult;
import org.wikipedia.api.wikidata_action.json.SitematrixResult;
import org.wikipedia.tools.RegexUtil;
......@@ -40,7 +40,7 @@ public final class WikidataActionApiQuery<T> extends ApiQuery<T> {
);
}
public static WikidataActionApiQuery<CheckEntityExistsResult> wbgetentities(final Collection<String> qIds) {
public static WikidataActionApiQuery<WbgetentitiesResult> wbgetentities(final Collection<String> qIds) {
if (qIds.size() < 1) {
throw new IllegalArgumentException("You must supply at least one Q-ID to construct a checkEntityExists URL.");
}
......@@ -49,11 +49,11 @@ public final class WikidataActionApiQuery<T> extends ApiQuery<T> {
}
return new WikidataActionApiQuery<>(
FORMAT_PARAMS + "&action=wbgetentities&sites=&props=&ids=" + Utils.encodeUrl(String.join("|", qIds)),
CheckEntityExistsResult.SCHEMA
WbgetentitiesResult.SCHEMA
);
}
public static WikidataActionApiQuery<CheckEntityExistsResult> wbgetentities(final String siteId, final Collection<String> titles) {
public static WikidataActionApiQuery<WbgetentitiesResult> wbgetentities(final String siteId, final Collection<String> titles) {
if (siteId == null || titles == null || titles.size() <= 0) {
throw new IllegalArgumentException("The site ID and titles must be present!");
}
......@@ -64,7 +64,7 @@ public final class WikidataActionApiQuery<T> extends ApiQuery<T> {
FORMAT_PARAMS + "&action=wbgetentities&props=sitelinks&sites=" + siteId + // defines the language of the titles
"&sitefilter=" + siteId + // defines for which languages sitelinks should be returned
"&titles=" + Utils.encodeUrl(String.join("|", titles)),
CheckEntityExistsResult.SCHEMA
WbgetentitiesResult.SCHEMA
);
}
......
......@@ -20,14 +20,14 @@ import java.util.List;
import java.util.Map;
import org.wikipedia.api.SerializationSchema;
public final class CheckEntityExistsResult {
public static final SerializationSchema<CheckEntityExistsResult> SCHEMA = new SerializationSchema<>(
CheckEntityExistsResult.class,
public final class WbgetentitiesResult {
public static final SerializationSchema<WbgetentitiesResult> SCHEMA = new SerializationSchema<>(
WbgetentitiesResult.class,
it -> {
it.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
it.registerModule(new SimpleModule().addDeserializer(
CheckEntityExistsResult.AbstractEntity.class,
new CheckEntityExistsResult.AbstractEntity.Deserializer(it)
WbgetentitiesResult.AbstractEntity.class,
new WbgetentitiesResult.AbstractEntity.Deserializer(it)
));
}
);
......@@ -37,7 +37,7 @@ public final class CheckEntityExistsResult {
private final List<MissingEntity> missingEntities = new ArrayList<>();
@JsonCreator
public CheckEntityExistsResult(@JsonProperty("success") final int success, @JsonProperty("entities") final Map<String, AbstractEntity> entities) {
public WbgetentitiesResult(@JsonProperty("success") final int success, @JsonProperty("entities") final Map<String, AbstractEntity> entities) {
this.success = success;
for (final Map.Entry<String, AbstractEntity> entry : entities.entrySet()) {
entry.getValue().addTo(entry.getKey(), this);
......@@ -72,12 +72,12 @@ public final class CheckEntityExistsResult {
*/
public interface AbstractEntity {
/**
* Adds this entity to the entity lists/maps of {@link CheckEntityExistsResult}, depending on the implementing
* Adds this entity to the entity lists/maps of {@link WbgetentitiesResult}, depending on the implementing
* class it can vary to which list or map the entity is added.
* @param key the key to which the entity is associated in the JSON
* @param result the object to which the entity should be added
*/
void addTo(final String key, CheckEntityExistsResult result);
void addTo(final String key, WbgetentitiesResult result);
class Deserializer extends StdDeserializer<AbstractEntity> {
private final ObjectMapper mapper;
......@@ -127,7 +127,7 @@ public final class CheckEntityExistsResult {
}
@Override
public void addTo(final String key, final CheckEntityExistsResult result) {
public void addTo(final String key, final WbgetentitiesResult result) {
result.missingEntities.add(this);
}
}
......@@ -163,7 +163,7 @@ public final class CheckEntityExistsResult {
}
@Override
public void addTo(final String key, final CheckEntityExistsResult result) {
public void addTo(final String key, final WbgetentitiesResult result) {
result.entities.put(key, this);
}
......
......@@ -15,7 +15,7 @@ import org.openstreetmap.josm.tools.I18n;
import org.wikipedia.WikipediaPlugin;
import org.wikipedia.api.ApiQueryClient;
import org.wikipedia.api.wikidata_action.WikidataActionApiQuery;
import org.wikipedia.api.wikidata_action.json.CheckEntityExistsResult;
import org.wikipedia.api.wikidata_action.json.WbgetentitiesResult;
import org.wikipedia.tools.ListUtil;
import org.wikipedia.tools.RegexUtil;
......@@ -43,7 +43,7 @@ public class WikidataItemExists extends BatchProcessedTagTest<WikidataItemExists
protected void check(List<TestCompanion> allPrimitives) {
ListUtil.processInBatches(allPrimitives, BATCH_SIZE, primitiveBatch -> {
try {
final CheckEntityExistsResult entityQueryResult = ApiQueryClient.query(
final WbgetentitiesResult entityQueryResult = ApiQueryClient.query(
WikidataActionApiQuery.wbgetentities(primitiveBatch.stream().map(tc -> tc.wikidataId).collect(Collectors.toList()))
);
if (entityQueryResult.getSuccess() != 1) {
......@@ -69,12 +69,12 @@ public class WikidataItemExists extends BatchProcessedTagTest<WikidataItemExists
}
/**
* Checks an {@link OsmPrimitive} against a given {@link CheckEntityExistsResult}.
* Checks an {@link OsmPrimitive} against a given {@link WbgetentitiesResult}.
* @param tc the test companion for the {@link OsmPrimitive}
* @param entityQueryResult the result from the Wikidata Action API
*/
private void check(final TestCompanion tc, final CheckEntityExistsResult entityQueryResult) {
final CheckEntityExistsResult.Entity entity = entityQueryResult.getEntities().get(tc.wikidataId);
private void check(final TestCompanion tc, final WbgetentitiesResult entityQueryResult) {
final WbgetentitiesResult.Entity entity = entityQueryResult.getEntities().get(tc.wikidataId);
if (entityQueryResult.getMissingEntities().stream().anyMatch(it -> tc.wikidataId.equals(it.getId()))) {
errors.add(
AllValidationTests.WIKIDATA_ITEM_DOES_NOT_EXIST.getBuilder(this)
......
......@@ -17,7 +17,7 @@ import org.openstreetmap.josm.tools.Pair;
import org.wikipedia.WikipediaPlugin;
import org.wikipedia.api.ApiQueryClient;
import org.wikipedia.api.wikidata_action.WikidataActionApiQuery;
import org.wikipedia.api.wikidata_action.json.CheckEntityExistsResult;
import org.wikipedia.api.wikidata_action.json.WbgetentitiesResult;
import org.wikipedia.tools.ListUtil;
import org.wikipedia.tools.RegexUtil;
......@@ -66,7 +66,7 @@ public class WikipediaAgainstWikidata extends BatchProcessedTagTest<WikipediaAga
private void checkBatch(final String language, final List<TestCompanion> primitiveBatch) {
try {
final Map<String, CheckEntityExistsResult.Entity.Sitelink> sitelinks = ApiQueryClient
final Map<String, WbgetentitiesResult.Entity.Sitelink> sitelinks = ApiQueryClient
.query(WikidataActionApiQuery.wbgetentities(
language + "wiki",
primitiveBatch.stream().map(it -> it.title).collect(Collectors.toList())
......
......@@ -28,7 +28,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.wikipedia.api.ApiQueryClient;
import org.wikipedia.api.wikidata_action.json.CheckEntityExistsResult;
import org.wikipedia.api.wikidata_action.json.WbgetentitiesResult;
import org.wikipedia.testutils.ResourceFileLoader;
public class WikidataActionApiQueryTest {
......@@ -95,16 +95,16 @@ public class WikidataActionApiQueryTest {
)
);
final CheckEntityExistsResult result = ApiQueryClient.query(WikidataActionApiQuery.wbgetentities("dewiki", Collections.singletonList("Berlin")));
final WbgetentitiesResult result = ApiQueryClient.query(WikidataActionApiQuery.wbgetentities("dewiki", Collections.singletonList("Berlin")));
assertEquals(1, result.getSuccess());
assertEquals(0, result.getMissingEntities().size());
assertEquals(1, result.getEntities().size());
final Map.Entry<String, CheckEntityExistsResult.Entity> entityEntry = result.getEntities().entrySet().iterator().next();
final Map.Entry<String, WbgetentitiesResult.Entity> entityEntry = result.getEntities().entrySet().iterator().next();
assertEquals("Q64", entityEntry.getKey());
assertEquals("item", entityEntry.getValue().getType());
assertEquals("Q64", entityEntry.getValue().getId());
final Collection<CheckEntityExistsResult.Entity.Sitelink> sitelinks = entityEntry.getValue().getSitelinks();
final Collection<WbgetentitiesResult.Entity.Sitelink> sitelinks = entityEntry.getValue().getSitelinks();
assertEquals(1, sitelinks.size());
assertEquals("dewiki", sitelinks.iterator().next().getSite());
assertEquals("Berlin", sitelinks.iterator().next().getTitle());
......@@ -124,7 +124,7 @@ public class WikidataActionApiQueryTest {
)
);
final CheckEntityExistsResult result = ApiQueryClient.query(WikidataActionApiQuery.wbgetentities("enwiki", Arrays.asList("United States", "missing-article", "Great Britain", "Another missing article")));
final WbgetentitiesResult result = ApiQueryClient.query(WikidataActionApiQuery.wbgetentities("enwiki", Arrays.asList("United States", "missing-article", "Great Britain", "Another missing article")));
assertEquals(2, result.getEntities().size());
assertEquals(2, result.getMissingEntities().size());
......@@ -141,10 +141,10 @@ public class WikidataActionApiQueryTest {
assertEquals("enwiki", result.getEntities().get("Q23666").getSitelinks().iterator().next().getSite());
assertEquals("Great Britain", result.getEntities().get("Q23666").getSitelinks().iterator().next().getTitle());
final CheckEntityExistsResult.MissingEntity missing1 = result.getMissingEntities().stream().filter(it -> "missing-article".equals(it.getTitle())).findFirst().orElse(null);
final WbgetentitiesResult.MissingEntity missing1 = result.getMissingEntities().stream().filter(it -> "missing-article".equals(it.getTitle())).findFirst().orElse(null);
assertNull(missing1.getId());
assertEquals("enwiki", missing1.getSite());
final CheckEntityExistsResult.MissingEntity missing2 = result.getMissingEntities().stream().filter(it -> "Another missing article".equals(it.getTitle())).findFirst().orElse(null);
final WbgetentitiesResult.MissingEntity missing2 = result.getMissingEntities().stream().filter(it -> "Another missing article".equals(it.getTitle())).findFirst().orElse(null);
assertNull(missing2.getId());
assertEquals("enwiki", missing2.getSite());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment