Package random_text :: Module generator :: Class Generator
[hide private]
[frames] | no frames]

Class Generator

object --+
         |
        Generator

The class Generator serves as a random text generator. Random text generation is the only thing a generator object knows how to do. See the method randomize for details.

Usage Examples

Local file (faster):

   test = Generator()
   print test.randomize("alice.txt")

File on the net (slower):

   test = Generator()
   print test.randomize("http:#www.textfiles.com/etext/FICTION/alice.txt")

See Also: #randomize(string)

Instance Methods [hide private]
 
__init__(self)
Creates a new random text generator.
 
randomize(self, source_file_or_URL)
Returns a lengthy fragment of random text generated based on the text in the given plain text file or URL pointing to a plain text data file.
 
form_chains(self, source_data)
 
generate(self, start_node, length)
 
format(self, raw_output)

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  DEPTH = 9
  OUTPUT_SIZE = 2000
  MAXIMUM_INPUT_SIZE = 100000
  MAXIMUM_DEPTH = 12
  RANDOM_SEED = None
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

 

Creates a new random text generator.

Overrides: object.__init__

randomize(self, source_file_or_URL)

 

Returns a lengthy fragment of random text generated based on the text in the given plain text file or URL pointing to a plain text data file. (Local files work faster.)

NOTE: the file pointed to by the parameter string must be a plain text file, not a Word document, HTML page or some such.

Parameters:
  • source_file_or_URL - either the name of a local plain text file in the working directory (project folder) or a web address pointing to a plain text file somewhere on the web e.g. "myfile.txt" or "http://www.textfiles.com/etext/FICTION/alice.txt"
Returns:
random text or an error message string if something went wrong