Simple haiku generator written in Python. Validates haiku syllable count and generates random haikus from a corpus of words.
This
overestimates
mouths incontrovertible
equivalency
or this
edna liturgy
afterlives abdicated
taunts justifying
okay, last one
inexperienced
felucca tarts remarriage
prescribed bengali
- Minimum requirements
- Recommended
# vanilla python
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
python haiku_generator.py
# asdf
asdf install python 3.11.5
asdf install poetry latest
# poetry
poetry install
poetry run python haiku_generator.py- Use the Docker image instead of installing locally
# by default, entrypoint is the script, command (option) is `--help`
λ docker run -it --rm ghcr.io/pythoninthegrass/haiku_generator:main
Usage: haiku_generator.py [OPTIONS]
╭─ Options ────────────────────────────────────────────────────────────╮
│ --validate -v Validate a haiku │
│ --generate -g Generate a haiku │
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────╯
# override command (option) with `--validate` or `-v`
λ docker run -it --rm ghcr.io/pythoninthegrass/haiku_generator:main -v
Downloading words_dictionary.json...
Downloading cmudict...
[nltk_data] Downloading package cmudict to /app/nltk_data...
[nltk_data] Unzipping corpora/cmudict.zip.
Validating haiku...
Enter the first line: <ctrl-c>
# override command (option) with `--generate` or `-g`
λ docker run -it --rm ghcr.io/pythoninthegrass/haiku_generator:main -g
Downloading words_dictionary.json...
Downloading cmudict...
[nltk_data] Downloading package cmudict to /app/nltk_data...
[nltk_data] Unzipping corpora/cmudict.zip.
Generating haiku...
extenuating
anesthesiologists
insubordinate
# override entrypoint with `bash` and run the script from within the container
λ docker run -it --rm --entrypoint=bash ghcr.io/pythoninthegrass/haiku_generator:main
appuser@1d5cc39be76d:/app$ ll
total 80
drwxr-xr-x 1 appuser appuser 126 Oct 17 01:58 .
drwxr-xr-x 1 root root 0 Oct 17 02:06 ..
-rwxr-xr-x 1 appuser appuser 6536 Oct 17 01:57 haiku_generator.py
-rw-r--r-- 1 appuser appuser 64245 Oct 17 01:57 poetry.lock
-rw-r--r-- 1 appuser appuser 2030 Oct 17 01:57 pyproject.toml
-rw-r--r-- 1 appuser appuser 2302 Oct 17 01:57 requirements.txt
drwxr-xr-x 1 appuser appuser 230 Oct 17 01:57 test
appuser@1d5cc39be76d:/app$ ./haiku_generator.py --help
Usage: haiku_generator.py [OPTIONS]
╭─ Options ────────────────────────────────────────────────────────────╮
│ --validate -v Validate a haiku │
│ --generate -g Generate a haiku │
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────╯
# run without any options
λ docker run -it --rm --entrypoint=bash ghcr.io/pythoninthegrass/haiku_generator:main
appuser@b1aff86b728f:/app$ ./haiku_generator.py
Downloading words_dictionary.json...
Downloading cmudict...
[nltk_data] Downloading package cmudict to /app/nltk_data...
[nltk_data] Unzipping corpora/cmudict.zip.
Welcome to the Haiku Generator!
Would you like to validate or generate a haiku?
1. validate
2. generate
3. exit
Please enter a number: 3
Goodbye!
# exit the container
appuser@1d5cc39be76d:/app$ exit
exit- Testing
# activate virtual environment poetry shell # generate tests hypothesis write haiku_generator.validate_haiku > test_validate_haiku.py # run specific test pytest -k test_validate_haiku
- Open Issues
- Generate more human-esque poems lmao
- CI
- Auto format (e.g., pep8)
- Re-add devcontainer
- Use
docker.ymlto build image
- Use
- Write more tests
- properties based (hypothesis)
- unit
- integration
- QA
- 479K word json file
- json vs. sqlite vs. something else (parquet?)
- 479K word json file
- GUI
How to Write a Haiku, With Examples | Grammarly Blog
NLTK :: nltk.corpus.reader.cmudict