5th_fix excel problem
This commit is contained in:
167
fix_d_column_translations.py
Normal file
167
fix_d_column_translations.py
Normal file
@@ -0,0 +1,167 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
修復D2-D8欄位的翻譯快取 - 手動補充正確的翻譯
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# 設定編碼
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
|
||||
from app import create_app
|
||||
|
||||
def fix_d_column_translations():
|
||||
"""修復D2-D8欄位的翻譯快取"""
|
||||
|
||||
print("=" * 80)
|
||||
print("修復D2-D8欄位的翻譯快取")
|
||||
print("手動補充正確的中文->日文翻譯")
|
||||
print("=" * 80)
|
||||
|
||||
# 根據調試輸出,手動提供D2-D8的正確翻譯對照
|
||||
d_column_translations = [
|
||||
{
|
||||
'source_text': '與 WB inline 串線(DB→WB)、時效快;支援 Sn/Au 晶片\n最小可支援9mil晶粒\n支援EAP管控',
|
||||
'translated_text': 'WBインライン(DB→WB)による直列接続で、処理時間が短い;Sn/Auダイ対応\n最小9milダイ対応\nEAP制御対応'
|
||||
},
|
||||
{
|
||||
'source_text': '空洞表現穩定、尺寸/厚度範圍廣\n最小可支援9mil晶粒\n支援EAP管控',
|
||||
'translated_text': '空洞の表現が安定している、サイズ/厚さの範囲が広い\n最小9milダイ対応\nEAP制御対応'
|
||||
},
|
||||
{
|
||||
'source_text': 'DB到焊接爐為串機、時效快,減少人員碰觸之風險\n支援Ag/Au晶片\n支援含氧量監控\n支援EAP',
|
||||
'translated_text': 'DBから溶接炉へのインライン接続により処理時間が短く、人員の接触リスクを削減\nAg/Auダイ対応\n酸素含有量監視対応\nEAP対応'
|
||||
},
|
||||
{
|
||||
'source_text': '爐後氣孔少,提升焊接接縫均勻度、強度高、氣密性好\n支援Ag/Au晶片\n支援含氧量監控\n支援EAP',
|
||||
'translated_text': '炉後の気孔が少なく、溶接継ぎ目の均一性が向上、強度が高く、気密性が良好\nAg/Auダイ対応\n酸素含有量監視対応\nEAP対応'
|
||||
},
|
||||
{
|
||||
'source_text': 'Wire size: 0.8 mil ~ 2.4 mil(量產成熟)\n最薄 Al bond pad 1.3 μm;最小 bond pad size 55 × 55 μm\n支援EAP管控',
|
||||
'translated_text': 'ワイヤサイズ: 0.8 mil ~ 2.4 mil(量産成熟)\n最薄 Alボンドパッド 1.3 μm;最小ボンドパッドサイズ 55 × 55 μm\nEAP制御対応'
|
||||
},
|
||||
{
|
||||
'source_text': '1.全自動貼片減少人為作業的風險\n2.機台封閉式設計及有HEPA機構能減少落塵造成的異常風險\n3.自動讀取晶片刻號及貼晶片條碼\n支援EAP管控',
|
||||
'translated_text': '1.全自動貼付により人的作業のリスクを削減\n2.装置の密閉設計およびHEPA機構により落下塵による異常リスクを削減\n3.ダイの刻印とダイバーコードの自動読み取り\nEAP制御対応'
|
||||
},
|
||||
{
|
||||
'source_text': '1.晶片切割後chipping的品質檢驗\n2.晶片上的缺點檢驗',
|
||||
'translated_text': '1.ダイカット後のチッピング品質検査\n2.ダイ上の欠陥検査'
|
||||
}
|
||||
]
|
||||
|
||||
app = create_app()
|
||||
|
||||
with app.app_context():
|
||||
from app.models.cache import TranslationCache
|
||||
from app import db
|
||||
|
||||
source_language = 'zh'
|
||||
target_language = 'ja'
|
||||
|
||||
print(f"準備添加 {len(d_column_translations)} 筆D欄位翻譯...")
|
||||
print("-" * 60)
|
||||
|
||||
added_count = 0
|
||||
updated_count = 0
|
||||
|
||||
for i, trans in enumerate(d_column_translations, 2):
|
||||
source_text = trans['source_text']
|
||||
translated_text = trans['translated_text']
|
||||
|
||||
print(f"\nD{i} 欄位處理:")
|
||||
print(f" 原文: {repr(source_text[:50])}...")
|
||||
print(f" 譯文: {repr(translated_text[:50])}...")
|
||||
|
||||
# 檢查是否已存在
|
||||
existing = TranslationCache.get_translation(source_text, source_language, target_language)
|
||||
|
||||
if existing:
|
||||
if existing.strip() != translated_text.strip():
|
||||
print(f" 🔄 更新現有翻譯")
|
||||
TranslationCache.save_translation(source_text, source_language, target_language, translated_text)
|
||||
updated_count += 1
|
||||
else:
|
||||
print(f" ⚠️ 翻譯已存在且相同")
|
||||
else:
|
||||
print(f" ✅ 新增翻譯記錄")
|
||||
TranslationCache.save_translation(source_text, source_language, target_language, translated_text)
|
||||
added_count += 1
|
||||
|
||||
print(f"\n" + "-" * 60)
|
||||
print(f"D欄位翻譯補充結果:")
|
||||
print(f" 新增: {added_count}")
|
||||
print(f" 更新: {updated_count}")
|
||||
print(f" 總計: {added_count + updated_count}")
|
||||
|
||||
# 驗證結果
|
||||
print(f"\n驗證補充結果:")
|
||||
print("-" * 60)
|
||||
|
||||
success_count = 0
|
||||
|
||||
for i, trans in enumerate(d_column_translations, 2):
|
||||
source_text = trans['source_text']
|
||||
|
||||
cached_translation = TranslationCache.get_translation(source_text, source_language, target_language)
|
||||
|
||||
if cached_translation:
|
||||
if cached_translation.strip() == trans['translated_text'].strip():
|
||||
print(f"✅ D{i}: 驗證成功")
|
||||
success_count += 1
|
||||
else:
|
||||
print(f"⚠️ D{i}: 驗證失敗 - 內容不一致")
|
||||
else:
|
||||
print(f"❌ D{i}: 驗證失敗 - 快取中沒有")
|
||||
|
||||
print(f"\n驗證結果: {success_count}/{len(d_column_translations)} 成功")
|
||||
|
||||
# 測試整體映射覆蓋率
|
||||
print(f"\n測試整體映射覆蓋率:")
|
||||
print("-" * 60)
|
||||
|
||||
from app.services.translation_service import ExcelParser
|
||||
from pathlib import Path
|
||||
from sqlalchemy import text as sql_text
|
||||
|
||||
original_file = Path(r"C:\Users\EGG\WORK\data\user_scrip\TOOL\Document_translator_V2\uploads\f8b0febc-c0df-4902-8dc3-c90f5634f3b3") / "original_panjit_f8b0febc.xlsx"
|
||||
|
||||
if original_file.exists():
|
||||
parser = ExcelParser(str(original_file))
|
||||
segments = parser.extract_text_segments()
|
||||
|
||||
mapping_count = 0
|
||||
|
||||
for segment in segments:
|
||||
result = db.session.execute(sql_text("""
|
||||
SELECT translated_text
|
||||
FROM dt_translation_cache
|
||||
WHERE source_text = :text AND target_language = :lang
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1
|
||||
"""), {'text': segment, 'lang': target_language})
|
||||
|
||||
row = result.fetchone()
|
||||
if row:
|
||||
mapping_count += 1
|
||||
|
||||
mapping_rate = mapping_count / len(segments) * 100 if segments else 0
|
||||
print(f"映射覆蓋率: {mapping_count}/{len(segments)} = {mapping_rate:.1f}%")
|
||||
|
||||
if mapping_rate >= 90:
|
||||
print("🎉 映射覆蓋率優秀!翻譯功能應該正常工作")
|
||||
elif mapping_rate >= 80:
|
||||
print("✅ 映射覆蓋率良好,翻譯功能基本正常")
|
||||
else:
|
||||
print("⚠️ 映射覆蓋率待改善,部分文字可能無法翻譯")
|
||||
|
||||
print(f"\n" + "=" * 80)
|
||||
print("D欄位翻譯快取修復完成!")
|
||||
print("建議: 重新上傳檔案測試D2-D8翻譯功能")
|
||||
print("=" * 80)
|
||||
|
||||
if __name__ == "__main__":
|
||||
fix_d_column_translations()
|
Reference in New Issue
Block a user