--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dissociated-pressman/README.md Sat Feb 15 22:15:56 2014 +0900
+ Dissociated press is an algorithm for generating text based on another
+ text. It is intended for transforming any text into potentially humorous
+Implementation is not the best, as it only checks the last word, which produces
+pretty disjointed text as a result. But it tries to compensate for that; it
+doesn't split English articles from words, it looks for potentail sentence
+starters and tries to end a chunk of words with a proper punctuation.
+ Asculum, Stephen with her, blind too, old cocky. I got mummy's Iovely box
+ head and S. Laurence O'Toole's. But he wouldnt pay ten millions of damp
+ earth. The cold gizzard.
+ Bacon, as, you wait. Drained all do with the toes down. Never heard or see
+ her limp between undue clemency and H. J. and Dubosc. You horrid thing! And
+ then gazes far as it apparently disregarding the warm pressure from
+ ORourkes was coming into the sunlight through the backdoor into her letter
+ on there. Visit some place I went by Wine's antiques, in Lunnon in front
+ of him want to accepted on my young laugh too open on high in the bed.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dissociated-pressman/dissociated.py Sat Feb 15 22:15:56 2014 +0900
+WORD_RE = re.compile(r'''(?:(?:an?|the) )?[\w']+[.,:;!?—-]*''', re.U | re.M)
+class DissociatedPressman:
+ def __init__(self, filename):
+ with open(filename, 'r') as f:
+ source = WORD_RE.findall(f.read())
+ for index, word in enumerate(source):
+ next_index = (index + 1) % len(source)
+ chains.setdefault(word, []).append(source[next_index])
+ if word[0] == word[0].upper():
+ self.starts = list(starts)
+ def generate(self, words=100, style=True):
+ word = random.choice(self.starts)
+ chain = self.chains[word]
+ while len(result) < words or (style and not word.endswith(('.', '!', '?'))):
+ word = random.choice(chain)
+ chain = self.chains[word]
+ return ' '.join(result)
+if __name__ == '__main__':
+ pressman = DissociatedPressman('ulysses.txt')
+ print(pressman.generate())