Prefer OSM translations to wikidata (#55)

This commit is contained in:
Michael Barry
2022-12-03 07:18:32 -05:00
committed by GitHub
parent 7171538bd5
commit e33b2bd2fe
7 changed files with 28 additions and 83 deletions

View File

@@ -9,7 +9,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>16</maven.compiler.source> <maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target> <maven.compiler.target>16</maven.compiler.target>
<planetiler.version>0.5-SNAPSHOT</planetiler.version> <planetiler.version>0.6-SNAPSHOT</planetiler.version>
<junit.version>5.9.1</junit.version> <junit.version>5.9.1</junit.version>
<mainClass>org.openmaptiles.OpenMapTilesMain</mainClass> <mainClass>org.openmaptiles.OpenMapTilesMain</mainClass>

View File

@@ -416,26 +416,26 @@ public class Generate {
for (var entry : tables.entrySet()) { for (var entry : tables.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
Imposm3Table table = entry.getValue(); Imposm3Table table = entry.getValue();
List<OsmTableField> fields = parseTableFields(table);
for (var field : fields) {
String existing = fieldNameToType.get(field.name);
if (existing == null) {
fieldNameToType.put(field.name, field.clazz);
} else if (!existing.equals(field.clazz)) {
throw new IllegalArgumentException(
"Field " + field.name + " has both " + existing + " and " + field.clazz + " types");
}
}
Expression mappingExpression = parseImposm3MappingExpression(table);
String mapping = """
/** Imposm3 "mapping" to filter OSM elements that should appear in this "table". */
public static final Expression MAPPING = %s;
""".formatted(
mappingExpression.generateJavaCode()
);
String tableName = "osm_" + key;
String className = lowerUnderscoreToUpperCamel(tableName);
if (!"relation_member".equals(table.type)) { if (!"relation_member".equals(table.type)) {
List<OsmTableField> fields = parseTableFields(table);
for (var field : fields) {
String existing = fieldNameToType.get(field.name);
if (existing == null) {
fieldNameToType.put(field.name, field.clazz);
} else if (!existing.equals(field.clazz)) {
throw new IllegalArgumentException(
"Field " + field.name + " has both " + existing + " and " + field.clazz + " types");
}
}
Expression mappingExpression = parseImposm3MappingExpression(table);
String mapping = """
/** Imposm3 "mapping" to filter OSM elements that should appear in this "table". */
public static final Expression MAPPING = %s;
""".formatted(
mappingExpression.generateJavaCode()
);
String tableName = "osm_" + key;
String className = lowerUnderscoreToUpperCamel(tableName);
classNames.add(className); classNames.add(className);
tablesClass.append(""" tablesClass.append("""

View File

@@ -851,11 +851,6 @@ public class Tables {
String access(); String access();
} }
/** Rows with a long adminLevel attribute. */
public interface WithAdminLevel {
long adminLevel();
}
/** Rows with a String aerialway attribute. */ /** Rows with a String aerialway attribute. */
public interface WithAerialway { public interface WithAerialway {
String aerialway(); String aerialway();
@@ -926,11 +921,6 @@ public class Tables {
String capital(); String capital();
} }
/** Rows with a String claimedBy attribute. */
public interface WithClaimedBy {
String claimedBy();
}
/** Rows with a String colour attribute. */ /** Rows with a String colour attribute. */
public interface WithColour { public interface WithColour {
String colour(); String colour();
@@ -1151,11 +1141,6 @@ public class Tables {
String operator(); String operator();
} }
/** Rows with a String osmcSymbol attribute. */
public interface WithOsmcSymbol {
String osmcSymbol();
}
/** Rows with a String place attribute. */ /** Rows with a String place attribute. */
public interface WithPlace { public interface WithPlace {
String place(); String place();
@@ -1191,51 +1176,11 @@ public class Tables {
String ref(); String ref();
} }
/** Rows with a String relbuildingheight attribute. */
public interface WithRelbuildingheight {
String relbuildingheight();
}
/** Rows with a String relbuildinglevels attribute. */
public interface WithRelbuildinglevels {
String relbuildinglevels();
}
/** Rows with a String relbuildingminHeight attribute. */
public interface WithRelbuildingminHeight {
String relbuildingminHeight();
}
/** Rows with a String relbuildingminLevel attribute. */
public interface WithRelbuildingminLevel {
String relbuildingminLevel();
}
/** Rows with a String relheight attribute. */
public interface WithRelheight {
String relheight();
}
/** Rows with a String religion attribute. */ /** Rows with a String religion attribute. */
public interface WithReligion { public interface WithReligion {
String religion(); String religion();
} }
/** Rows with a String rellevels attribute. */
public interface WithRellevels {
String rellevels();
}
/** Rows with a String relminHeight attribute. */
public interface WithRelminHeight {
String relminHeight();
}
/** Rows with a String relminLevel attribute. */
public interface WithRelminLevel {
String relminLevel();
}
/** Rows with a String sacScale attribute. */ /** Rows with a String sacScale attribute. */
public interface WithSacScale { public interface WithSacScale {
String sacScale(); String sacScale();

View File

@@ -15,7 +15,7 @@ class OpenMapTilesProfileTest {
private final Wikidata.WikidataTranslations wikidataTranslations = new Wikidata.WikidataTranslations(); private final Wikidata.WikidataTranslations wikidataTranslations = new Wikidata.WikidataTranslations();
private final Translations translations = Translations.defaultProvider(List.of("en", "es", "de")) private final Translations translations = Translations.defaultProvider(List.of("en", "es", "de"))
.addTranslationProvider(wikidataTranslations); .addFallbackTranslationProvider(wikidataTranslations);
private final OpenMapTilesProfile profile = new OpenMapTilesProfile(translations, PlanetilerConfig.defaults(), private final OpenMapTilesProfile profile = new OpenMapTilesProfile(translations, PlanetilerConfig.defaults(),
Stats.inMemory()); Stats.inMemory());

View File

@@ -33,7 +33,7 @@ public abstract class AbstractLayerTest {
final Wikidata.WikidataTranslations wikidataTranslations = new Wikidata.WikidataTranslations(); final Wikidata.WikidataTranslations wikidataTranslations = new Wikidata.WikidataTranslations();
final Translations translations = Translations.defaultProvider(List.of("en", "es", "de")) final Translations translations = Translations.defaultProvider(List.of("en", "es", "de"))
.addTranslationProvider(wikidataTranslations); .addFallbackTranslationProvider(wikidataTranslations);
final PlanetilerConfig params = PlanetilerConfig.defaults(); final PlanetilerConfig params = PlanetilerConfig.defaults();
final OpenMapTilesProfile profile = new OpenMapTilesProfile(translations, PlanetilerConfig.defaults(), final OpenMapTilesProfile profile = new OpenMapTilesProfile(translations, PlanetilerConfig.defaults(),

View File

@@ -25,7 +25,7 @@ class PlaceTest extends AbstractLayerTest {
"class", "continent", "class", "continent",
"name", "North America", "name", "North America",
"name:en", "North America", "name:en", "North America",
"name:es", "América del Norte y América Central", "name:es", "América del Norte",
"name:latin", "North America", "name:latin", "North America",
"rank", 1, "rank", 1,
@@ -60,7 +60,7 @@ class PlaceTest extends AbstractLayerTest {
"class", "country", "class", "country",
"name", "United States of America", "name", "United States of America",
"name_en", "United States of America", "name_en", "United States of America",
"name:es", "Estados Unidos", "name:es", "Estados Unidos de América",
"name:latin", "United States of America", "name:latin", "United States of America",
"iso_a2", "US", "iso_a2", "US",
"rank", 6, "rank", 6,
@@ -86,7 +86,7 @@ class PlaceTest extends AbstractLayerTest {
"class", "country", "class", "country",
"name", "United States of America", "name", "United States of America",
"name_en", "United States of America", "name_en", "United States of America",
"name:es", "Estados Unidos", "name:es", "Estados Unidos de América",
"name:latin", "United States of America", "name:latin", "United States of America",
"iso_a2", "US", "iso_a2", "US",
"rank", 1, "rank", 1,

View File

@@ -19,7 +19,7 @@ class OmtLanguageUtilsTest {
private final Wikidata.WikidataTranslations wikidataTranslations = new Wikidata.WikidataTranslations(); private final Wikidata.WikidataTranslations wikidataTranslations = new Wikidata.WikidataTranslations();
private final Translations translations = Translations.defaultProvider(List.of("en", "es", "de")) private final Translations translations = Translations.defaultProvider(List.of("en", "es", "de"))
.addTranslationProvider(wikidataTranslations); .addFallbackTranslationProvider(wikidataTranslations);
@Test @Test
void testSimpleExample() { void testSimpleExample() {
@@ -227,15 +227,15 @@ class OmtLanguageUtilsTest {
} }
@Test @Test
void testPreferWikidata() { void testPreferOsm() {
wikidataTranslations.put(123, "es", "wd es name"); wikidataTranslations.put(123, "es", "wd es name");
wikidataTranslations.put(123, "de", "wd de name");
assertSubmap(Map.of( assertSubmap(Map.of(
"name:es", "wd es name", "name:es", "wd es name",
"name:de", "de name osm" "name:de", "de name osm"
), OmtLanguageUtils.getNames(Map.of( ), OmtLanguageUtils.getNames(Map.of(
"name", "name", "name", "name",
"wikidata", "Q123", "wikidata", "Q123",
"name:es", "es name osm",
"name:de", "de name osm" "name:de", "de name osm"
), translations)); ), translations));
} }