← back to Japan Enrich
auto-save: 2026-07-01T19:08:14 (1 files) — upgrade_lilycolor_titles.py
a6b995b017adc92a7f2c440fc3a03d5f8a3ce273 · 2026-07-01 19:08:18 -0700 · Steve Abrams
Files touched
A upgrade_lilycolor_titles.py
Diff
commit a6b995b017adc92a7f2c440fc3a03d5f8a3ce273
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Wed Jul 1 19:08:18 2026 -0700
auto-save: 2026-07-01T19:08:14 (1 files) — upgrade_lilycolor_titles.py
---
upgrade_lilycolor_titles.py | 56 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/upgrade_lilycolor_titles.py b/upgrade_lilycolor_titles.py
new file mode 100644
index 0000000..efee0dc
--- /dev/null
+++ b/upgrade_lilycolor_titles.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+"""
+Upgrade the 151 derived-fallback Lilycolor titles to real English translations
+now that ollama has recovered. Targets rows with title_en_source=='derived-fallback'
+that still have a Japanese title_ja pattern name (first '|' segment). Per-item
+translation (reliable, no count-mismatch). Atomic temp+rename. $0 local.
+"""
+import os, json, re, urllib.request
+
+SRC = "staging/lilycolor-unified-staging.jsonl"
+OLLAMA = "http://127.0.0.1:11434/api/generate"
+MODEL = "qwen2.5:latest"
+PIPE = "|"
+CJK = re.compile(r'[-ゟ゠-ヿ一-鿿]')
+
+def translate_one(name):
+ prompt = ("Translate this Japanese wallcovering pattern name to a concise English "
+ "design term (1-3 words, e.g. Boucle, Velour, Damask, Stucco, Pottery). "
+ "Output ONLY the English term, nothing else.\n" + name)
+ body = json.dumps({"model": MODEL, "stream": False, "prompt": prompt,
+ "options": {"temperature": 0, "num_predict": 24}}).encode()
+ req = urllib.request.Request(OLLAMA, data=body, headers={"Content-Type": "application/json"})
+ raw = json.loads(urllib.request.urlopen(req, timeout=60).read())["response"]
+ if "</think>" in raw: raw = raw.split("</think>")[-1]
+ return next((l.strip().strip('"\'`.').strip() for l in raw.splitlines() if l.strip()), "")
+
+def main():
+ rows = [json.loads(l) for l in open(SRC) if l.strip()]
+ def pname(r):
+ t = r.get("title_ja")
+ return t.split(PIPE)[0].strip() if t else None
+ targets = [r for r in rows if r.get("title_en_source") == "derived-fallback" and pname(r)]
+ uniq = sorted({pname(r) for r in targets})
+ print(f"{len(targets)} derived-fallback rows w/ JP source across {len(uniq)} unique names", flush=True)
+ fixed = {}
+ for i, jp in enumerate(uniq):
+ try:
+ en = translate_one(jp)
+ if en and not CJK.search(en): fixed[jp] = en
+ except Exception as ex:
+ print(f" '{jp}' failed ({ex})", flush=True)
+ if (i + 1) % 25 == 0: print(f" {i+1}/{len(uniq)}", flush=True)
+ n = 0
+ for r in rows:
+ p = pname(r)
+ if r.get("title_en_source") == "derived-fallback" and p in fixed:
+ r["title_en"] = fixed[p]; r["title_en_source"] = "qwen-mt-draft-peritem"; n += 1
+ TMP = SRC + ".tmp"
+ with open(TMP, "w") as f:
+ for r in rows: f.write(json.dumps(r, ensure_ascii=False) + "\n")
+ os.replace(TMP, SRC)
+ remain = sum(1 for r in rows if r.get("title_en_source") == "derived-fallback" and pname(r))
+ print(f"\nDONE: upgraded {n} rows to real EN; {remain} derived-fallback w/ JP source remain -> {SRC}", flush=True)
+
+if __name__ == "__main__":
+ main()
← aac5201 ledger: title residual cleared (0 katakana live on japan.)
·
back to Japan Enrich
·
title upgrade tool + ledger: 151-title real-translation bloc 84a131a →