Skip to content

Commit b95eca6

Browse files
committed
Add default for names not in specific language, remove duplicated code.
1 parent dd33c2d commit b95eca6

File tree

1 file changed

+32
-44
lines changed

1 file changed

+32
-44
lines changed

src/main/java/il/org/osm/israelhiking/PlanetSearchProfile.java

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ static private final void CoalesceIntoMap(Map<String, String> map, String langua
7676
}
7777
}
7878

79+
private void convertTagsToDocument(PointDocument pointDocument, WithTags feature) {
80+
for (String language : supportedLanguages) {
81+
CoalesceIntoMap(pointDocument.name, language, feature.getString("name:" + language));
82+
CoalesceIntoMap(pointDocument.description, language, feature.getString("description:" + language));
83+
}
84+
if (feature.hasTag("name")) {
85+
CoalesceIntoMap(pointDocument.name, "default", feature.getString("name"));
86+
}
87+
pointDocument.wikidata = feature.getString("wikidata");
88+
pointDocument.image = feature.getString("image");
89+
pointDocument.wikimedia_commons = feature.getString("wikimedia_commons");
90+
}
91+
7992
@Override
8093
public List<OsmRelationInfo> preprocessOsmRelation(OsmElement.Relation relation) {
8194
// If this is a "route" relation ...
@@ -102,14 +115,8 @@ public List<OsmRelationInfo> preprocessOsmRelation(OsmElement.Relation relation)
102115
}
103116
var info = new RelationInfo(relation.id());
104117

