def surface(chapter): "turn a chapter into surface text." title = chapter[0] paragraph_src = chapter[1] paragraphs = list() for para_i, para in enumerate(paragraph_src): sentences = list() i = 0 while i < len(para): # randomly conjoin sentences when possible sentence = para[i][1] if i < len(para) - 1: next_s = para[i+1][1] # haxx: suppress conjunction behavior in final paragraph # (for novel-final affective sentences) if i < len(para)-1 and len(sentence) < 60 and len(next_s) < 60 and \ not(re.search(r"\b(and|but)\b", sentence+next_s)) and \ para_i != len(paragraph_src)-1 and \ random.randrange(2) == 0: if random.randrange(4) == 0: conj = "; " else: conj = " and " sentences.append( punctuate(normalize(depunct(sentence)+conj+next_s))) i += 2 else: sentences.append(punctuate(normalize(sentence))) i += 1 paragraphs.append(sentences) return title, paragraphs
def surface(chapter): "turn a chapter into surface text." title = chapter[0] paragraph_src = chapter[1] paragraphs = list() for para_i, para in enumerate(paragraph_src): sentences = list() i = 0 while i < len(para): # randomly conjoin sentences when possible sentence = para[i][1] if i < len(para) - 1: next_s = para[i + 1][1] # haxx: suppress conjunction behavior in final paragraph # (for novel-final affective sentences) if i < len(para)-1 and len(sentence) < 60 and len(next_s) < 60 and \ not(re.search(r"\b(and|but)\b", sentence+next_s)) and \ para_i != len(paragraph_src)-1 and \ random.randrange(2) == 0: if random.randrange(4) == 0: conj = "; " else: conj = " and " sentences.append( punctuate(normalize(depunct(sentence) + conj + next_s))) i += 2 else: sentences.append(punctuate(normalize(sentence))) i += 1 paragraphs.append(sentences) return title, paragraphs
def chapter(sdb, state): "a chapter consists of a series of paragraphs." heading = normalize(chapter_heading(sdb)) if random.randrange(3) == 0: dds = str(int(state.current_date.strftime("%d"))) heading += ". " + state.current_date.strftime("%A, %B ") + dds if random.randrange(2) == 0: delta = state.current_date - state.start_date delta_dds = delta.days + 1 heading += " (Day %d)" % delta_dds paragraphs = list() paragraph_count = random.choice([1,2,2,2,3,3,3,3,3,4,4,4,4,5,5,5,6,7,8]) for i in range(paragraph_count): st = ChapterState(paragraphs=paragraphs, novel=state, paragraph_count=paragraph_count, i=i) new_p = paragraph(sdb, st) paragraphs.append(new_p) return heading, paragraphs
def chapter(sdb, state): "a chapter consists of a series of paragraphs." heading = normalize(chapter_heading(sdb)) if random.randrange(3) == 0: dds = str(int(state.current_date.strftime("%d"))) heading += ". " + state.current_date.strftime("%A, %B ") + dds if random.randrange(2) == 0: delta = state.current_date - state.start_date delta_dds = delta.days + 1 heading += " (Day %d)" % delta_dds paragraphs = list() paragraph_count = random.choice( [1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 7, 8]) for i in range(paragraph_count): st = ChapterState(paragraphs=paragraphs, novel=state, paragraph_count=paragraph_count, i=i) new_p = paragraph(sdb, st) paragraphs.append(new_p) return heading, paragraphs