Ignore:
Timestamp:
2016-01-18T14:07:47+01:00 (9 years ago)
Author:
simon04
Message:

JOSM/wikipedia: Wikidata label fallback - #josm12397

Location:
applications/editors/josm/plugins/wikipedia
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java

    r32001 r32003  
    239239                    }
    240240                }
    241                 return null;
     241                final String fallBackLabel = (String) X_PATH.compile("//label/@value").evaluate(xml, XPathConstants.STRING);
     242                return fallBackLabel == null || fallBackLabel.isEmpty() ? null : fallBackLabel;
    242243            }
    243244        } catch (Exception ex) {
  • applications/editors/josm/plugins/wikipedia/test/unit/org/wikipedia/WikipediaAppTest.java

    r32001 r32003  
    157157        assertThat(WikipediaApp.getLabelForWikidata("Q1741", Locale.GERMAN), is("Wien"));
    158158        assertThat(WikipediaApp.getLabelForWikidata("Q1741", Locale.ENGLISH), is("Vienna"));
     159        // fallback to any label
     160        assertThat(WikipediaApp.getLabelForWikidata("Q21849466", new Locale("aa")), is("Leoben - Straßennamen mit Geschichte"));
     161        // not found -> null
    159162        assertThat(WikipediaApp.getLabelForWikidata("Q" + Long.MAX_VALUE, Locale.ENGLISH), nullValue());
    160163    }
Note: See TracChangeset for help on using the changeset viewer.