Autarkia-Textkit 0.1.0__py3-none-any.whl
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.
- autarkia_textkit/__init__.py +100 -0
- autarkia_textkit/clean.py +152 -0
- autarkia_textkit/emoji.py +85 -0
- autarkia_textkit/force.py +128 -0
- autarkia_textkit/merge.py +218 -0
- autarkia_textkit/numbered.py +95 -0
- autarkia_textkit/py.typed +0 -0
- autarkia_textkit/rules.py +65 -0
- autarkia_textkit/segmenter.py +445 -0
- autarkia_textkit/similarity.py +79 -0
- autarkia_textkit-0.1.0.dist-info/METADATA +266 -0
- autarkia_textkit-0.1.0.dist-info/RECORD +14 -0
- autarkia_textkit-0.1.0.dist-info/WHEEL +4 -0
- autarkia_textkit-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: Autarkia-Textkit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Chinese chat text segmentation and set similarity measures: bubble splitting, cleaning, numbered lists, emoji gluing, Markdown span repair, IoMax/containment/Jaccard/ngram.
|
|
5
|
+
Project-URL: Homepage, https://qishihao.icu/projects/autarkia
|
|
6
|
+
Project-URL: Repository, https://github.com/hakituo/Autarkia-Textkit
|
|
7
|
+
Project-URL: Roadmap, https://github.com/hakituo/Autarkia-tool/blob/main/ROADMAP.md
|
|
8
|
+
Project-URL: Autarkia Runtime, https://github.com/hakituo/Autarkia
|
|
9
|
+
Project-URL: Author, https://qishihao.icu
|
|
10
|
+
Author-email: Shihao Qi <qishihao512@gmail.com>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: autarkia,chat,chinese,containment,jaccard,nlp,similarity,text-segmentation
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
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: Topic :: Text Processing :: Linguistic
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Provides-Extra: segmenter
|
|
27
|
+
Requires-Dist: jieba>=0.42; extra == 'segmenter'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
<p align="center">
|
|
31
|
+
<picture>
|
|
32
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/hakituo/Autarkia-Textkit/main/autarkia-dark.svg">
|
|
33
|
+
<img src="https://raw.githubusercontent.com/hakituo/Autarkia-Textkit/main/autarkia.svg" alt="Autarkia" width="300">
|
|
34
|
+
</picture>
|
|
35
|
+
</p>
|
|
36
|
+
|
|
37
|
+
<p align="center">
|
|
38
|
+
<b>Autarkia-Textkit</b><br>
|
|
39
|
+
<sub>中文聊天消息切分 + 集合相似度 · Chinese chat bubble segmentation & set similarity</sub>
|
|
40
|
+
</p>
|
|
41
|
+
|
|
42
|
+
<p align="center">
|
|
43
|
+
<a href="https://pypi.org/project/Autarkia-Textkit/"><img alt="PyPI" src="https://img.shields.io/pypi/v/autarkia-textkit.svg"></a>
|
|
44
|
+
<a href="https://pypi.org/project/Autarkia-Textkit/"><img alt="Python" src="https://img.shields.io/pypi/pyversions/autarkia-textkit.svg"></a>
|
|
45
|
+
<a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
<p align="center">
|
|
49
|
+
<a href="#中文">简体中文</a> · <a href="#english">English</a>
|
|
50
|
+
</p>
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 中文
|
|
55
|
+
|
|
56
|
+
把模型**一段回复**切成**几条像人打出来的消息**,外加几个分母说得清的集合相似度函数。
|
|
57
|
+
|
|
58
|
+
来自长期在线的 [Autarkia](https://qishihao.icu/projects/autarkia) agent 运行时——那里的切分规则是对着真实 QQ / Android 聊天行为一条条调出来的。整个系列见[组件库路线图](https://github.com/hakituo/Autarkia-tool/blob/main/ROADMAP.md)。
|
|
59
|
+
|
|
60
|
+
### 为什么:切气泡不是 `text.split("。")`
|
|
61
|
+
|
|
62
|
+
下面每条规则都对应一次线上翻车:
|
|
63
|
+
|
|
64
|
+
- **标点要攒够字数才切**,否则「啊。好。」会变成两条机器人气泡。
|
|
65
|
+
- **省略号是情绪,不是句号**:`就是……戳废了` 保持一条,`……哈?!` 不会被撕开。
|
|
66
|
+
- **括号、引号、数学区间是原子**:`[1, 3]` 不会变成 `[1` + `3]`。
|
|
67
|
+
- **编号列表各自成条**,`1. … 2. … 3. …` 不会从条目中间断开。
|
|
68
|
+
- **标点后的 emoji 跟着句子走**:`真的吗?😊` 不拆。
|
|
69
|
+
- **Markdown 结构整体保留**:代码块、表格、标题、`$$` 行都不切。
|
|
70
|
+
- **模型抄进来的时间戳会清掉**:`[今天 20:00] 早啊` → `早啊`。
|
|
71
|
+
- **句尾的句号/逗号去掉,省略号保留**。
|
|
72
|
+
- **承接词合并回去**:以「然后…」开头的碎片不会单独成条。
|
|
73
|
+
|
|
74
|
+
相似度一起发,是因为运行时里「相似度」被不同分母实现了四遍。这里把分母写进函数名:
|
|
75
|
+
|
|
76
|
+
| 函数 | 分母 | 用途 |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| `intersection_over_max` | `max(|A|, |B|)` | 宽容的重叠度 |
|
|
79
|
+
| `containment` | `min(|A|, |B|)` | 「短文本是否被长文本覆盖」 |
|
|
80
|
+
| `jaccard` | `|A ∪ B|` | 经典 Jaccard |
|
|
81
|
+
|
|
82
|
+
### 安装
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pip install autarkia-textkit
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
可选的承接词词性判断:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install "autarkia-textkit[segmenter]"
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
没装 `jieba` 时自动退回一套紧凑的连词前缀兜底逻辑。
|
|
95
|
+
|
|
96
|
+
### 快速开始
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from autarkia_textkit import split_chat_message, split_for_display
|
|
100
|
+
|
|
101
|
+
split_chat_message("我觉得你今天真的特别辛苦,早点休息吧。明天还要早起呢。", min_split_len=10)
|
|
102
|
+
# ["我觉得你今天真的特别辛苦,早点休息吧", "明天还要早起呢"]
|
|
103
|
+
|
|
104
|
+
split_for_display("[今天 20:00] 好呀好呀。")
|
|
105
|
+
# ["好呀好呀"]
|
|
106
|
+
|
|
107
|
+
split_for_display("看这个:\n```python\nprint(1)\n```")
|
|
108
|
+
# ["看这个:", "```python\nprint(1)\n```"]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
确定性切分(把随机源交出去):
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
import random
|
|
115
|
+
split_chat_message(text, comma_split_prob=0.2, rng=random.Random(7))
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
相似度:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from autarkia_textkit import char_ngrams, containment, intersection_over_max, jaccard
|
|
122
|
+
|
|
123
|
+
a = char_ngrams("外卖点了吗")
|
|
124
|
+
b = char_ngrams("外卖点好没")
|
|
125
|
+
containment(a, b) # 短文本覆盖度
|
|
126
|
+
intersection_over_max(a, b) # max 分母的重叠
|
|
127
|
+
jaccard(a, b) # 并集分母
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 模块分工
|
|
131
|
+
|
|
132
|
+
| 组件 | 模块 | 做什么 |
|
|
133
|
+
| --- | --- | --- |
|
|
134
|
+
| `split_chat_message` | `autarkia_textkit.segmenter` | 全部边界规则下的气泡切分 |
|
|
135
|
+
| `clean_chat_text` | `autarkia_textkit.clean` | 时间戳与句尾标点清理 |
|
|
136
|
+
| `split_for_display` | `autarkia_textkit.clean` | 清理 → 归并 Markdown 块 → 切分 |
|
|
137
|
+
| `normalize_numbered_list` | `autarkia_textkit.numbered` | 行内 `1. 2. 3.` 摊成多行 |
|
|
138
|
+
| `merge_continuation_chunks` | `autarkia_textkit.merge` | 合并不自然的断点 |
|
|
139
|
+
| `repair_broken_inline_spans` | `autarkia_textkit.force` | 修复被切开的 `**粗体**` |
|
|
140
|
+
| `intersection_over_max` 等 | `autarkia_textkit.similarity` | 集合度量 |
|
|
141
|
+
|
|
142
|
+
### 设计说明
|
|
143
|
+
|
|
144
|
+
- **不绑渠道**:`preprocess` 与 `pass_through_markers` 都是参数,QQ 专有的清洗/透传标记留在适配层。
|
|
145
|
+
- **只有一个随机缝**:`rng=` 取代模块级 `random`,行为可测。
|
|
146
|
+
- **必需依赖为零**:`jieba` 只是可选 extra,且仅用于词性判断的承接词检测。
|
|
147
|
+
|
|
148
|
+
### 系列与链接
|
|
149
|
+
|
|
150
|
+
- 项目页:<https://qishihao.icu/projects/autarkia>
|
|
151
|
+
- 运行时仓库:<https://github.com/hakituo/Autarkia>
|
|
152
|
+
- 本包:<https://github.com/hakituo/Autarkia-Textkit>
|
|
153
|
+
- 组件库路线图:<https://github.com/hakituo/Autarkia-tool/blob/main/ROADMAP.md>
|
|
154
|
+
- 作者:Shihao Qi — <https://qishihao.icu>
|
|
155
|
+
|
|
156
|
+
### 许可
|
|
157
|
+
|
|
158
|
+
MIT
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## English
|
|
163
|
+
|
|
164
|
+
Turn **one model reply** into **several messages that read like a human typed them** — plus set-similarity functions whose names state their actual denominator.
|
|
165
|
+
|
|
166
|
+
Extracted from the [Autarkia](https://qishihao.icu/projects/autarkia) agent runtime, where these rules were tuned against real QQ/Android chat behavior. See the [component roadmap](https://github.com/hakituo/Autarkia-tool/blob/main/ROADMAP.md).
|
|
167
|
+
|
|
168
|
+
### Why
|
|
169
|
+
|
|
170
|
+
Splitting a reply into chat bubbles is not `text.split("。")`. The rules here exist because each naive rule failed in production:
|
|
171
|
+
|
|
172
|
+
- **Sentence punctuation only splits after enough text.** Otherwise "啊。好。" becomes two robotic bubbles.
|
|
173
|
+
- **Ellipses are emotion, not punctuation.** `就是……戳废了` stays one bubble; `……哈?!` is never torn apart.
|
|
174
|
+
- **Brackets, quotes and math ranges are atomic.** `[1, 3]` does not become `[1` + `3]`.
|
|
175
|
+
- **Numbered lists become separate bubbles.** `1. ... 2. ... 3. ...` never breaks mid-item.
|
|
176
|
+
- **Emoji after punctuation sticks to the sentence.** `真的吗?😊` stays together.
|
|
177
|
+
- **Markdown structure survives.** Fenced code, tables, headings and `$$` lines are kept whole.
|
|
178
|
+
- **Model-copied timestamps are stripped.** `[今天 20:00] 早啊` -> `早啊`.
|
|
179
|
+
- **Trailing periods/commas are removed, ellipses preserved.**
|
|
180
|
+
- **Continuation words are merged back.** "然后..." does not start a lonely bubble.
|
|
181
|
+
|
|
182
|
+
Set similarity is included because "similarity" was implemented four times with different denominators in the runtime. Here the names are explicit:
|
|
183
|
+
|
|
184
|
+
| Function | Denominator | Use |
|
|
185
|
+
| --- | --- | --- |
|
|
186
|
+
| `intersection_over_max` | `max(|A|, |B|)` | tolerant overlap |
|
|
187
|
+
| `containment` | `min(|A|, |B|)` | "is the short text covered by the long one" |
|
|
188
|
+
| `jaccard` | `|A ∪ B|` | classic Jaccard |
|
|
189
|
+
|
|
190
|
+
### Install
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
pip install autarkia-textkit
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Optional continuation-word POS detection:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
pip install "autarkia-textkit[segmenter]"
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Without `jieba`, a compact conjunction-prefix fallback is used.
|
|
203
|
+
|
|
204
|
+
### Quick start
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from autarkia_textkit import split_chat_message, split_for_display
|
|
208
|
+
|
|
209
|
+
split_chat_message("我觉得你今天真的特别辛苦,早点休息吧。明天还要早起呢。", min_split_len=10)
|
|
210
|
+
# ["我觉得你今天真的特别辛苦,早点休息吧", "明天还要早起呢"]
|
|
211
|
+
|
|
212
|
+
split_for_display("[今天 20:00] 好呀好呀。")
|
|
213
|
+
# ["好呀好呀"]
|
|
214
|
+
|
|
215
|
+
split_for_display("看这个:\n```python\nprint(1)\n```")
|
|
216
|
+
# ["看这个:", "```python\nprint(1)\n```"]
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Deterministic splitting:
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
import random
|
|
223
|
+
split_chat_message(text, comma_split_prob=0.2, rng=random.Random(7))
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Similarity:
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
from autarkia_textkit import char_ngrams, containment, intersection_over_max, jaccard
|
|
230
|
+
|
|
231
|
+
a = char_ngrams("外卖点了吗")
|
|
232
|
+
b = char_ngrams("外卖点好没")
|
|
233
|
+
containment(a, b) # short text coverage
|
|
234
|
+
intersection_over_max(a, b) # max-denominator overlap
|
|
235
|
+
jaccard(a, b) # union denominator
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Concepts
|
|
239
|
+
|
|
240
|
+
| Piece | Module | What it does |
|
|
241
|
+
| --- | --- | --- |
|
|
242
|
+
| `split_chat_message` | `autarkia_textkit.segmenter` | bubble splitting with all boundary rules |
|
|
243
|
+
| `clean_chat_text` | `autarkia_textkit.clean` | timestamp + trailing punctuation cleanup |
|
|
244
|
+
| `split_for_display` | `autarkia_textkit.clean` | clean -> group Markdown blocks -> split |
|
|
245
|
+
| `normalize_numbered_list` | `autarkia_textkit.numbered` | inline `1. 2. 3.` -> lines |
|
|
246
|
+
| `merge_continuation_chunks` | `autarkia_textkit.merge` | rejoin unnatural breaks |
|
|
247
|
+
| `repair_broken_inline_spans` | `autarkia_textkit.force` | rejoin split `**bold**` |
|
|
248
|
+
| `intersection_over_max` etc. | `autarkia_textkit.similarity` | set measures |
|
|
249
|
+
|
|
250
|
+
### Design notes
|
|
251
|
+
|
|
252
|
+
- **No channel coupling.** `preprocess` and `pass_through_markers` are parameters, so QQ-specific stripping or passthrough codes stay in the adapter.
|
|
253
|
+
- **One RNG seam.** `rng=` replaces the module-global `random`, making behavior testable.
|
|
254
|
+
- **Zero required dependencies.** `jieba` is an optional extra used only for POS-based continuation detection.
|
|
255
|
+
|
|
256
|
+
### The bigger picture
|
|
257
|
+
|
|
258
|
+
- Project page: <https://qishihao.icu/projects/autarkia>
|
|
259
|
+
- Runtime repository: <https://github.com/hakituo/Autarkia>
|
|
260
|
+
- This package: <https://github.com/hakituo/Autarkia-Textkit>
|
|
261
|
+
- Roadmap: <https://github.com/hakituo/Autarkia-tool/blob/main/ROADMAP.md>
|
|
262
|
+
- Author: Shihao Qi — <https://qishihao.icu>
|
|
263
|
+
|
|
264
|
+
### License
|
|
265
|
+
|
|
266
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
autarkia_textkit/__init__.py,sha256=JH6qcYhxxavxuhrTv5mtsaHmRcqZKnKFErPmtF_Ul-E,2412
|
|
2
|
+
autarkia_textkit/clean.py,sha256=U-3OyLjeNGDACCoaOJMX_5TKWGZF61JTiQJde_kjBwg,4544
|
|
3
|
+
autarkia_textkit/emoji.py,sha256=9Egf752IEPNk4FfzfiUShTTjErlCFv36drl5q4O8eJY,1979
|
|
4
|
+
autarkia_textkit/force.py,sha256=MXljmcSp_fu3lZ8CqCkMqQ7U_jhnEn5nFOe-cfQq3nE,4203
|
|
5
|
+
autarkia_textkit/merge.py,sha256=1LFQseHgk920en8Z2s0pLga7g5VA4Gm7ZJIKih2T2e0,6793
|
|
6
|
+
autarkia_textkit/numbered.py,sha256=ZVwkE0tRRKPh7Vx46pFN0YMhdqE2S8qju-tuEOFthwQ,3091
|
|
7
|
+
autarkia_textkit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
autarkia_textkit/rules.py,sha256=1yXVSxF1mto6QYLTupLdYaXv8Je-wHedRHVMEn2sJVw,2572
|
|
9
|
+
autarkia_textkit/segmenter.py,sha256=S5Gnk59lrVOz9uIijVukUydRJBEhIxGvwdN0HszEtQw,17352
|
|
10
|
+
autarkia_textkit/similarity.py,sha256=1CFIz3TrsD8rn-SICb2wzh8aqKppRP09QCAevoHgj9I,2388
|
|
11
|
+
autarkia_textkit-0.1.0.dist-info/METADATA,sha256=anD5ceqWNtDrBspx_BrN1g8bhmjaRcu81urM6mpL_HQ,10962
|
|
12
|
+
autarkia_textkit-0.1.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
13
|
+
autarkia_textkit-0.1.0.dist-info/licenses/LICENSE,sha256=KjCC0TPNgxUUjuiaiDm4bNjiDFPtghA1apRPKt_8cU0,1066
|
|
14
|
+
autarkia_textkit-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shihao Qi
|
|
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.
|