浏览代码

Fix capitalization function calls.

scossu 2 月之前
父节点
当前提交
a5531d0f11
共有 2 个文件被更改,包括 22 次插入27 次删除
  1. 4 12
      scriptshifter/hooks/hebrew/dicta_api.py
  2. 18 15
      scriptshifter/hooks/korean/romanizer.py

+ 4 - 12
scriptshifter/hooks/hebrew/dicta_api.py

@@ -3,7 +3,7 @@ from os import environ
 from requests import post
 
 from scriptshifter.exceptions import BREAK, UpstreamError
-from scriptshifter.tools import capitalize
+from scriptshifter.hooks.general import capitalize_post_assembly
 
 EP = environ.get("TXL_DICTA_EP")
 DEFAULT_GENRE = "rabbinic"
@@ -25,16 +25,8 @@ def s2r_post_config(ctx):
     except Exception:
         raise UpstreamError("Error received from Dicta service.")
 
-    rom = rsp.json().get("transliteration")
-
-    if rom:
-        if ctx.options["capitalize"] == "all":
-            rom = capitalize(rom)
-        elif ctx.options["capitalize"] == "first":
-            rom = rom[0].upper() + rom[1:]
-    else:
-        ctx.warnings.append("Upstream service returned empty result.")
-
-    ctx.dest = rom
+    ctx.dest = rsp.json().get("transliteration")
+    if ctx.dest:
+        ctx.dest = capitalize_post_assembly(ctx)
 
     return BREAK

+ 18 - 15
scriptshifter/hooks/korean/romanizer.py

@@ -28,7 +28,7 @@ from os import path
 
 from scriptshifter.exceptions import BREAK
 from scriptshifter.hooks.korean import KCONF
-from scriptshifter.tools import capitalize
+from scriptshifter.hooks.general import capitalize_post_assembly
 
 
 PWD = path.dirname(path.realpath(__file__))
@@ -62,6 +62,12 @@ def s2r_nonames_post_config(ctx):
     ctx.dest, ctx.warnings = _romanize_nonames(
             ctx.src, ctx.options)
 
+    if ctx.dest:
+        # FKR042: Capitalize all first letters
+        # FKR043: Capitalize the first letter
+        logger.debug(f"Before capitalization: {ctx.dest}")
+        ctx.dest = capitalize_post_assembly(ctx)
+
     return BREAK
 
 
@@ -74,6 +80,12 @@ def s2r_names_post_config(ctx):
     """
     ctx.dest, ctx.warnings = _romanize_names(ctx.src, ctx.options)
 
+    if ctx.dest:
+        # FKR042: Capitalize all first letters
+        # FKR043: Capitalize the first letter
+        logger.debug(f"Before capitalization: {ctx.dest}")
+        ctx.dest = capitalize_post_assembly(ctx)
+
     return BREAK
 
 
@@ -105,19 +117,9 @@ def _romanize_nonames(src, options):
 
     rom = _romanize_oclc_auto(kor)
 
-    logger.debug(f"Before capitalization: {rom}")
-    # FKR042: Capitalize all first letters
-    if options["capitalize"] == "all":
-        rom = capitalize(rom)
-    # FKR043: Capitalize the first letter
-    elif options["capitalize"] == "first":
-        rom = rom[0].upper() + rom[1:]
-
     # FKR044: Ambiguities
     ambi = re.sub("[,.\";: ]+", " ", rom)
 
-    # TODO Decide what to do with these. There is no facility for outputting
-    # warnings or notes to the user yet.
     warnings = []
     _fkr_log(45)
     for exp, warn in KCONF["fkr045"].items():
@@ -308,10 +310,11 @@ def _kor_corp_name_rom(src):
         src = src[:-4]
         yu = "R"
 
-    rom_tok = []
-    for tok in src.split(" "):
-        rom_tok.append(_romanize_oclc_auto(tok))
-    rom = capitalize(" ".join(rom_tok))
+    rom_tok = [
+        _romanize_oclc_auto(tok)
+        for tok in src.split(" ")
+    ]
+    rom = " ".join(rom_tok)
 
     if chu == "L":
         rom = "(Chu) " + rom