From e9e935303ce204d1c86fffaf46f48c966633dc23 Mon Sep 17 00:00:00 2001 From: Moritz Kobitzsch Date: Wed, 27 Apr 2016 18:08:15 +0200 Subject: [PATCH] switched to space separated suffix/prefix only --- features/guidance/suffix-changes.feature | 13 ++++++ include/extractor/guidance/toolkit.hpp | 56 +++++++++++------------- profiles/car.lua | 2 +- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/features/guidance/suffix-changes.feature b/features/guidance/suffix-changes.feature index e389506db..c456486cb 100644 --- a/features/guidance/suffix-changes.feature +++ b/features/guidance/suffix-changes.feature @@ -18,6 +18,19 @@ Feature: Suppress New Names on dedicated Suffices | waypoints | route | turns | | a,c | 42 N,42 S | depart,arrive | + Scenario: Prefix Change + Given the node map + | a | | b | | c | + + And the ways + | nodes | name | + | ab | West 42 | + | bc | East 42 | + + When I route I should get + | waypoints | route | turns | + | a,c | West 42,East 42 | depart,arrive | + Scenario: Suffix To Suffix - Turn Given the node map | a | | b | | c | diff --git a/include/extractor/guidance/toolkit.hpp b/include/extractor/guidance/toolkit.hpp index c80ef4205..9a16722f0 100644 --- a/include/extractor/guidance/toolkit.hpp +++ b/include/extractor/guidance/toolkit.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -307,6 +308,19 @@ inline bool isDistinct(const DirectionModifier first, const DirectionModifier se return true; } +inline std::pair getPrefixAndSuffix(const std::string &data) +{ + const auto suffix_pos = data.find_last_of(' '); + if( suffix_pos == std::string::npos ) + return {}; + + const auto prefix_pos = data.find_first_of(' '); + auto result = std::make_pair(data.substr(0,prefix_pos), data.substr(suffix_pos+1)); + boost::to_lower(result.first); + boost::to_lower(result.second); + return result; +} + inline bool requiresNameAnnounced(const std::string &from, const std::string &to, const SuffixTable &suffix_table) @@ -336,12 +350,6 @@ inline bool requiresNameAnnounced(const std::string &from, } }; - const auto getCommonLength = [](const std::string &first, const std::string &second) { - BOOST_ASSERT(first.size() <= second.size()); - const auto mismatch_result = std::mismatch(first.begin(), first.end(), second.begin()); - return std::distance(first.begin(), mismatch_result.first); - }; - split(from, from_name, from_ref); split(to, to_name, to_ref); @@ -358,36 +366,22 @@ inline bool requiresNameAnnounced(const std::string &from, (from_ref.find(to_ref) != std::string::npos || to_ref.find(from_ref) != std::string::npos); const auto ref_is_removed = !from_ref.empty() && to_ref.empty(); - const auto checkForSuffixChange = [](const std::size_t common_length, const std::string &first, - const std::string &second, - const SuffixTable &suffix_table) { - if (0 == common_length) - return false; + const auto checkForPrefixOrSuffixChange = []( + const std::string &first, const std::string &second, const SuffixTable &suffix_table) { - const auto endsOnSuffix = [](const std::size_t trim_length, - const std::string &string_with_possible_suffix, - const SuffixTable &suffix_table) { - auto suffix = - string_with_possible_suffix.size() > trim_length - ? string_with_possible_suffix.substr( - trim_length + (string_with_possible_suffix[trim_length] == ' ' ? 1 : 0)) - : " "; - boost::algorithm::to_lower(suffix); - return suffix.empty() || suffix_table.isSuffix(suffix); + const auto first_prefix_and_suffixes = getPrefixAndSuffix(first); + const auto second_prefix_and_suffixes = getPrefixAndSuffix(second); + // reverse strings, get suffices and reverse them to get prefixes + + const auto isValid = [suffix_table](const std::string &orig, const std::string &delta) { + return orig.size() > delta.size() && (delta.empty() || suffix_table.isSuffix(delta)); }; - const auto first_delta_is_suffix = endsOnSuffix(common_length, first, suffix_table); - const auto second_delta_is_suffix = endsOnSuffix(common_length, second, suffix_table); - - return first_delta_is_suffix && second_delta_is_suffix; + return (isValid(first, first_prefix_and_suffixes.first) && isValid(second,second_prefix_and_suffixes.first)) || + (isValid(first, first_prefix_and_suffixes.second) && isValid(second,second_prefix_and_suffixes.second)); }; - const auto common_length = from_name.size() < to_name.size() - ? getCommonLength(from_name, to_name) - : getCommonLength(to_name, from_name); - - const auto is_suffix_change = - checkForSuffixChange(common_length, from_name, to_name, suffix_table); + const auto is_suffix_change = checkForPrefixOrSuffixChange(from_name, to_name, suffix_table); const auto obvious_change = (names_are_empty && refs_are_empty) || (names_are_equal && ref_is_contained) || diff --git a/profiles/car.lua b/profiles/car.lua index 4855dcf73..c2ca53efc 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -12,7 +12,7 @@ service_tag_restricted = { ["parking_aisle"] = true } restriction_exception_tags = { "motorcar", "motor_vehicle", "vehicle" } -- A list of suffixes to suppress in name change instructions -suffix_list = { "N", "NE", "E", "SE", "S", "SW", "W", "NW" } +suffix_list = { "N", "NE", "E", "SE", "S", "SW", "W", "NW", "North", "South", "West", "East" } speed_profile = { ["motorway"] = 90,