Add test
This commit is contained in:
		
							
								
								
									
										87
									
								
								scripts/test-jmdict-conversion.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								scripts/test-jmdict-conversion.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,87 @@
 | 
			
		||||
#!/usr/bin/env bun
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Test script for JMdict-based English to Katakana conversion
 | 
			
		||||
 * Usage: bun run scripts/test-jmdict-conversion.ts
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import {
 | 
			
		||||
  convertEnglishToKatakanaWithJMdictFallback,
 | 
			
		||||
  convertEnglishWordsOnly,
 | 
			
		||||
  getTextConverterInfo,
 | 
			
		||||
  initializeTextConverter,
 | 
			
		||||
} from "../services/text-converter.js";
 | 
			
		||||
 | 
			
		||||
async function testJMdictConversion() {
 | 
			
		||||
  console.log("🧪 JMdict English→Katakana変換テスト開始\n");
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    // Initialize the text converter
 | 
			
		||||
    console.log("📚 テキストコンバーターを初期化中...");
 | 
			
		||||
    await initializeTextConverter();
 | 
			
		||||
 | 
			
		||||
    // Get status information
 | 
			
		||||
    const info = getTextConverterInfo();
 | 
			
		||||
    console.log("✅ 初期化完了:");
 | 
			
		||||
    console.log(`   - Kuroshiro: ${info.kuroshiro ? "✓" : "✗"}`);
 | 
			
		||||
    console.log(`   - JMdict: ${info.jmdict ? "✓" : "✗"}`);
 | 
			
		||||
    if (info.jmdictInfo) {
 | 
			
		||||
      console.log(`   - JMdict バージョン: ${info.jmdictInfo.version}`);
 | 
			
		||||
      console.log(`   - 辞書日付: ${info.jmdictInfo.dictDate}`);
 | 
			
		||||
    }
 | 
			
		||||
    console.log();
 | 
			
		||||
 | 
			
		||||
    // Test words
 | 
			
		||||
    const testWords = [
 | 
			
		||||
      "hello world",
 | 
			
		||||
      "computer science",
 | 
			
		||||
      "artificial intelligence",
 | 
			
		||||
      "machine learning",
 | 
			
		||||
      "programming language",
 | 
			
		||||
      "JavaScript TypeScript",
 | 
			
		||||
      "database management",
 | 
			
		||||
      "software development",
 | 
			
		||||
      "This is a test of English to Katakana conversion using JMdict.",
 | 
			
		||||
      "Coffee shop restaurant hotel",
 | 
			
		||||
      "Business meeting presentation report",
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    console.log("🔄 変換テスト:");
 | 
			
		||||
    console.log("━".repeat(80));
 | 
			
		||||
 | 
			
		||||
    for (const testText of testWords) {
 | 
			
		||||
      console.log(`\n📝 入力: "${testText}"`);
 | 
			
		||||
 | 
			
		||||
      try {
 | 
			
		||||
        // Test JMdict-enhanced conversion
 | 
			
		||||
        const jmdictResult =
 | 
			
		||||
          await convertEnglishToKatakanaWithJMdictFallback(testText);
 | 
			
		||||
        console.log(`🎯 JMdict: "${jmdictResult}"`);
 | 
			
		||||
 | 
			
		||||
        // Test original conversion for comparison
 | 
			
		||||
        const originalResult = await convertEnglishWordsOnly(testText);
 | 
			
		||||
        console.log(`📖 従来版: "${originalResult}"`);
 | 
			
		||||
 | 
			
		||||
        // Show difference if any
 | 
			
		||||
        if (jmdictResult !== originalResult) {
 | 
			
		||||
          console.log("💡 JMdictによる改善が確認されました");
 | 
			
		||||
        }
 | 
			
		||||
      } catch (error) {
 | 
			
		||||
        console.error(`❌ 変換エラー: ${error}`);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    console.log("\n━".repeat(80));
 | 
			
		||||
    console.log("✅ テスト完了");
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    console.error("❌ テスト失敗:", error);
 | 
			
		||||
    process.exit(1);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Run the test
 | 
			
		||||
if (import.meta.main) {
 | 
			
		||||
  testJMdictConversion().catch(console.error);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export { testJMdictConversion };
 | 
			
		||||
		Reference in New Issue
	
	Block a user