From e6fe9d0d677c66d8c1b901140466d66de696fa66 Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Fri, 9 Sep 2016 18:28:44 +0200 Subject: [PATCH] Fixes issue where two ways with same name but different pronunciation where deduplicated, resolves #2860 --- features/car/names.feature | 17 +++++++++++++++++ include/extractor/extractor_callbacks.hpp | 12 ++++++++---- src/extractor/extractor_callbacks.cpp | 17 +++++++++-------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/features/car/names.feature b/features/car/names.feature index d95c9f2ee..de76b252e 100644 --- a/features/car/names.feature +++ b/features/car/names.feature @@ -35,6 +35,23 @@ Feature: Car - Street names in instructions | a | d | My Way,My Way | ,meyeway | ,A1 | | 1 | c | Your Way,Your Way | yourewaye,yourewaye | , | + # See #2860 + Scenario: Car - same street name but different pronunciation + Given the node map + | a | b | c | + | | d | | + | | e | | + + And the ways + | nodes | name | name:pronunciation | + | abc | Houston St | hew-stun | + | bde | Houston St | how-stun | + + When I route I should get + | from | to | route | pronunciations | + | a | c | Houston St,Houston St | hew-stun,hew-stun | + | a | e | Houston St,Houston St,Houston St | hew-stun,how-stun,how-stun | + @todo Scenario: Car - Use way type to describe unnamed ways Given the node map diff --git a/include/extractor/extractor_callbacks.hpp b/include/extractor/extractor_callbacks.hpp index 80bfca69a..e5cb86c32 100644 --- a/include/extractor/extractor_callbacks.hpp +++ b/include/extractor/extractor_callbacks.hpp @@ -18,14 +18,17 @@ class Way; namespace std { -template <> struct hash> +template <> struct hash> { - std::size_t operator()(const std::tuple &mk) const noexcept + std::size_t + operator()(const std::tuple &mk) const + noexcept { std::size_t seed = 0; boost::hash_combine(seed, std::get<0>(mk)); boost::hash_combine(seed, std::get<1>(mk)); boost::hash_combine(seed, std::get<2>(mk)); + boost::hash_combine(seed, std::get<3>(mk)); return seed; } }; @@ -51,8 +54,9 @@ struct ExtractionWay; class ExtractorCallbacks { private: - // used to deduplicate street names and street destinations: actually maps to name ids - using MapKey = std::tuple; + // used to deduplicate street names, refs, destinations, pronunciation: actually maps to name + // ids + using MapKey = std::tuple; using MapVal = unsigned; std::unordered_map string_map; guidance::LaneDescriptionMap lane_description_map; diff --git a/src/extractor/extractor_callbacks.cpp b/src/extractor/extractor_callbacks.cpp index d3e130adf..ef76b7b1e 100644 --- a/src/extractor/extractor_callbacks.cpp +++ b/src/extractor/extractor_callbacks.cpp @@ -1,8 +1,8 @@ +#include "extractor/extractor_callbacks.hpp" #include "extractor/external_memory_node.hpp" #include "extractor/extraction_containers.hpp" #include "extractor/extraction_node.hpp" #include "extractor/extraction_way.hpp" -#include "extractor/extractor_callbacks.hpp" #include "extractor/guidance/road_classification.hpp" #include "extractor/restriction.hpp" @@ -34,8 +34,8 @@ namespace TurnLaneType = guidance::TurnLaneType; ExtractorCallbacks::ExtractorCallbacks(ExtractionContainers &extraction_containers) : external_memory(extraction_containers) { - // we reserved 0, 1, 2 for the empty case - string_map[MapKey("", "", "")] = 0; + // we reserved 0, 1, 2, 3 for the empty case + string_map[MapKey("", "", "", "")] = 0; lane_description_map[TurnLaneDescription()] = 0; } @@ -233,16 +233,16 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti } }; - // Deduplicates street names, destination names and refs based on the string_map map. - // In case we do not already store the name, inserts (name, id) tuple and return id. + // Deduplicates street names, refs, destinations, pronunciation based on the string_map. + // In case we do not already store the key, inserts (key, id) tuple and return id. // Otherwise fetches the id based on the name and returns it without insertion. const auto turn_lane_id_forward = requestId(parsed_way.turn_lanes_forward); const auto turn_lane_id_backward = requestId(parsed_way.turn_lanes_backward); const constexpr auto MAX_STRING_LENGTH = 255u; // Get the unique identifier for the street name, destination, and ref - const auto name_iterator = - string_map.find(MapKey(parsed_way.name, parsed_way.destinations, parsed_way.ref)); + const auto name_iterator = string_map.find( + MapKey(parsed_way.name, parsed_way.destinations, parsed_way.ref, parsed_way.pronunciation)); unsigned name_id = EMPTY_NAMEID; if (string_map.end() == name_iterator) { @@ -280,7 +280,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti std::back_inserter(external_memory.name_char_data)); external_memory.name_offsets.push_back(external_memory.name_char_data.size()); - auto k = MapKey{parsed_way.name, parsed_way.destinations, parsed_way.ref}; + auto k = MapKey{ + parsed_way.name, parsed_way.destinations, parsed_way.ref, parsed_way.pronunciation}; auto v = MapVal{name_id}; string_map.emplace(std::move(k), std::move(v)); }