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

@@ -416,26 +416,26 @@ public class Generate {
for (var entry : tables.entrySet()) {
String key = entry.getKey();
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)) {
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);
tablesClass.append("""

View File

@@ -851,11 +851,6 @@ public class Tables {
String access();
}
/** Rows with a long adminLevel attribute. */
public interface WithAdminLevel {
long adminLevel();
}
/** Rows with a String aerialway attribute. */
public interface WithAerialway {
String aerialway();
@@ -926,11 +921,6 @@ public class Tables {
String capital();
}
/** Rows with a String claimedBy attribute. */
public interface WithClaimedBy {
String claimedBy();
}
/** Rows with a String colour attribute. */
public interface WithColour {
String colour();
@@ -1151,11 +1141,6 @@ public class Tables {
String operator();
}
/** Rows with a String osmcSymbol attribute. */
public interface WithOsmcSymbol {
String osmcSymbol();
}
/** Rows with a String place attribute. */
public interface WithPlace {
String place();
@@ -1191,51 +1176,11 @@ public class Tables {
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. */
public interface WithReligion {
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. */
public interface WithSacScale {
String sacScale();

View File

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

View File

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

View File

@@ -25,7 +25,7 @@ class PlaceTest extends AbstractLayerTest {
"class", "continent",
"name", "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",
"rank", 1,
@@ -60,7 +60,7 @@ class PlaceTest extends AbstractLayerTest {
"class", "country",
"name", "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",
"iso_a2", "US",
"rank", 6,
@@ -86,7 +86,7 @@ class PlaceTest extends AbstractLayerTest {
"class", "country",
"name", "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",
"iso_a2", "US",
"rank", 1,

View File

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