Use Chinese word dices to generate contrasting sentences. A poetry teaching aid designed by lyy0323 from Guoxue Club, SJTU.
Project description
Pin-How-Poem
This project is a Python-based tool for generating Chinese poetry using a dice-rolling mechanism. It allows users to create poems by randomly selecting words based on predefined rules and tones (平/仄). The project is designed to simulate the creative process of poetry composition in a fun and interactive way.
Features
- Dice-based Word Selection: Words are selected randomly from a predefined bank of words using dice objects. This predefined word bank is a collaborative work of members in Wenyun Department, Guoxue Club, SJTU.
- Tone Rules: Supports tone rules (平/仄) for Chinese poetry.
- Customizable Rules: Users can define their own rhyme schemes for word selection. The default rhyme scheme is
[("double", "ze"), ("double", "ping"), ("single", "ping"), ("double", "ze")], which stands for "仄仄平平平仄仄,平平仄仄仄平平", a common rhyme scheme of traditional 7-syllable verses. - Batch Experiments: Generate multiple poems with customizable draw and roll counts.
- Save Results: Option to save generated poems and their attributes to a file.
Project Structure
roll.py: Main script containing the implementation of the dice and dice bank, as well as the experiment logic.bank.txt: Word bank file containing the words used for poem generation.save.txt: File where generated poems and their attributes are saved.
Installation
From PyPI
-
Install from PyPI
pip install pin-how-poem
-
Ensure you have Python 3 installed.
From GitHub
-
Clone the repository:
git clone https://github.com/lyy0323/pin-how-poem.git cd pin-how-poem
-
Ensure you have Python 3 installed.
Usage
-
Prepare the word bank file (bank.txt) with the following format(This should be already predefined, but feel free to define your own):
1. word1 ... word6 | word7 ... word12 2. word13 ... word18 | word19 ... word24 ...
Each line represents a pair of words with their tones (平/仄).
-
If you installed it from GitHub, run the script:
python roll.pyIf you installed it from PyPI, you can call the library from Python code:
from pin_how_poem import experiment print(experiment())
Feel free to use it in your own application!
-
You can customize the rules and experiment parameters in the
__main__section of roll.py:- rule: Define the structure of the poem (e.g., word length and tone).
- draws: Number of times to draw a sample.
- rolls: Number of times to roll the dice for each sample.
- save: Whether to save the results to
save.txt. - save_attr: Whether to save the attributes of the dice used.
-
View the generated poems in the terminal or in the
save.txtfile.
Example Output
鸟迹空梁留彩笔,花香古渡见朱楼。
Customization
- Modify the
bank.txtfile to include your own words. - Adjust the rules in the experiment function to create different poem structures.
- Adjust number of draws and rolls of each draw in an experiment.
License
This project is licensed under the MIT License.
Acknowledgments
Special thanks to the creators of the word bank and the inspiration behind this project.
- The inspiration is put forward by lyy0323(林雨夜/芋椰) during her chat with 萌萌(长安).
- The word bank is created by collaborative work of members in Wenyun Department, Guoxue Club, SJTU.
- This project has an off-line version with REAL WOODEN DICES and a rule board. Contact Guoxue Club, SJTU to have access to the cute dices :)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pin_how_poem-0.0.1.tar.gz.
File metadata
- Download URL: pin_how_poem-0.0.1.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11ed860e866ba31e02291fd474e1f071af9b19a36805dece21577553c7c2e520
|
|
| MD5 |
5ae59a554e9f2393b1c3b05666ad0612
|
|
| BLAKE2b-256 |
86f881052b719b7bc98e5495294e1c37201f2e5edb94b28f7b3c7514d6eced39
|
File details
Details for the file pin_how_poem-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pin_how_poem-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87ca7ff6c1172c67e662103754e98bae297402b0ca46399bc0cdf5dde00a0460
|
|
| MD5 |
f3fc42a1f0e95e659ed56c7915a46b09
|
|
| BLAKE2b-256 |
58f36cba71fa9a8f7d4c81d90cf853b5a983d4a7e99a80ba817e094621b36f2b
|