Skip to content

Commit 013d15a

Browse files
committed
Grammar notes update for Swift implementation
1 parent 06c7124 commit 013d15a

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

Grammar.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The quite universal and simplier solution is the changing street names with the
1515
The required grammatical case should be specified right in instruction's substitution variables:
1616

1717
- `{way_name}` and `{rotary_name}` variables in translated instructions should be appended with required grammar case name after colon: `{way_name:accusative}` for example
18-
- [languages/grammar](languages/grammar/) folder should contain language-specific JSON file with regular expressions for specified grammar case:
18+
- [languages/grammar](languages/grammar/) folder should contain language-specific JSON file with regular expressions for specified grammatical case:
1919
```json
2020
{
2121
"v5": {
@@ -28,9 +28,21 @@ The required grammatical case should be specified right in instruction's substit
2828
- Instruction text formatter ([index.js](index.js) in this module) should:
2929
- check `{way_name}` and `{rotary_name}` variables for optional grammar case after colon: `{way_name:accusative}`
3030
- find appropriate regular expressions block for target language and specified grammar case
31-
- call standard [string replace with regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) for each expression in block passing result from previous call to the next; the first call should enclose original street name with whitespaces to make parsing words in names a bit simplier.
31+
- call standard [string replace with regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) for each expression in block passing result from previous call to the next; the first call should enclose original street name with whitespaces to make parsing several words inside name a bit simplier.
3232
- Strings replacement with regular expression is available in almost all other programming language and so this should not be the problem for other code used OSRM Text Instructions' data only.
33-
- If there is no regular expression matched source name (that's for names from foreign country for example), original name is returned without changes. This is also expected behavior of standard [string replace with regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace). And the same behavior is expected in case of missing grammar JSON file or grammar case inside it.
33+
- Grammar JSON could have [regular expression flags in JS notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp):
34+
```json
35+
{
36+
"meta": {
37+
"regExpFlags": "ig"
38+
},
39+
```
40+
- Please note, not all JS regular expression flags could be supported in other languages.
41+
For example, [OSRM Text Instructions for Swift](https://github.com/Project-OSRM/osrm-text-instructions.swift/) don't support "non-global match" and so always supposes `g` flag turned on.
42+
So if some regular expressions suppose stopping after their match, please include `^` and/or `$` into patterns for exact matching or return "finished" string in replace expression without enclosing whitespaces.
43+
- If there is no regular expression matched source name (that's for names from foreign country for example), original name is returned without changes.
44+
This is also expected behavior of standard [string replace with regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace).
45+
And the same behavior is expected in case of missing grammar JSON file or grammar case inside it.
3446

3547
### Example
3648

@@ -50,4 +62,5 @@ Russian _"Большая Монетная улица"_ street from St Petersburg
5062

5163
- Russian regular expressions are based on [Garmin Russian TTS voices update](https://github.com/yuryleb/garmin-russian-tts-voices) project; see [file with regular expressions to apply to source text before pronouncing by TTS](https://github.com/yuryleb/garmin-russian-tts-voices/blob/master/src/Pycckuu__Milena%202.10/RULESET.TXT).
5264
- There is another grammar-supporting module - [jquery.i18n](https://github.com/wikimedia/jquery.i18n) - but unfortunately it has very poor implementation in part of grammatical case applying and is supposed to work with single words only.
53-
- Actually it would be great to get street names also in target language not from default OSM `name` only - there are several multi-lingual countries supporting several `name:<lang>` names for streets. But this the subject to address to [OSRM engine](https://github.com/Project-OSRM/osrm-backend) first.
65+
- Actually it would be great to get street names also in target language not from default OSM `name` only - there are several multi-lingual countries supporting several `name:<lang>` names for streets.
66+
But this the subject to address to [OSRM engine](https://github.com/Project-OSRM/osrm-backend).

languages/grammar/ru.json

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,9 @@
370370
["^ (\\d+)-е (\\S+[ео])е [Шш]оссе ", " $1му $2му шоссе "],
371371
["^ (\\d+)-е (\\S+ье) [Шш]оссе ", " $1му $2му шоссе "],
372372

373-
[" Третому ", " Третьему "],
374-
[" третому ", " третьему "],
375-
["жому ", "жьему "],
376-
["жой ", "жей "],
377-
["чому ", "чьему "],
378-
["чой ", "чей "]
373+
[" ([Тт])ретому ", " $1ретьему "],
374+
["([жч])ому ", "$1ьему "],
375+
["([жч])ой ", "$1ей "]
379376
],
380377
"genitive": [
381378
["^ (\\S+)ая [Аа]ллея ", " $1ой аллеи "],
@@ -663,10 +660,8 @@
663660
["^ (\\d+)-е (\\S+[ео])е [Шш]оссе ", " $1го $2го шоссе "],
664661
["^ (\\d+)-е (\\S+ье) [Шш]оссе ", " $1го $2го шоссе "],
665662

666-
[" Третого ", " Третьего "],
667-
[" третого ", " третьего "],
668-
["жого ", "жьего "],
669-
["чого ", "чьего "]
663+
[" ([Тт])ретого ", " $1ретьего "],
664+
["([жч])ого ", "$1ьего "]
670665
],
671666
"prepositional": [
672667
["^ (\\S+)ая [Аа]ллея ", " $1ой аллее "],
@@ -954,10 +949,8 @@
954949
["^ (\\d+)-е (\\S+[ео])е [Шш]оссе ", " $1м $2м шоссе "],
955950
["^ (\\d+)-е (\\S+ье) [Шш]оссе ", " $1м $2м шоссе "],
956951

957-
[" Третом ", " Третьем "],
958-
[" третом ", " третьем "],
959-
["жом ", "жьем "],
960-
["чом ", "чьем "]
952+
[" ([Тт])ретом ", " $1ретьем "],
953+
["([жч])ом ", "$1ьем "]
961954
]
962955
}
963956
}

0 commit comments

Comments
 (0)