xytpai's picture
Replace books with strict-cleaned quality-first subset; quarantine hard-to-repair source text
00b8e9c verified
Raw History Blame Contribute Delete
1.01 kB
import strict_rules as s
def check(t,repo,title):
out,rem=s.clean(t,repo,title);rebuilt=[];a=b=0
for r in rem:
n=r['start']-a;rebuilt += [out[b:b+n],r['text']];b+=n;a=r['end']
rebuilt.append(out[b:]);assert ''.join(rebuilt)==t
return out,rem
x="```text\nSave as PDF\nSkip to main content\n```\n\\[x+y=3\\]\n"
assert check(x,'common-pile/libretexts_filtered','Test')[0]==x
x="Title\nSkip to main content\nLast updated\nSome content is preserved.\n"
out,rem=check(x,'common-pile/libretexts_filtered','Title')
assert 'Some content is preserved.' in out and 'Skip to main content' not in out
x='Produced by David Widger\n\n'+('Long narrative. '*150)+'\n\nEnd of Project Gutenberg\'s My Book\n'
out,rem=check(x,'common-pile/project_gutenberg_filtered','My Book')
assert 'Produced by' not in out and 'End of Project' not in out
x='```python\nprint("Grosset & Dunlap")\n```\n'
assert check(x,'common-pile/project_gutenberg_filtered','Code book')[0]==x
print('Strict removal and protected-math/code tests OK')