enable suppression name suffix changes
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "extractor/guidance/intersection.hpp"
|
||||
#include "extractor/query_node.hpp"
|
||||
#include "extractor/suffix_table.hpp"
|
||||
|
||||
#include "util/name_table.hpp"
|
||||
#include "util/node_based_graph.hpp"
|
||||
@@ -26,7 +27,8 @@ class IntersectionHandler
|
||||
public:
|
||||
IntersectionHandler(const util::NodeBasedDynamicGraph &node_based_graph,
|
||||
const std::vector<QueryNode> &node_info_list,
|
||||
const util::NameTable &name_table);
|
||||
const util::NameTable &name_table,
|
||||
const SuffixTable &street_name_suffix_table);
|
||||
virtual ~IntersectionHandler();
|
||||
|
||||
// check whether the handler can actually handle the intersection
|
||||
@@ -41,6 +43,7 @@ class IntersectionHandler
|
||||
const util::NodeBasedDynamicGraph &node_based_graph;
|
||||
const std::vector<QueryNode> &node_info_list;
|
||||
const util::NameTable &name_table;
|
||||
const SuffixTable &street_name_suffix_table;
|
||||
|
||||
// counts the number on allowed entry roads
|
||||
std::size_t countValid(const Intersection &intersection) const;
|
||||
|
||||
@@ -24,7 +24,8 @@ class MotorwayHandler : public IntersectionHandler
|
||||
public:
|
||||
MotorwayHandler(const util::NodeBasedDynamicGraph &node_based_graph,
|
||||
const std::vector<QueryNode> &node_info_list,
|
||||
const util::NameTable &name_table);
|
||||
const util::NameTable &name_table,
|
||||
const SuffixTable &street_name_suffix_table);
|
||||
~MotorwayHandler() override final;
|
||||
|
||||
// check whether the handler can actually handle the intersection
|
||||
|
||||
@@ -40,8 +40,9 @@ class RoundaboutHandler : public IntersectionHandler
|
||||
public:
|
||||
RoundaboutHandler(const util::NodeBasedDynamicGraph &node_based_graph,
|
||||
const std::vector<QueryNode> &node_info_list,
|
||||
const CompressedEdgeContainer &compressed_edge_container,
|
||||
const util::NameTable &name_table,
|
||||
const CompressedEdgeContainer &compressed_edge_container);
|
||||
const SuffixTable &street_name_suffix_table);
|
||||
|
||||
~RoundaboutHandler() override final;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "extractor/compressed_edge_container.hpp"
|
||||
#include "extractor/query_node.hpp"
|
||||
#include "extractor/suffix_table.hpp"
|
||||
|
||||
#include "extractor/guidance/classification_data.hpp"
|
||||
#include "extractor/guidance/discrete_angle.hpp"
|
||||
@@ -20,6 +21,7 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
namespace osrm
|
||||
@@ -305,7 +307,9 @@ inline bool isDistinct(const DirectionModifier first, const DirectionModifier se
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool requiresNameAnnounced(const std::string &from, const std::string &to)
|
||||
inline bool requiresNameAnnounced(const std::string &from,
|
||||
const std::string &to,
|
||||
const SuffixTable &suffix_table)
|
||||
{
|
||||
// FIXME, handle in profile to begin with?
|
||||
// this uses the encoding of references in the profile, which is very BAD
|
||||
@@ -332,12 +336,19 @@ inline bool requiresNameAnnounced(const std::string &from, const std::string &to
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
// check similarity of names
|
||||
const auto names_are_empty = from_name.empty() && to_name.empty();
|
||||
const auto name_is_contained = boost::starts_with(from_name,to_name) || boost::starts_with(to_name,from_name);
|
||||
const auto name_is_contained =
|
||||
boost::starts_with(from_name, to_name) || boost::starts_with(to_name, from_name);
|
||||
const auto names_are_equal = from_name == to_name || name_is_contained;
|
||||
const auto name_is_removed = !from_name.empty() && to_name.empty();
|
||||
// references are contained in one another
|
||||
@@ -347,9 +358,41 @@ inline bool requiresNameAnnounced(const std::string &from, const std::string &to
|
||||
(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 obvious_change =
|
||||
(names_are_empty && refs_are_empty) || (names_are_equal && ref_is_contained) ||
|
||||
(names_are_equal && refs_are_empty) || name_is_removed || ref_is_removed;
|
||||
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 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_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;
|
||||
};
|
||||
|
||||
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) ||
|
||||
(names_are_equal && ref_is_contained) ||
|
||||
(names_are_equal && refs_are_empty) || name_is_removed ||
|
||||
ref_is_removed || is_suffix_change;
|
||||
|
||||
return !obvious_change;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "extractor/guidance/turn_handler.hpp"
|
||||
#include "extractor/query_node.hpp"
|
||||
#include "extractor/restriction_map.hpp"
|
||||
#include "extractor/suffix_table.hpp"
|
||||
|
||||
#include "util/name_table.hpp"
|
||||
#include "util/node_based_graph.hpp"
|
||||
@@ -39,7 +40,8 @@ class TurnAnalysis
|
||||
const RestrictionMap &restriction_map,
|
||||
const std::unordered_set<NodeID> &barrier_nodes,
|
||||
const CompressedEdgeContainer &compressed_edge_container,
|
||||
const util::NameTable &name_table);
|
||||
const util::NameTable &name_table,
|
||||
const SuffixTable &street_name_suffix_table);
|
||||
|
||||
// the entry into the turn analysis
|
||||
std::vector<TurnOperation> getTurns(const NodeID from_node, const EdgeID via_eid) const;
|
||||
|
||||
@@ -26,7 +26,8 @@ class TurnHandler : public IntersectionHandler
|
||||
public:
|
||||
TurnHandler(const util::NodeBasedDynamicGraph &node_based_graph,
|
||||
const std::vector<QueryNode> &node_info_list,
|
||||
const util::NameTable &name_table);
|
||||
const util::NameTable &name_table,
|
||||
const SuffixTable &street_name_suffix_table);
|
||||
~TurnHandler() override final;
|
||||
|
||||
// check whether the handler can actually handle the intersection
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef OSRM_EXTRACTOR_SUFFIX_LIST_HPP_
|
||||
#define OSRM_EXTRACTOR_SUFFIX_LIST_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
struct lua_State;
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace extractor
|
||||
{
|
||||
// A table containing suffixes.
|
||||
// At the moment, it is only a front for an unordered set. At some point we might want to make it
|
||||
// country dependent and have it behave accordingly
|
||||
class SuffixTable final
|
||||
{
|
||||
public:
|
||||
SuffixTable(lua_State *lua_state);
|
||||
|
||||
// check whether a string is part of the know suffix list
|
||||
bool isSuffix(const std::string &possible_suffix) const;
|
||||
|
||||
private:
|
||||
std::unordered_set<std::string> suffix_set;
|
||||
};
|
||||
} /* namespace extractor */
|
||||
} /* namespace osrm */
|
||||
|
||||
#endif /* OSRM_EXTRACTOR_SUFFIX_LIST_HPP_ */
|
||||
Reference in New Issue
Block a user