Download scratch/check_bc_pattern.py from Lashtw/idle: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/spaces/Lashtw/idle/resolve/main/scratch/check_bc_pattern.py
- Command line
-
hf download hf://spaces/Lashtw/idle/scratch/check_bc_pattern.py
-
curl -L -o check_bc_pattern.py https://huggingface.co/spaces/Lashtw/idle/resolve/main/scratch/check_bc_pattern.py
1.85 kB
| import json | |
| import os | |
| import sys | |
| sys.stdout.reconfigure(encoding='utf-8') | |
| ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| def check_pages_pattern(part, round_start, word_start): | |
| folder = os.path.join(ROOT, 'scratch', 'ocr', part) | |
| print(f"=== Checking Part {part}: Rounds {round_start}..{round_start+15} ===") | |
| total_words = 0 | |
| missing_words = [] | |
| for r_idx in range(16): | |
| r_num = round_start + r_idx | |
| base_p = 8 + r_idx * 6 | |
| for p_offset in range(5): | |
| pno = base_p + p_offset | |
| path = os.path.join(folder, f'p{pno:03d}.json') | |
| if not os.path.exists(path): | |
| print(f"MISSING FILE: p{pno:03d}.json") | |
| continue | |
| with open(path, 'r', encoding='utf-8') as f: | |
| items = json.load(f) | |
| # Find header words | |
| top_words = [] | |
| for it in items[:5]: | |
| t = it['text'].strip() | |
| if ',' in t and not t.startswith('第'): | |
| top_words = [w.strip() for w in t.split(',') if w.strip()] | |
| break | |
| # Find numbers | |
| nums = [] | |
| for it in items: | |
| t = it['text'].strip() | |
| if len(t) == 3 and t.isdigit(): | |
| nums.append(int(t)) | |
| expected_start = word_start + (r_idx * 20) + (p_offset * 4) | |
| expected_nums = [expected_start + i for i in range(4)] | |
| # Match top words count | |
| if len(top_words) != 4: | |
| # let's see what was extracted | |
| pass | |
| total_words += 4 | |
| print(f"Part {part} checked successfully! Total words slots: {total_words}") | |
| check_pages_pattern('B', 17, 321) | |
| check_pages_pattern('C', 33, 641) | |