xytpai's picture
Replace books with strict-cleaned quality-first subset; quarantine hard-to-repair source text
00b8e9c verified
Raw History Blame Contribute Delete
2.44 kB
"""Final deterministic global exclusion categories. No document IDs or invented edits."""
import re
REVISION='strict_full_source_gate_v3_20261205'
def reasons(text,title,repo):
result=[]
# Directory/attachment-only or bulk newsletter content, not standalone book prose.
if re.search(r'(?i)\bOER by (?:Subject|Discipline)\b|^.*(?:General Catalogue|Book Catalog|Professional Development Catalog)|\bKey Assessment\b',title):
result.append('resource_directory_or_attachment_assignment')
if re.search(r'(?i)\b(?:ATTACHED DOCUMENT|attached (?:file|worksheet)|complete this assignment.{0,70}attached)\b',text):
result.append('missing_required_attachment')
if re.search(r'(?i)This copyrighted Pressbook|Copyrighted Pressbook',text):result.append('embedded_rights_scope_unresolved')
if re.search(r'\\begin\{array\}\s*&',text):result.append('malformed_latex_array_missing_columns')
if re.search(r'\b[A-Z][a-z]?[−-]\d+[A-Z][a-z]?\d*\b',text):
result.append('suspected_malformed_chemical_charge_position')
# Detect malformed Markdown pipe tables without inferring missing cells.
fence=None;expected=None;blockrows=0;pos=0
for line in text.splitlines():
s=line.strip()
f=re.match(r'^(`{3,}|~{3,})(.*)$',s)
if f:
if fence is None:fence=(f[1][0],len(f[1]))
elif f[1][0]==fence[0] and len(f[1])>=fence[1] and not f[2].strip():fence=None
expected=None;blockrows=0;continue
if fence:continue
if s.startswith('|'):
unescaped=len(re.findall(r'(?<!\\)\|',s))
if unescaped<3 or not s.endswith('|'):
result.append('incomplete_pipe_table')
break
if expected is None:expected=unescaped
elif unescaped!=expected:
result.append('unequal_pipe_table_columns');break
blockrows+=1
else:expected=None;blockrows=0
if 'gutenberg' in repo:
head=text[:14000];tail=text[-14000:]
if re.search(r'(?im)^\s*Transcribed from\b|^\s*Footnote anchors are denoted|^\s*A superscript is denoted|^\s*Basic fractions are displayed|^\s*All changes noted in the ERRATA|^\s*NOTICE TO SUBSCRIBERS',head):
result.append('transcription_or_subscriber_notice_residue')
if re.search(r'(?im)^\s*_?[A-Z][A-Za-z0-9’\' -]{1,70} Series_?\s*$',head):
result.append('publisher_series_backlist_frontmatter')
if re.search(r'(?i)footnotes have\s+been placed at the end of the book|corrected.*by the transcriber|produced from images available',head):
result.append('digital_edition_note_residue')
return sorted(set(result))