mirror of
https://github.com/cfpwastaken/planetiler-openmaptiles.git
synced 2026-02-04 12:31:10 +00:00
Separate Planetiler-core LangUtils and OmtLangUtils (#9)
* Seperate Planetiler-core LangUtils and OmtLangUtils
This commit is contained in:
@@ -43,7 +43,7 @@ import com.onthegomap.planetiler.config.PlanetilerConfig;
|
||||
import com.onthegomap.planetiler.expression.MultiExpression;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.OpenMapTilesSchema;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.Tables;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.LanguageUtils;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.OmtLanguageUtils;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.Utils;
|
||||
import com.onthegomap.planetiler.stats.Stats;
|
||||
import com.onthegomap.planetiler.util.Translations;
|
||||
@@ -74,7 +74,7 @@ public class AerodromeLabel implements
|
||||
features.centroid(LAYER_NAME)
|
||||
.setBufferPixels(BUFFER_SIZE)
|
||||
.setMinZoom(important ? 8 : 10)
|
||||
.putAttrs(LanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(Utils.elevationTags(element.ele()))
|
||||
.setAttr(Fields.IATA, nullIfEmpty(element.iata()))
|
||||
.setAttr(Fields.ICAO, nullIfEmpty(element.icao()))
|
||||
|
||||
@@ -47,7 +47,7 @@ import com.onthegomap.planetiler.geo.GeometryException;
|
||||
import com.onthegomap.planetiler.openmaptiles.OpenMapTilesProfile;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.OpenMapTilesSchema;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.Tables;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.LanguageUtils;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.OmtLanguageUtils;
|
||||
import com.onthegomap.planetiler.reader.SourceFeature;
|
||||
import com.onthegomap.planetiler.stats.Stats;
|
||||
import com.onthegomap.planetiler.util.Parse;
|
||||
@@ -117,7 +117,7 @@ public class MountainPeak implements
|
||||
if (meters != null && Math.abs(meters) < 10_000) {
|
||||
var feature = features.point(LAYER_NAME)
|
||||
.setAttr(Fields.CLASS, element.source().getTag("natural"))
|
||||
.putAttrs(LanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(elevationTags(meters))
|
||||
.setSortKeyDescending(
|
||||
meters.intValue() +
|
||||
@@ -146,7 +146,7 @@ public class MountainPeak implements
|
||||
features.line(LAYER_NAME)
|
||||
.setAttr(Fields.CLASS, element.source().getTag("natural"))
|
||||
.setAttr(Fields.RANK, rank)
|
||||
.putAttrs(LanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
|
||||
.setSortKey(rank)
|
||||
.setMinZoom(13)
|
||||
.setBufferPixels(100);
|
||||
|
||||
@@ -51,7 +51,7 @@ import com.onthegomap.planetiler.geo.GeometryType;
|
||||
import com.onthegomap.planetiler.openmaptiles.OpenMapTilesProfile;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.OpenMapTilesSchema;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.Tables;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.LanguageUtils;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.OmtLanguageUtils;
|
||||
import com.onthegomap.planetiler.stats.Stats;
|
||||
import com.onthegomap.planetiler.util.SortKey;
|
||||
import com.onthegomap.planetiler.util.Translations;
|
||||
@@ -113,14 +113,14 @@ public class Park implements
|
||||
double area = element.source().area();
|
||||
int minzoom = getMinZoomForArea(area);
|
||||
|
||||
var names = LanguageUtils.getNamesWithoutTranslations(element.source().tags());
|
||||
var names = OmtLanguageUtils.getNamesWithoutTranslations(element.source().tags());
|
||||
|
||||
outline.putAttrsWithMinzoom(names, 5);
|
||||
|
||||
features.pointOnSurface(LAYER_NAME).setBufferPixels(256)
|
||||
.setAttr(Fields.CLASS, clazz)
|
||||
.putAttrs(names)
|
||||
.putAttrs(LanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
|
||||
.setPointLabelGridPixelSize(14, 100)
|
||||
.setSortKey(SortKey
|
||||
.orderByTruesFirst("national_park".equals(clazz))
|
||||
|
||||
@@ -52,7 +52,7 @@ import com.onthegomap.planetiler.geo.PolygonIndex;
|
||||
import com.onthegomap.planetiler.openmaptiles.OpenMapTilesProfile;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.OpenMapTilesSchema;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.Tables;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.LanguageUtils;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.OmtLanguageUtils;
|
||||
import com.onthegomap.planetiler.reader.SourceFeature;
|
||||
import com.onthegomap.planetiler.stats.Stats;
|
||||
import com.onthegomap.planetiler.util.Parse;
|
||||
@@ -200,10 +200,10 @@ public class Place implements
|
||||
public void process(Tables.OsmContinentPoint element, FeatureCollector features) {
|
||||
if (!nullOrEmpty(element.name())) {
|
||||
features.point(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
|
||||
.putAttrs(LanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
|
||||
.setAttr(Fields.CLASS, FieldValues.CLASS_CONTINENT)
|
||||
.setAttr(Fields.RANK, 1)
|
||||
.putAttrs(LanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
|
||||
.setZoomRange(0, 3);
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ public class Place implements
|
||||
// should be lower
|
||||
int rank = 7;
|
||||
NaturalEarthRegion country = countries.get(element.source().worldGeometry().getCentroid());
|
||||
var names = LanguageUtils.getNames(element.source().tags(), translations);
|
||||
var names = OmtLanguageUtils.getNames(element.source().tags(), translations);
|
||||
|
||||
if (country != null) {
|
||||
if (nullOrEmpty(names.get(Fields.NAME_EN))) {
|
||||
@@ -257,7 +257,7 @@ public class Place implements
|
||||
// use natural earth to filter out any spurious states, and to set the rank field
|
||||
NaturalEarthRegion state = states.getOnlyContaining(element.source().worldGeometry().getCentroid());
|
||||
if (state != null) {
|
||||
var names = LanguageUtils.getNames(element.source().tags(), translations);
|
||||
var names = OmtLanguageUtils.getNames(element.source().tags(), translations);
|
||||
if (nullOrEmpty(names.get(Fields.NAME_EN))) {
|
||||
names.put(Fields.NAME_EN, state.name);
|
||||
}
|
||||
@@ -284,7 +284,7 @@ public class Place implements
|
||||
int minzoom = rank <= 3 ? 8 : rank <= 4 ? 9 : 10;
|
||||
|
||||
features.pointOnSurface(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
|
||||
.putAttrs(LanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
|
||||
.setAttr(Fields.CLASS, "island")
|
||||
.setAttr(Fields.RANK, rank)
|
||||
.setMinZoom(minzoom)
|
||||
@@ -298,7 +298,7 @@ public class Place implements
|
||||
@Override
|
||||
public void process(Tables.OsmIslandPoint element, FeatureCollector features) {
|
||||
features.point(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
|
||||
.putAttrs(LanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
|
||||
.setAttr(Fields.CLASS, "island")
|
||||
.setAttr(Fields.RANK, 7)
|
||||
.setMinZoom(12);
|
||||
@@ -345,7 +345,7 @@ public class Place implements
|
||||
placeType.ordinal() <= PlaceType.SUBURB.ordinal() ? 11 : 14;
|
||||
|
||||
var feature = features.point(LAYER_NAME).setBufferPixels(BUFFER_SIZE)
|
||||
.putAttrs(LanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
|
||||
.setAttr(Fields.CLASS, element.place())
|
||||
.setAttr(Fields.RANK, rank)
|
||||
.setMinZoom(minzoom)
|
||||
|
||||
@@ -50,7 +50,7 @@ import com.onthegomap.planetiler.config.PlanetilerConfig;
|
||||
import com.onthegomap.planetiler.expression.MultiExpression;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.OpenMapTilesSchema;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.Tables;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.LanguageUtils;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.OmtLanguageUtils;
|
||||
import com.onthegomap.planetiler.stats.Stats;
|
||||
import com.onthegomap.planetiler.util.Parse;
|
||||
import com.onthegomap.planetiler.util.Translations;
|
||||
@@ -172,7 +172,7 @@ public class Poi implements
|
||||
.setAttr(Fields.LAYER, nullIfLong(element.layer(), 0))
|
||||
.setAttr(Fields.LEVEL, Parse.parseLongOrNull(element.source().getTag("level")))
|
||||
.setAttr(Fields.INDOOR, element.indoor() ? 1 : null)
|
||||
.putAttrs(LanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
|
||||
.setPointLabelGridPixelSize(14, 64)
|
||||
.setSortKey(rankOrder)
|
||||
.setMinZoom(minzoom(element.subclass(), element.mappingKey()));
|
||||
|
||||
@@ -53,7 +53,7 @@ import com.onthegomap.planetiler.config.PlanetilerConfig;
|
||||
import com.onthegomap.planetiler.openmaptiles.OpenMapTilesProfile;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.OpenMapTilesSchema;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.Tables;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.LanguageUtils;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.OmtLanguageUtils;
|
||||
import com.onthegomap.planetiler.reader.osm.OsmElement;
|
||||
import com.onthegomap.planetiler.stats.Stats;
|
||||
import com.onthegomap.planetiler.util.Parse;
|
||||
@@ -201,7 +201,7 @@ public class TransportationName implements
|
||||
|
||||
features.point(LAYER_NAME)
|
||||
.setBufferPixels(BUFFER_SIZE)
|
||||
.putAttrs(LanguageUtils.getNamesWithoutTranslations(element.source().tags()))
|
||||
.putAttrs(OmtLanguageUtils.getNamesWithoutTranslations(element.source().tags()))
|
||||
.setAttr(Fields.REF, ref)
|
||||
.setAttr(Fields.REF_LENGTH, ref != null ? ref.length() : null)
|
||||
.setAttr(Fields.CLASS, highwayClass(cls.highwayValue, null, null, null))
|
||||
@@ -258,7 +258,7 @@ public class TransportationName implements
|
||||
.setBufferPixels(BUFFER_SIZE)
|
||||
.setBufferPixelOverrides(MIN_LENGTH)
|
||||
// TODO abbreviate road names - can't port osml10n because it is AGPL
|
||||
.putAttrs(LanguageUtils.getNamesWithoutTranslations(element.source().tags()))
|
||||
.putAttrs(OmtLanguageUtils.getNamesWithoutTranslations(element.source().tags()))
|
||||
.setAttr(Fields.REF, ref)
|
||||
.setAttr(Fields.REF_LENGTH, ref != null ? ref.length() : null)
|
||||
.setAttr(Fields.NETWORK,
|
||||
@@ -306,7 +306,7 @@ public class TransportationName implements
|
||||
features.line(LAYER_NAME)
|
||||
.setBufferPixels(BUFFER_SIZE)
|
||||
.setBufferPixelOverrides(MIN_LENGTH)
|
||||
.putAttrs(LanguageUtils.getNamesWithoutTranslations(element.source().tags()))
|
||||
.putAttrs(OmtLanguageUtils.getNamesWithoutTranslations(element.source().tags()))
|
||||
.setAttr(Fields.CLASS, "aerialway")
|
||||
.setAttr(Fields.SUBCLASS, element.aerialway())
|
||||
.setMinPixelSize(0)
|
||||
@@ -321,7 +321,7 @@ public class TransportationName implements
|
||||
features.line(LAYER_NAME)
|
||||
.setBufferPixels(BUFFER_SIZE)
|
||||
.setBufferPixelOverrides(MIN_LENGTH)
|
||||
.putAttrs(LanguageUtils.getNamesWithoutTranslations(element.source().tags()))
|
||||
.putAttrs(OmtLanguageUtils.getNamesWithoutTranslations(element.source().tags()))
|
||||
.setAttr(Fields.CLASS, element.shipway())
|
||||
.setMinPixelSize(0)
|
||||
.setSortKey(element.zOrder())
|
||||
|
||||
@@ -46,7 +46,7 @@ import com.onthegomap.planetiler.geo.GeometryException;
|
||||
import com.onthegomap.planetiler.openmaptiles.OpenMapTilesProfile;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.OpenMapTilesSchema;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.Tables;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.LanguageUtils;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.OmtLanguageUtils;
|
||||
import com.onthegomap.planetiler.reader.SourceFeature;
|
||||
import com.onthegomap.planetiler.stats.Stats;
|
||||
import com.onthegomap.planetiler.util.Parse;
|
||||
@@ -162,7 +162,7 @@ public class WaterName implements
|
||||
int minZoom = "ocean".equals(place) ? 0 : rank != null ? rank : 8;
|
||||
features.point(LAYER_NAME)
|
||||
.setBufferPixels(BUFFER_SIZE)
|
||||
.putAttrs(LanguageUtils.getNames(source.tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(source.tags(), translations))
|
||||
.setAttr(Fields.CLASS, place)
|
||||
.setAttr(Fields.INTERMITTENT, element.isIntermittent() ? 1 : 0)
|
||||
.setMinZoom(minZoom);
|
||||
@@ -191,7 +191,7 @@ public class WaterName implements
|
||||
feature
|
||||
.setAttr(Fields.CLASS, FieldValues.CLASS_LAKE)
|
||||
.setBufferPixels(BUFFER_SIZE)
|
||||
.putAttrs(LanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
|
||||
.setAttr(Fields.INTERMITTENT, element.isIntermittent() ? 1 : 0)
|
||||
.setMinZoom(minzoom);
|
||||
} catch (GeometryException e) {
|
||||
|
||||
@@ -48,7 +48,7 @@ import com.onthegomap.planetiler.geo.GeometryException;
|
||||
import com.onthegomap.planetiler.openmaptiles.OpenMapTilesProfile;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.OpenMapTilesSchema;
|
||||
import com.onthegomap.planetiler.openmaptiles.generated.Tables;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.LanguageUtils;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.OmtLanguageUtils;
|
||||
import com.onthegomap.planetiler.openmaptiles.util.Utils;
|
||||
import com.onthegomap.planetiler.reader.SourceFeature;
|
||||
import com.onthegomap.planetiler.reader.osm.OsmElement;
|
||||
@@ -148,7 +148,7 @@ public class Waterway implements
|
||||
synchronized (riverRelationLengths) {
|
||||
riverRelationLengths.put(relation.id(), new AtomicDouble());
|
||||
}
|
||||
return List.of(new WaterwayRelation(relation.id(), LanguageUtils.getNames(relation.tags(), translations)));
|
||||
return List.of(new WaterwayRelation(relation.id(), OmtLanguageUtils.getNames(relation.tags(), translations)));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -192,7 +192,7 @@ public class Waterway implements
|
||||
features.line(LAYER_NAME)
|
||||
.setBufferPixels(BUFFER_SIZE)
|
||||
.setAttr(Fields.CLASS, element.waterway())
|
||||
.putAttrs(LanguageUtils.getNames(element.source().tags(), translations))
|
||||
.putAttrs(OmtLanguageUtils.getNames(element.source().tags(), translations))
|
||||
.setMinZoom(minzoom)
|
||||
// details only at higher zoom levels so that named rivers can be merged more aggressively
|
||||
.setAttrWithMinzoom(Fields.BRUNNEL, Utils.brunnel(element.isBridge(), element.isTunnel()), 12)
|
||||
|
||||
@@ -35,15 +35,13 @@ See https://github.com/openmaptiles/openmaptiles/blob/master/LICENSE.md for deta
|
||||
*/
|
||||
package com.onthegomap.planetiler.openmaptiles.util;
|
||||
|
||||
import static com.onthegomap.planetiler.openmaptiles.util.Utils.coalesce;
|
||||
import static com.onthegomap.planetiler.openmaptiles.util.Utils.nullIfEmpty;
|
||||
import static com.onthegomap.planetiler.util.LanguageUtils.*;
|
||||
import static com.onthegomap.planetiler.util.Utils.coalesce;
|
||||
|
||||
import com.onthegomap.planetiler.util.LanguageUtils;
|
||||
import com.onthegomap.planetiler.util.Translations;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@@ -53,62 +51,7 @@ import java.util.stream.Stream;
|
||||
* Ported from
|
||||
* <a href="https://github.com/openmaptiles/openmaptiles-tools/blob/master/sql/zzz_language.sql">openmaptiles-tools</a>.
|
||||
*/
|
||||
public class LanguageUtils {
|
||||
// Name tags that should be eligible for finding a latin name.
|
||||
// See https://wiki.openstreetmap.org/wiki/Multilingual_names
|
||||
private static final Predicate<String> 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)
|
||||
.asMatchPredicate();
|
||||
// See https://github.com/onthegomap/planetiler/issues/86
|
||||
// Match strings that only contain latin characters.
|
||||
private static final Predicate<String> ONLY_LATIN = Pattern
|
||||
.compile("^[\\P{IsLetter}[\\p{IsLetter}&&\\p{IsLatin}]]+$")
|
||||
.asMatchPredicate();
|
||||
// Match only latin letters
|
||||
private static final Pattern LATIN_LETTER = Pattern.compile("[\\p{IsLetter}&&\\p{IsLatin}]+");
|
||||
private static final Pattern EMPTY_PARENS = Pattern.compile("(\\([ -.]*\\)|\\[[ -.]*])");
|
||||
private static final Pattern LEADING_TRAILING_JUNK = Pattern.compile("((^[\\s./-]*)|([\\s./-]*$))");
|
||||
private static final Pattern WHITESPACE = Pattern.compile("\\s+");
|
||||
private static final Set<String> EN_DE_NAME_KEYS = Set.of("name:en", "name:de");
|
||||
|
||||
private LanguageUtils() {}
|
||||
|
||||
private static void putIfNotEmpty(Map<String, Object> dest, String key, Object value) {
|
||||
if (value != null && !value.equals("")) {
|
||||
dest.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private static String string(Object obj) {
|
||||
return nullIfEmpty(obj == null ? null : obj.toString());
|
||||
}
|
||||
|
||||
static boolean containsOnlyLatinCharacters(String string) {
|
||||
return string != null && ONLY_LATIN.test(string);
|
||||
}
|
||||
|
||||
private static String transliteratedName(Map<String, Object> tags) {
|
||||
return Translations.transliterate(string(tags.get("name")));
|
||||
}
|
||||
|
||||
static String removeLatinCharacters(String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
var matcher = LATIN_LETTER.matcher(name);
|
||||
if (matcher.find()) {
|
||||
String result = matcher.replaceAll("");
|
||||
// if the name was "<nonlatin text> (<latin description)"
|
||||
// or "<nonlatin text> - <latin description>"
|
||||
// then remove any of those extra characters now
|
||||
result = EMPTY_PARENS.matcher(result).replaceAll("");
|
||||
result = LEADING_TRAILING_JUNK.matcher(result).replaceAll("");
|
||||
return WHITESPACE.matcher(result).replaceAll(" ");
|
||||
}
|
||||
return name.trim();
|
||||
}
|
||||
|
||||
public class OmtLanguageUtils {
|
||||
/**
|
||||
* Returns a map with default name attributes (name, name_en, name_de, name:latin, name:nonlatin, name_int) that every
|
||||
* element should have, derived from name, int_name, name:en, and name:de tags on the input element.
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.onthegomap.planetiler.openmaptiles.util;
|
||||
|
||||
import static com.onthegomap.planetiler.TestUtils.assertSubmap;
|
||||
import static com.onthegomap.planetiler.openmaptiles.util.LanguageUtils.containsOnlyLatinCharacters;
|
||||
import static com.onthegomap.planetiler.util.LanguageUtils.containsOnlyLatinCharacters;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
@@ -15,7 +15,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
class LanguageUtilsTest {
|
||||
class OmtLanguageUtilsTest {
|
||||
|
||||
private final Wikidata.WikidataTranslations wikidataTranslations = new Wikidata.WikidataTranslations();
|
||||
private final Translations translations = Translations.defaultProvider(List.of("en", "es", "de"))
|
||||
@@ -27,7 +27,7 @@ class LanguageUtilsTest {
|
||||
"name", "name",
|
||||
"name_en", "english name",
|
||||
"name_de", "german name"
|
||||
), LanguageUtils.getNames(Map.of(
|
||||
), OmtLanguageUtils.getNames(Map.of(
|
||||
"name", "name",
|
||||
"name:en", "english name",
|
||||
"name:de", "german name"
|
||||
@@ -37,7 +37,7 @@ class LanguageUtilsTest {
|
||||
"name", "name",
|
||||
"name_en", "name",
|
||||
"name_de", "german name"
|
||||
), LanguageUtils.getNames(Map.of(
|
||||
), OmtLanguageUtils.getNames(Map.of(
|
||||
"name", "name",
|
||||
"name:de", "german name"
|
||||
), translations));
|
||||
@@ -46,7 +46,7 @@ class LanguageUtilsTest {
|
||||
"name", "name",
|
||||
"name_en", "english name",
|
||||
"name_de", "name"
|
||||
), LanguageUtils.getNames(Map.of(
|
||||
), OmtLanguageUtils.getNames(Map.of(
|
||||
"name", "name",
|
||||
"name:en", "english name"
|
||||
), translations));
|
||||
@@ -72,7 +72,7 @@ class LanguageUtilsTest {
|
||||
if (!isLatin) {
|
||||
assertFalse(containsOnlyLatinCharacters(in));
|
||||
} else {
|
||||
assertEquals(in, LanguageUtils.getNames(Map.of(
|
||||
assertEquals(in, OmtLanguageUtils.getNames(Map.of(
|
||||
"name", in
|
||||
), translations).get("name:latin"));
|
||||
}
|
||||
@@ -90,7 +90,7 @@ class LanguageUtilsTest {
|
||||
"Japan / 日本 / Japan , 日本",
|
||||
}, nullValues = "null")
|
||||
void testRemoveNonLatin(String in, String out) {
|
||||
assertEquals(out, LanguageUtils.getNames(Map.of(
|
||||
assertEquals(out, OmtLanguageUtils.getNames(Map.of(
|
||||
"name", in
|
||||
), translations).get("name:nonlatin"));
|
||||
}
|
||||
@@ -135,13 +135,13 @@ class LanguageUtilsTest {
|
||||
"name:gsw",
|
||||
})
|
||||
void testLatinFallbacks(String key) {
|
||||
assertEquals("a", LanguageUtils.getNames(Map.of(
|
||||
assertEquals("a", OmtLanguageUtils.getNames(Map.of(
|
||||
key, "a"
|
||||
), translations).get("name:latin"));
|
||||
assertNull(LanguageUtils.getNames(Map.of(
|
||||
assertNull(OmtLanguageUtils.getNames(Map.of(
|
||||
key, "ア"
|
||||
), translations).get("name:latin"));
|
||||
assertNull(LanguageUtils.getNames(Map.of(
|
||||
assertNull(OmtLanguageUtils.getNames(Map.of(
|
||||
key, "غ"
|
||||
), translations).get("name:latin"));
|
||||
}
|
||||
@@ -171,7 +171,7 @@ class LanguageUtilsTest {
|
||||
"name_de", "Branch Hill–Loveland Road",
|
||||
"name:latin", "Branch Hill–Loveland Road",
|
||||
"name_int", "Branch Hill–Loveland Road"
|
||||
), LanguageUtils.getNames(Map.of(
|
||||
), OmtLanguageUtils.getNames(Map.of(
|
||||
"name", "Branch Hill–Loveland Road",
|
||||
key, "Q22133584;Q843993"
|
||||
), translations));
|
||||
@@ -181,7 +181,7 @@ class LanguageUtilsTest {
|
||||
"name_de", "日",
|
||||
"name:latin", "rì",
|
||||
"name_int", "rì"
|
||||
), LanguageUtils.getNames(Map.of(
|
||||
), OmtLanguageUtils.getNames(Map.of(
|
||||
"name", "日",
|
||||
key, "other" // don't use this latin string with invalid name keys
|
||||
), translations));
|
||||
@@ -194,11 +194,11 @@ class LanguageUtilsTest {
|
||||
"биологическом, biologičeskom",
|
||||
})
|
||||
void testTransliterate(String in, String out) {
|
||||
assertEquals(out, LanguageUtils.getNames(Map.of(
|
||||
assertEquals(out, OmtLanguageUtils.getNames(Map.of(
|
||||
"name", in
|
||||
), translations).get("name:latin"));
|
||||
translations.setShouldTransliterate(false);
|
||||
assertNull(LanguageUtils.getNames(Map.of(
|
||||
assertNull(OmtLanguageUtils.getNames(Map.of(
|
||||
"name", in
|
||||
), translations).get("name:latin"));
|
||||
}
|
||||
@@ -208,7 +208,7 @@ class LanguageUtilsTest {
|
||||
wikidataTranslations.put(123, "es", "es name");
|
||||
assertSubmap(Map.of(
|
||||
"name:es", "es name"
|
||||
), LanguageUtils.getNames(Map.of(
|
||||
), OmtLanguageUtils.getNames(Map.of(
|
||||
"name", "name",
|
||||
"wikidata", "Q123"
|
||||
), translations));
|
||||
@@ -218,7 +218,7 @@ class LanguageUtilsTest {
|
||||
void testUseOsm() {
|
||||
assertSubmap(Map.of(
|
||||
"name:es", "es name osm"
|
||||
), LanguageUtils.getNames(Map.of(
|
||||
), OmtLanguageUtils.getNames(Map.of(
|
||||
"name", "name",
|
||||
"wikidata", "Q123",
|
||||
"name:es", "es name osm"
|
||||
@@ -231,7 +231,7 @@ class LanguageUtilsTest {
|
||||
assertSubmap(Map.of(
|
||||
"name:es", "wd es name",
|
||||
"name:de", "de name osm"
|
||||
), LanguageUtils.getNames(Map.of(
|
||||
), OmtLanguageUtils.getNames(Map.of(
|
||||
"name", "name",
|
||||
"wikidata", "Q123",
|
||||
"name:es", "es name osm",
|
||||
@@ -241,7 +241,7 @@ class LanguageUtilsTest {
|
||||
|
||||
@Test
|
||||
void testDontUseTranslationsWhenNotSpecified() {
|
||||
var result = LanguageUtils.getNamesWithoutTranslations(Map.of(
|
||||
var result = OmtLanguageUtils.getNamesWithoutTranslations(Map.of(
|
||||
"name", "name",
|
||||
"wikidata", "Q123",
|
||||
"name:es", "es name osm",
|
||||
@@ -255,7 +255,7 @@ class LanguageUtilsTest {
|
||||
@Test
|
||||
void testIgnoreLanguages() {
|
||||
wikidataTranslations.put(123, "ja", "ja name wd");
|
||||
var result = LanguageUtils.getNamesWithoutTranslations(Map.of(
|
||||
var result = OmtLanguageUtils.getNamesWithoutTranslations(Map.of(
|
||||
"name", "name",
|
||||
"wikidata", "Q123",
|
||||
"name:ja", "ja name osm"
|
||||
Reference in New Issue
Block a user