Download code/src/tlhdig_integration/hpm_web_scrape.py from savastakan/hitit-cuneiform-ocr: direct link, hf CLI and curl.
- Browser
- Download file 3.57 kB
-
https://huggingface.co/savastakan/hitit-cuneiform-ocr/resolve/main/code/src/tlhdig_integration/hpm_web_scrape.py
- Command line
-
hf download hf://savastakan/hitit-cuneiform-ocr/code/src/tlhdig_integration/hpm_web_scrape.py
-
curl -L -o hpm_web_scrape.py https://huggingface.co/savastakan/hitit-cuneiform-ocr/resolve/main/code/src/tlhdig_integration/hpm_web_scrape.py
3.57 kB
| #!/usr/bin/env python3 | |
| """Hethitologie-Portal Mainz (HPM) web scraper. | |
| TLHdig XML'lerinde foto URL yok — HPM web interface'den tablet detay | |
| sayfalarını crawl ederek foto bulmak gerek. | |
| Reference: https://www.hethport.uni-wuerzburg.de/HPM/ | |
| LEGAL: Request permission from Würzburg/Schwemer group before scraping. | |
| Rate-limit: 1 req/sec, respectful. | |
| Bu bir RECIPE; gerçek scraping için etik izin gerekli. | |
| """ | |
| import json | |
| from pathlib import Path | |
| ROOT = Path("/arf/scratch/stakan/hitit-proje") | |
| def extract_tablet_ids(): | |
| """TLHdig'den tablet ID listesini çıkar.""" | |
| import xml.etree.ElementTree as ET | |
| ids = set() | |
| xml_dir = ROOT / "datasets/sources/tlhdig/extracted/TLHbasisONLINE25.1_ZENODO" | |
| for xml_path in xml_dir.rglob("*.xml"): | |
| try: | |
| tree = ET.parse(xml_path) | |
| root = tree.getroot() | |
| # Title or filename | |
| for title in root.iter('{http://www.tei-c.org/ns/1.0}title'): | |
| if title.text: | |
| # Extract KBo/KUB/IBoT prefixed ID | |
| text = title.text.strip() | |
| import re | |
| m = re.search(r'(KBo|KUB|IBoT|VBoT|VAT|Bo|ABoT)\s*[\d\.]+', text) | |
| if m: | |
| ids.add(m.group(0)) | |
| except Exception: | |
| pass | |
| return sorted(ids) | |
| def generate_hpm_urls(tablet_ids): | |
| """HPM'e beklenen foto URL pattern'leri.""" | |
| # Format tahmini — gerçek pattern HPM tarafından verilir | |
| urls = [] | |
| for tid in tablet_ids: | |
| urls.append({ | |
| 'tablet_id': tid, | |
| 'hpm_detail_url': f"https://www.hethport.uni-wuerzburg.de/HPM/tabellen/{tid.replace(' ', '_')}.html", | |
| 'potential_photo_url': f"https://www.hethport.uni-wuerzburg.de/HPM/images/{tid.replace(' ', '_')}.jpg", | |
| }) | |
| return urls | |
| def main(): | |
| ids = extract_tablet_ids() | |
| print(f"TLHdig'de {len(ids)} unique tablet ID bulundu") | |
| if ids: | |
| print(f"Örnekler: {ids[:5]}") | |
| urls = generate_hpm_urls(ids) | |
| out = ROOT / "datasets/processed/hpm_scrape_targets.jsonl" | |
| with open(out, 'w') as f: | |
| for u in urls: | |
| f.write(json.dumps(u, ensure_ascii=False) + '\n') | |
| print(f"\nHPM scrape target listesi: {out}") | |
| print(f" Toplam URL: {len(urls)}") | |
| # Recipe | |
| recipe = { | |
| "status": "TEMPLATE — requires institutional permission", | |
| "contact_person": "Prof. Daniel Schwemer (Universität Würzburg)", | |
| "email_template": """ | |
| Sayın Prof. Schwemer, | |
| Hitit çivi yazısı OCR doktora projemizde DINOv3 + transformer tabanlı | |
| image-to-transliteration modeli eğitiyoruz. TLHdig corpus'u LM pretraining için | |
| kritik, ancak transliteration-photograph eşleştirmesi için Hethitologie-Portal | |
| Mainz'daki tablet fotoğraflarına ihtiyacımız var. | |
| TLHdig 1.0 CC-BY-4.0 lisansı altında fotoğraflarını bizimle paylaşmanız mümkün mü? | |
| Hazırladığımız dataset v2.1 (831K kayıt, 11 kaynak, Croissant metadata) + pipeline | |
| v4 (DINOv3+LoRA+ensemble) çıktılarımızı topluluğa açık paylaşacağız. | |
| Akademik atıf + collaboration memnuniyetle kabul edilir. | |
| Saygılarımla, | |
| Savaş Takan | |
| """, | |
| "rate_limit": "1 req/sec", | |
| "user_agent": "HititOCR-Research-Bot (contact: savastakan@gmail.com)", | |
| "expected_outcome": "5K-20K tablet photo, CC-BY attribution with transliteration", | |
| } | |
| with open(ROOT / "datasets/processed/hpm_request_template.json", 'w') as f: | |
| json.dump(recipe, f, indent=2, ensure_ascii=False) | |
| if __name__ == '__main__': | |
| main() | |