forked from hrs/markov-sentence-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpoetry_generator.py
executable file
·42 lines (31 loc) · 1.56 KB
/
poetry_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""This module provides an object that creates poem-like text based on existing
poem-like text. That is, given a set of existing poems, this object creates
similar new "poems." It subclasses the generic text_generator object and serves
as an example of how to override its methods to produce new effects.
This module also provides a command-line interface to that object so that
"poems" can be generated in a terminal.
"""
import text_generator as tg
force_test = False
class PoemGenerator(tg.TextGenerator):
"""A subclass of TextGenerator for writing poem-like texts. Very much a work in
progress, and will be for some time.
This is also a demonstration of how to write a new text generator that
subclasses TextGenerator, though at the moment it's not a particularly impressive
example of one.
"""
def train(self, the_files, markov_length=3, character_tokens=True):
"""For now, we're just altering some defaults here"""
tg.TextGenerator.train(self, the_files=the_files, markov_length=markov_length, character_tokens=character_tokens)
def _printer(self, what, *pargs, **kwargs):
"""Override TextGenerator's printer method by just using standard built-in
print().
"""
print(what)
if __name__ == "__main__":
if force_test:
tg.main(generator_class=PoemGenerator, chars=True, count=8, input='/home/patrick/Documents/corpora/poetry/Laurence Hope: Last Poems.txt')
else:
tg.main(generator_class=PoemGenerator, **tg.process_command_line())