Revert "switched to space separated suffix/prefix only"

This reverts commit e9e935303c.
This commit is contained in:
Patrick Niklaus 2016-04-27 23:20:10 +02:00
parent 21f64c75eb
commit e88106e990
No known key found for this signature in database
GPG Key ID: E426891B5F978B1B
3 changed files with 32 additions and 39 deletions

View File

@ -18,19 +18,6 @@ Feature: Suppress New Names on dedicated Suffices
| waypoints | route | turns | | waypoints | route | turns |
| a,c | 42 N,42 S | depart,arrive | | 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 Scenario: Suffix To Suffix - Turn
Given the node map Given the node map
| a | | b | | c | | a | | b | | c |

View File

@ -20,7 +20,6 @@
#include <cstdint> #include <cstdint>
#include <map> #include <map>
#include <string> #include <string>
#include <utility>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
@ -308,19 +307,6 @@ inline bool isDistinct(const DirectionModifier first, const DirectionModifier se
return true; return true;
} }
inline std::pair<std::string, std::string> 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, inline bool requiresNameAnnounced(const std::string &from,
const std::string &to, const std::string &to,
const SuffixTable &suffix_table) const SuffixTable &suffix_table)
@ -350,6 +336,12 @@ 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(from, from_name, from_ref);
split(to, to_name, to_ref); split(to, to_name, to_ref);
@ -366,22 +358,36 @@ inline bool requiresNameAnnounced(const std::string &from,
(from_ref.find(to_ref) != std::string::npos || to_ref.find(from_ref) != std::string::npos); (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 ref_is_removed = !from_ref.empty() && to_ref.empty();
const auto checkForPrefixOrSuffixChange = []( const auto checkForSuffixChange = [](const std::size_t common_length, const std::string &first,
const std::string &first, const std::string &second, const SuffixTable &suffix_table) { const std::string &second,
const SuffixTable &suffix_table) {
if (0 == common_length)
return false;
const auto first_prefix_and_suffixes = getPrefixAndSuffix(first); const auto endsOnSuffix = [](const std::size_t trim_length,
const auto second_prefix_and_suffixes = getPrefixAndSuffix(second); const std::string &string_with_possible_suffix,
// reverse strings, get suffices and reverse them to get prefixes const SuffixTable &suffix_table) {
auto suffix =
const auto isValid = [suffix_table](const std::string &orig, const std::string &delta) { string_with_possible_suffix.size() > trim_length
return orig.size() > delta.size() && (delta.empty() || suffix_table.isSuffix(delta)); ? 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);
}; };
return (isValid(first, first_prefix_and_suffixes.first) && isValid(second,second_prefix_and_suffixes.first)) || const auto first_delta_is_suffix = endsOnSuffix(common_length, first, suffix_table);
(isValid(first, first_prefix_and_suffixes.second) && isValid(second,second_prefix_and_suffixes.second)); const auto second_delta_is_suffix = endsOnSuffix(common_length, second, suffix_table);
return first_delta_is_suffix && second_delta_is_suffix;
}; };
const auto is_suffix_change = checkForPrefixOrSuffixChange(from_name, to_name, suffix_table); 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 obvious_change = (names_are_empty && refs_are_empty) || const auto obvious_change = (names_are_empty && refs_are_empty) ||
(names_are_equal && ref_is_contained) || (names_are_equal && ref_is_contained) ||

View File

@ -12,7 +12,7 @@ service_tag_restricted = { ["parking_aisle"] = true }
restriction_exception_tags = { "motorcar", "motor_vehicle", "vehicle" } restriction_exception_tags = { "motorcar", "motor_vehicle", "vehicle" }
-- A list of suffixes to suppress in name change instructions -- A list of suffixes to suppress in name change instructions
suffix_list = { "N", "NE", "E", "SE", "S", "SW", "W", "NW", "North", "South", "West", "East" } suffix_list = { "N", "NE", "E", "SE", "S", "SW", "W", "NW" }
speed_profile = { speed_profile = {
["motorway"] = 90, ["motorway"] = 90,