Commit 0a3504d8 authored by Simon Legner's avatar Simon Legner

JOSM/wikipedia: fix ISE: Duplicate key again - #josm13991

git-svn-id: https://svn.openstreetmap.org/applications/editors/josm/plugins/wikipedia@33070 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
parent 37e31cd9
......@@ -215,7 +215,9 @@ public final class WikipediaApp {
X_PATH.evaluateNodes("//entity", xml).forEach(node -> {
final String wikidata = X_PATH.evaluateString("./@id", node);
final String wikipedia = X_PATH.evaluateString("./sitelinks/sitelink/@title", node);
r.put(wikipedia, wikidata);
if (WIKIDATA_PATTERN.matcher(wikidata).matches()) { // non existing entries result in negative integers
r.put(wikipedia, wikidata);
}
});
}
return r;
......
......@@ -7,7 +7,6 @@ import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.wikipedia.data.WikidataEntry;
import org.wikipedia.data.WikipediaEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
......@@ -115,7 +114,7 @@ public class WikipediaAppTest {
assertThat(map.get("Vienna"), is("Q1741"));
assertThat(map.get("Völs, Tyrol"), is("Q278250"));
assertThat(map.get("a-non-existing-article"), nullValue());
assertThat(map.size(), is(4));
assertThat(map.size(), is(3));
}
@Test
......@@ -123,6 +122,10 @@ public class WikipediaAppTest {
final Map<String, String> map = WikipediaApp.getWikidataForArticles("en",
Stream.iterate("London", x -> x).limit(100).collect(Collectors.toList()));
assertThat(map, is(Collections.singletonMap("London", "Q84")));
final List<String> articles = IntStream.range(0, 200)
.mapToObj(i -> "a-non-existing-article-" + i)
.collect(Collectors.toList());
assertTrue(WikipediaApp.getWikidataForArticles("en", articles).isEmpty());
}
@Test
......
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