Expose pronunciation in RouteStep

Uses name:pronunciation by default for cars.
This commit is contained in:
Patrick Niklaus 2016-05-26 03:35:38 +02:00
parent 9cdc9008aa
commit 0a53775fb3
No known key found for this signature in database
GPG Key ID: E426891B5F978B1B
17 changed files with 76 additions and 9 deletions

View File

@ -22,9 +22,11 @@
- `bearing_before`/`bearing_after` of `StepManeuver` are now deprecated and will be removed in the next major release
- `location` of `StepManeuvers` is now deprecated and will be removed in the next major release
- every `RouteStep` now has property `intersections` containing a list of `Intersection` objects.
- Support for name pronounciations. New member `pronounciation` in `RouteStep`, based on `name:pronounciation`.
- Profile changes:
- duration parser now accepts P[n]DT[n]H[n]M[n]S, P[n]W, PTHHMMSS and PTHH:MM:SS ISO8601 formats.
- `result.pronounciation` allows you to set way name pronounciations.
- Infrastructure:
- Better support for osrm-routed binary upgrade on the fly [UNIX specific]:

View File

@ -436,6 +436,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.
- `pronunciation`: The pronunciation hint of the way name. Will be `undefined` if there is no pronunciation hit.
- `mode`: A string signifying the mode of transportation.
- `maneuver`: A `StepManeuver` object representing the maneuver.
- `intersections`: A list of `Intersections` that are passed along the segment, the very first belonging to the StepManeuver

View File

@ -18,6 +18,23 @@ Feature: Car - Street names in instructions
| from | to | route |
| a | c | My Way,Your Way (A1),Your Way (A1) |
Scenario: Car - A named street with pronunciation
Given the node map
| a | b | d |
| | 1 | |
| | c | |
And the ways
| 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 |
@todo
Scenario: Car - Use way type to describe unnamed ways
Given the node map

View File

@ -139,6 +139,10 @@ module.exports = function () {
return this.extractInstructionList(instructions, s => s.name);
};
this.pronunciationList = (instructions) => {
return this.extractInstructionList(instructions, s => s.pronunciation || '');
};
this.bearingList = (instructions) => {
return this.extractInstructionList(instructions, s => s.maneuver.bearing_before + '->' + s.maneuver.bearing_after);
};

View File

