From 5bd213d4dbfde12c4e74eb570ab76cb016c0b490 Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Sat, 7 Oct 2023 14:39:55 -0300 Subject: [PATCH] [classifier] Setup for amenity-parking-*-* types processing. Signed-off-by: Viktor Govako --- data/mapcss-mapping.csv | 21 ++++---- .../include/priorities_1_BG-by-size.prio.txt | 5 +- .../include/priorities_4_overlays.prio.txt | 12 +++-- .../include/priorities_1_BG-by-size.prio.txt | 5 +- .../include/priorities_4_overlays.prio.txt | 8 +++- generator/generator_tests/osm_type_test.cpp | 9 +++- generator/osm2type.cpp | 48 +++++++++++++++---- indexer/indexer_tests/classificator_tests.cpp | 4 +- 8 files changed, 80 insertions(+), 32 deletions(-) diff --git a/data/mapcss-mapping.csv b/data/mapcss-mapping.csv index 24d2cae2b3..44e9a0236b 100644 --- a/data/mapcss-mapping.csv +++ b/data/mapcss-mapping.csv @@ -13,7 +13,12 @@ # - optional: a replacement type for a deprecated one # A "mandatory" mapcss selector like [fee?] or [fee] matches all tag values except [fee=no], # a "forbidden" selector like [!oneway] matches [oneway=no] only or absence of this tag. -# Longer (more detailed) types are preferred when matching, e.g. highway-primary-bridge wins over highway-primary. +# If first 2 (1 for short types like "building") components of pre-matched types are the same, +# then leave only the longest types (there could be a few of them). Equal arity types are kept. +# - highway-primary-bridge is left while highway-primary is removed; +# - building-garages is left while building is removed; +# - amenity-parking-underground-fee is left while amenity-parking and amenity-parking-fee are removed; +# - both amenity-charging_station-motorcar and amenity-charging_station-bicycle are left; # # A shorter format for the above example: # highway|bus_stop;22; @@ -188,7 +193,7 @@ highway|motorway_junction;121; amenity|telephone;122; waterway|stream|tunnel;[waterway=stream][tunnel?];;name;int_name;123; tourism|information|guidepost;[tourism=information][information=guidepost];;name;int_name;124; -amenity|parking|fee;[amenity=parking][fee?];;name;int_name;125; +amenity|parking|fee;[amenity=parking][fee];;name;int_name;125; amenity|kindergarten;126; leisure|swimming_pool|private;[leisure=swimming_pool][access=private],[amenity=swimming_pool][access=private];;name;int_name;127; place|suburb;128; @@ -426,19 +431,19 @@ sport|scuba_diving;352; highway|cycleway|permissive;[highway=cycleway][access=permissive];;name;int_name;353; highway|unclassified|area;[highway=unclassified][area?];;name;int_name;354; natural|volcano;355; -deprecated:amenity|parking|underground|fee:01.2020;[amenity=parking][location=underground][fee?],[amenity=parking][parking=underground][fee?];x;name;int_name;356;amenity|parking|underground +amenity|parking|underground|fee;[amenity=parking][location=underground][fee],[amenity=parking][parking=underground][fee];;name;int_name;356; amenity|parking|underground;[amenity=parking][location=underground],[amenity=parking][parking=underground];;name;int_name;357; -amenity|parking|street_side;[amenity=parking][parking=street_side][!fee];;name;int_name;358; +amenity|parking|street_side;[amenity=parking][parking=street_side];;name;int_name;358; amenity|parking|multi-storey;[amenity=parking][parking=multi-storey];;name;int_name;359; leisure|recreation_ground;360; highway|footway|mountain_hiking;[highway=footway][sac_scale=mountain_hiking];;name;int_name;361; deprecated:highway|service|driveway|bridge:01.2020;[highway=service][service=driveway][bridge?];x;name;int_name;362;highway|service|driveway -deprecated:amenity|parking|multi-storey|fee:01.2020;[amenity=parking][parking=multi-storey][fee?];x;name;int_name;363;amenity|parking|multi-storey +amenity|parking|multi-storey|fee;[amenity=parking][parking=multi-storey][fee];;name;int_name;363; sport|9pin;364; sport|10pin;365; piste:type|downhill|novice;[piste:type=downhill][piste:difficulty=novice];;name;int_name;366; railway|narrow_gauge|bridge;[railway=narrow_gauge][bridge?];;name;int_name;367; -amenity|parking|lane;[amenity=parking][parking=lane][!fee];;name;int_name;368; +amenity|parking|lane;[amenity=parking][parking=lane];;name;int_name;368; railway|rail|main|tunnel;[railway=rail][usage=main][!highspeed][!service][tunnel?];;name;int_name;369; highway|bridleway|permissive;[highway=bridleway][access=permissive];;name;int_name;370; railway|construction;371; @@ -513,8 +518,8 @@ healthcare|speech_therapist;438; deprecated|deprecated;439;x deprecated|deprecated;440;x aerialway|t-bar;441; -amenity|parking|fee|lane;[amenity=parking][fee?][parking=lane];;name;int_name;442; -amenity|parking|fee|street_side;[amenity=parking][fee?][parking=street_side];;name;int_name;443; +amenity|parking|lane|fee;[amenity=parking][parking=lane][fee];;name;int_name;442; +amenity|parking|street_side|fee;[amenity=parking][parking=street_side][fee];;name;int_name;443; highway|path|difficult_alpine_hiking;[highway=path][sac_scale=difficult_alpine_hiking];;name;int_name;444; earthquake:damage|spontaneous_camp;445; natural|water|drain;[natural=water][water=drain];;name;int_name;446; diff --git a/data/styles/clear/include/priorities_1_BG-by-size.prio.txt b/data/styles/clear/include/priorities_1_BG-by-size.prio.txt index 3140b398ba..cc6f9fa1c6 100644 --- a/data/styles/clear/include/priorities_1_BG-by-size.prio.txt +++ b/data/styles/clear/include/priorities_1_BG-by-size.prio.txt @@ -84,15 +84,16 @@ railway-platform # area z16- (also has captio amenity-parking # area z15- (also has icon z16-, caption(optional) z18-) amenity-parking-fee # area z15- (also has icon z16-, caption(optional) z18-) -amenity-parking-fee-lane # area z17- (also has icon z18-, caption(optional) z18-) -amenity-parking-fee-street_side # area z17- (also has icon z18-, caption(optional) z18-) amenity-parking-lane # area z17- (also has icon z18-, caption(optional) z18-) +amenity-parking-lane-fee # area z17- (also has icon z18-, caption(optional) z18-) amenity-parking-multi-storey # area z15- (also has icon z16-, caption(optional) z18-) +amenity-parking-multi-storey-fee # area z15- (also has icon z16-, caption(optional) z18-) amenity-parking-no-access # area z15- (also has icon z16-, caption(optional) z18-) amenity-parking-park_and_ride # area z15- (also has icon z16-, caption(optional) z18-) amenity-parking-permissive # area z15- (also has icon z16-, caption(optional) z18-) amenity-parking-private # area z17- (also has icon z18-, caption(optional) z18-) amenity-parking-street_side # area z17- (also has icon z18-, caption(optional) z18-) +amenity-parking-street_side-fee # area z17- (also has icon z18-, caption(optional) z18-) === 100 natural-wetland # area z11- (also has caption z16-) diff --git a/data/styles/clear/include/priorities_4_overlays.prio.txt b/data/styles/clear/include/priorities_4_overlays.prio.txt index 3de725336f..446bdc5cbd 100644 --- a/data/styles/clear/include/priorities_4_overlays.prio.txt +++ b/data/styles/clear/include/priorities_4_overlays.prio.txt @@ -1244,8 +1244,10 @@ leisure-outdoor_seating # icon z18- amenity-parking # icon z16- (also has caption(optional) z18-, area z15-) amenity-parking-fee # icon z16- (also has caption(optional) z18-, area z15-) amenity-parking-multi-storey # icon z16- (also has caption(optional) z18-, area z15-) +amenity-parking-multi-storey-fee # icon z16- (also has caption(optional) z18-, area z15-) amenity-parking-park_and_ride # icon z16- (also has caption(optional) z18-, area z15-) amenity-parking-underground # icon z16- (also has caption(optional) z18-) +amenity-parking-underground-fee # icon z16- (also has caption(optional) z18-) === 300 amenity-bicycle_parking # icon z17- (also has caption(optional) z17-) @@ -1275,10 +1277,10 @@ historic-memorial-stolperstein # icon z19- (also has captio leisure-garden-residential # caption z18- (also has area z12-) === 200 -amenity-parking-fee-lane # icon z18- (also has caption(optional) z18-, area z17-) -amenity-parking-fee-street_side # icon z18- (also has caption(optional) z18-, area z17-) amenity-parking-lane # icon z18- (also has caption(optional) z18-, area z17-) +amenity-parking-lane-fee # icon z18- (also has caption(optional) z18-, area z17-) amenity-parking-street_side # icon z18- (also has caption(optional) z18-, area z17-) +amenity-parking-street_side-fee # icon z18- (also has caption(optional) z18-, area z17-) === 150 amenity-parking-no-access # icon z16- (also has caption(optional) z18-, area z15-) @@ -2134,8 +2136,10 @@ amenity-parking-private # icon z18- (also has captio # amenity-parking # caption(optional) z18- (also has icon z16-, area z15-) # amenity-parking-fee # caption(optional) z18- (also has icon z16-, area z15-) # amenity-parking-multi-storey # caption(optional) z18- (also has icon z16-, area z15-) +# amenity-parking-multi-storey-fee # caption(optional) z18- (also has icon z16-, area z15-) # amenity-parking-park_and_ride # caption(optional) z18- (also has icon z16-, area z15-) # amenity-parking-underground # caption(optional) z18- (also has icon z16-) +# amenity-parking-underground-fee # caption(optional) z18- (also has icon z16-) # === -9700 # amenity-bicycle_parking # caption(optional) z17- (also has icon z17-) @@ -2159,10 +2163,10 @@ amenity-parking-private # icon z18- (also has captio # historic-memorial-stolperstein # caption(optional) z19- (also has icon z19-) # === -9800 -# amenity-parking-fee-lane # caption(optional) z18- (also has icon z18-, area z17-) -# amenity-parking-fee-street_side # caption(optional) z18- (also has icon z18-, area z17-) # amenity-parking-lane # caption(optional) z18- (also has icon z18-, area z17-) +# amenity-parking-lane-fee # caption(optional) z18- (also has icon z18-, area z17-) # amenity-parking-street_side # caption(optional) z18- (also has icon z18-, area z17-) +# amenity-parking-street_side-fee # caption(optional) z18- (also has icon z18-, area z17-) # === -9850 # amenity-parking-no-access # caption(optional) z18- (also has icon z16-, area z15-) diff --git a/data/styles/vehicle/include/priorities_1_BG-by-size.prio.txt b/data/styles/vehicle/include/priorities_1_BG-by-size.prio.txt index 8865422e18..c639423e50 100644 --- a/data/styles/vehicle/include/priorities_1_BG-by-size.prio.txt +++ b/data/styles/vehicle/include/priorities_1_BG-by-size.prio.txt @@ -16,15 +16,16 @@ amenity-parking # area z15- (also has icon z15-, caption(optional) z16-) amenity-parking-fee # area z15- (also has icon z15-, caption(optional) z16-) -amenity-parking-fee-lane # area z15- (also has icon z15-) -amenity-parking-fee-street_side # area z15- (also has icon z15-) amenity-parking-lane # area z15- (also has icon z17-) +amenity-parking-lane-fee # area z15- (also has icon z15-) amenity-parking-multi-storey # area z15- (also has icon z15-, caption(optional) z16-) +amenity-parking-multi-storey-fee # area z15- (also has icon z15-, caption(optional) z16-) amenity-parking-no-access # area z15- (also has icon z15-, caption(optional) z16-) amenity-parking-park_and_ride # area z15- (also has icon z15-, caption(optional) z16-) amenity-parking-permissive # area z15- (also has icon z15-, caption(optional) z16-) amenity-parking-private # area z15- (also has icon z17-, caption(optional) z17-) amenity-parking-street_side # area z15- (also has icon z17-) +amenity-parking-street_side-fee # area z15- (also has icon z15-) === 160 leisure-stadium # area z15- diff --git a/data/styles/vehicle/include/priorities_4_overlays.prio.txt b/data/styles/vehicle/include/priorities_4_overlays.prio.txt index d50b88bb4b..c5ffddfd7e 100644 --- a/data/styles/vehicle/include/priorities_4_overlays.prio.txt +++ b/data/styles/vehicle/include/priorities_4_overlays.prio.txt @@ -230,9 +230,11 @@ shop-caravan # icon z17- amenity-parking # icon z15- (also has caption(optional) z16-, area z15-) amenity-parking-fee # icon z15- (also has caption(optional) z16-, area z15-) amenity-parking-multi-storey # icon z15- (also has caption(optional) z16-, area z15-) +amenity-parking-multi-storey-fee # icon z15- (also has caption(optional) z16-, area z15-) amenity-parking-park_and_ride # icon z15- (also has caption(optional) z16-, area z15-) amenity-parking-permissive # icon z15- (also has caption(optional) z16-, area z15-) amenity-parking-underground # icon z15- (also has caption(optional) z16-) +amenity-parking-underground-fee # icon z15- (also has caption(optional) z16-) === 2550 amenity-motorcycle_parking # icon z17- @@ -240,10 +242,10 @@ amenity-parking_entrance # icon z16- amenity-parking_entrance-permissive # icon z16- === 2530 -amenity-parking-fee-lane # icon z15- (also has area z15-) -amenity-parking-fee-street_side # icon z15- (also has area z15-) amenity-parking-lane # icon z17- (also has area z15-) +amenity-parking-lane-fee # icon z15- (also has area z15-) amenity-parking-street_side # icon z17- (also has area z15-) +amenity-parking-street_side-fee # icon z15- (also has area z15-) === 2520 boundary-national_park # icon z12- (also has caption(optional) z12-) @@ -768,9 +770,11 @@ entrance-main # icon z18- (also has captio # amenity-parking # caption(optional) z16- (also has icon z15-, area z15-) # amenity-parking-fee # caption(optional) z16- (also has icon z15-, area z15-) # amenity-parking-multi-storey # caption(optional) z16- (also has icon z15-, area z15-) +# amenity-parking-multi-storey-fee # caption(optional) z16- (also has icon z15-, area z15-) # amenity-parking-park_and_ride # caption(optional) z16- (also has icon z15-, area z15-) # amenity-parking-permissive # caption(optional) z16- (also has icon z15-, area z15-) # amenity-parking-underground # caption(optional) z16- (also has icon z15-) +# amenity-parking-underground-fee # caption(optional) z16- (also has icon z15-) # === -7450 # boundary-national_park # caption(optional) z12- (also has icon z12-) diff --git a/generator/generator_tests/osm_type_test.cpp b/generator/generator_tests/osm_type_test.cpp index 0c37ee9654..a06841f183 100644 --- a/generator/generator_tests/osm_type_test.cpp +++ b/generator/generator_tests/osm_type_test.cpp @@ -12,7 +12,6 @@ #include "indexer/feature_data.hpp" #include "indexer/classificator.hpp" -#include "indexer/classificator_loader.hpp" #include "platform/platform.hpp" @@ -2344,14 +2343,20 @@ UNIT_CLASS_TEST(TestWithClassificator, OsmType_ComplexTypesSmoke) {{"addr:interpolation"}, {{"addr:interpolation", "all"}}}, {{"aeroway", "aerodrome", "international"}, {{"aeroway", "aerodrome"}, {"aerodrome", "international"}}}, {{"amenity", "grave_yard", "christian"}, {{"amenity", "grave_yard"}, {"religion", "christian"}}}, + {{"amenity", "parking"}, {{"amenity", "parking"}, {"fee", "no"}}}, {{"amenity", "parking", "fee"}, {{"amenity", "parking"}, {"fee", "any_value"}}}, + {{"amenity", "parking", "lane"}, {{"amenity", "parking"}, {"parking", "lane"}}}, + {{"amenity", "parking", "lane", "fee"}, {{"amenity", "parking"}, {"parking", "lane"}, {"fee", "any_value"}}}, {{"amenity", "parking", "multi-storey"}, {{"amenity", "parking"}, {"parking", "multi-storey"}}}, + {{"amenity", "parking", "multi-storey", "fee"}, {{"amenity", "parking"}, {"parking", "multi-storey"}, {"fee", "any_value"}}}, {{"amenity", "parking", "no-access"}, {{"amenity", "parking"}, {"access", "no"}}}, {{"amenity", "parking", "park_and_ride"}, {{"amenity", "parking"}, {"parking", "park_and_ride"}}}, {{"amenity", "parking", "permissive"}, {{"amenity", "parking"}, {"access", "permissive"}}}, {{"amenity", "parking", "private"}, {{"amenity", "parking"}, {"access", "private"}}}, + {{"amenity", "parking", "street_side"}, {{"amenity", "parking"}, {"parking", "street_side"}}}, + {{"amenity", "parking", "street_side", "fee"}, {{"amenity", "parking"}, {"parking", "street_side"}, {"fee", "any_value"}}}, {{"amenity", "parking", "underground"}, {{"amenity", "parking"}, {"location", "underground"}}}, - {{"amenity", "parking", "underground"}, {{"amenity", "parking"}, {"parking", "underground"}}}, + {{"amenity", "parking", "underground", "fee"}, {{"amenity", "parking"}, {"parking", "underground"}, {"fee", "any_value"}}}, {{"amenity", "parking_space", "permissive"}, {{"amenity", "parking_space"}, {"access", "permissive"}}}, {{"amenity", "parking_space", "private"}, {{"amenity", "parking_space"}, {"access", "private"}}}, {{"amenity", "parking_space", "underground"}, {{"amenity", "parking_space"}, {"parking", "underground"}}}, diff --git a/generator/osm2type.cpp b/generator/osm2type.cpp index efcc804739..c041289df9 100644 --- a/generator/osm2type.cpp +++ b/generator/osm2type.cpp @@ -315,19 +315,47 @@ private: buffer_vector(Type::Count)> m_types; }; -// Removes types that are prefixes of another longer type, -// e.g. highway-primary-bridge is left while highway-primary is removed. +// If first 2 (1 for short types like "building") components of pre-matched types are the same, +// then leave only the longest types (there could be a few of them). Equal arity types are kept. +// - highway-primary-bridge is left while highway-primary is removed; +// - building-garages is left while building is removed; +// - amenity-parking-underground-fee is left while amenity-parking and amenity-parking-fee is removed; +// - both amenity-charging_station-motorcar and amenity-charging_station-bicycle are left; void LeaveLongestTypes(vector & matchedTypes) { - auto const less = [](auto const & lhs, auto const & rhs) { return lhs > rhs; }; - - auto const equals = [](auto const & lhs, auto const & rhs) { - if (rhs.size() > lhs.size()) - return equal(lhs.begin(), lhs.end(), rhs.begin()); - return equal(rhs.begin(), rhs.end(), lhs.begin()); + auto const equalPrefix = [](auto const & lhs, auto const & rhs) + { + size_t const prefixSz = std::min(lhs.size(), rhs.size()); + return equal(lhs.begin(), lhs.begin() + std::min(size_t(2), prefixSz), rhs.begin()); }; - base::SortUnique(matchedTypes, less, equals); + auto const isBetter = [&equalPrefix](auto const & lhs, auto const & rhs) + { + if (equalPrefix(lhs, rhs)) + { + // Longest type is better. + if (lhs.size() != rhs.size()) + return lhs.size() > rhs.size(); + } + + // Default less order for sort, doesn't matter here. + return lhs < rhs; + }; + + auto const isEqual = [&equalPrefix](auto const & lhs, auto const & rhs) + { + if (equalPrefix(lhs, rhs)) + { + // Keep longest type only, so return equal is true. + if (lhs.size() != rhs.size()) + return true; + + return lhs == rhs; + } + return false; + }; + + base::SortUnique(matchedTypes, isBetter, isEqual); } void MatchTypes(OsmElement * p, FeatureBuilderParams & params, function const & filterType) @@ -590,7 +618,7 @@ void PreprocessElement(OsmElement * p) /// @todo Unfortunately, it's not working in many cases (route=subway, transport=subway). /// Actually, it's better to process subways after feature types assignment. {"station", "subway", [&isSubway] { isSubway = true; }}, - + {"station", "light_rail", [&isLightRail] { isLightRail = true; }}, }); diff --git a/indexer/indexer_tests/classificator_tests.cpp b/indexer/indexer_tests/classificator_tests.cpp index 41ee2a454c..58d3f8d65d 100644 --- a/indexer/indexer_tests/classificator_tests.cpp +++ b/indexer/indexer_tests/classificator_tests.cpp @@ -90,7 +90,7 @@ UNIT_CLASS_TEST(TestWithClassificator, Classificator_StableIndex) // amenity|parking|underground|fee;[amenity=parking][location=underground][fee?],[amenity=parking][parking=underground][fee?];x;name;int_name;356;amenity|parking|underground // amenity|parking|underground;[amenity=parking][location=underground],[amenity=parking][parking=underground];;name;int_name;357; // - // The main definition of amenity|parking|underground goes second but we must use it for index. Test both indexes + // The main definition of amenity|parking|underground goes second but we must use it for index. Test both indexes. // belong to amenity|parking|underground type and GetIndexForType returns second one. Classificator const & c = classif(); @@ -99,6 +99,6 @@ UNIT_CLASS_TEST(TestWithClassificator, Classificator_StableIndex) TEST(c.IsTypeValid(type), ()); uint32_t const index = c.GetIndexForType(type); TEST_EQUAL(index, 357 - 1, ()); - TEST_EQUAL(type, c.GetTypeForIndex(356 - 1), ()); + TEST_NOT_EQUAL(type, c.GetTypeForIndex(356 - 1), ()); // Restored underground-fee TEST_EQUAL(type, c.GetTypeForIndex(357 - 1), ()); }