Changeset 33993 in osm
- Timestamp:
- 2018-01-11T00:07:20+01:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/wikipedia
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java
r33541 r33993 35 35 import org.openstreetmap.josm.tools.HttpClient; 36 36 import org.openstreetmap.josm.tools.Logging; 37 import org.openstreetmap.josm.tools.Pair; 37 38 import org.openstreetmap.josm.tools.Utils; 38 39 import org.w3c.dom.Document; … … 258 259 .collect(Collectors.toList()); 259 260 if (!unresolved.isEmpty()) { 260 final Map<String, String> redirects = resolveRedirectsForArticles(unresolved); 261 final Map<String, String> result2 = getWikidataForArticles0(redirects.values()); 261 doResolveWikidataItems(unresolved, result); 262 } 263 return result; 264 } 265 266 private Pair<Map<String, String>, Map<String, String>> doResolveWikidataItems(List<String> unresolved, Map<String, String> result) { 267 final Map<String, String> redirects = resolveRedirectsForArticles(unresolved); 268 final Map<String, String> result2 = getWikidataForArticles0(redirects.values()); 269 final List<String> unresolved2 = new ArrayList<>(); 270 redirects.forEach((original, resolved) -> { 271 if (result2.containsKey(resolved)) { 272 result.put(original, result2.get(resolved)); 273 } else if (!Objects.equals(original, resolved)) { 274 // Handle double redirection like USA -> United States of America -> United States (as of 9th January 2018) 275 unresolved2.add(resolved); 276 } 277 }); 278 if (!unresolved2.isEmpty()) { 279 Pair<Map<String, String>, Map<String, String>> p = doResolveWikidataItems(unresolved2, result); 262 280 redirects.forEach((original, resolved) -> { 263 if (result2.containsKey(resolved)) { 264 result.put(original, result2.get(resolved)); 281 if (!result2.containsKey(resolved)) { 282 p.a.forEach((original2, resolved2) -> { 283 if (p.b.containsKey(resolved2)) { 284 result.put(original, p.b.get(resolved2)); 285 } 286 }); 265 287 } 266 288 }); 267 289 } 268 return result;290 return Pair.create(redirects, result2); 269 291 } 270 292 -
applications/editors/josm/plugins/wikipedia/test/unit/org/wikipedia/WikipediaAppTest.java
r33098 r33993 124 124 assertThat(map.get("einstein"), is("Q937")); 125 125 assertThat(map.get("USA"), is("Q30")); 126 assertThat(map.size(), is( 2));126 assertThat(map.size(), is(3)); 127 127 } 128 128
Note:
See TracChangeset
for help on using the changeset viewer.