@ -1,3 +1,5 @@
'use strict';
var util = require('util');
var assert = require('assert');
@ -31,14 +33,15 @@ module.exports = function () {
var afterRequest = (err, res, body) => {
if (err) return cb(err);
if (body && body.length) {
var instructions, bearings, turns, modes, times, distances, summary, intersections;
let pronunciations, instructions, bearings, turns, modes, times, distances, summary, intersections;
var json = JSON.parse(body);
let json = JSON.parse(body);
var hasRoute = json.code === 'Ok';
let hasRoute = json.code === 'Ok';
if (hasRoute) {
instructions = this.wayList(json.routes[0]);
pronunciations = this.pronunciationList(json.routes[0]);
bearings = this.bearingList(json.routes[0]);
turns = this.turnList(json.routes[0]);
intersections = this.intersectionList(json.routes[0]);
@ -122,6 +125,7 @@ module.exports = function () {
putValue('modes', modes);
putValue('times', times);
putValue('distances', distances);
putValue('pronunciations', pronunciations);
}
var ok = true;

View File

@ -145,6 +145,8 @@ class BaseDataFacade
virtual std::string GetNameForID(const unsigned name_id) const = 0;
virtual std::string GetPronunciationForID(const unsigned name_id) const = 0;
virtual std::size_t GetCoreSize() const = 0;
virtual std::string GetTimestamp() const = 0;

View File

@ -591,6 +591,14 @@ class InternalDataFacade final : public BaseDataFacade
return result;
}
std::string GetPronunciationForID(const unsigned name_id) const override final
{
// We store the pronounciation directly 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.
return GetNameForID(name_id + 1);
}
virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const override final
{
return m_via_node_list.at(id);

View File

@ -660,6 +660,11 @@ class SharedDataFacade final : public BaseDataFacade
return result;
}
std::string GetPronunciationForID(const unsigned name_id) const override final
{
return GetNameForID(name_id + 1);
}
bool IsCoreNode(const NodeID id) const override final
{
if (m_is_core_node.size() > 0)

View File

@ -98,10 +98,12 @@ std::vector<RouteStep> assembleSteps(const DataFacadeT &facade,
{
BOOST_ASSERT(segment_duration >= 0);
const auto name = facade.GetNameForID(step_name_id);
const auto pronunciation = facade.GetPronunciationForID(step_name_id);
const auto distance = leg_geometry.segment_distances[segment_index];
steps.push_back(RouteStep{step_name_id,
name,
std::move(name),
std::move(pronunciation),
NO_ROTARY_NAME,
segment_duration / 10.0,
distance,
@ -152,6 +154,7 @@ std::vector<RouteStep> assembleSteps(const DataFacadeT &facade,
BOOST_ASSERT(duration >= 0);
steps.push_back(RouteStep{step_name_id,
facade.GetNameForID(step_name_id),
facade.GetPronunciationForID(step_name_id),
NO_ROTARY_NAME,
duration / 10.,
distance,
@ -175,6 +178,7 @@ std::vector<RouteStep> assembleSteps(const DataFacadeT &facade,
steps.push_back(RouteStep{source_node.name_id,
facade.GetNameForID(source_node.name_id),
facade.GetPronunciationForID(source_node.name_id),
NO_ROTARY_NAME,
duration / 10.,
leg_geometry.segment_distances[segment_index],
@ -204,6 +208,7 @@ std::vector<RouteStep> assembleSteps(const DataFacadeT &facade,
BOOST_ASSERT(!leg_geometry.locations.empty());
steps.push_back(RouteStep{target_node.name_id,
facade.GetNameForID(target_node.name_id),
facade.GetPronunciationForID(target_node.name_id),
NO_ROTARY_NAME,
ZERO_DURATION,
ZERO_DISTANCE,

View File

@ -49,6 +49,7 @@ struct RouteStep
{
unsigned name_id;
std::string name;
std::string pronunciation;
std::string rotary_name;
double duration;
double distance;
@ -63,6 +64,7 @@ struct RouteStep
inline RouteStep getInvalidRouteStep()
{
return {0,
"",
"",
"",
0,

View File

@ -31,6 +31,7 @@ struct ExtractionWay
is_startpoint = true;
is_access_restricted = false;
name.clear();
pronunciation.clear();
forward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
backward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
}
@ -46,6 +47,7 @@ struct ExtractionWay
double backward_speed;
double duration;
std::string name;
std::string pronunciation;
bool roundabout;
bool is_access_restricted;
bool is_startpoint;

View File

@ -349,6 +349,7 @@ function way_function (way, result)
-- parse the remaining tags
local name = way:get_value_by_key("name")
local pronunciation = way:get_value_by_key("name:pronunciation")
local ref = way:get_value_by_key("ref")
local junction = way:get_value_by_key("junction")
-- local barrier = way:get_value_by_key("barrier", "")
@ -358,6 +359,7 @@ function way_function (way, result)
-- Set the name that will be used for instructions
local has_ref = ref and "" ~= ref
local has_name = name and "" ~= name
local has_pronunciation = pronunciation and "" ~= pronunciation
if has_name and has_ref then
result.name = name .. " (" .. ref .. ")"
@ -365,8 +367,10 @@ function way_function (way, result)
result.name = ref
elseif has_name then
result.name = name
-- else
-- result.name = highway -- if no name exists, use way type
end
if has_pronunciation then
result.pronunciation = pronunciation
end
if junction and ("roundabout" == junction or "mini_roundabout" == highway) then

View File

@ -196,6 +196,8 @@ 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.pronunciation.empty())
route_step.values["pronunciation"] = std::move(step.pronunciation);
if (!step.rotary_name.empty())
route_step.values["rotary_name"] = std::move(step.rotary_name);

View File

@ -146,9 +146,9 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
const constexpr auto MAX_STRING_LENGTH = 255u;
// Get the unique identifier for the street name
const auto string_map_iterator = string_map.find(parsed_way.name);
const auto name_iterator = string_map.find(parsed_way.name);
unsigned name_id = external_memory.name_lengths.size();
if (string_map.end() == string_map_iterator)
if (string_map.end() == name_iterator)
{
auto name_length = std::min<unsigned>(MAX_STRING_LENGTH, parsed_way.name.size());
@ -158,11 +158,17 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
std::back_inserter(external_memory.name_char_data));
external_memory.name_lengths.push_back(name_length);
auto pronunciation_length = std::min<unsigned>(255u, parsed_way.pronunciation.size());
std::copy(parsed_way.pronunciation.c_str(), parsed_way.pronunciation.c_str() + pronunciation_length,
std::back_inserter(external_memory.name_char_data));
external_memory.name_lengths.push_back(pronunciation_length);
string_map.insert(std::make_pair(parsed_way.name, name_id));
}
else
{
name_id = string_map_iterator->second;
name_id = name_iterator->second;
}
const bool split_edge = (parsed_way.forward_speed > 0) &&

View File

@ -135,6 +135,7 @@ void ScriptingEnvironment::InitContext(ScriptingEnvironment::Context &context)
.def_readwrite("forward_speed", &ExtractionWay::forward_speed)
.def_readwrite("backward_speed", &ExtractionWay::backward_speed)
.def_readwrite("name", &ExtractionWay::name)
.def_readwrite("pronunciation", &ExtractionWay::pronunciation)
.def_readwrite("roundabout", &ExtractionWay::roundabout)
.def_readwrite("is_access_restricted", &ExtractionWay::is_access_restricted)
.def_readwrite("is_startpoint", &ExtractionWay::is_startpoint)

View File

@ -57,6 +57,7 @@
{"key": "maxspeed:advisory"},
{"key": "maxspeed:advisory:forward"},
{"key": "maxspeed:advisory:backward"},
{"key": "name:pronunciation", "description": "Pronunciation hint for names", "object_types": ["way"]},
{"key": "bridge", "value": "movable", "description": "uses capacity and duration"},
{"key": "capacity:car", "description": "used for movable bridges"},
{"key": "side_road", "value": "yes", "description": "gets speed penalty"},

View File

@ -171,6 +171,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 GetPronunciationForID(const unsigned /* name_id */) const override { return ""; }
std::size_t GetCoreSize() const override { return 0; }
std::string GetTimestamp() const override { return ""; }
bool GetContinueStraightDefault() const override { return true; }