PEGEAI / simple_extract.py
Alp Ege Bedir
PEGEAI dosyaları yükleniyor
db5e0ee
Raw
History Blame Contribute Delete
1.24 kB
#!/usr/bin/env python3
import bz2
import re
import os
os.makedirs("data", exist_ok=True)
print("Wikipedia açıyor... (196MB, ~2-3 dk sürebilir)")
with bz2.open("data/trwiki-latest-pages-articles.xml.bz2", "rt", encoding="utf-8", errors="ignore") as f:
content = f.read()
print("Metin çıkarılıyor...")
# Sayfa metinlerini bul
pages = re.findall(r'<text[^>]*>(.*?)</text>', content, re.DOTALL)
count = 0
with open("data/wikipedia_tr.txt", "w", encoding="utf-8") as out:
for text in pages:
# Wiki markup temizle
text = re.sub(r'\{\{.*?\}\}', '', text, flags=re.DOTALL)
text = re.sub(r'\[\[([^\]]*\|)?', '', text)
text = re.sub(r'\]\]', '', text)
text = re.sub(r'==.*?==', '', text)
text = re.sub(r"''+", '', text)
text = re.sub(r'__.*?__', '', text)
text = re.sub(r'&lt;.*?&gt;', '', text)
text = re.sub(r'\n+', ' ', text)
text = re.sub(r'\s+', ' ', text)
if len(text.strip()) > 100:
out.write(text.strip() + "\n\n")
count += 1
if count % 10000 == 0:
print(f"İşlendi: {count} sayfa")
print(f"Tamamlandı! {count} sayya çıkarıldı.")
print("Dosya: data/wikipedia_tr.txt")