105-
for (String language : supportedLanguages) {
106-
CoalesceIntoMap(pointDocument.name, language, relation.getString("name:" + language), relation.getString("name"));
107-
CoalesceIntoMap(pointDocument.description, language, relation.getString("description:" + language), relation.getString("description"));
108-
}
118+
convertTagsToDocument(pointDocument, relation);
109119
pointDocument.poiSource = "OSM";
110-
pointDocument.wikidata = relation.getString("wikidata");
111-
pointDocument.image = relation.getString("image");
112-
pointDocument.wikimedia_commons = relation.getString("wikimedia_commons");
113120
info.pointDocument = pointDocument;
114121
info.firstMemberId = members_ids.getFirst();
115122
info.secondMemberId = members_ids.size() > 1 ? members_ids.get(1) : -1;
@@ -174,14 +181,8 @@ private void processExternalFeautre(SourceFeature feature, FeatureCollector feat
174181
pointDocument.poiIcon = feature.getString("poiIcon");
175182
pointDocument.poiIconColor = feature.getString("poiIconColor");
176183
pointDocument.poiCategory = feature.getString("poiCategory");
177-
for (String language : supportedLanguages) {
178-
CoalesceIntoMap(pointDocument.name, language, feature.getString("name:" + language), feature.getString("name"));
179-
CoalesceIntoMap(pointDocument.description, language, feature.getString("description:" + language), feature.getString("description"));
180-
}
181184
pointDocument.poiSource = feature.getString("poiSource");
182-
pointDocument.wikidata = feature.getString("wikidata");
183-
pointDocument.image = feature.getString("image");
184-
pointDocument.wikimedia_commons = feature.getString("wikimedia_commons");
185+
convertTagsToDocument(pointDocument, feature);
185186
var point = feature.canBePolygon() ? (Point)feature.centroidIfConvex() : GeoUtils.point(feature.worldGeometry().getCoordinate());
186187
var docId = pointDocument.poiSource + "_" + feature.getString("identifier");
187188
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
@@ -261,13 +262,13 @@ private boolean processMtbNameFeature(SourceFeature feature, FeatureCollector fe
261262
var point = GeoUtils.point(((Geometry)single.lineMerger.getMergedLineStrings().iterator().next()).getCoordinate());
262263

263264
var pointDocument = new PointDocument();
265+
convertTagsToDocument(pointDocument, feature);
264266
for (String language : supportedLanguages) {
265-
CoalesceIntoMap(pointDocument.name, language, minIdFeature.getString("mtb:name:" + language), minIdFeature.getString("name:" + language), minIdFeature.getString("name"), minIdFeature.getString("mtb:name"));
266-
CoalesceIntoMap(pointDocument.description, language, minIdFeature.getString("description:" + language), minIdFeature.getString("description"));
267+
CoalesceIntoMap(pointDocument.name, language, minIdFeature.getString("mtb:name:" + language));
268+
}
269+
if (minIdFeature.hasTag("mtb:name")) {
270+
CoalesceIntoMap(pointDocument.name, "default", minIdFeature.getString("mtb:name"));
267271
}
268-
pointDocument.wikidata = minIdFeature.getString("wikidata");
269-
pointDocument.image = minIdFeature.getString("image");
270-
pointDocument.wikimedia_commons = minIdFeature.getString("wikimedia_commons");
271272
pointDocument.poiCategory = "Bicycle";
272273
pointDocument.poiIcon = "icon-bike";
273274
pointDocument.poiIconColor = "gray";
@@ -324,13 +325,7 @@ private boolean processWaterwayFeature(SourceFeature feature, FeatureCollector f
324325
var point = GeoUtils.point(((Geometry)waterway.lineMerger.getMergedLineStrings().iterator().next()).getCoordinate());
325326

326327
var pointDocument = new PointDocument();
327-
for (String language : supportedLanguages) {
328-
CoalesceIntoMap(pointDocument.name, language, minIdFeature.getString("name:" + language), minIdFeature.getString("name"));
329-
CoalesceIntoMap(pointDocument.description, language, minIdFeature.getString("description:" + language), minIdFeature.getString("description"));
330-
}
331-
pointDocument.wikidata = minIdFeature.getString("wikidata");
332-
pointDocument.image = minIdFeature.getString("image");
333-
pointDocument.wikimedia_commons = minIdFeature.getString("wikimedia_commons");
328+
convertTagsToDocument(pointDocument, feature);
334329
pointDocument.poiCategory = "Water";
335330
pointDocument.poiIcon = "icon-waterfall";
336331
pointDocument.poiIconColor = "blue";
@@ -362,14 +357,7 @@ private boolean processHighwayFeautre(SourceFeature feature, FeatureCollector fe
362357
}
363358
var point = GeoUtils.point(feature.worldGeometry().getCoordinate());
364359
var pointDocument = new PointDocument();
365-
for (String language : supportedLanguages) {
366-
CoalesceIntoMap(pointDocument.name, language, feature.getString("name:" + language), feature.getString("name"));
367-
CoalesceIntoMap(pointDocument.description, language, feature.getString("description:" + language), feature.getString("description"));
368-
}
369-
370-
pointDocument.wikidata = feature.getString("wikidata");
371-
pointDocument.image = feature.getString("image");
372-
pointDocument.wikimedia_commons = feature.getString("wikimedia_commons");
360+
convertTagsToDocument(pointDocument, feature);
373361
pointDocument.poiSource = "OSM";
374362
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
375363
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};
@@ -397,13 +385,7 @@ private boolean processOtherSourceFeature(SourceFeature feature, FeatureCollecto
397385
var point = feature.canBePolygon() ? (Point)feature.centroidIfConvex() : GeoUtils.point(feature.worldGeometry().getCoordinate());
398386

399387
var pointDocument = new PointDocument();
400-
for (String language : supportedLanguages) {
401-
CoalesceIntoMap(pointDocument.name, language, feature.getString("name:" + language), feature.getString("name"));
402-
CoalesceIntoMap(pointDocument.description, language, feature.getString("description:" + language), feature.getString("description"));
403-
}
404-
pointDocument.wikidata = feature.getString("wikidata");
405-
pointDocument.image = feature.getString("image");
406-
pointDocument.wikimedia_commons = feature.getString("wikimedia_commons");
388+
convertTagsToDocument(pointDocument, feature);
407389
pointDocument.poiSource = "OSM";
408390
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
409391
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};
@@ -482,8 +464,11 @@ private void addNonIconFeaturesToElasricseach(SourceFeature feature) throws Geom
482464
pointDocument.poiCategory = "Wikipedia";
483465
}
484466
for (String language : supportedLanguages) {
485-
CoalesceIntoMap(pointDocument.name, language, feature.getString("name:" + language), feature.getString("name"));
486-
CoalesceIntoMap(pointDocument.description, language, feature.getString("description:" + language), feature.getString("description"));
467+
CoalesceIntoMap(pointDocument.name, language, feature.getString("name:" + language));
468+
CoalesceIntoMap(pointDocument.description, language, feature.getString("description:" + language));
469+
}
470+
if (feature.hasTag("name")) {
471+
CoalesceIntoMap(pointDocument.name, "default", feature.getString("name"));
487472
}
488473
pointDocument.wikidata = feature.getString("wikidata");
489474
pointDocument.image = feature.getString("image");
@@ -521,7 +506,10 @@ private void insertBboxToElasticsearch(SourceFeature feature, String[] supported
521506

522507
bbox.setBBox(polygon);
523508
for (String lang : supportedLanguages) {
524-
CoalesceIntoMap(bbox.name, lang, feature.getString("name:" + lang), feature.getString("name"));
509+
CoalesceIntoMap(bbox.name, lang, feature.getString("name:" + lang));
510+
}
511+
if (feature.hasTag("name")) {
512+
CoalesceIntoMap(bbox.name, "default", feature.getString("name"));
525513
}
526514
esClient.index(i -> i
527515
.index(this.bboxIndexName)

0 commit comments

Comments
 (0)