with open ("data/alice_unclean.txt", "r") as f:
text = f.read()
print (text[:1000])
Alice's Adventures in Wonderland ALICE'S ADVENTURES IN WONDERLAND Lewis Carroll THE MILLENNIUM FULCRUM EDITION 3.0 CHAPTER I Down the Rabbit-Hole Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, `and what is the use of a book,' thought Alice `without pictures or conversation?' So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her. There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, `Oh d
chapters = text.split("CHAPTER")[1:]
print (chapters[0][0:1000])
I Down the Rabbit-Hole Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, `and what is the use of a book,' thought Alice `without pictures or conversation?' So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her. There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, `Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A
complete_text = []
for chapter in chapters:
chapter = "CHAPTER"+chapter
chapter = chapter.split("* * * * * * *")[0]
paras = chapter.split("\n\n")
chapter_num = paras[0]
print (chapter_num)
chapter_title = paras[1].strip()
print (chapter_title)
chapter_text = paras[2:]
final_paragraphs = []
for para in chapter_text:
para = para.strip().replace("\n-", "").replace("\n", " ")
while " " in para:
para = para.replace(" "," ")
if len(para) > 1:
final_paragraphs.append(para)
complete_text.append((chapter_num, chapter_title, final_paragraphs))
CHAPTER I Down the Rabbit-Hole CHAPTER II The Pool of Tears CHAPTER III A Caucus-Race and a Long Tale CHAPTER IV The Rabbit Sends in a Little Bill CHAPTER V Advice from a Caterpillar CHAPTER VI Pig and Pepper CHAPTER VII A Mad Tea-Party CHAPTER VIII The Queen's Croquet-Ground CHAPTER IX The Mock Turtle's Story CHAPTER X The Lobster Quadrille CHAPTER XI Who Stole the Tarts? CHAPTER XII Alice's Evidence
import json
with open ("data/alice.json", "w") as f:
json.dump(complete_text, f, indent=4)