Skip to content

Commit d9a93a4

Browse files
authored
Merge pull request #241 from lcnetdev/gurmukhi
Create Gurmukhi base and nasalization hooks.
2 parents 514ce58 + d693a7b commit d9a93a4

7 files changed

Lines changed: 5137 additions & 20 deletions

File tree

doc/hooks.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ class. This may change in the future as specific needs arise.
127127

128128
The following members of the context object are available in all the hooks:
129129

130-
- `ctx.src`: Source text. Read only.
130+
- `ctx.orig`: Original source text. Read only.
131+
- `ctx.src`: Source text, initially equal to `ctx.orig` but it may be modified,
132+
e.g. during normalization.
131133
- `ctx.general`: Configuration general options.
132134
- `ctx.langsec`: language section (S2R or R2S) of configuration.
133135
- `ctx.options`: language-specific options defined in configuration and set
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from logging import getLogger
2+
from os import path
3+
from re import compile
4+
5+
from yaml import load as yload
6+
try:
7+
from yaml import CLoader as Loader
8+
except ImportError:
9+
from yaml import Loader
10+
11+
12+
logger = getLogger(__name__)
13+
14+
MOD_BASEDIR = path.dirname(__file__)
15+
16+
with open(path.join(MOD_BASEDIR, "gurmukhi_nasalization_pre.yml")) as fh:
17+
nas_config = {"initial": {}, "default": {}}
18+
19+
for k, v in yload(fh, Loader=Loader).items():
20+
if "%" in k:
21+
nas_config["initial"][compile(k.replace("%", "\\b"))] = v
22+
else:
23+
nas_config["default"][k] = v
24+
25+
26+
def nasalize_post_config(ctx):
27+
"""
28+
Preprocess Roman input to get a uniform nasalization.
29+
30+
The result is not a correct romanization: it is an intermediate stage
31+
to be passed to the Gurmukhi table.
32+
"""
33+
for k, v in nas_config["initial"].items():
34+
ctx.src = k.sub(v, ctx.src)
35+
for k, v in nas_config["default"].items():
36+
ctx.src = ctx.src.replace(k, v)
37+
38+
if ctx.orig != ctx.src:
39+
logger.debug(f"Corrected nasalization: {ctx.orig} -> {ctx.src}")

0 commit comments

Comments
 (0)