Extra name tags (#1187)

pull/1190/head^2
Eric Schoen 2025-02-24 05:20:16 -06:00 zatwierdzone przez GitHub
rodzic 9557dc77a1
commit 695cc57d33
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
5 zmienionych plików z 69 dodań i 4 usunięć

Wyświetl plik

@ -628,7 +628,9 @@ public class Planetiler {
this.defaultLanguages.stream()
).toList();
}
translations = Translations.defaultProvider(languages).setShouldTransliterate(transliterate);
translations = Translations.defaultProvider(languages)
.setShouldTransliterate(transliterate)
.setExtraNameTags(config.extraNameTags());
}
return translations;
}

Wyświetl plik

@ -10,6 +10,7 @@ import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
import java.util.stream.Stream;
/**
@ -61,7 +62,8 @@ public record PlanetilerConfig(
Path tileWeights,
double maxPointBuffer,
boolean logJtsExceptions,
int featureSourceIdMultiplier
int featureSourceIdMultiplier,
List<String> extraNameTags
) {
public static final int MIN_MINZOOM = 0;
@ -125,6 +127,8 @@ public record PlanetilerConfig(
arguments.getInteger("render_maxzoom", "maximum rendering zoom level up to " + MAX_MAXZOOM,
Math.max(maxzoom, DEFAULT_MAXZOOM));
Path tmpDir = arguments.file("tmpdir|tmp", "temp directory", Path.of("data", "tmp"));
List<String> extraNameTags = arguments.getList("extra_name_tags", "Extra name tags to copy from OSM to output",
List.of());
return new PlanetilerConfig(
arguments,
@ -218,7 +222,8 @@ public record PlanetilerConfig(
arguments.getInteger("feature_source_id_multiplier",
"Set vector tile feature IDs to (featureId * thisValue) + sourceId " +
"where sourceId is 1 for OSM nodes, 2 for ways, 3 for relations, and 0 for other sources. Set to false to disable.",
10)
10),
extraNameTags
);
}

Wyświetl plik

@ -6,6 +6,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Holds planetiler configuration and utilities for translating element names to other languages.
@ -26,6 +27,8 @@ public class Translations {
private final Set<String> includeLanguages;
private final Set<String> excludeLanguages;
private boolean defaultInclude = false;
private List<String> extraNameTags = List.of();
private Translations(List<String> languages) {
this.includeLanguages = new HashSet<>();
@ -107,6 +110,7 @@ public class Translations {
}
}
}
addExtraNameTags(output, input);
}
public boolean getShouldTransliterate() {
@ -165,4 +169,37 @@ public class Translations {
public static String transliterate(String input) {
return input == null ? null : TRANSLITERATOR.get().transliterate(input);
}
/**
* Get the configured list of extra name tags to inject into translation outputs.
* @return List of extra name tags
*/
public List<String> getExtraNameTags() {
return extraNameTags;
}
/**
* Set a list of extra name tags to be copied from the OSM source to the output result
* @param extraNameTags: List of extra name tags to copy to translation outputs.
* @return this
*/
public Translations setExtraNameTags(List<String> extraNameTags) {
if (extraNameTags != null) {
this.extraNameTags = extraNameTags;
}
return this;
}
private void addExtraNameTags(Map<String, Object> output, Map<String, Object> input) {
if (!extraNameTags.isEmpty()) {
Map<String,Object> extraTags = extraNameTags.stream()
.filter(input::containsKey)
.filter(tag -> input.get(tag) != null && !input.get(tag).equals(""))
.collect(Collectors.toMap(t -> t, input::get));
if (!extraTags.isEmpty()) {
output.putAll(extraTags);
}
}
}
}

Wyświetl plik

@ -6,6 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@ -70,4 +71,24 @@ class TranslationsTest {
Arguments.of(List.of("tlh", "-tlh"), List.of(), List.of("tlh", "en"))
);
}
@Test
void testExtraNameTags() {
Map<String, Object> input = Map.of(
"extra", "extra",
"name", "name",
"name:en", "english name",
"name:de", "german name"
);
var translations = Translations.defaultProvider(List.of("en", "es", "de"));
Map<String, Object> output1 = new HashMap<String,Object>();
translations.addTranslations(output1, input);
assertFalse(output1.containsKey("extra"));
Map<String, Object> output2 = new HashMap<String,Object>();
translations.setExtraNameTags(List.of("extra"));
translations.addTranslations(output2, input);
assertTrue(output2.containsKey("extra"));
}
}

@ -1 +1 @@
Subproject commit 0818cb981fb9b7ead2c0a093794ccda07bb02c31
Subproject commit f0e530faa5d69bcc48e75819fbc0155a8d84041f