Changeset 32671 in osm for applications/editors/josm/plugins/wikipedia
- Timestamp:
- 2016-07-17T19:01:57+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/wikipedia/src/org/wikipedia
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/FetchWikidataAction.java
r32667 r32671 126 126 "Fetching {0} Wikidata ID for language ''{1}''", 127 127 "Fetching {0} Wikidata IDs for language ''{1}''", size, size, lang)); 128 final Map<String, String> wikidataByWikipedia = WikipediaApp.getWikidataForArticles(lang, byArticle.keySet());128 final Map<String, String> wikidataByWikipedia = WikipediaApp.getWikidataForArticles(lang, new ArrayList<>(byArticle.keySet())); 129 129 ConditionalOptionPaneUtil.startBulkOperation(GuiUtils.PREF_OVERWRITE); 130 130 for (Map.Entry<String, Set<OsmPrimitive>> i : byArticle.entrySet()) { -
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java
r32670 r32671 102 102 } 103 103 if ("wikidata".equals(wikipediaLang)) { 104 final List<WikipediaEntry> entriesWithLabel = new ArrayList<>(nodes.getLength()); 105 for (final List<WikipediaEntry> chunk : partitionList(entries, 50)) { 106 entriesWithLabel.addAll(getLabelForWikidata(chunk, Locale.getDefault())); 107 } 108 return entriesWithLabel; 104 final List<WikidataEntry> withLabel = getLabelForWikidata(entries, Locale.getDefault()); 105 return new ArrayList<WikipediaEntry>(withLabel); 109 106 } else { 110 107 return entries; … … 238 235 * Returns a map mapping wikipedia articles to wikidata ids. 239 236 */ 240 static Map<String, String> getWikidataForArticles(String wikipediaLang, Collection<String> articles) { 237 static Map<String, String> getWikidataForArticles(String wikipediaLang, List<String> articles) { 238 if (articles.size() > 50) { 239 final Map<String, String> wikidataItems = new HashMap<>(); 240 for (final List<String> chunk : partitionList(articles, 50)) { 241 wikidataItems.putAll(getWikidataForArticles(wikipediaLang, chunk)); 242 } 243 return wikidataItems; 244 } 241 245 try { 242 246 final String url = "https://www.wikidata.org/w/api.php" + … … 297 301 static String getLabelForWikidata(String wikidataId, Locale locale, String ... preferredLanguage) { 298 302 try { 299 return getLabelForWikidata(Collections.singleton (new WikidataEntry(wikidataId, null, null, null)), locale, preferredLanguage).get(0).label;303 return getLabelForWikidata(Collections.singletonList(new WikidataEntry(wikidataId, null, null, null)), locale, preferredLanguage).get(0).label; 300 304 } catch (IndexOutOfBoundsException ignore) { 301 305 return null; … … 303 307 } 304 308 305 static List<WikidataEntry> getLabelForWikidata(Collection<? extends WikipediaEntry> entries, Locale locale, String ... preferredLanguage) { 309 static List<WikidataEntry> getLabelForWikidata(List<? extends WikipediaEntry> entries, Locale locale, String ... preferredLanguage) { 310 if (entries.size() > 50) { 311 final List<WikidataEntry> entriesWithLabel = new ArrayList<>(entries.size()); 312 for (final List<? extends WikipediaEntry> chunk : partitionList(entries, 50)) { 313 entriesWithLabel.addAll(getLabelForWikidata(chunk, locale, preferredLanguage)); 314 } 315 return entriesWithLabel; 316 } 306 317 final Collection<String> wikidataIds = Utils.transform(entries, new Function<WikipediaEntry, String>() { 307 318 @Override
Note:
See TracChangeset
for help on using the changeset viewer.