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,23 @@
|
||||
"""Split the Project Gutenberg text of George and Weedon Grossmith, *The Diary of a Nobody* (1892, eBook #1026),
|
||||
one story per chapter. It is one continuous diary, a clerk's life at home and in the office, so chapters are
|
||||
episodes of one world rather than separate tales. The body heads each chapter with `CHAPTER <roman>` and then a
|
||||
one-paragraph synopsis, which is dropped: it summarises the chapter and would be read as a scene."""
|
||||
import re, sys
|
||||
sys.path.insert(0, '..')
|
||||
from gutenberg_chunks import gutenberg_body, paragraphs, write
|
||||
|
||||
VOLUME = 'The Diary of a Nobody (George and Weedon Grossmith, 1892)'
|
||||
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/diary-of-a-nobody.txt')
|
||||
heads = [i for i, l in enumerate(lines) if re.fullmatch(r'CHAPTER [IVXL]+\.?', l.strip())]
|
||||
assert [roman(lines[i].split()[1].rstrip('.')) for i in heads] == list(range(1, len(heads) + 1)), [lines[i] for i in heads]
|
||||
stories = []
|
||||
for n, a in enumerate(heads):
|
||||
paras = paragraphs('\n'.join(lines[a + 1:(heads[n + 1] if n + 1 < len(heads) else len(lines))]),
|
||||
drop=(r'THE END\.?', r'\[Illustration[^\]]*\]'))
|
||||
synopsis, paras = paras[0], paras[1:]
|
||||
stories.append({'volume': VOLUME, 'title': f'Chapter {n + 1}: {synopsis[:70]}', 'synopsis': synopsis,
|
||||
'words': sum(len(p.split()) for p in paras), 'text': '\n\n'.join(paras)})
|
||||
write('.', stories)
|
||||
Reference in New Issue
Block a user