该项目基于真实世界的中文字符频率生成随机文本(乱数假文)。它从现代汉语语料库词频表中读取词语频率,并按照词频生成随机句子。
默认情况下,它会生成包含 3~5 段,每段 4~8 句,每句不超过20个字的随机文本,大约300字。
但是你可以通过传递不同的参数轻松自定义段落数、每段句子数和每句字数。此外还可以生成指定字数的随机文本。
Chinese-lorem-ipsum/
├── website/ # 网站
│ ├── api/ # 后端 API
│ │ ├── apidoc.md # API 文档
│ │ └── app.py # flask app
│ ├── index.html # 主页
│ └── ... # 其他网站文件
├── data/ # 数据源
│ ├── word_freq.txt # 词频表(预处理时生成)
│ ├── char_freq.txt # 字频表(预处理时生成)
│ ├── 现代汉语语料库词频表 # 词频表
│ └── 现代汉语语料库字频表 # 字频表
├── train/ # 使用了Markov模型的测试版本
│ ├── clean_corpus.py # 清理语料库的脚本
│ └── model.py # Markov模型
├── model/ # Markov模型文件
│ └── model.json # Markov模型
├── lorem_ipsum.py # 生成随机文本的脚本
├── preprocess.py # 预处理词频表的脚本
└── ... # 其他文件
-
克隆仓库:
git clone https://github.com/SunnyCloudYang/Chinese-lorem-ipsum.git
-
进入项目目录:
cd Chinese-lorem-ipsum
-
设置虚拟环境:
python -m venv venv
-
激活虚拟环境:
-
在 Windows 上:
venv\Scripts\activate
-
在 macOS/Linux 上:
source venv/bin/activate
-
-
安装依赖:
pip install -r requirements.txt
-
克隆仓库:
git clone https://github.com/SunnyCloudYang/Chinese-lorem-ipsum.git
-
进入项目目录:
cd Chinese-lorem-ipsum/website
-
安装依赖:
npm install
-
进入网站目录:
cd Chinese-lorem-ipsum/website
-
运行 Vercel 开发服务器:
vercel dev
-
打开浏览器并导航到
http://localhost:3000
。 -
点击“生成”按钮生成随机文本。
-
确保项目目录中有
word_freq.txt
文件。 -
运行脚本生成包含 3~5 段,每段 4~8 句的随机文本:
python lorem_ipsum.py
-
Fork 仓库。
-
创建新分支:
git checkout -b feature/your-feature
-
进行更改并提交:
git commit -m "Add your message"
-
推送到分支:
git push origin feature/your-feature
-
提交 pull request。
该项目使用 MIT 许可证。