#!/bin/bash
# 多語系同義詞功能測試腳本

echo "=== 多語系同義詞功能測試 ==="
echo ""

# 設置環境
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
EXAMPLES_DIR="$BASE_DIR/docs_v1.0/examples/multilingual"
SCRIPTS_DIR="$BASE_DIR/scripts"

echo "1. 測試語言檢測工具..."
echo "測試中文文本:"
echo "這是一個測試文本，用於測試語言檢測功能。" | python3 "$SCRIPTS_DIR/detect_language.py" -v
echo ""

echo "測試英文文本:"
echo "This is a test text for language detection." | python3 "$SCRIPTS_DIR/detect_language.py" -v
echo ""

echo "2. 測試語言路由工具..."
echo "路由中文語言:"
python3 "$SCRIPTS_DIR/language_router.py" zh-CN -v --base-dir "$EXAMPLES_DIR"
echo ""

echo "路由日文語言:"
python3 "$SCRIPTS_DIR/language_router.py" ja-JP -v --base-dir "$EXAMPLES_DIR"
echo ""

echo "3. 測試統一格式處理器..."
echo "列出支援的語言:"
python3 "$SCRIPTS_DIR/unified_synonym_processor.py" "$EXAMPLES_DIR/unified_multilingual_synonyms.json" languages
echo ""

echo "提取中文同義詞:"
python3 "$SCRIPTS_DIR/unified_synonym_processor.py" "$EXAMPLES_DIR/unified_multilingual_synonyms.json" extract zh-CN
echo ""

echo "搜索術語 '電腦':"
python3 "$SCRIPTS_DIR/unified_synonym_processor.py" "$EXAMPLES_DIR/unified_multilingual_synonyms.json" search 電腦
echo ""

echo "搜索術語 'computer':"
python3 "$SCRIPTS_DIR/unified_synonym_processor.py" "$EXAMPLES_DIR/unified_multilingual_synonyms.json" search computer
echo ""

echo "4. 創建測試輸出..."
TEST_OUTPUT_DIR="/tmp/momentry_test_$(date +%s)"
mkdir -p "$TEST_OUTPUT_DIR"

echo "導出中文同義詞庫:"
python3 "$SCRIPTS_DIR/unified_synonym_processor.py" "$EXAMPLES_DIR/unified_multilingual_synonyms.json" export zh-CN -o "$TEST_OUTPUT_DIR/synonyms_zh_CN.json"
echo ""

echo "導出英文同義詞庫:"
python3 "$SCRIPTS_DIR/unified_synonym_processor.py" "$EXAMPLES_DIR/unified_multilingual_synonyms.json" export en-US -o "$TEST_OUTPUT_DIR/synonyms_en_US.json"
echo ""

echo "5. 驗證輸出檔案..."
echo "生成的檔案:"
ls -la "$TEST_OUTPUT_DIR/"
echo ""

echo "中文同義詞庫內容預覽:"
head -20 "$TEST_OUTPUT_DIR/synonyms_zh_CN.json"
echo ""

echo "英文同義詞庫內容預覽:"
head -20 "$TEST_OUTPUT_DIR/synonyms_en_US.json"
echo ""

echo "=== 測試完成 ==="
echo "測試輸出目錄: $TEST_OUTPUT_DIR"
echo "請檢查生成的檔案是否符合預期。"
