File size: 8,653 Bytes
3c6e2f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
"""
Comprehensive verification script for Quran translation files
Checks:
1. All 114 files exist
2. Correct ayah counts
3. All translations present
4. Valid JSON structure
5. No empty translations
"""
import json
from pathlib import Path

OUTPUT_DIR = Path(__file__).parent.parent / "data" / "quran_translation"

# Expected translations
EXPECTED_TRANSLATIONS = ["en.sahih", "ur.jalandhry", "ur.junagarhi", "hi.farooq"]

# Expected ayah counts for each surah
AYAH_COUNTS = [
    7, 286, 200, 176, 120, 165, 206, 75, 129, 109,
    123, 111, 43, 52, 99, 128, 111, 110, 98, 135,
    112, 78, 118, 64, 77, 227, 93, 88, 69, 60,
    34, 30, 73, 54, 45, 83, 182, 88, 75, 85,
    54, 53, 89, 59, 37, 35, 38, 29, 18, 45,
    60, 49, 62, 55, 78, 96, 29, 22, 24, 13,
    14, 11, 11, 18, 12, 12, 30, 52, 52, 44,
    28, 28, 20, 56, 40, 31, 50, 40, 46, 42,
    29, 19, 36, 25, 22, 17, 19, 26, 30, 20,
    15, 21, 11, 8, 8, 19, 5, 8, 8, 11,
    11, 8, 3, 9, 5, 4, 7, 3, 6, 3,
    5, 4, 5, 6
]

