Spaces:
Sleeping
Sleeping
File size: 6,996 Bytes
dfdd9cb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | #!/usr/bin/env python3
"""
اختبار معالج النصوص المتكامل
"""
from whisper_text_processor import WhisperTextProcessor
import logging
# إعداد التسجيل
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def test_text_correction():
"""اختبار تصحيح النصوص"""
logger.info("🧪 بدء اختبار تصحيح النصوص")
# إنشاء معالج النصوص (بدون تحميل نموذج Whisper للاختبار السريع)
processor = WhisperTextProcessor()
# نصوص مرجعية لبناء القاموس
reference_texts = [
"يهتز غشاء الطبل تنتقل عظيمات السمع الاهتزازات إلى النافذة البيضية",
"يهتز غشاء النافذة البيضية يهتز اللمف الخارجي في القناة الدهليزية",
"يهتز غشاء رايسنر تنتقل الاهتزازات إلى اللمف الداخلي في القناة القوقعية",
"اهتزاز الغشاء القاعدي بشكل موجي"
]
# إنشاء القاموس
dictionary = processor.create_dictionary(reference_texts)
logger.info(f"تم إنشاء قاموس يحتوي على {len(dictionary)} كلمة")
# نص للاختبار (يحتوي على أخطاء)
test_text = "يحتاز غشاء الطبل تنتقل عظيمات السماء الاحتزازات إلى النافذة البيضية يحتاز الملف الخارجي"
logger.info(f"النص الأصلي: {test_text}")
# تصحيح النص
corrected_text, corrections = processor.correct_text(test_text, max_distance=3, threshold_freq=1)
logger.info(f"النص المصحح: {corrected_text}")
logger.info(f"عدد التصحيحات: {len(corrections)}")
for correction in corrections:
logger.info(f" تصحيح: '{correction['original']}' → '{correction['corrected']}' "
f"(تكرار: {correction['frequency']}, مسافة: {correction['distance']})")
return corrected_text, corrections
def test_text_comparison():
"""اختبار مقارنة النصوص"""
logger.info("🧪 بدء اختبار مقارنة النصوص")
processor = WhisperTextProcessor()
# نصوص للمقارنة
reference_text = "يهتز غشاء الطبل تنتقل عظيمات السمع الاهتزازات إلى النافذة البيضية"
transcribed_text = "يحتاز غشاء الطبل تنتقل عظيمات السماء الاحتزازات إلى النافذة البيضية"
# مقارنة النصوص
comparison_result = processor.compare_texts(reference_text, transcribed_text)
logger.info(f"معدل خطأ الكلمات (WER): {comparison_result['wer_percentage']}")
logger.info(f"معدل خطأ الأحرف (CER): {comparison_result['cer_percentage']}")
logger.info(f"عدد كلمات النص المرجعي: {comparison_result['reference_words']}")
logger.info(f"عدد كلمات النص المستخرج: {comparison_result['transcribed_words']}")
logger.info(f"فرق عدد الكلمات: {comparison_result['word_differences']}")
return comparison_result
def test_html_report():
"""اختبار إنشاء تقرير HTML"""
logger.info("🧪 بدء اختبار إنشاء تقرير HTML")
processor = WhisperTextProcessor()
# بيانات وهمية للاختبار
test_results = {
"audio_path": "/path/to/test_audio.wav",
"reference_text": "يهتز غشاء الطبل تنتقل عظيمات السمع الاهتزازات إلى النافذة البيضية",
"original_transcription": "يحتاز غشاء الطبل تنتقل عظيمات السماء الاحتزازات إلى النافذة البيضية",
"corrected_transcription": "يهتز غشاء الطبل تنتقل عظيمات السمع الاهتزازات إلى النافذة البيضية",
"corrections": [
{"original": "يحتاز", "corrected": "يهتز", "frequency": 4, "distance": 2},
{"original": "السماء", "corrected": "السمع", "frequency": 1, "distance": 2},
{"original": "الاحتزازات", "corrected": "الاهتزازات", "frequency": 2, "distance": 1}
],
"original_metrics": {
"wer": 0.15,
"cer": 0.08,
"wer_percentage": "15.00%",
"cer_percentage": "8.00%",
"html_diff": "<span>مقارنة النص الأصلي</span>",
"reference_words": 10,
"transcribed_words": 10,
"word_differences": 0
},
"corrected_metrics": {
"wer": 0.0,
"cer": 0.0,
"wer_percentage": "0.00%",
"cer_percentage": "0.00%",
"html_diff": "<span>مقارنة النص المصحح</span>",
"reference_words": 10,
"transcribed_words": 10,
"word_differences": 0
},
"improvement": {
"wer_improvement": 0.15,
"cer_improvement": 0.08
},
"timestamps": []
}
# إنشاء تقرير HTML
html_report = processor.generate_html_report(test_results)
# حفظ التقرير
with open("/home/ubuntu/test_report.html", "w", encoding="utf-8") as f:
f.write(html_report)
logger.info("تم إنشاء تقرير HTML وحفظه في test_report.html")
return html_report
def main():
"""الدالة الرئيسية للاختبار"""
logger.info("🚀 بدء اختبارات معالج النصوص المتكامل")
try:
# اختبار تصحيح النصوص
corrected_text, corrections = test_text_correction()
# اختبار مقارنة النصوص
comparison_result = test_text_comparison()
# اختبار إنشاء تقرير HTML
html_report = test_html_report()
logger.info("✅ تم إنجاز جميع الاختبارات بنجاح!")
# عرض ملخص النتائج
print("\n" + "="*60)
print("📊 ملخص نتائج الاختبارات")
print("="*60)
print(f"عدد التصحيحات المطبقة: {len(corrections)}")
print(f"معدل خطأ الكلمات: {comparison_result['wer_percentage']}")
print(f"معدل خطأ الأحرف: {comparison_result['cer_percentage']}")
print(f"تم إنشاء تقرير HTML بحجم: {len(html_report)} حرف")
print("="*60)
except Exception as e:
logger.error(f"❌ فشل في الاختبارات: {str(e)}")
raise
if __name__ == "__main__":
main()
|