From dcc1b5ab2b89a7908cde30045ae57ef4a9268e93 Mon Sep 17 00:00:00 2001 From: karenzshea Date: Mon, 5 Sep 2016 09:01:51 -0400 Subject: [PATCH] return name and reference separately --- CHANGELOG.md | 2 ++ docs/http.md | 3 ++- features/bicycle/names.feature | 4 ++-- features/bicycle/ref.feature | 8 +++---- features/car/names.feature | 12 +++++------ features/foot/names.feature | 2 +- features/foot/ref.feature | 6 +++--- .../guidance/dedicated-turn-roads.feature | 4 ++-- features/guidance/destination-signs.feature | 20 +++++++++--------- features/guidance/roundabout.feature | 6 +++--- features/guidance/suffix-changes.feature | 8 +++---- features/guidance/suppressed.feature | 4 ++-- features/support/route.js | 4 ++++ features/support/shared_steps.js | 4 +++- include/engine/datafacade/datafacade_base.hpp | 2 ++ .../engine/datafacade/internal_datafacade.hpp | 9 ++++++++ .../engine/datafacade/shared_datafacade.hpp | 13 ++++++++++-- include/engine/guidance/assemble_steps.hpp | 5 +++++ include/engine/guidance/route_step.hpp | 6 ++++-- include/extractor/extraction_way.hpp | 2 ++ include/extractor/extractor_callbacks.hpp | 21 ++++++++++++++++--- profiles/bicycle.lua | 13 ++++++------ profiles/car.lua | 14 +++++-------- profiles/foot.lua | 9 ++++---- src/engine/api/json_factory.cpp | 1 + src/engine/guidance/post_processing.cpp | 2 ++ src/extractor/extractor_callbacks.cpp | 19 ++++++++++------- src/extractor/scripting_environment_lua.cpp | 1 + unit_tests/mocks/mock_datafacade.hpp | 1 + 29 files changed, 131 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4feea86ea..35e9090b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,13 @@ - includes library guidance.lua that offers preliminary configuration on guidance. - added left_hand_driving flag in global profile properties - modified turn penalty function for car profile - better fit to real data + - return `ref` and `name` as separate fields. Do no use ref or destination as fallback for name value - Guidance - Handle Access tags for lanes, only considering valid lanes in lane-guidance (think car | car | bike | car) - API: - `annotations=true` now returns the data source id for each segment as `datasources` - Reduced semantic of merge to refer only to merges from a lane onto a motorway-like road + - new `ref` field in the `RouteStep` object. It contains the reference code or name of a way. Previously merged into the `name` property like `name (ref)` and are now separate fields. - Bugfixes - Fixed an issue that would result in segfaults for viaroutes with an invalid intermediate segment when u-turns were allowed at the via-location - Invalid only_* restrictions could result in loss of connectivity. As a fallback, we assume all turns allowed when the restriction is not valid diff --git a/docs/http.md b/docs/http.md index 04b01b653..778902344 100644 --- a/docs/http.md +++ b/docs/http.md @@ -40,7 +40,7 @@ http://{server}/{service}/{version}/{profile}/{coordinates}[.{format}]?option=va - `version`: Version of the protocol implemented by the service. - `profile`: Mode of transportation, is determined by the profile that is used to prepare the data - `coordinates`: String of format `{longitude},{latitude};{longitude},{latitude}[;{longitude},{latitude} ...]` or `polyline({polyline})`. -- `format`: Only `json` is supportest at the moment. This parameter is optional and defaults to `json`. +- `format`: Only `json` is supported at the moment. This parameter is optional and defaults to `json`. Passing any `option=value` is optional. `polyline` follows Google's polyline format with precision 5 and can be generated using [this package](https://www.npmjs.com/package/polyline). To pass parameters to each location some options support an array like encoding: @@ -469,6 +469,7 @@ step. | geojson | [GeoJSON `LineString`](http://geojson.org/geojson-spec.html#linestring) or [GeoJSON `Point`](http://geojson.org/geojson-spec.html#point) if it is only one coordinate (not wrapped by a GeoJSON feature)| - `name`: The name of the way along which travel proceeds. +- `ref`: A reference number or code for the way. Optionally included, if ref data is available for the given way. - `pronunciation`: The pronunciation hint of the way name. Will be `undefined` if there is no pronunciation hit. - `destinations`: The destinations of the way. Will be `undefined` if there are no destinations. - `mode`: A string signifying the mode of transportation. diff --git a/features/bicycle/names.feature b/features/bicycle/names.feature index b19685704..38b1d2ea7 100644 --- a/features/bicycle/names.feature +++ b/features/bicycle/names.feature @@ -15,8 +15,8 @@ Feature: Bike - Street names in instructions | bc | Your Way | A7 | When I route I should get - | from | to | route | - | a | c | My Way (A6),Your Way (A7),Your Way (A7) | + | from | to | route | ref | + | a | c | My Way,Your Way,Your Way | A6,A7,A7 | @unnamed Scenario: Bike - Use way type to describe unnamed ways diff --git a/features/bicycle/ref.feature b/features/bicycle/ref.feature index a9c908442..8c64232fa 100644 --- a/features/bicycle/ref.feature +++ b/features/bicycle/ref.feature @@ -13,8 +13,8 @@ Feature: Bike - Way ref | ab | Utopia Drive | E7 | When I route I should get - | from | to | route | - | a | b | Utopia Drive (E7),Utopia Drive (E7) | + | from | to | route | ref | + | a | b | Utopia Drive,Utopia Drive | E7,E7 | Scenario: Bike - Way with only ref Given the node map @@ -25,8 +25,8 @@ Feature: Bike - Way ref | ab | | E7 | When I route I should get - | from | to | route | - | a | b | E7,E7 | + | from | to | route | ref | + | a | b | {highway:primary},{highway:primary} | E7,E7 | Scenario: Bike - Way with only name Given the node map diff --git a/features/car/names.feature b/features/car/names.feature index e03a0308a..d95c9f2ee 100644 --- a/features/car/names.feature +++ b/features/car/names.feature @@ -15,8 +15,8 @@ Feature: Car - Street names in instructions | bc | Your Way | A1 | When I route I should get - | from | to | route | - | a | c | My Way,Your Way (A1),Your Way (A1) | + | from | to | route | ref | + | a | c | My Way,Your Way,Your Way | ,A1,A1| Scenario: Car - A named street with pronunciation Given the node map @@ -25,15 +25,15 @@ Feature: Car - Street names in instructions | | c | | And the ways - | nodes | name |name:pronunciation | ref | + | nodes | name |name:pronunciation | ref | | ab | My Way | | | | bd | My Way | meyeway | A1 | | cd | Your Way | yourewaye | | When I route I should get - | from | to | route | pronunciations | - | a | d | My Way,My Way (A1) | ,meyeway | - | 1 | c | Your Way,Your Way | yourewaye,yourewaye | + | from | to | route | pronunciations | ref | + | a | d | My Way,My Way | ,meyeway | ,A1 | + | 1 | c | Your Way,Your Way | yourewaye,yourewaye | , | @todo Scenario: Car - Use way type to describe unnamed ways diff --git a/features/foot/names.feature b/features/foot/names.feature index 6a28aaf31..2c3d76bf6 100644 --- a/features/foot/names.feature +++ b/features/foot/names.feature @@ -16,7 +16,7 @@ Feature: Foot - Street names in instructions When I route I should get | from | to | route | - | a | c | My Way (A6),Your Way (B7),Your Way (B7) | + | a | c | My Way,Your Way,Your Way | @unnamed Scenario: Foot - Use way type to describe unnamed ways diff --git a/features/foot/ref.feature b/features/foot/ref.feature index 39bc3e8dc..a99c24bb3 100644 --- a/features/foot/ref.feature +++ b/features/foot/ref.feature @@ -14,7 +14,7 @@ Feature: Foot - Way ref When I route I should get | from | to | route | - | a | b | Utopia Drive (E7),Utopia Drive (E7) | + | a | b | Utopia Drive,Utopia Drive | Scenario: Foot - Way with only ref Given the node map @@ -25,8 +25,8 @@ Feature: Foot - Way ref | ab | | E7 | When I route I should get - | from | to | route | - | a | b | E7,E7 | + | from | to | route | + | a | b | {highway:primary},{highway:primary} | Scenario: Foot - Way with only name Given the node map diff --git a/features/guidance/dedicated-turn-roads.feature b/features/guidance/dedicated-turn-roads.feature index ad0e2d68b..aa9e9be37 100644 --- a/features/guidance/dedicated-turn-roads.feature +++ b/features/guidance/dedicated-turn-roads.feature @@ -165,8 +165,8 @@ Feature: Slipways and Dedicated Turn Lanes | qe | secondary_link | Ettlinger Allee | | yes | When I route I should get - | waypoints | route | turns | - | a,o | Schwarzwaldstrasse (L561),Ettlinger Allee,Ettlinger Allee | depart,turn right,arrive | + | waypoints | route | turns | ref | + | a,o | Schwarzwaldstrasse,Ettlinger Allee,Ettlinger Allee | depart,turn right,arrive | L561,, | Scenario: Traffic Lights everywhere #http://map.project-osrm.org/?z=18¢er=48.995336%2C8.383813&loc=48.995467%2C8.384548&loc=48.995115%2C8.382761&hl=en&alt=0 diff --git a/features/guidance/destination-signs.feature b/features/guidance/destination-signs.feature index 3c5aa4e69..73f90d9b0 100644 --- a/features/guidance/destination-signs.feature +++ b/features/guidance/destination-signs.feature @@ -29,13 +29,13 @@ Feature: Destination Signs | qr | QR | | | A1;A2 | yes | | When I route I should get - | from | to | route | destinations | # | - | a | b | AB (E1),AB (E1) | , | | - | c | d | CD (Berlin),CD (Berlin) | Berlin,Berlin | | - | e | f | EF (A1: Berlin),EF (A1: Berlin) | A1: Berlin,A1: Berlin | | - | g | h | , | A1: Berlin,A1: Berlin | | - | i | j | , | Berlin,Berlin | | - | k | l | KL (E1),KL (E1) | A1: Berlin,A1: Berlin | | - | m | n | MN (A1, A2: Berlin, Hamburg),MN (A1, A2: Berlin, Hamburg) | A1, A2: Berlin, Hamburg,A1, A2: Berlin, Hamburg | | - | o | p | OP,OP | , | guard against mis-tagging | - | q | r | QR (A1, A2),QR (A1, A2) | A1, A2,A1, A2 | | + | from | to | route | destinations | ref | # | + | a | b | AB,AB | , | E1,E1 | | + | c | d | CD,CD | Berlin,Berlin | , | | + | e | f | EF,EF | A1: Berlin,A1: Berlin | , | | + | g | h | , | A1: Berlin,A1: Berlin | , | | + | i | j | , | Berlin,Berlin | , | | + | k | l | KL,KL | A1: Berlin,A1: Berlin | E1,E1 | | + | m | n | MN,MN | A1, A2: Berlin, Hamburg,A1, A2: Berlin, Hamburg | , | | + | o | p | OP,OP | , | , | guard against mis-tagging | + | q | r | QR,QR | A1, A2,A1, A2 | , | | diff --git a/features/guidance/roundabout.feature b/features/guidance/roundabout.feature index 9700cae89..4dcd0f0d8 100644 --- a/features/guidance/roundabout.feature +++ b/features/guidance/roundabout.feature @@ -283,9 +283,9 @@ Feature: Basic Roundabout | dmg | roundabout | | trunk_link | yes | | When I route I should get - | waypoints | route | turns | - | a,e | crescent (US 130),crescent (US 130),crescent (US 130) | depart,roundabout-exit-3,arrive | - | j,l | NJ 38,NJ 38,NJ 38 | depart,roundabout-exit-2,arrive | + | waypoints | route | turns | ref | + | a,e | crescent,crescent,crescent | depart,roundabout-exit-3,arrive | US 130,US 130,US 130 | + | j,l | ,, | depart,roundabout-exit-2,arrive | NJ 38,NJ 38,NJ 38 | Scenario: Double Roundabout with through-lane #http://map.project-osrm.org/?z=18¢er=38.911752%2C-77.048667&loc=38.912003%2C-77.050831&loc=38.909277%2C-77.042516&hl=en&alt=0 diff --git a/features/guidance/suffix-changes.feature b/features/guidance/suffix-changes.feature index 06a5d2189..ae7a79a45 100644 --- a/features/guidance/suffix-changes.feature +++ b/features/guidance/suffix-changes.feature @@ -28,8 +28,8 @@ Feature: Suppress New Names on dedicated Suffices | bc | 42 S | 101 | When I route I should get - | waypoints | route | turns | - | a,c | 42 N,42 S (101) | depart,arrive | + | waypoints | route | turns | ref | + | a,c | 42 N,42 S | depart,arrive | ,101 | Scenario: Prefix Change Given the node map @@ -67,8 +67,8 @@ Feature: Suppress New Names on dedicated Suffices | bc | East 42 | | When I route I should get - | waypoints | route | turns | - | a,c | West 42 (101),East 42 | depart,arrive | + | waypoints | route | turns | ref | + | a,c | West 42,East 42 | depart,arrive | 101, | Scenario: Suffix To Suffix - Turn Given the node map diff --git a/features/guidance/suppressed.feature b/features/guidance/suppressed.feature index 89b58655c..02555add5 100644 --- a/features/guidance/suppressed.feature +++ b/features/guidance/suppressed.feature @@ -32,8 +32,8 @@ Feature: Suppressed Turns | ef | motorway | highway | A1 | When I route I should get - | waypoints | route | turns | - | a,f | highway (A1),highway (A1) | depart,arrive | + | waypoints | route | turns | ref | + | a,f | highway,highway | depart,arrive | A1,A1 | Scenario: Don't Announce Turn on following major road class -- service diff --git a/features/support/route.js b/features/support/route.js index 56e5c9e1e..408a2a4e5 100644 --- a/features/support/route.js +++ b/features/support/route.js @@ -139,6 +139,10 @@ module.exports = function () { return this.extractInstructionList(instructions, s => s.name); }; + this.refList = (instructions) => { + return this.extractInstructionList(instructions, s => s.ref || ''); + }; + this.pronunciationList = (instructions) => { return this.extractInstructionList(instructions, s => s.pronunciation || ''); }; diff --git a/features/support/shared_steps.js b/features/support/shared_steps.js index bd6850ab3..40c0a6530 100644 --- a/features/support/shared_steps.js +++ b/features/support/shared_steps.js @@ -34,7 +34,7 @@ module.exports = function () { var afterRequest = (err, res, body) => { if (err) return cb(err); if (body && body.length) { - let destinations, pronunciations, instructions, bearings, turns, modes, times, + let destinations, pronunciations, instructions, refs, bearings, turns, modes, times, distances, summary, intersections, lanes; let json = JSON.parse(body); @@ -44,6 +44,7 @@ module.exports = function () { if (hasRoute) { instructions = this.wayList(json.routes[0]); pronunciations = this.pronunciationList(json.routes[0]); + refs = this.refList(json.routes[0]); destinations = this.destinationsList(json.routes[0]); bearings = this.bearingList(json.routes[0]); turns = this.turnList(json.routes[0]); @@ -128,6 +129,7 @@ module.exports = function () { if (headers.has(key)) got[key] = instructions ? value : ''; }; + putValue('ref', refs); putValue('bearing', bearings); putValue('turns', turns); putValue('modes', modes); diff --git a/include/engine/datafacade/datafacade_base.hpp b/include/engine/datafacade/datafacade_base.hpp index 81cdde129..e837e0730 100644 --- a/include/engine/datafacade/datafacade_base.hpp +++ b/include/engine/datafacade/datafacade_base.hpp @@ -152,6 +152,8 @@ class BaseDataFacade virtual std::string GetNameForID(const unsigned name_id) const = 0; + virtual std::string GetRefForID(const unsigned name_id) const = 0; + virtual std::string GetPronunciationForID(const unsigned name_id) const = 0; virtual std::string GetDestinationsForID(const unsigned name_id) const = 0; diff --git a/include/engine/datafacade/internal_datafacade.hpp b/include/engine/datafacade/internal_datafacade.hpp index e7dc965d8..20dfe89a5 100644 --- a/include/engine/datafacade/internal_datafacade.hpp +++ b/include/engine/datafacade/internal_datafacade.hpp @@ -636,6 +636,15 @@ class InternalDataFacade final : public BaseDataFacade return result; } + std::string GetRefForID(const unsigned name_id) const override final + { + // We store the ref after the name, destination and pronunciation of a street. + // We do this to get around the street length limit of 255 which would hit + // if we concatenate these. Order (see extractor_callbacks): + // name (0), destination (1), pronunciation (2), ref (3) + return GetNameForID(name_id + 3); + } + std::string GetPronunciationForID(const unsigned name_id) const override final { // We store the pronunciation after the name and destination of a street. diff --git a/include/engine/datafacade/shared_datafacade.hpp b/include/engine/datafacade/shared_datafacade.hpp index 3622c0a0f..eb58c5743 100644 --- a/include/engine/datafacade/shared_datafacade.hpp +++ b/include/engine/datafacade/shared_datafacade.hpp @@ -707,12 +707,21 @@ class SharedDataFacade final : public BaseDataFacade return result; } + std::string GetRefForID(const unsigned name_id) const override final + { + // We store the ref after the name, destination and pronunciation of a street. + // We do this to get around the street length limit of 255 which would hit + // if we concatenate these. Order (see extractor_callbacks): + // name (0), destination (1), pronunciation (2), ref (3) + return GetNameForID(name_id + 3); + } + std::string GetPronunciationForID(const unsigned name_id) const override final { // We store the pronunciation after the name and destination of a street. // We do this to get around the street length limit of 255 which would hit // if we concatenate these. Order (see extractor_callbacks): - // name (0), destination (1), pronunciation (2) + // name (0), destination (1), pronunciation (2), ref (3) return GetNameForID(name_id + 2); } @@ -721,7 +730,7 @@ class SharedDataFacade final : public BaseDataFacade // We store the destination after the name of a street. // We do this to get around the street length limit of 255 which would hit // if we concatenate these. Order (see extractor_callbacks): - // name (0), destination (1), pronunciation (2) + // name (0), destination (1), pronunciation (2), ref (3) return GetNameForID(name_id + 1); } diff --git a/include/engine/guidance/assemble_steps.hpp b/include/engine/guidance/assemble_steps.hpp index c930dab5d..116312f22 100644 --- a/include/engine/guidance/assemble_steps.hpp +++ b/include/engine/guidance/assemble_steps.hpp @@ -103,12 +103,14 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa { BOOST_ASSERT(segment_duration >= 0); const auto name = facade.GetNameForID(step_name_id); + const auto ref = facade.GetRefForID(step_name_id); const auto pronunciation = facade.GetPronunciationForID(step_name_id); const auto destinations = facade.GetDestinationsForID(step_name_id); const auto distance = leg_geometry.segment_distances[segment_index]; steps.push_back(RouteStep{step_name_id, std::move(name), + std::move(ref), std::move(pronunciation), std::move(destinations), NO_ROTARY_NAME, @@ -168,6 +170,7 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa BOOST_ASSERT(duration >= 0); steps.push_back(RouteStep{step_name_id, facade.GetNameForID(step_name_id), + facade.GetRefForID(step_name_id), facade.GetPronunciationForID(step_name_id), facade.GetDestinationsForID(step_name_id), NO_ROTARY_NAME, @@ -194,6 +197,7 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa steps.push_back(RouteStep{source_node.name_id, facade.GetNameForID(source_node.name_id), + facade.GetRefForID(source_node.name_id), facade.GetPronunciationForID(source_node.name_id), facade.GetDestinationsForID(source_node.name_id), NO_ROTARY_NAME, @@ -229,6 +233,7 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa BOOST_ASSERT(!leg_geometry.locations.empty()); steps.push_back(RouteStep{target_node.name_id, facade.GetNameForID(target_node.name_id), + facade.GetRefForID(target_node.name_id), facade.GetPronunciationForID(target_node.name_id), facade.GetDestinationsForID(target_node.name_id), NO_ROTARY_NAME, diff --git a/include/engine/guidance/route_step.hpp b/include/engine/guidance/route_step.hpp index 6435137a7..5e15c8a66 100644 --- a/include/engine/guidance/route_step.hpp +++ b/include/engine/guidance/route_step.hpp @@ -25,10 +25,10 @@ namespace guidance // a --> b --> c // this struct saves the information of the segment b,c. // Notable exceptions are Departure and Arrival steps. -// Departue: s --> a --> b. Represents the segment s,a with location being s. +// Departure: s --> a --> b. Represents the segment s,a with location being s. // Arrive: a --> b --> t. The segment (b,t) is already covered by the previous segment. -// A represenetation of intermediate intersections +// A representation of intermediate intersections struct Intersection { static const constexpr std::size_t NO_INDEX = std::numeric_limits::max(); @@ -58,6 +58,7 @@ struct RouteStep { unsigned name_id; std::string name; + std::string ref; std::string pronunciation; std::string destinations; std::string rotary_name; @@ -80,6 +81,7 @@ inline RouteStep getInvalidRouteStep() "", "", "", + "", 0, 0, TRAVEL_MODE_INACCESSIBLE, diff --git a/include/extractor/extraction_way.hpp b/include/extractor/extraction_way.hpp index 9ac9da1c4..8024f6b92 100644 --- a/include/extractor/extraction_way.hpp +++ b/include/extractor/extraction_way.hpp @@ -33,6 +33,7 @@ struct ExtractionWay is_startpoint = true; is_access_restricted = false; name.clear(); + ref.clear(); pronunciation.clear(); destinations.clear(); forward_travel_mode = TRAVEL_MODE_INACCESSIBLE; @@ -53,6 +54,7 @@ struct ExtractionWay double backward_speed; double duration; std::string name; + std::string ref; std::string pronunciation; std::string destinations; std::string turn_lanes_forward; diff --git a/include/extractor/extractor_callbacks.hpp b/include/extractor/extractor_callbacks.hpp index dd11c86cf..80bfca69a 100644 --- a/include/extractor/extractor_callbacks.hpp +++ b/include/extractor/extractor_callbacks.hpp @@ -16,6 +16,21 @@ class Node; class Way; } +namespace std +{ +template <> struct hash> +{ + 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)); + return seed; + } +}; +} + namespace osrm { namespace extractor @@ -27,7 +42,7 @@ struct ExtractionNode; struct ExtractionWay; /** - * This class is uses by the extractor with the results of the + * This class is used by the extractor with the results of the * osmium based parsing and the customization through the lua profile. * * It mediates between the multi-threaded extraction process and the external memory containers. @@ -37,9 +52,9 @@ class ExtractorCallbacks { private: // used to deduplicate street names and street destinations: actually maps to name ids - using MapKey = std::pair; + using MapKey = std::tuple; using MapVal = unsigned; - std::unordered_map> string_map; + std::unordered_map string_map; guidance::LaneDescriptionMap lane_description_map; ExtractionContainers &external_memory; diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index cfdb50aae..7bcc65ef7 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -211,19 +211,20 @@ function way_function (way, result) local bicycle = way:get_value_by_key("bicycle") -- name - if ref and "" ~= ref and name and "" ~= name then - result.name = name .. " (" .. ref .. ")" - elseif ref and "" ~= ref then - result.name = ref - elseif name and "" ~= name then + if name and "" ~= name then result.name = name -- TODO find a better solution for encoding way type elseif fallback_names and highway then -- if no name exists, use way type - -- this encoding scheme is excepted to be a temporary solution + -- this encoding scheme is expected to be a temporary solution result.name = "{highway:"..highway.."}" end + -- ref + if ref and "" ~= ref then + result.ref = ref + end + -- roundabout handling if junction and "roundabout" == junction then result.roundabout = true diff --git a/profiles/car.lua b/profiles/car.lua index 9daff8ff7..e9cb11d1c 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -387,14 +387,14 @@ function way_function (way, result) local has_name = name and "" ~= name local has_pronunciation = pronunciation and "" ~= pronunciation - if has_name and has_ref then - result.name = name .. " (" .. ref .. ")" - elseif has_ref then - result.name = ref - elseif has_name then + if has_name then result.name = name end + if has_ref then + result.ref = ref + end + if has_pronunciation then result.pronunciation = pronunciation end @@ -456,10 +456,6 @@ function way_function (way, result) local destination = get_destination(way) local has_destination = destination and "" ~= destination - if has_destination and has_name and not has_ref then - result.name = name .. " (" .. destination .. ")" - end - result.destinations = destination end end diff --git a/profiles/foot.lua b/profiles/foot.lua index 002f06d78..25ed19fd1 100644 --- a/profiles/foot.lua +++ b/profiles/foot.lua @@ -150,16 +150,15 @@ function way_function (way, result) local surface = way:get_value_by_key("surface") -- name - if ref and "" ~= ref and name and "" ~= name then - result.name = name .. " (" .. ref .. ")" - elseif ref and "" ~= ref then - result.name = ref - elseif name and "" ~= name then + if name and "" ~= name then result.name = name elseif highway and fallback_names then result.name = "{highway:"..highway.."}" -- if no name exists, use way type -- this encoding scheme is excepted to be a temporary solution end + if ref and "" ~= ref then + result.ref = ref + end -- roundabouts if "roundabout" == junction then diff --git a/src/engine/api/json_factory.cpp b/src/engine/api/json_factory.cpp index 9252bd0de..8ebfac8b5 100644 --- a/src/engine/api/json_factory.cpp +++ b/src/engine/api/json_factory.cpp @@ -235,6 +235,7 @@ util::json::Object makeRouteStep(guidance::RouteStep step, util::json::Value geo route_step.values["distance"] = std::round(step.distance * 10) / 10.; route_step.values["duration"] = std::round(step.duration * 10) / 10.; route_step.values["name"] = std::move(step.name); + if (!step.ref.empty()) route_step.values["ref"] = std::move(step.ref); if (!step.pronunciation.empty()) route_step.values["pronunciation"] = std::move(step.pronunciation); if (!step.destinations.empty()) diff --git a/src/engine/guidance/post_processing.cpp b/src/engine/guidance/post_processing.cpp index 3dbe0a214..4f0582ab9 100644 --- a/src/engine/guidance/post_processing.cpp +++ b/src/engine/guidance/post_processing.cpp @@ -52,6 +52,8 @@ inline void forwardStepSignage(RouteStep &destination, const RouteStep &origin) destination.name = origin.name; destination.pronunciation = origin.pronunciation; destination.destinations = origin.destinations; + destination.destinations = origin.destinations; + destination.ref = origin.ref; } inline bool choiceless(const RouteStep &step, const RouteStep &previous) diff --git a/src/extractor/extractor_callbacks.cpp b/src/extractor/extractor_callbacks.cpp index 55bfff4a6..b9c6e547a 100644 --- a/src/extractor/extractor_callbacks.cpp +++ b/src/extractor/extractor_callbacks.cpp @@ -35,9 +35,7 @@ ExtractorCallbacks::ExtractorCallbacks(ExtractionContainers &extraction_containe : external_memory(extraction_containers) { // we reserved 0, 1, 2 for the empty case - string_map[MapKey("", "")] = 0; - - // The map should be empty before we start initializing it + string_map[MapKey("", "", "")] = 0; lane_description_map[TurnLaneDescription()] = 0; } @@ -235,16 +233,15 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti } }; - // Deduplicates street names and street destination names based on the street_map map. + // 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. // 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 - // Get the unique identifier for the street name and destination - const auto name_iterator = string_map.find(MapKey(parsed_way.name, parsed_way.destinations)); + // 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)); unsigned name_id = EMPTY_NAMEID; if (string_map.end() == name_iterator) { @@ -253,6 +250,7 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti std::min(MAX_STRING_LENGTH, parsed_way.destinations.size()); const auto pronunciation_length = std::min(MAX_STRING_LENGTH, parsed_way.pronunciation.size()); + const auto ref_length = std::min(MAX_STRING_LENGTH, parsed_way.ref.size()); // name_offsets already has an offset of a new name, take the offset index as the name id name_id = external_memory.name_offsets.size() - 1; @@ -275,7 +273,12 @@ 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}; + std::copy(parsed_way.ref.c_str(), + parsed_way.ref.c_str() + ref_length, + 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 v = MapVal{name_id}; string_map.emplace(std::move(k), std::move(v)); } diff --git a/src/extractor/scripting_environment_lua.cpp b/src/extractor/scripting_environment_lua.cpp index f6c2cffe8..b0aadf97e 100644 --- a/src/extractor/scripting_environment_lua.cpp +++ b/src/extractor/scripting_environment_lua.cpp @@ -175,6 +175,7 @@ void LuaScriptingEnvironment::InitContext(LuaScriptingContext &context) .def_readwrite("forward_speed", &ExtractionWay::forward_speed) .def_readwrite("backward_speed", &ExtractionWay::backward_speed) .def_readwrite("name", &ExtractionWay::name) + .def_readwrite("ref", &ExtractionWay::ref) .def_readwrite("pronunciation", &ExtractionWay::pronunciation) .def_readwrite("destinations", &ExtractionWay::destinations) .def_readwrite("roundabout", &ExtractionWay::roundabout) diff --git a/unit_tests/mocks/mock_datafacade.hpp b/unit_tests/mocks/mock_datafacade.hpp index f18b9b539..ebe00d14e 100644 --- a/unit_tests/mocks/mock_datafacade.hpp +++ b/unit_tests/mocks/mock_datafacade.hpp @@ -175,6 +175,7 @@ class MockDataFacade final : public engine::datafacade::BaseDataFacade bool IsCoreNode(const NodeID /* id */) const override { return false; } unsigned GetNameIndexFromEdgeID(const unsigned /* id */) const override { return 0; } std::string GetNameForID(const unsigned /* name_id */) const override { return ""; } + std::string GetRefForID(const unsigned /* name_id */) const override { return ""; } std::string GetPronunciationForID(const unsigned /* name_id */) const override { return ""; } std::string GetDestinationsForID(const unsigned /* name_id */) const override { return ""; } std::size_t GetCoreSize() const override { return 0; }