def verify_all_files():
    print("πŸ” COMPREHENSIVE VERIFICATION")
    print("=" * 80)
    
    all_files = list(OUTPUT_DIR.glob("*_Translation.json"))
    
    # Statistics
    total_surahs = 114
    complete_surahs = 0
    incomplete_surahs = []
    missing_surahs = []
    corrupted_files = []
    
    # Track issues
    ayah_count_issues = []
    missing_translation_issues = []
    empty_text_issues = []
    
    print(f"πŸ“ Found {len(all_files)} translation files\n")
    
    # Create a map of surah_no to file
    surah_files = {}
    for file in all_files:
        try:
            with open(file, 'r', encoding='utf-8') as f:
                data = json.load(f)
                surah_no = data['surah']['surah_no']
                surah_files[surah_no] = {
                    'file': file,
                    'data': data
                }
        except Exception as e:
            corrupted_files.append({'file': file.name, 'error': str(e)})
            print(f"❌ {file.name}: Corrupted JSON - {e}")
    
    # Check each surah
    for surah_no in range(1, total_surahs + 1):
        expected_ayahs = AYAH_COUNTS[surah_no - 1]
        
        # Check if file exists
        if surah_no not in surah_files:
            missing_surahs.append(surah_no)
            print(f"❌ Surah {surah_no:3d}: File missing")
            continue
        
        file_info = surah_files[surah_no]
        data = file_info['data']
        surah_name = data['surah']['name_english']
        actual_ayahs = len(data['ayahs'])
        
        # Initialize issue tracking for this surah
        has_issues = False
        surah_issues = []
        
        # Check 1: Ayah count
        if actual_ayahs != expected_ayahs:
            has_issues = True
            issue = f"Expected {expected_ayahs} ayahs, got {actual_ayahs}"
            surah_issues.append(issue)
            ayah_count_issues.append({
                'surah_no': surah_no,
                'name': surah_name,
                'expected': expected_ayahs,
                'actual': actual_ayahs
            })
        
        # Check 2: All ayahs have all translations
        for ayah in data['ayahs']:
            ayah_no = ayah['ayah_no']
            
            # Check if all expected translations are present
            for trans_key in EXPECTED_TRANSLATIONS:
                if trans_key not in ayah.get('translations', {}):
                    has_issues = True
                    issue = f"Ayah {ayah_no} missing {trans_key}"
                    if issue not in surah_issues:
                        surah_issues.append(issue)
                    missing_translation_issues.append({
                        'surah_no': surah_no,
                        'surah_name': surah_name,
                        'ayah_no': ayah_no,
                        'missing': trans_key
                    })
                else:
                    # Check 3: Translation text is not empty
                    text = ayah['translations'][trans_key].get('text', '').strip()
                    if not text:
                        has_issues = True
                        issue = f"Ayah {ayah_no} has empty {trans_key}"
                        if issue not in surah_issues:
                            surah_issues.append(issue)
                        empty_text_issues.append({
                            'surah_no': surah_no,
                            'surah_name': surah_name,
                            'ayah_no': ayah_no,
                            'translation': trans_key
                        })
        
        # Print result
        if has_issues:
            incomplete_surahs.append(surah_no)
            print(f"⚠️  Surah {surah_no:3d} ({surah_name:20s}): {', '.join(surah_issues[:3])}")
            if len(surah_issues) > 3:
                print(f"     ... and {len(surah_issues) - 3} more issues")
        else:
            complete_surahs += 1
            print(f"βœ… Surah {surah_no:3d} ({surah_name:20s}): Complete ({actual_ayahs} ayahs, {len(EXPECTED_TRANSLATIONS)} translations)")
    
    # Final Summary
    print("\n" + "=" * 80)
    print("πŸ“Š VERIFICATION SUMMARY")
    print("=" * 80)
    print(f"βœ… Complete Surahs:    {complete_surahs}/{total_surahs} ({complete_surahs*100/total_surahs:.1f}%)")
    print(f"⚠️  Incomplete Surahs:  {len(incomplete_surahs)}/{total_surahs}")
    print(f"❌ Missing Surahs:     {len(missing_surahs)}/{total_surahs}")
    print(f"πŸ’₯ Corrupted Files:    {len(corrupted_files)}")
    
    print("\n" + "-" * 80)
    print("ISSUE BREAKDOWN:")
    print(f"  Ayah count mismatches:     {len(ayah_count_issues)}")
    print(f"  Missing translations:      {len(missing_translation_issues)}")
    print(f"  Empty translation texts:   {len(empty_text_issues)}")
    
    if missing_surahs:
        print(f"\n❌ MISSING SURAHS: {', '.join(map(str, missing_surahs))}")
    
    if corrupted_files:
        print(f"\nπŸ’₯ CORRUPTED FILES:")
        for cf in corrupted_files:
            print(f"   - {cf['file']}: {cf['error']}")
    
    if incomplete_surahs:
        print(f"\n⚠️  INCOMPLETE SURAHS ({len(incomplete_surahs)}):")
        for surah_no in incomplete_surahs[:20]:  # Show first 20
            print(f"   - Surah {surah_no}")
        if len(incomplete_surahs) > 20:
            print(f"   ... and {len(incomplete_surahs) - 20} more")
    
    # Detailed issue reports (if any)
    if ayah_count_issues:
        print(f"\nπŸ“Š AYAH COUNT ISSUES ({len(ayah_count_issues)}):")
        for issue in ayah_count_issues[:10]:
            print(f"   - Surah {issue['surah_no']} ({issue['name']}): Expected {issue['expected']}, got {issue['actual']}")
        if len(ayah_count_issues) > 10:
            print(f"   ... and {len(ayah_count_issues) - 10} more")
    
    if missing_translation_issues:
        print(f"\nπŸ”€ MISSING TRANSLATION ISSUES ({len(missing_translation_issues)}):")
        # Group by translation key
        by_trans = {}
        for issue in missing_translation_issues:
            key = issue['missing']
            by_trans.setdefault(key, []).append(issue)
        
        for trans_key, issues in by_trans.items():
            print(f"   {trans_key}: {len(issues)} ayahs missing")
            for issue in issues[:5]:
                print(f"      - Surah {issue['surah_no']} ({issue['surah_name']}), Ayah {issue['ayah_no']}")
            if len(issues) > 5:
                print(f"      ... and {len(issues) - 5} more")
    
    if empty_text_issues:
        print(f"\nπŸ“ EMPTY TEXT ISSUES ({len(empty_text_issues)}):")
        for issue in empty_text_issues[:10]:
            print(f"   - Surah {issue['surah_no']} ({issue['surah_name']}), Ayah {issue['ayah_no']}: {issue['translation']}")
        if len(empty_text_issues) > 10:
            print(f"   ... and {len(empty_text_issues) - 10} more")
    
    print("\n" + "=" * 80)
    
    # Final verdict
    if complete_surahs == total_surahs:
        print("πŸŽ‰ ALL FILES ARE COMPLETE AND VALID!")
    elif complete_surahs >= 110:
        print("βœ… MOSTLY COMPLETE - Only minor issues")
    elif complete_surahs >= 100:
        print("⚠️  SOME ISSUES FOUND - Review recommended")
    else:
        print("❌ SIGNIFICANT ISSUES FOUND - Re-download recommended")
    
    print("=" * 80)
    
    return {
        'complete': complete_surahs,
        'incomplete': len(incomplete_surahs),
        'missing': len(missing_surahs),
        'corrupted': len(corrupted_files),
        'total_issues': len(ayah_count_issues) + len(missing_translation_issues) + len(empty_text_issues)
    }

if __name__ == "__main__":
    verify_all_files()