qikou 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,74 @@
1
+ # Changelog
2
+
3
+ 本文件记录 qikou 的显著变更。格式参考
4
+ [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),
5
+ 版本号遵循[语义化版本](https://semver.org/lang/zh-CN/)。
6
+
7
+ ## [2.2.0] — 2026-10-08
8
+
9
+ 首个公开发布版本。
10
+
11
+ ### Added
12
+
13
+ - 自动化测试套件 `tests/test_qikou.py`(pytest,44 项),覆盖公开 API 契约、
14
+ 切分行为、`Config` 语义、语料加载与命令行。
15
+ - GitHub Actions CI:Python 3.8–3.13 跑测试、`mypy --strict` 类型检查、
16
+ 构建并校验 wheel 元数据。
17
+ - `CHANGELOG.md`、`SECURITY.md`、`CONTRIBUTING.md`。
18
+ - `pyproject.toml`:`[project.optional-dependencies]` 的 `dev` 组、
19
+ `[tool.pytest.ini_options]`、`[tool.mypy]`(strict)。
20
+
21
+ ### Changed
22
+
23
+ - **全量类型注解**:补齐 40 个内部函数的签名,`mypy --strict` 现在零报错。
24
+ - 语料的懒加载改为线程安全(可重入锁 + 双检锁):多线程并发首次调用
25
+ `split()` 只会真正加载一次。
26
+ - `Development Status` 分类器由 `5 - Production/Stable` 调整为 `4 - Beta`
27
+ ——这是第一次公开发布,尚无外部使用者反馈。
28
+ - `splitter` / `protect` / `postprocess` 补上模块级 `__all__`,明确内部
29
+ 辅助函数不属于公开接口。
30
+
31
+ ### Fixed
32
+
33
+ - 修复在非 UTF-8 输出环境(如 `PYTHONIOENCODING=ascii`)下打印中文与边框
34
+ 直接抛 `UnicodeEncodeError` 的问题;现在启动时会把 stdout/stderr 切到
35
+ UTF-8,切不过则安全跳过。
36
+
37
+ ## [2.1.0] — 2026-10-08
38
+
39
+ **未公开发布**,仅上传 TestPyPI 演练。
40
+
41
+ ### Changed
42
+
43
+ - API 规范化:`split_reply()` → `split(text, config=None) -> list[str]`,
44
+ 配置不再兼作返回值通道;`Config` 改为 dataclass。
45
+ - 命令行改为子命令:`qikou split` / `qikou test` / `qikou menu`,
46
+ 支持标准输入、`--json`、`--version`,退出码规范为 0/1/2。
47
+ - 颜文字语料随 wheel 分发,首次调用自动加载(此前必须手动加载,
48
+ 忘记加载会静默降级)。
49
+
50
+ ### Removed
51
+
52
+ - 拟人延迟功能:`Config` 的 `base_ms` / `per_char_ms` / `jitter_ms` /
53
+ `min_ms` / `max_ms` 与 `delay_for()`、`split_with_delays()`、
54
+ `Message` 类型全部移除。项目专注切分本身。
55
+
56
+ ## [2.0.0] — 2026-10-07
57
+
58
+ **未公开发布**。
59
+
60
+ ### Added
61
+
62
+ - 拆分为 `qikou` 包:`patterns` / `lexicon` / `config` / `kaomoji` /
63
+ `protect` / `postprocess` / `splitter` / `cli`。
64
+ - `pyproject.toml`(PEP 621)、`MANIFEST.in`、`LICENSE`。
65
+ - 结构化测试用例 `tests/test.txt` 与确定性报告生成(`qikou test`)。
66
+
67
+ ### Security
68
+
69
+ - 修复 `Kaomoji/` 目录大小写与实际代码不一致的问题:在大小写敏感的文件
70
+ 系统上会导致语料静默加载 0 条。现在语料位于 `qikou/kaomojis.txt`,
71
+ 且加载失败会明确报错。
72
+
73
+ [2.2.0]: https://github.com/Grabrun/qikou/releases/tag/v2.2.0
74
+ [2.1.0]: https://test.pypi.org/project/qikou/2.1.0/
qikou-2.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Grabrun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ # sdist 内容清单。
2
+ # wheel 的内容由 pyproject.toml 的 [tool.setuptools] 决定,这里只补默认不包含的文件。
3
+ # README / LICENSE / pyproject.toml 由 setuptools 自动包含,无需在此声明。
4
+
5
+ # 用例语料与测试代码:主要面向源码仓库,但随 sdist 分发以便下游打包者跑测试。
6
+ include tests/test.txt
7
+ include tests/test_qikou.py
8
+
9
+ # 变更记录
10
+ include CHANGELOG.md
qikou-2.2.0/PKG-INFO ADDED
@@ -0,0 +1,532 @@
1
+ Metadata-Version: 2.4
2
+ Name: qikou
3
+ Version: 2.2.0
4
+ Summary: Cadence (气口) — semantics-aware chat bubble splitter: turn one long AI reply into several short chat messages.
5
+ Author: Grabrun
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Grabrun/qikou
8
+ Project-URL: Repository, https://github.com/Grabrun/qikou
9
+ Project-URL: Issues, https://github.com/Grabrun/qikou/issues
10
+ Keywords: text-segmentation,sentence-splitter,chatbot,markdown,kaomoji,nlp,chinese
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Natural Language :: Chinese (Simplified)
14
+ Classifier: Natural Language :: English
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Topic :: Text Processing :: Linguistic
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.8
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7; extra == "dev"
31
+ Requires-Dist: mypy>=1.8; extra == "dev"
32
+ Requires-Dist: build>=1.0; extra == "dev"
33
+ Requires-Dist: twine>=4.0; extra == "dev"
34
+ Dynamic: license-file
35
+
36
+ # Cadence (气口)
37
+
38
+ **English** | [中文](README.md)
39
+
40
+ > Let AI replies breathe.
41
+
42
+ [![PyPI](https://img.shields.io/pypi/v/qikou.svg)](https://pypi.org/project/qikou/)
43
+ [![Python](https://img.shields.io/pypi/pyversions/qikou.svg)](https://pypi.org/project/qikou/)
44
+ [![CI](https://github.com/Grabrun/qikou/actions/workflows/ci.yml/badge.svg)](https://github.com/Grabrun/qikou/actions/workflows/ci.yml)
45
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
46
+
47
+ **气口 (qìkǒu)** is a term from Chinese opera and storytelling. It is the breath point — the spot where a performer pauses mid-passage to take a new breath. A good qikou makes the words land naturally, with rhythm, never running out of air. A bad one leaves the audience behind and gasping. The English name, **Cadence**, comes from music: the close of a phrase, the rhythm of speech.
48
+
49
+ That is exactly what this project does for AI replies: **find the breath points in a long reply** — split one long response into several short messages so they read like a real person sending them one after another.
50
+
51
+ ---
52
+
53
+ ## Table of Contents
54
+
55
+ - [Why This Exists](#why-this-exists)
56
+ - [Features](#features)
57
+ - [Installation](#installation)
58
+ - [Quick Start](#quick-start)
59
+ - [Using It as a Library](#using-it-as-a-library)
60
+ - [Configuration](#configuration)
61
+ - [Test Case Format](#test-case-format)
62
+ - [Project Structure](#project-structure)
63
+ - [Design Tradeoffs](#design-tradeoffs)
64
+ - [Version History](#version-history)
65
+ - [Roadmap](#roadmap)
66
+ - [Naming](#naming)
67
+ - [License](#license)
68
+
69
+ ---
70
+
71
+ ## Why This Exists
72
+
73
+ AI replies tend to be long. Sent as-is to a social platform, they read like an essay. On WeChat, QQ, Discord, or Telegram, real people send messages like this:
74
+
75
+ - one idea per message, 10–40 characters
76
+ - a break after punctuation, with tone particles standing on their own
77
+ - lists, code blocks, and URLs kept intact
78
+
79
+ Chopping by character count breaks Markdown, URLs, and code blocks, and reads like a machine. Cadence does **semantics-aware soft splitting**.
80
+
81
+ ---
82
+
83
+ ## Features
84
+
85
+ ### Core
86
+
87
+ - **Chinese/English mixed sentence splitting**: breaks after `。!?!?…`, and after `. ` when followed by whitespace or CJK
88
+ - **English abbreviation protection**: 40+ entries such as `Mr.` `Dr.` `e.g.` `i.e.` `U.S.` `U.S.A.` are never mis-split
89
+ - **Conjunction protection**: Chinese correlatives (`虽然…但是`, `因为…所以`) and English connectives (`because`, `although`, `however`)
90
+ - **Tilde as a soft sentence end**: 8 variants (`~` `~` `〜` and more), only after a real character; the operator `~=`, the range `18~25`, and the sub/superscript `H~2~O` are recognised and never treated as ends
91
+
92
+ ### Structure Awareness
93
+
94
+ - **Markdown**: never splits inside `**` `__` `~~` `` ` `` `*` `_`
95
+ - **Quotes and brackets**: never splits inside `“”` `「」` `『』` `()` `()`
96
+ - **Code blocks**: triple-backtick and `~~~` fences are protected as a whole
97
+ - **URLs**: `http(s)://` is protected as a whole, and a short prefix is merged automatically
98
+ - **Lists**: unordered, ordered, task, and nested lists become their own messages
99
+ - **Tables**: a Markdown table stays one message
100
+ - **Headings**: `#` through `######` stand alone
101
+ - **Horizontal rules**: `---` `***` `___` stand alone
102
+ - **HTML breaks**: `<br>` `<br/>` `<br />` count as cut points
103
+
104
+ ### Kaomoji
105
+
106
+ - **55,000+ kaomoji** in a trie index, exact match
107
+ - kaomoji at the end, the start, or the middle of a sentence are attached to the right message
108
+ - multiple upstream corpora can be merged
109
+
110
+ ### Post-processing
111
+
112
+ - **Unclosed Markdown**: `**` and `__` are paired up at the end
113
+ - **Unclosed quotes**: `“”` `「」` `『』` are paired up at the end
114
+ - **Half-width brackets are never auto-closed**: avoids misfiring inside kaomoji, formulas, and code
115
+
116
+ ### Output
117
+
118
+ - **Adaptive length**: long text relaxes the per-message cap so it does not shatter into pieces
119
+ - **Message-count control**: over the cap, the shortest adjacent pair is merged — but list items, headings, tables, and tilde endings are skipped
120
+
121
+ ---
122
+
123
+ ## Installation
124
+
125
+ **Requirements**: Python 3.8+. Zero third-party dependencies. The kaomoji corpus ships inside the package, so it works right after install.
126
+
127
+ ```bash
128
+ git clone https://github.com/Grabrun/qikou.git
129
+ cd qikou
130
+ pip install .
131
+ ```
132
+
133
+ This installs the `qikou` command; `python -m qikou` keeps working too. Installing is optional — you can also run it straight from the repository root.
134
+
135
+ ---
136
+
137
+ ## Quick Start
138
+
139
+ ### Command line
140
+
141
+ ```bash
142
+ qikou split file.txt # split a file
143
+ echo "long text" | qikou split # or read from stdin
144
+ qikou test # run the test cases (source checkout)
145
+ qikou menu # interactive menu
146
+ qikou --version
147
+ qikou --help
148
+ ```
149
+
150
+ `python -m qikou` is equivalent to `qikou`; with no subcommand it prints the help.
151
+
152
+ ### Splitting
153
+
154
+ On a terminal you get decorated output:
155
+
156
+ ```
157
+ $ qikou split reply.txt
158
+
159
+ ====================================================
160
+ 切分结果:5 条
161
+ 参数:max=60 target=20 min=4 max_messages=6
162
+ ====================================================
163
+
164
+ ─── [1/5] 11 字 ───
165
+ 好的,我来帮你规划。
166
+
167
+ ─── [2/5] 27 字 ───
168
+ 首先你需要确定目标,比如你想在三个月内学会 Python。
169
+ ...
170
+ ```
171
+
172
+ When the output is piped, only the message bodies are printed (blank-line separated), so `grep` / `wc` work as expected:
173
+
174
+ ```bash
175
+ $ echo "你好。今天不错。再见。" | qikou split
176
+ 你好。今天不错。
177
+
178
+ 再见。
179
+ ```
180
+
181
+ For machine-readable output use `--json`:
182
+
183
+ ```bash
184
+ $ qikou split --json reply.txt
185
+ [
186
+ "好的,我来帮你规划。",
187
+ "首先你需要确定目标,比如你想在三个月内学会 Python。"
188
+ ]
189
+ ```
190
+
191
+ | Option | Effect |
192
+ |---|---|
193
+ | `-j`, `--json` | JSON output (array of strings) |
194
+ | `-q`, `--quiet` | message bodies only |
195
+ | `-c N`, `--max-chars N` | hard cap per message (smaller = choppier) |
196
+ | `-T N`, `--target-chars N` | ideal length |
197
+ | `-m N`, `--max-messages N` | soft cap on the message count |
198
+
199
+ ### Interactive menu
200
+
201
+ ```bash
202
+ qikou menu
203
+ ```
204
+
205
+ ```
206
+ ====================================================
207
+ 气口 —— AI 回复分句器
208
+ ====================================================
209
+ [信息] 已加载 55213 条颜文字
210
+
211
+ 请选择模式:
212
+ [1] 手动输入
213
+ [2] 自动测试(读取 test.txt)
214
+ [q] 退出
215
+ ```
216
+
217
+ The command-line interface is currently Chinese-only; the menu labels above are quoted verbatim from the program. The `split` subcommand's *output* is your text, and `--json` is language-neutral.
218
+
219
+ ### Manual input
220
+
221
+ Choose `[1]`, paste your text, and finish with a line containing `EOF` or with Ctrl-D:
222
+
223
+ ```
224
+ > 好的,我来帮你规划。首先你需要确定目标,比如你想在三个月内学会 Python。然后每天安排 30 分钟练习基础语法。接着做一个小项目,比如爬虫或自动化脚本。最后定期复习并调整计划。
225
+ EOF
226
+
227
+ ─── [1/5] 11 字 ───
228
+ 好的,我来帮你规划。
229
+
230
+ ─── [2/5] 27 字 ───
231
+ 首先你需要确定目标,比如你想在三个月内学会 Python。
232
+
233
+ ─── [3/5] 18 字 ───
234
+ 然后每天安排 30 分钟练习基础语法。
235
+
236
+ ─── [4/5] 21 字 ───
237
+ 接着做一个小项目,比如爬虫或自动化脚本。
238
+
239
+ ─── [5/5] 12 字 ───
240
+ 最后定期复习并调整计划。
241
+
242
+ ----------------------------------------------------
243
+ 合计 89 字(最长 27 字)
244
+ ```
245
+
246
+ The header of each block is `[index/total] <character count> 字`.
247
+
248
+ ### Running the test cases
249
+
250
+ ```bash
251
+ qikou test # runs tests/test.txt
252
+ qikou test path/to/cases.txt # runs a specific file
253
+ ```
254
+
255
+ Reads the case file, runs every case, and writes the report to `tests/results/test_result_<timestamp>.txt`. The report body is deterministic — no timestamps — so two runs over the same cases are byte-identical and can be diffed.
256
+
257
+ ```
258
+ 开始自动测试:.../tests/test.txt
259
+ ----------------------------------------------------
260
+ [ 1/N] 001 中文句号后紧跟英文 → 2 条
261
+ [ 2/N] 002 中文问号后无空格 → 3 条
262
+ ...
263
+ ----------------------------------------------------
264
+ 用时:<T> 秒
265
+ 结果已保存到:
266
+ .../tests/results/test_result_<时间戳>.txt
267
+ ```
268
+
269
+ ### Help
270
+
271
+ ```bash
272
+ qikou --help
273
+ ```
274
+
275
+ ---
276
+
277
+ ## Using It as a Library
278
+
279
+ ```python
280
+ from qikou import split
281
+
282
+ text = "好的,我来帮你规划。首先你需要确定目标。然后每天练习。最后定期复习。"
283
+
284
+ for message in split(text):
285
+ print(message)
286
+ ```
287
+
288
+ `split()` returns `list[str]`. The kaomoji corpus is **loaded automatically** on first use (about 0.1 s); you normally never have to touch it.
289
+
290
+ ### Custom configuration
291
+
292
+ ```python
293
+ from qikou import Config, split
294
+
295
+ config = Config(
296
+ max_chars=80, # hard cap per message
297
+ target_chars=30, # ideal length
298
+ min_chars=5, # below this, try to merge
299
+ max_messages=8, # soft cap on the number of messages
300
+ )
301
+ messages = split(text, config=config) # config is never modified
302
+ ```
303
+
304
+ `Config` is a dataclass, so `dataclasses.replace()` gives you a derived copy:
305
+
306
+ ```python
307
+ import dataclasses
308
+ from qikou import Config
309
+
310
+ loose = dataclasses.replace(Config(), max_chars=200, target_chars=80)
311
+ ```
312
+
313
+ ### Preloading or replacing the corpus
314
+
315
+ ```python
316
+ from qikou import load_kaomojis, kaomoji_count
317
+
318
+ load_kaomojis() # preload the bundled corpus, returns the count
319
+ load_kaomojis("my-kaomojis.txt") # use your own
320
+ print(kaomoji_count()) # entries currently loaded
321
+ ```
322
+
323
+ A missing corpus only logs a warning; splitting continues without kaomoji recognition.
324
+
325
+ ---
326
+
327
+ ## Configuration
328
+
329
+ Every parameter of the `Config` class:
330
+
331
+ | Parameter | Default | Meaning |
332
+ |---|---|---|
333
+ | `max_chars` | 60 | Hard cap per message. Exceeding it triggers a split |
334
+ | `target_chars` | 20 | Ideal length. The preferred region for a cut |
335
+ | `min_chars` | 4 | Below this, try to merge with a neighbour |
336
+ | `max_messages` | 6 | Soft cap on the message count. Over it, the shortest adjacent pair is merged |
337
+ | `atomic_merge_prefix` | 20 | Threshold for merging a short prefix with a long atomic fragment |
338
+ | `merge_max_chars` | 60 | Cap after a merge (scaled up to that tier's `max_chars`) |
339
+
340
+ **`max_messages` is a soft cap**: over it the shortest adjacent pair is merged, but list items, headings, tables, horizontal rules, standalone code blocks / URLs, and entries ending in a tilde never take part in a merge — so a reply full of structure can end up above this value. Plain prose does reach the cap: a merged message stays within `merge_max_chars`, which is scaled up together with the tier (see the table below).
341
+
342
+ **Adaptive length**: `split()` relaxes the per-message cap and the message-count cap according to the total length:
343
+
344
+ | Total length | max_chars | target_chars | max_messages | merge_max_chars |
345
+ |---|---|---|---|---|
346
+ | ≤ 150 | 60 | 20 | 6 | 60 |
347
+ | ≤ 400 | 90 | 30 | 6 | 90 |
348
+ | ≤ 800 | 120 | 45 | 8 | 120 |
349
+ | > 800 | 160 | 60 | 10 | 160 |
350
+
351
+ To shift the overall feel (choppier or longer), change `max_chars` and `target_chars`.
352
+
353
+ `split()` never modifies the `Config` you pass in; the scaling is applied to an internal copy.
354
+
355
+ ---
356
+
357
+ ## Test Case Format
358
+
359
+ The format of `tests/test.txt`:
360
+
361
+ ```
362
+ [CASE] 001 Chinese full stop
363
+ 你好。今天不错。再见。
364
+
365
+ [CASE] 002 English period
366
+ Hello. How are you?
367
+
368
+ [CASE] 003 Tilde
369
+ 好耶~ 就这么定了!
370
+ ```
371
+
372
+ - every case starts with `[CASE] <number> <short description>`
373
+ - the body runs until the next `[CASE]` or the end of the file
374
+ - whitespace-only cases are kept (0 messages) for boundary testing
375
+
376
+ To add a case, just edit the file.
377
+
378
+ Cases hold **inputs only** — there are no expected outputs. `--test` is therefore a deterministic report generator rather than an assertion suite: it fails only if a case raises. Read the reports, or diff two of them, to catch behaviour changes.
379
+
380
+ ---
381
+
382
+ ## Project Structure
383
+
384
+ ```
385
+ qikou/
386
+ ├── qikou/ # core package
387
+ │ ├── __init__.py # public exports
388
+ │ ├── __main__.py # python -m qikou entry point
389
+ │ ├── cli.py # CLI / menu / auto test
390
+ │ ├── config.py # Config class
391
+ │ ├── patterns.py # regexes and structural checks
392
+ │ ├── lexicon.py # abbreviation list, conjunction list, base scores
393
+ │ ├── kaomoji.py # kaomoji trie
394
+ │ ├── protect.py # code block / URL placeholder protection
395
+ │ ├── postprocess.py # closing unclosed markers
396
+ │ ├── splitter.py # core splitting logic
397
+ │ ├── kaomojis.txt # kaomoji corpus, 55,213 entries (shipped in the wheel)
398
+ │ └── py.typed # PEP 561 marker
399
+ ├── tests/
400
+ │ ├── test.txt # test cases (inputs only)
401
+ │ └── results/ # generated reports (not tracked)
402
+ ├── legacy/ # archived single-file versions
403
+ │ ├── ChatSplit-v1.0.py
404
+ │ └── ChatSplit-v2.0.py
405
+ ├── pyproject.toml # packaging metadata (PEP 621)
406
+ ├── MANIFEST.in # sdist contents
407
+ ├── README.md # Chinese README
408
+ ├── README_en-US.md # this file
409
+ └── LICENSE # MIT
410
+ ```
411
+
412
+ ### Module responsibilities
413
+
414
+ | Module | Responsibility |
415
+ |---|---|
416
+ | `patterns.py` | all regexes, character sets, and structural predicates |
417
+ | `lexicon.py` | abbreviation list, conjunction list, base punctuation scores |
418
+ | `config.py` | configuration parameters, adaptive length |
419
+ | `kaomoji.py` | loading and matching the kaomoji trie |
420
+ | `protect.py` | protecting and restoring code block / URL placeholders |
421
+ | `postprocess.py` | closing unclosed Markdown and quotes |
422
+ | `splitter.py` | sentence splitting, packing, scoring, cut search, main entry point |
423
+ | `cli.py` | argument parsing, manual input, automated test |
424
+
425
+ ---
426
+
427
+ ## Design Tradeoffs
428
+
429
+ Every decision in the splitter is a tradeoff between **semantic completeness** and **length tidiness**. The following are deliberate choices, not bugs:
430
+
431
+ | Scenario | Behaviour | Reason |
432
+ |---|---|---|
433
+ | Long run with no punctuation | kept whole, allowed to exceed the cap | an arbitrary hard cut would be meaningless |
434
+ | Over-long code block / table | stays one message | splitting it would break the structure |
435
+ | A sentence after `etc.` | not split | abbreviation ambiguity has no clean answer; stay conservative |
436
+ | Unclosed half-width bracket | not auto-closed | too risky inside kaomoji, formulas, and code |
437
+ | A single message slightly over `max_chars` | allowed | semantics first; better long than shattered |
438
+ | Very long text cut after a preposition | unsolved | the ceiling of the rule approach; v3.0 addresses it |
439
+ | Kaomoji next to a tilde | each becomes its own message | `~` is a soft sentence end and stands semantically alone |
440
+
441
+ ---
442
+
443
+ ## Version History
444
+
445
+ ### v2.1 (current)
446
+
447
+ - packaging standardised: `pyproject.toml` (PEP 621), `py.typed` (PEP 561), a `qikou` console entry point
448
+ - API standardised: `split(text, config=None) -> list[str]`, `Config` is a dataclass
449
+ - CLI switched to subcommands: `qikou split` / `qikou test` / `qikou menu`, with stdin and `--json`
450
+ - the kaomoji corpus ships inside the wheel and is loaded lazily on first use
451
+ - **human-like delays removed** — the project now focuses on splitting quality alone
452
+
453
+ ### v2.0
454
+
455
+ **Cadence**. Rules plus scoring.
456
+
457
+ - split into the `qikou` package
458
+ - modularised: patterns / lexicon / config / kaomoji / protect / postprocess / splitter / cli
459
+ - 120 test cases covering a broad range of edge cases, all running without error
460
+ - command: `python -m qikou`
461
+ - `ChatSplit-v1.0.py` / `ChatSplit-v2.0.py` archived under `legacy/`
462
+ - human-like delay timeline (removed in v2.1)
463
+
464
+ ### v1.0
465
+
466
+ **ChatSplit**. Single-file rule-based version.
467
+
468
+ - basic sentence splitting: `。!?!?…`
469
+ - 8 tilde variants as soft sentence ends
470
+ - kaomoji trie
471
+ - code block and URL protection
472
+ - list, table, and quote detection
473
+ - unclosed Markdown / quote completion
474
+ - human-like delay timeline
475
+ - interactive menu plus automated test
476
+
477
+ ---
478
+
479
+ ## Roadmap
480
+
481
+ ### v3.0 Prosody (planned)
482
+
483
+ **Model-based splitting**. Binary classification of candidate cut points, with LightGBM.
484
+
485
+ - data: LLM synthesis + rule-based weak supervision + user feedback
486
+ - features: local characters + position and length + semantic lexicon + structural state + rule scores
487
+ - model: LightGBM (40 features, ~5 minutes to train, under 10 ms to infer)
488
+ - fusion: rules generate candidates, the model decides the cuts, greedy packing, post-processing to finish
489
+ - hardware: **an ordinary 4-core CPU and 8 GB of RAM is enough** — no GPU needed
490
+
491
+ It addresses the ceiling of the rule approach:
492
+
493
+ - semantic boundary ≠ punctuation boundary (e.g. `我觉得吧,这个方案,可能还需要再想想`)
494
+ - long-text cut optimisation (e.g. after `to` rather than after `and`)
495
+ - tone versus information (e.g. is `好吧。那就这样。` one message or two?)
496
+
497
+ ### v4.0 Breathing (long term)
498
+
499
+ **Small Transformer**. Reconsider once there are more than 50,000 samples. Training needs a GPU; inference runs on CPU. Learns candidate generation, cut selection, and packing end to end.
500
+
501
+ ---
502
+
503
+ ## Naming
504
+
505
+ **气口 (qìkǒu)** — a term from Chinese opera and storytelling: the spot where a performer breathes and pauses. A good qikou makes a passage land naturally, with rhythm, never out of air; a bad one leaves the listener gasping.
506
+
507
+ The English name is **Cadence** (the close of a musical phrase; the rhythm of speech), and the package name is `qikou`.
508
+
509
+ Version names:
510
+
511
+ | Version | Name | Kernel |
512
+ |---|---|---|
513
+ | v1 | 吐字 (Articulation) | hard rules |
514
+ | v2 | 气口 (Cadence) | rules + scoring |
515
+ | v3 | 韵律 (Prosody) | LightGBM |
516
+ | v4 | 呼吸 (Breathing) | Transformer |
517
+
518
+ Each version is another step towards learning how to breathe.
519
+
520
+ ---
521
+
522
+ ## License
523
+
524
+ [MIT](LICENSE) © 2026 Grabrun
525
+
526
+ ### Note on the kaomoji data
527
+
528
+ The kaomoji corpus in `qikou/kaomojis.txt` comes from **https://kaomojis.jp**.
529
+
530
+ A kaomoji is a combination of symbols and normally does not constitute a copyrightable original work. Terms of use differ between sources, however, so this project makes no legal warranty regarding the redistribution of the corpus.
531
+
532
+ If a rights holder considers the inclusion or redistribution of the corpus inappropriate, please reach out through a GitHub Issue and we will adjust or remove it promptly.