story-to-pack: add the corpora and the catalogue v2/v3
Fourteen corpora split and classified: aesop, bierce, chekhov, holmes, keefe, lawson, lorimer, maupassant, nobody, plaintales, poe, torchy, wallingford and winesburg, each with its splitter and the hand-written groups and pages; catalogue v2 and v3; and the shared splitters gutenberg_chunks.py, se_split.py and se_build.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019rwKTmug58sEsJ72AuWsEi
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e5617b86ba
commit
3a4758172d
@@ -0,0 +1,28 @@
|
||||
"""Split the Project Gutenberg text of George Randolph Chester, *Get-Rich-Quick Wallingford* (eBook #37010),
|
||||
one story per chapter. It is a novel of linked episodes: each of the promoter's schemes runs over several
|
||||
chapters, so for the recurrence rule the reader groups chapters into schemes (ARCS in claude/groups_src.py)
|
||||
and a situation must recur across schemes, not merely across chapters of one scheme.
|
||||
The body heads each chapter with a bare `CHAPTER <roman>` line followed by an upper-case title that may
|
||||
wrap; the headings must number 1..28."""
|
||||
import re, sys
|
||||
sys.path.insert(0, '..')
|
||||
from gutenberg_chunks import gutenberg_body, paragraphs, write
|
||||
|
||||
VOLUME = 'Get-Rich-Quick Wallingford (George Randolph Chester, 1908)'
|
||||
ROMAN = {'I': 1, 'V': 5, 'X': 10, 'L': 50}
|
||||
def roman(s): return sum(-ROMAN[a] if ROMAN[a] < ROMAN.get(b, 0) else ROMAN[a] for a, b in zip(s, s[1:] + ' '))
|
||||
|
||||
lines = gutenberg_body('corpus/get-rich-quick-wallingford.txt')
|
||||
heads = [i for i, l in enumerate(lines) if re.fullmatch(r'CHAPTER [IVXL]+', l.strip())]
|
||||
assert [roman(lines[i].split()[1]) for i in heads] == list(range(1, 29)), [lines[i] for i in heads]
|
||||
stories = []
|
||||
for n, a in enumerate(heads):
|
||||
body = lines[a + 1:(heads[n + 1] if n + 1 < len(heads) else len(lines))]
|
||||
k = next(j for j, l in enumerate(body) if l.strip())
|
||||
title = []
|
||||
while body[k].strip() and body[k].strip().upper() == body[k].strip():
|
||||
title.append(body[k].strip()); k += 1
|
||||
paras = paragraphs('\n'.join(body[k:]), drop=(r'THE END\.?', r'\[Illustration[^\]]*\]'))
|
||||
stories.append({'volume': VOLUME, 'title': ' '.join(title).capitalize(), 'words': sum(len(p.split()) for p in paras),
|
||||
'text': '\n\n'.join(paras)})
|
||||
write('.', stories)
|
||||
Reference in New Issue
Block a user