Skip to main content

Easy Markov chain text generator.

Project description

Markovchatter

Easy Markov chain text generator. (CLI / Web API)

Install

pip install markovchatter

This installs The markovchatter Python module and the markovchatter command line program. You can run the program like both

$ python3 -m markovchatter ...

and

$ markovchatter ...

Usage

Use as a command

usage: markovchatter run [-h] [-l] [-d] file [file ...]

positional arguments:
  file              text file(s) to learn

options:
  -h, --help        show this help message and exit
  -l, --new-line    files are in new-line text format
  -d, --no-divider  join words without spaces

Example:

$ markovchatter run source.txt
Enim ut sem nulla pharetra diam sit amet risus nullam eget felis eget nunc scelerisque viverra.

(Of course, the output text is depends on your source.)

Run as a Web API server

usage: markovchatter.py server [-h] [-l] [-d] [-p PORT] file [file ...]

positional arguments:
  file                  text file(s) to learn

options:
  -h, --help            show this help message and exit
  -l, --new-line        files are in new-line text format
  -d, --no-divider      join words without spaces
  -p PORT, --port PORT  listen port number [5000]

Start the server:

$ markovchatter server source.txt
 * Serving Flask app 'markovchatter'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:8080
 * Running on http://...:8080
 Press CTRL+C to quit

And send GET request to http://hostname:port/text in another terminal:

$ curl http://localhost:5000/text
Cursus sit amet consectetur adipiscing elit ut aliquam purus sit amet nisl suscipit adipiscing bibendum est.

(The response text is depends on your source, again.)

Options details

Files

The files given to the program is the source text file, which contain sentences it uses as the model. They are normally well-punctuationed text which terminates its sentence with a dot ('.').

If your source text is not suitable for the style; e.g. languages doesn't use dots for its period, you can use new-line format text file with --new-line option. See option details bellow.

-l, --new-line

If this option is set, given files are treated as new-line formatted text; which has each sentence on a newline. This is suitable for languages that doesn't use dot (".") for its sentence period.

The feature comes from a library implementation:

Markovify works best with large, well-punctuated texts. If your text does not use .s to delineate sentences, put each sentence on a newline, and use the markovify.NewlineText class instead of markovify.Text class.

jsvine/markovify: A simple, extensible Markov chain generator.

When the option is set, marcovchatter uses markovify.NewlineText class instead of markovify.Text as described above.

-d, --no-divider

The markovify library suppose languages that separate words with spaces, and its output is in the same way too. This is annoying when the language doesn't use spaces for its word divider. When the option is set, markovchatter joins words without spaces; which is more suitable for languages like Japanese.

License

MIT. See LICENSE.

Thanks

This tool uses markovify by Jeremy Singer-Vine and Flask by Armin Ronacher. Thank you for these libraries and its developers.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

markovchatter-1.0.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

markovchatter-1.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file markovchatter-1.0.1.tar.gz.

File metadata

  • Download URL: markovchatter-1.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for markovchatter-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2a06c0b0ff1b64cb419e100e7b4db10c9fffd6fab340869c8c4b2bf3a28c15f8
MD5 20d091eb29f3821f228100493e01e5c3
BLAKE2b-256 cac5a801246231fc70586baa5850d4127013d2fcb4e86f0ecdda0f734c725f76

See more details on using hashes here.

File details

Details for the file markovchatter-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: markovchatter-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for markovchatter-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 54ae1c016b6be42aadc7945a019b8aa086b7391846c1d55517c16e354b579871
MD5 6039c59d2997989eaae71c8eb02e1d97
BLAKE2b-256 7ebf776fd74c6411a9ed2166d7d202e5c8c1f734c9691cc562058e20694086ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page