vox-tier2-backup / scripts /count_clean_available.py
addyo07's picture
Tier-2 parking snapshot 2026-10-04
46e27b5 verified
Raw History Blame Contribute Delete
1.24 kB
import glob, json, os, re
import pyarrow.parquet as pq
TERMINALS = set('.?!')
def is_eligible(s):
s = s.strip()
if not s or s[-1] not in TERMINALS:
return False
if any(c in s for c in ':;"“”‘’!—–()[]'):
return False
words = s.split()
if not (6 <= len(words) <= 24):
return False
if not words[0][0].isalpha() or not words[0][0].isupper():
return False
return True
gutenberg_count = 0
for f in glob.glob('/opt/vox/temp/downloads/clean_corpora/gutenberg_books/*.txt'):
for line in open(f, errors='ignore'):
line = line.strip()
if is_eligible(line):
gutenberg_count += 1
ubuntu_count = 0
if os.path.exists('/opt/vox/temp/downloads/clean_corpora/ubuntu_dialogue_qa/train.parquet'):
t = pq.read_table('/opt/vox/temp/downloads/clean_corpora/ubuntu_dialogue_qa/train.parquet')
for row in t.to_pylist():
txt = (row.get('question') or '') + ' ' + (row.get('answer') or '')
for part in txt.split('.'):
p = part.strip() + '.'
if is_eligible(p):
ubuntu_count += 1
print(f'Gutenberg eligible sentences: {gutenberg_count}')
print(f'Ubuntu eligible sentences: {ubuntu_count}')