Skip to content

Commit e95bf7b

Browse files
authored
Merge pull request #212 from lcnetdev/cli
Add some table inspection CLI utilities.
2 parents 6f5ddf6 + 99dc34f commit e95bf7b

2 files changed

Lines changed: 60 additions & 2 deletions

File tree

scriptshifter_base.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM python:3.10-slim-bookworm
22

33
RUN apt update
4-
RUN apt install -y build-essential tzdata gfortran libopenblas-dev libboost-all-dev libpcre2-dev
4+
RUN apt install -y build-essential cmake tzdata gfortran libopenblas-dev libboost-all-dev libpcre2-dev
55

66
ENV TZ=America/New_York
77
ARG WORKROOT "/usr/local/scriptshifter/src"
@@ -16,6 +16,7 @@ ENV HF_DATASETS_CACHE /data/hf/datasets
1616
WORKDIR ${WORKROOT}
1717
COPY ext ./ext/
1818
COPY deps.txt ./
19+
ENV CFLAGS="-DCMAKE_POLICY_VERSION_MINIMUM=3.5"
1920
RUN pip install --no-cache-dir -r deps.txt
2021

2122
# Remove development packages.

sscli

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from glob import glob
99
from os import path
1010

1111
from scriptshifter import DB_PATH
12-
from scriptshifter.tables import init_db as _init_db
12+
from scriptshifter.tables import get_language, list_tables, init_db as _init_db
1313
from scriptshifter.trans import transliterate as _transliterate
1414
from test.integration import test_sample
1515

@@ -34,6 +34,63 @@ def init_db():
3434
click.echo(f"Initialized Scriptshifter DB in {DB_PATH}")
3535

3636

37+
@cli.group(name="tables")
38+
def table_grp():
39+
""" Commands to display table information. """
40+
pass
41+
42+
43+
@table_grp.command()
44+
def list():
45+
""" List all languages. """
46+
click.echo("\nLanguage and script tables available:")
47+
for tcode, tdata in list_tables().items():
48+
click.echo()
49+
click.echo(click.style(tcode, fg="green"))
50+
for k, v in tdata.items():
51+
if v is not None:
52+
click.echo(f"\t{k}: {v}")
53+
54+
55+
@table_grp.command()
56+
@click.argument("lang")
57+
@click.argument("t_dir", default="s2r")
58+
def show(lang, t_dir):
59+
"""
60+
Show character mappings for a language.
61+
62+
Only one direction (script to Roman or Roman to script) is diplayed. The
63+
mappings are in descending order of priority.
64+
65+
LANG is one of the language codes obtained by `sscli tables list`.
66+
67+
T_DIR is the direction to be displayed (`s2r` or `r2s`). Default is `s2r`.
68+
"""
69+
try:
70+
lang_md = get_language(lang)
71+
except KeyError:
72+
click.echo(
73+
click.style("ERROR: ", fg="red") +
74+
f"{lang} table does not exist.")
75+
exit(1)
76+
77+
dir_k = "script_to_roman" if t_dir == "s2r" else "roman_to_script"
78+
if dir_k not in lang_md:
79+
click.echo(
80+
click.style("ERROR: ", fg="red") +
81+
f"{lang} table has no `{dir_k}` section.")
82+
exit(1)
83+
84+
out = lang_md[dir_k].get("map")
85+
86+
click.echo(f"\nMapping table for {lang}, direction: {t_dir}")
87+
click.echo("Tokens are listed in descending order of priority.")
88+
click.echo("\nsrc\tdest")
89+
click.echo("-" * 12)
90+
for src, dest in out:
91+
click.echo(f"{src}\t{dest}")
92+
93+
3794
@cli.group(name="test")
3895
def test_grp():
3996
""" Test operations. """

0 commit comments

Comments
 (0)