- cherry: orofacial/TMD PPTX presentations + 음악가 구강건강 가이드 - papa: sinus/infraoccluded PPTX, garden-monitor Arduino, MIDI files - databases: PCSP scraper, translation scripts, vision benchmark, batch JSONs - web-ui: code.js/companion.py/styles.css major updates, autostart installer - src: ollama-client, session, LLMProvider, ollama-adapter patches - .gitignore: add claude-key, SQLite WAL/SHM, __pycache__, nohup.out Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
119 lines
3.8 KiB
Python
119 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Translate psychiatry_cases diagnosis names to Korean using the Anthropic API."""
|
|
|
|
import sqlite3
|
|
import json
|
|
import time
|
|
import sys
|
|
import urllib.request
|
|
|
|
DB_PATH = "/home/kim/homeclaw/.smallclaw/databases/psychiatry_cases.db"
|
|
API_URL = "http://localhost:11434/v1/chat/completions"
|
|
MODEL = "kimi-k2.6:cloud"
|
|
|
|
|
|
def translate_batch(items):
|
|
prompt = """Translate the following DSM-5 psychiatric disorder names from English to Korean.
|
|
Rules:
|
|
- Use official/standard Korean DSM-5 terminology where established
|
|
- Keep acronyms like ADHD, PTSD, OCD as-is if commonly used in Korean
|
|
- Keep the parenthetical clarifications when present
|
|
- Each line has format: NUMBER|ENGLISH_NAME
|
|
- Return ONLY the translations in format: NUMBER|KOREAN_NAME
|
|
- No explanations, no notes
|
|
|
|
"""
|
|
for id_, name in items:
|
|
prompt += f"{id_}|{name}\n"
|
|
|
|
data = json.dumps({
|
|
"model": MODEL,
|
|
"messages": [
|
|
{"role": "system", "content": "You are a professional Korean-English translator specializing in psychiatry and DSM-5 terminology. Use accurate, standard Korean psychiatric terms."},
|
|
{"role": "user", "content": prompt},
|
|
],
|
|
"temperature": 0.2,
|
|
}).encode("utf-8")
|
|
|
|
req = urllib.request.Request(
|
|
API_URL,
|
|
data=data,
|
|
headers={"Content-Type": "application/json"},
|
|
)
|
|
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=120) as resp:
|
|
result = json.loads(resp.read().decode("utf-8"))
|
|
return result["choices"][0]["message"]["content"]
|
|
except Exception as e:
|
|
print(f"API error: {e}", file=sys.stderr, flush=True)
|
|
return None
|
|
|
|
|
|
def main():
|
|
conn = sqlite3.connect(DB_PATH)
|
|
c = conn.cursor()
|
|
|
|
c.execute("SELECT id, diagnosis_en FROM cases WHERE (diagnosis_ko = '' OR diagnosis_ko IS NULL) AND diagnosis_en != '' ORDER BY id")
|
|
rows = c.fetchall()
|
|
|
|
if not rows:
|
|
print("All diagnoses translated!")
|
|
conn.close()
|
|
return
|
|
|
|
print(f"Translating {len(rows)} diagnosis names...", flush=True)
|
|
|
|
batch_size = 30
|
|
total_translated = 0
|
|
|
|
for i in range(0, len(rows), batch_size):
|
|
batch = rows[i:i + batch_size]
|
|
print(f"\nBatch {i // batch_size + 1}/{(len(rows) + batch_size - 1) // batch_size} ({len(batch)} items)...", flush=True)
|
|
|
|
result = translate_batch(batch)
|
|
if not result:
|
|
print("Translation failed, skipping batch", flush=True)
|
|
continue
|
|
|
|
updates = []
|
|
for line in result.strip().split("\n"):
|
|
line = line.strip()
|
|
if "|" not in line:
|
|
continue
|
|
parts = line.split("|", 1)
|
|
try:
|
|
id_ = int(parts[0].strip())
|
|
ko = parts[1].strip().strip("*").strip()
|
|
updates.append((ko, id_))
|
|
total_translated += 1
|
|
except (ValueError, IndexError):
|
|
print(f" Skipping: {line}", flush=True)
|
|
|
|
if updates:
|
|
c.executemany("UPDATE cases SET diagnosis_ko = ? WHERE id = ?", updates)
|
|
conn.commit()
|
|
|
|
print(f" Translated so far: {total_translated}", flush=True)
|
|
time.sleep(2)
|
|
|
|
c.execute("SELECT COUNT(*) FROM cases WHERE diagnosis_ko != '' AND diagnosis_ko IS NOT NULL")
|
|
done = c.fetchone()[0]
|
|
c.execute("SELECT COUNT(*) FROM cases WHERE diagnosis_ko = '' OR diagnosis_ko IS NULL")
|
|
remaining = c.fetchone()[0]
|
|
|
|
print(f"\nDone! Translated: {done}, Remaining: {remaining}", flush=True)
|
|
|
|
print("\n--- Sample translations ---")
|
|
c.execute("SELECT diagnosis_en, diagnosis_ko FROM cases WHERE diagnosis_ko != '' AND diagnosis_ko IS NOT NULL ORDER BY RANDOM() LIMIT 10")
|
|
for row in c.fetchall():
|
|
print(f" EN: {row[0]}")
|
|
print(f" KO: {row[1]}")
|
|
print()
|
|
|
|
conn.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|