From 8066c80ea58d99746007364ec1cb028a1d500aea Mon Sep 17 00:00:00 2001 From: Mike Barry Date: Mon, 25 Nov 2024 20:17:29 -0500 Subject: [PATCH] filter name tags --- .../com/onthegomap/planetiler/util/LanguageUtils.java | 2 +- .../com/onthegomap/planetiler/util/Translations.java | 2 +- .../onthegomap/planetiler/util/TranslationsTest.java | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LanguageUtils.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LanguageUtils.java index 76b7af55c4..ffcf26a73d 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LanguageUtils.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LanguageUtils.java @@ -10,7 +10,7 @@ public class LanguageUtils { // See https://wiki.openstreetmap.org/wiki/Multilingual_names public static final Predicate VALID_NAME_TAGS = Pattern - .compile("^name:[a-z]{2,3}(-[a-z]{4})?([-_](x-)?[a-z]{2,})?(-([a-z]{2}|[0-9]{3}))?$", Pattern.CASE_INSENSITIVE) + .compile("^name:[a-z]{2,3}(-[a-z]{4})?([-_](x-)?[a-z]{2,})?(-([a-z]{2}|\\d{3}))?$", Pattern.CASE_INSENSITIVE) .asMatchPredicate(); // See https://github.com/onthegomap/planetiler/issues/86 // Match strings that only contain latin characters. diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/Translations.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/Translations.java index 85c87deecf..92924f0fd5 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/Translations.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/Translations.java @@ -148,7 +148,7 @@ public Map getNameTranslations(Map tags) { Map result = new HashMap<>(); for (var entry : tags.entrySet()) { String key = entry.getKey(); - if (key.startsWith("name:") && entry.getValue() instanceof String stringVal) { + if (LanguageUtils.isValidOsmNameTag(key) && entry.getValue() instanceof String stringVal) { result.put(key, stringVal); } } diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/util/TranslationsTest.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/util/TranslationsTest.java index 091efd95af..589afcea98 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/util/TranslationsTest.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/util/TranslationsTest.java @@ -20,6 +20,16 @@ void testNull() { assertEquals(Map.of(), translations.getTranslations(Map.of("name:en", "name"))); } + @Test + void testWildcard() { + var translations = Translations.defaultProvider(List.of("*")); + assertEquals(Map.of("name:en", "name"), translations.getTranslations(Map.of("name:en", "name"))); + assertEquals(Map.of("name:sr-Latn", "name"), translations.getTranslations(Map.of("name:sr-Latn", "name"))); + assertEquals(Map.of("name:zh-Hant-TW", "name"), translations.getTranslations(Map.of("name:zh-Hant-TW", "name"))); + assertEquals(Map.of(), translations.getTranslations(Map.of("name:left", "name"))); + assertEquals(Map.of(), translations.getTranslations(Map.of("name:etymology:wikidata", "name"))); + } + @Test void testDefaultProvider() { var translations = Translations.defaultProvider(List.of("en"));