|
|
@@ -0,0 +1,62 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+"""Simple translation test with glossary support."""
|
|
|
+
|
|
|
+import sys
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+# Add project root to path
|
|
|
+project_root = Path('/mnt/code/223-236-template-6')
|
|
|
+sys.path.insert(0, str(project_root))
|
|
|
+
|
|
|
+# Direct imports to avoid circular/__init__ issues
|
|
|
+from src.glossary.models import Glossary, GlossaryEntry, TermCategory
|
|
|
+from src.translator.engine import TranslationEngine
|
|
|
+from src.translator.pipeline import TranslationPipeline
|
|
|
+
|
|
|
+
|
|
|
+def main():
|
|
|
+ # 1. 创建术语表并添加术语
|
|
|
+ glossary = Glossary()
|
|
|
+ entry = GlossaryEntry(
|
|
|
+ source="林风",
|
|
|
+ target="Lin Feng",
|
|
|
+ category=TermCategory.CHARACTER,
|
|
|
+ context="Main protagonist"
|
|
|
+ )
|
|
|
+ glossary.add(entry)
|
|
|
+ print(f"Added glossary entry: {entry.source} -> {entry.target}")
|
|
|
+
|
|
|
+ # 2. 创建翻译引擎
|
|
|
+ print("\nLoading translation engine...")
|
|
|
+ engine = TranslationEngine()
|
|
|
+ print(f"Engine loaded. Device: {'GPU' if engine.is_gpu_enabled else 'CPU'}")
|
|
|
+
|
|
|
+ # 3. 创建翻译管道
|
|
|
+ pipeline = TranslationPipeline(
|
|
|
+ engine=engine,
|
|
|
+ glossary=glossary,
|
|
|
+ src_lang="zh",
|
|
|
+ tgt_lang="en"
|
|
|
+ )
|
|
|
+
|
|
|
+ # 4. 测试翻译
|
|
|
+ source_text = "林风是青云宗的一名外门弟子"
|
|
|
+ print(f"\nSource: {source_text}")
|
|
|
+
|
|
|
+ result = pipeline.translate(source_text, return_details=True)
|
|
|
+
|
|
|
+ print(f"\n=== Results ===")
|
|
|
+ print(f"Raw translation: {result.raw_translation}")
|
|
|
+ print(f"Final translation: {result.translated}")
|
|
|
+ print(f"Terms used: {result.terms_used}")
|
|
|
+
|
|
|
+ if result.validation:
|
|
|
+ print(f"\nValidation:")
|
|
|
+ print(f" Success: {result.validation.is_valid}")
|
|
|
+ print(f" Success rate: {result.validation.success_rate:.1f}%")
|
|
|
+ for term, term_result in result.validation.term_results.items():
|
|
|
+ print(f" {term}: {'✓' if term_result.success else '✗'} ({term_result.expected})")
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ main()
|