https://github.com/reagentx/markov_python
Codecademy Final Project supplementary code patched for Python 3.6.x
https://github.com/reagentx/markov_python
learning-python markov-chain patch
Last synced: about 1 year ago
JSON representation
Codecademy Final Project supplementary code patched for Python 3.6.x
- Host: GitHub
- URL: https://github.com/reagentx/markov_python
- Owner: ReagentX
- License: gpl-3.0
- Created: 2017-11-25T04:38:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-25T04:41:22.000Z (over 8 years ago)
- Last Synced: 2025-01-31T16:15:00.468Z (about 1 year ago)
- Topics: learning-python, markov-chain, patch
- Language: Python
- Size: 17.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# markov_python
Codecademy Final Project supplementary code patched for Python 3.6.x
# Description
Codecademy Markov Chain text generator module.
This is an implementation of a [Markov Chain](https://en.wikipedia.org/wiki/Markov_chain) that generates random text based on content provided by the user. It is designed to be used as a local Python module for instructional purposes.
## How to add this to your project
1. Clone this repository into your Python project folder. Alternatively, you can download the zip archive and extract it into a directory in your project folder called `markov_python`.
2. You will need to import this file based on it's relative path. If your main runnable Python script is in the same directory as the `markov_python` directory, you can import this by including the following at the top of the runnable script: `from markov_python.cc_markov import MarkovChain`
## How to use the Markov Chain text generator
1. After importing this module into your main project script, create an instance of MarkovChain and assign it to a variable. For example `mc = MarkovChain()`
2. Use one of the methods `mc.add_string()` or `mc.add_file()` to read a local text file or a string. You can call this method multiple times to add additional data.
3. Call the `generate_text()` function on the instance of MarkovChain you created to generate text from the Markov Chain. You can call this method multiple times to generate additional data. This function will output a list of words. If your project requires a different format, you should convert the output accordingly.
## License
This code is released under the terms of the GPL v3 License.