Skip to content

Conversation

1ec5
Copy link
Member

@1ec5 1ec5 commented Oct 6, 2017

Added a formatToken option to compile, getWayName, and tokenize that gives the client an opportunity to manipulate a road name or other token value after any transformations built into this library but before the value is inserted into the overall instruction string. This feature is based on a similar feature built into the Swift version of this library.

Serving suggestion:

var instruction = osrmTextInstructions.compile(language, step, {
  formatToken: function (token, value) {
    // Mark up numbers to be pronounced like numbers in addresses.
    value = value.replace(/\w*[\d.-]+\w*/g, `<say-as interpret-as="address">${value}</say-as>`);
    // Wrap road names in their pronunciations, if available.
    switch (token) {
      case 'name': case 'way_name':
        return step.pronunciation ? `<phoneme ph="${step.pronunciation}">${value}</phoneme>` : value;
      case 'rotary_name':
        return step.rotary_pronunciation ? `<phoneme ph="${step.rotary_pronunciation}">${value}</phoneme>` : nil;
      default:
        return value;
    }
  }
});

Fixes #52.

/cc @mcwhittemore @allierowan @bsudekum

@1ec5 1ec5 self-assigned this Oct 6, 2017
@1ec5 1ec5 requested review from bsudekum and mcwhittemore October 6, 2017 02:08
@1ec5
Copy link
Member Author

1ec5 commented Oct 6, 2017

This feature enables a superset of the use cases addressed by the tokenizedInstruction hook that was added in #79, although this feature is a little more verbose. Should we remove tokenizedInstruction?

Added a formatToken option to compile, getWayName, and tokenize that gives the client an opportunity to manipulate a road name or other token value after any transformations built into this library but before the value is inserted into the overall instruction string.
return that.grammarize(language, name, grammar);
}
var startedWithToken = false;
var output = instruction.replace(/\{(\w+)(?::(\w+))?\}/g, function(token, tag, grammar, offset) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, non-capturing group 👍

Copy link
Contributor

@mcwhittemore mcwhittemore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1ec5 - I think this is a big step up on tokenizedInstruction and I agree we should drop that.

Lets merge and roll.

@1ec5
Copy link
Member Author

1ec5 commented Oct 6, 2017

7903e28 removes tokenizedInstruction and indeed the entire options parameter to the module (to avoid warnings about unused variables).

@1ec5 1ec5 merged commit 40c51f5 into master Oct 6, 2017
@1ec5 1ec5 deleted the 1ec5-denver branch October 6, 2017 20:38
@1ec5 1ec5 mentioned this pull request Oct 6, 2017
lyzidiamond added a commit that referenced this pull request Oct 19, 2017
…ize` that allows you to manipulate any token value after any grammar or capitalization rules are applied but before the value is inserted into the instruction. [#170](#170)

- Removed the `options` parameter to this module, including the `tokenizedInstruction` hook. Use the `formatToken` option instead. [#170](#170)
- Added `namedistance` option to the depart instructions and added tests for `namedistance` in depart and continue instructions. Some typo fixes. [#177](#177 (comment))
@lyzidiamond lyzidiamond mentioned this pull request Oct 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants