dsh-lifecard 0.1.2 → 0.2.1
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.
- package/README.md +62 -1
- package/cordis.patch.yml +163 -2
- package/lib/career.js +488 -0
- package/lib/client.js +797 -46
- package/lib/game.js +373 -0
- package/lib/index.js +690 -49
- package/lib/novel.js +109 -10
- package/lib/presets.js +459 -0
- package/lib/store.js +89 -15
- package/lib/tavern.js +56 -1
- package/lifecard-tools.js +549 -0
- package/package.json +11 -3
- package/skills/blind-review-loop/SKILL.md +205 -0
- package/skills/human-writing/LICENSE +21 -0
- package/skills/human-writing/SKILL.md +170 -0
- package/skills/human-writing/VERSION +1 -0
- package/skills/human-writing/agents/openai.yaml +4 -0
- package/skills/human-writing/dist/human-writing-lite.md +29 -0
- package/skills/human-writing/references/essay-or-fiction.md +79 -0
- package/skills/human-writing/references/fiction.md +115 -0
- package/skills/human-writing/references/formats.md +99 -0
- package/skills/human-writing/references/forum-prose.md +349 -0
- package/skills/human-writing/references/reality.md +119 -0
- package/skills/human-writing/references/revision.md +204 -0
- package/skills/human-writing/references/story-diagnosis.md +131 -0
- package/skills/human-writing/references/writing-ceiling.md +151 -0
- package/skills/human-writing/scripts/check_prose.py +781 -0
- package/skills/lifecard-novel-writing/SKILL.md +88 -0
- package/skills/visual-novel/SKILL.md +139 -0
- package/skills/visual-novel/references/script-and-flow.md +89 -0
|
@@ -0,0 +1,781 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""检查中文成稿的硬禁令与常见模型化形状。只报警,不自动改文。
|
|
3
|
+
|
|
4
|
+
标点口径:冒号、破折号、引号都不再按“出现即失败”处理,改为按密度判定。
|
|
5
|
+
引号本身不限量,只提醒同一篇里混用两套以上引号。冒号每千汉字允许两处,
|
|
6
|
+
长破折号(`——`)每千汉字允许六处,不足一千字的短稿各保底两处;超出限额才判失败。
|
|
7
|
+
单处破折号(`—`、`–`)只表停顿,不计入、也不判失败。
|
|
8
|
+
提示性抬价冒号(“一句话总结:”“核心是:”这类)仍然是硬失败。
|
|
9
|
+
|
|
10
|
+
体裁口径:默认 `--genre prose`,按说明文/观点文判。`--genre fiction` 走小说口径,
|
|
11
|
+
跳过商业黑话、硬停词、模型路标、名词化、连词密度,以及句长变异系数、短段连排、
|
|
12
|
+
单句段占比、借喻聚类这四类散文化节律警告——它们的参照系是长文散文,用在通篇短句
|
|
13
|
+
对白的小说上只会全中。小说的硬禁令(翻案句、抬价冒号、破折号密度、三连同构排比、
|
|
14
|
+
抽象名词配具体动词)一条不减。
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import collections
|
|
21
|
+
import re
|
|
22
|
+
import sys
|
|
23
|
+
from dataclasses import dataclass
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
HARD_STOPS = (
|
|
28
|
+
"说白了",
|
|
29
|
+
"说穿了",
|
|
30
|
+
"先说结论",
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
HARD_JARGON = (
|
|
34
|
+
"赋能",
|
|
35
|
+
"抓手",
|
|
36
|
+
"商业闭环",
|
|
37
|
+
"价值闭环",
|
|
38
|
+
"能力沉淀",
|
|
39
|
+
"拉通",
|
|
40
|
+
"底层逻辑",
|
|
41
|
+
"顶层设计",
|
|
42
|
+
"认知跃迁",
|
|
43
|
+
"价值释放",
|
|
44
|
+
"能力建设",
|
|
45
|
+
"降本增效",
|
|
46
|
+
"内容矩阵",
|
|
47
|
+
"全链路",
|
|
48
|
+
"组合拳",
|
|
49
|
+
"打开想象空间",
|
|
50
|
+
"结构性机会",
|
|
51
|
+
"关键命题",
|
|
52
|
+
"深层逻辑",
|
|
53
|
+
"技术底座",
|
|
54
|
+
"公共底座",
|
|
55
|
+
"技术主权",
|
|
56
|
+
"认知增量",
|
|
57
|
+
"迭代闭环",
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
CONTEXT_JARGON = (
|
|
61
|
+
"沉淀",
|
|
62
|
+
"颗粒度",
|
|
63
|
+
"对齐",
|
|
64
|
+
"协同",
|
|
65
|
+
"链路",
|
|
66
|
+
"生态位",
|
|
67
|
+
"心智",
|
|
68
|
+
"范式",
|
|
69
|
+
"方法论",
|
|
70
|
+
"核心变量",
|
|
71
|
+
"打法",
|
|
72
|
+
"想象空间",
|
|
73
|
+
"闭环",
|
|
74
|
+
"不丢",
|
|
75
|
+
"单点风险",
|
|
76
|
+
"主脊柱",
|
|
77
|
+
"材料锚点",
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
LYRIC_WORDS = (
|
|
81
|
+
"安放",
|
|
82
|
+
"抵达",
|
|
83
|
+
"微光",
|
|
84
|
+
"褶皱",
|
|
85
|
+
"丰盈",
|
|
86
|
+
"滚烫",
|
|
87
|
+
"轻盈",
|
|
88
|
+
"赤裸",
|
|
89
|
+
"剥开",
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
ROAD_SIGNS = (
|
|
93
|
+
"更微妙的是",
|
|
94
|
+
"还有一层",
|
|
95
|
+
"只说对了一半",
|
|
96
|
+
"值得注意的是",
|
|
97
|
+
"需要指出的是",
|
|
98
|
+
"从某种意义上说",
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
ROAD_STRIP_CHARS = "。!?!? \n"
|
|
102
|
+
|
|
103
|
+
QUOTE_OPENERS = ("「", "『", "“", "‘", '"', "'")
|
|
104
|
+
|
|
105
|
+
QUOTE_PAIR_STYLES = (
|
|
106
|
+
("「」", re.compile(r"「[^」\n]{0,40}」")),
|
|
107
|
+
("『』", re.compile(r"『[^』\n]{0,40}』")),
|
|
108
|
+
("“”", re.compile(r"“[^”\n]{0,40}”")),
|
|
109
|
+
('""', re.compile(r'"[^"\n]{0,40}"')),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
HOLLOW_COLON_LABELS = (
|
|
113
|
+
"一句话总结",
|
|
114
|
+
"一句话说",
|
|
115
|
+
"一句话概括",
|
|
116
|
+
"总结一下",
|
|
117
|
+
"核心是",
|
|
118
|
+
"关键是",
|
|
119
|
+
"重点是",
|
|
120
|
+
"先说结论",
|
|
121
|
+
"答案很",
|
|
122
|
+
"道理很",
|
|
123
|
+
"问题在于",
|
|
124
|
+
"本质是",
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
# 冒号每千汉字允许两处,长破折号每千汉字允许六处,短稿都保底两处。
|
|
128
|
+
COLON_ALLOWANCE_PER_1000 = 2
|
|
129
|
+
DASH_RUN_ALLOWANCE = 6
|
|
130
|
+
ALLOWANCE_FLOOR = 2
|
|
131
|
+
DASH_AFTER_COMMA = re.compile(r",\s*[—–]{2,}")
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def punctuation_allowance(total_han: int, per_1000: int) -> int:
|
|
135
|
+
return max(ALLOWANCE_FLOOR, total_han * per_1000 // 1000)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def count_flagged_lines(text: str, lines, limit: int = 8) -> str:
|
|
139
|
+
return "、".join(str(value) for value in lines[:limit])
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def dash_marks(text: str):
|
|
143
|
+
"""返回两处以上的破折号串。两处以内是正常停顿,不计。"""
|
|
144
|
+
|
|
145
|
+
return [
|
|
146
|
+
(match.start(), match.group())
|
|
147
|
+
for match in re.finditer(r"[—–]{2,}", text)
|
|
148
|
+
]
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
PIVOT_PATTERNS = (
|
|
152
|
+
re.compile(r"(?:并)?不是[^。!?\n]{0,90}而是"),
|
|
153
|
+
re.compile(r"并非[^。!?\n]{0,90}而是"),
|
|
154
|
+
re.compile(r"不在于[^。!?\n]{0,90}而在于"),
|
|
155
|
+
re.compile(r"与其说[^。!?\n]{0,90}(?:不如|毋宁|倒不如)"),
|
|
156
|
+
re.compile(r"[。!?!?]\s*而是"),
|
|
157
|
+
re.compile(r"表面(?:上)?[^。!?\n]{0,90}(?:其实|实际|实则)"),
|
|
158
|
+
re.compile(r"看似[^。!?\n]{0,90}(?:其实|实际|实则)"),
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
SEMANTIC_PIVOT_PATTERNS = (
|
|
162
|
+
re.compile(r"(?:总|一直|曾|都)?以为[^!?\n]{2,60}?(?:其实|才发现|才明白|才知道|后来才)"),
|
|
163
|
+
re.compile(r"(?:总|都|一直)以为[^!?\n]{2,60}?[。,](?:可|但|其实)"),
|
|
164
|
+
re.compile(r"回头(?:看|一看)?才(?:发现|明白|知道)"),
|
|
165
|
+
re.compile(r"(?:并)?不是[^。!?\n]{1,40},(?:更|才)?是[^,。!?\n]"),
|
|
166
|
+
re.compile(r"从来(?:都)?(?:不是|与[^。!?,\n]{1,12}无关)"),
|
|
167
|
+
re.compile(r"答案(?:是否定的|恰恰相反)|恰恰相反"),
|
|
168
|
+
re.compile(r"表面(?:上)?[^!?\n]{0,60}。[^!?\n]{0,12}(?:其实|实际|实则)"),
|
|
169
|
+
re.compile(r"看似[^!?\n]{0,60}。[^!?\n]{0,12}(?:其实|实际|实则)"),
|
|
170
|
+
re.compile(r"[^,。!?\n]{1,12}不重要,(?:重要|要紧)的是"),
|
|
171
|
+
re.compile(r"真正[^,。!?\n]{0,16}的(?:,)?是"),
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
NOMINALIZATION_PATTERNS = (
|
|
175
|
+
re.compile(r"进行(?:了|一次|一场|着)?[^。,!?\n]{0,10}(?:调整|优化|升级|分析|讨论|沟通|梳理|复盘|迭代|探索|尝试|思考|规划|布局)"),
|
|
176
|
+
re.compile(r"实现了?[^。,!?\n]{0,14}的?[^。,!?\n]{0,6}(?:提升|增长|突破|转变|跃升|落地)"),
|
|
177
|
+
re.compile(r"完成了?对[^。,!?\n]{0,16}的"),
|
|
178
|
+
re.compile(r"起到了?[^。,!?\n]{0,12}的?作用"),
|
|
179
|
+
re.compile(r"具有[^。,!?\n]{0,10}(?:意义|价值)"),
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
CONJUNCTIONS = (
|
|
183
|
+
"因为",
|
|
184
|
+
"所以",
|
|
185
|
+
"但是",
|
|
186
|
+
"然而",
|
|
187
|
+
"同时",
|
|
188
|
+
"此外",
|
|
189
|
+
"而且",
|
|
190
|
+
"并且",
|
|
191
|
+
"因此",
|
|
192
|
+
"不仅",
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
ROAD_SIGN_PATTERNS = (
|
|
196
|
+
re.compile(
|
|
197
|
+
rf"(?:^|[。!?!?]\s*){re.escape(ROAD_SIGNS[0])}[^。!?!?\n]{{0,24}}",
|
|
198
|
+
re.MULTILINE,
|
|
199
|
+
),
|
|
200
|
+
re.compile(
|
|
201
|
+
rf"(?:^|[。!?!?]\s*){re.escape(ROAD_SIGNS[1])}(?=(?:更|原因|问题|意思|考虑|变化|逻辑|价值|作用|风险|影响|值得|很少|不容易|常被|往往))[^。!?!?\n]{{0,24}}",
|
|
202
|
+
re.MULTILINE,
|
|
203
|
+
),
|
|
204
|
+
*(
|
|
205
|
+
re.compile(
|
|
206
|
+
rf"(?:^|[。!?!?]\s*){re.escape(phrase)}[^。!?!?\n]{{0,24}}",
|
|
207
|
+
re.MULTILINE,
|
|
208
|
+
)
|
|
209
|
+
for phrase in ROAD_SIGNS[2:]
|
|
210
|
+
),
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
SOFT_MARKERS = (
|
|
214
|
+
"真正",
|
|
215
|
+
"本质上",
|
|
216
|
+
"更深层次",
|
|
217
|
+
"归根结底",
|
|
218
|
+
"换句话说",
|
|
219
|
+
"不可否认",
|
|
220
|
+
"核心是",
|
|
221
|
+
"关键在于",
|
|
222
|
+
"这意味着",
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
REPEATED_OPENERS = (
|
|
226
|
+
"其实",
|
|
227
|
+
"不过",
|
|
228
|
+
"当然",
|
|
229
|
+
"所以",
|
|
230
|
+
"但是",
|
|
231
|
+
"后来",
|
|
232
|
+
"当时",
|
|
233
|
+
"很多人",
|
|
234
|
+
"问题是",
|
|
235
|
+
"更重要的是",
|
|
236
|
+
"说到这里",
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
LEFT_BRANCH_PATTERNS = (
|
|
240
|
+
re.compile(r"(?:^|[。!?]\s*)在[^,。!?\n]{12,70}(?:以后|之后|之前|以前|过程中|情况下|背景下),"),
|
|
241
|
+
re.compile(r"(?:^|[。!?]\s*)那些[^,。!?\n]{10,60}的[^,。!?\n]{2,30}[,。]"),
|
|
242
|
+
re.compile(r"(?:^|[。!?]\s*)(?:真正|最终|最后)让[^,。!?\n]{8,70}的,是"),
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
METAPHOR_FIELDS = {
|
|
246
|
+
"温度": ("降温", "升温", "冷却", "余温", "温度最高"),
|
|
247
|
+
"生死战争": ("杀死", "死因", "枪响", "开火", "战场", "引爆", "弹药"),
|
|
248
|
+
"建筑灾害": ("坍塌", "崩塌", "地基", "砖头", "支柱", "废墟"),
|
|
249
|
+
"仓储租赁": ("仓库", "库房", "租金", "取货", "入库", "库存"),
|
|
250
|
+
"道路竞赛": ("赛道", "跑道", "岔路", "十字路口", "终点线", "门票"),
|
|
251
|
+
"机器器官": ("齿轮", "引擎", "发动机", "血管", "骨架", "肌肉"),
|
|
252
|
+
"海洋航行": ("蓝海", "浪潮", "潮水", "航船", "灯塔", "彼岸"),
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
@dataclass
|
|
257
|
+
class Paragraph:
|
|
258
|
+
position: int
|
|
259
|
+
text: str
|
|
260
|
+
han: int
|
|
261
|
+
sentences: int
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def han_count(text: str) -> int:
|
|
265
|
+
return len(re.findall(r"[\u4e00-\u9fff]", text))
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def line_number(text: str, position: int) -> int:
|
|
269
|
+
return text.count("\n", 0, position) + 1
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def excerpt(value: str, width: int = 72) -> str:
|
|
273
|
+
value = re.sub(r"\s+", " ", value).strip()
|
|
274
|
+
return value if len(value) <= width else value[: width - 1] + "…"
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def mask_non_prose(text: str) -> str:
|
|
278
|
+
"""屏蔽代码、网址和机器元数据,同时保留字符位置与换行。"""
|
|
279
|
+
|
|
280
|
+
def mask(match: re.Match[str]) -> str:
|
|
281
|
+
return "".join("\n" if char == "\n" else " " for char in match.group())
|
|
282
|
+
|
|
283
|
+
patterns = (
|
|
284
|
+
re.compile(r"\A---\s*\n.*?\n---\s*(?:\n|\Z)", re.DOTALL),
|
|
285
|
+
re.compile(r"```.*?```", re.DOTALL),
|
|
286
|
+
re.compile(r"`[^`\n]*`"),
|
|
287
|
+
re.compile(r"\]\([^\n)]*\)"),
|
|
288
|
+
re.compile(r"https?://[^\s)>]+"),
|
|
289
|
+
re.compile(r"<[^>\n]+>"),
|
|
290
|
+
)
|
|
291
|
+
masked = text
|
|
292
|
+
for pattern in patterns:
|
|
293
|
+
masked = pattern.sub(mask, masked)
|
|
294
|
+
return masked
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def non_overlapping_terms(text: str, terms: tuple[str, ...]):
|
|
298
|
+
matches = []
|
|
299
|
+
occupied = []
|
|
300
|
+
for term in sorted(terms, key=len, reverse=True):
|
|
301
|
+
for match in re.finditer(re.escape(term), text):
|
|
302
|
+
start, end = match.span()
|
|
303
|
+
if any(start < old_end and end > old_start for old_start, old_end in occupied):
|
|
304
|
+
continue
|
|
305
|
+
matches.append((start, term))
|
|
306
|
+
occupied.append((start, end))
|
|
307
|
+
return sorted(matches)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def all_matches(text: str, patterns: tuple[re.Pattern[str], ...]):
|
|
311
|
+
matches = []
|
|
312
|
+
for pattern in patterns:
|
|
313
|
+
matches.extend(pattern.finditer(text))
|
|
314
|
+
return sorted(matches, key=lambda match: match.start())
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def heavy_de_sentences(text: str):
|
|
318
|
+
"""找出主干可能被多个“的”压到后面的长句。"""
|
|
319
|
+
|
|
320
|
+
matches = []
|
|
321
|
+
pattern = re.compile(r"[^。!?!?\n]+(?:[。!?!?]|$)")
|
|
322
|
+
for match in pattern.finditer(text):
|
|
323
|
+
value = match.group()
|
|
324
|
+
if han_count(value) >= 38 and value.count("的") >= 4:
|
|
325
|
+
matches.append(match)
|
|
326
|
+
return matches
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def anaphora_runs(text: str, minimum: int = 3):
|
|
330
|
+
"""找出同一句里三个以上小句用同一个开头的排比。"""
|
|
331
|
+
|
|
332
|
+
matches = []
|
|
333
|
+
for sentence in re.finditer(r"[^。!?!?\n]+(?:[。!?!?]|$)", text):
|
|
334
|
+
clauses = [
|
|
335
|
+
clause.strip()
|
|
336
|
+
for clause in re.split(r"[,、;,;]", sentence.group())
|
|
337
|
+
if han_count(clause) >= 3
|
|
338
|
+
]
|
|
339
|
+
if len(clauses) < minimum:
|
|
340
|
+
continue
|
|
341
|
+
run = 1
|
|
342
|
+
for previous, current in zip(clauses, clauses[1:]):
|
|
343
|
+
if previous[:2] == current[:2] and re.match(r"[一-鿿]{2}", current):
|
|
344
|
+
run += 1
|
|
345
|
+
if run >= minimum:
|
|
346
|
+
matches.append(sentence)
|
|
347
|
+
break
|
|
348
|
+
else:
|
|
349
|
+
run = 1
|
|
350
|
+
return matches
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def sentence_length_cv(text: str):
|
|
354
|
+
"""句长变异系数。人写的长短句差距大,模型的句长彼此接近。"""
|
|
355
|
+
|
|
356
|
+
lengths = [
|
|
357
|
+
han_count(match.group())
|
|
358
|
+
for match in re.finditer(r"[^。!?!?\n]+[。!?!?]", text)
|
|
359
|
+
if han_count(match.group()) >= 4
|
|
360
|
+
]
|
|
361
|
+
if len(lengths) < 12:
|
|
362
|
+
return None
|
|
363
|
+
mean = sum(lengths) / len(lengths)
|
|
364
|
+
if mean == 0:
|
|
365
|
+
return None
|
|
366
|
+
variance = sum((value - mean) ** 2 for value in lengths) / len(lengths)
|
|
367
|
+
return (variance ** 0.5) / mean, len(lengths)
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def bracket_highlights(text: str):
|
|
371
|
+
"""「」括起来的短语。太密说明在批量造金句。"""
|
|
372
|
+
|
|
373
|
+
return list(re.finditer(r"[「『][^」』\n]{1,6}[」』]", text))
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def prose_paragraphs(text: str) -> list[Paragraph]:
|
|
377
|
+
paragraphs = []
|
|
378
|
+
cursor = 0
|
|
379
|
+
for block in re.split(r"\n\s*\n", text):
|
|
380
|
+
position = text.find(block, cursor)
|
|
381
|
+
cursor = max(position + len(block), cursor)
|
|
382
|
+
clean = re.sub(r"[>*_`]", "", block).strip()
|
|
383
|
+
if not clean or clean.startswith(("#", "http", "![", "```")):
|
|
384
|
+
continue
|
|
385
|
+
if re.match(r"^(?:[-+*]|\d+[.、])\s", clean):
|
|
386
|
+
continue
|
|
387
|
+
count = han_count(clean)
|
|
388
|
+
if count < 4:
|
|
389
|
+
continue
|
|
390
|
+
sentences = max(1, len(re.findall(r"[。!?!?]", clean)))
|
|
391
|
+
paragraphs.append(Paragraph(position, clean, count, sentences))
|
|
392
|
+
return paragraphs
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def metaphor_cluster(text: str, distance: int = 800):
|
|
396
|
+
hits = []
|
|
397
|
+
for field, words in METAPHOR_FIELDS.items():
|
|
398
|
+
for word in words:
|
|
399
|
+
for match in re.finditer(re.escape(word), text):
|
|
400
|
+
hits.append((match.start(), field, word))
|
|
401
|
+
hits.sort()
|
|
402
|
+
for index, (start, _, _) in enumerate(hits):
|
|
403
|
+
window = [hit for hit in hits[index:] if hit[0] - start <= distance]
|
|
404
|
+
fields = {hit[1] for hit in window}
|
|
405
|
+
if len(fields) >= 3:
|
|
406
|
+
return window, fields
|
|
407
|
+
return None
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def short_streak(paragraphs: list[Paragraph], limit: int = 4):
|
|
411
|
+
streak = []
|
|
412
|
+
for paragraph in paragraphs:
|
|
413
|
+
if paragraph.han <= 24 and paragraph.sentences <= 1:
|
|
414
|
+
streak.append(paragraph)
|
|
415
|
+
if len(streak) >= limit:
|
|
416
|
+
return streak
|
|
417
|
+
else:
|
|
418
|
+
streak = []
|
|
419
|
+
return None
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def opener_counts(paragraphs: list[Paragraph]):
|
|
423
|
+
counts = collections.Counter()
|
|
424
|
+
examples = {}
|
|
425
|
+
for paragraph in paragraphs:
|
|
426
|
+
value = paragraph.text.lstrip("“‘\"((")
|
|
427
|
+
for opener in REPEATED_OPENERS:
|
|
428
|
+
if value.startswith(opener):
|
|
429
|
+
counts[opener] += 1
|
|
430
|
+
examples.setdefault(opener, paragraph.position)
|
|
431
|
+
break
|
|
432
|
+
return counts, examples
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def read_text(path: str) -> str:
|
|
436
|
+
if path == "-":
|
|
437
|
+
return sys.stdin.read()
|
|
438
|
+
return Path(path).read_text(encoding="utf-8")
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
def main() -> int:
|
|
442
|
+
parser = argparse.ArgumentParser(description="检查中文成稿的硬禁令与模型化形状")
|
|
443
|
+
parser.add_argument("path", help="Markdown 或文本文件路径。使用 - 从标准输入读取")
|
|
444
|
+
parser.add_argument(
|
|
445
|
+
"--genre",
|
|
446
|
+
choices=("prose", "fiction"),
|
|
447
|
+
default="prose",
|
|
448
|
+
help="prose(默认)按说明文/观点文判;fiction 走小说口径,跳过说明文专属项",
|
|
449
|
+
)
|
|
450
|
+
args = parser.parse_args()
|
|
451
|
+
|
|
452
|
+
try:
|
|
453
|
+
text = read_text(args.path)
|
|
454
|
+
except (OSError, UnicodeError) as error:
|
|
455
|
+
print(f"无法读取稿件。{error}", file=sys.stderr)
|
|
456
|
+
return 2
|
|
457
|
+
|
|
458
|
+
prose = mask_non_prose(text)
|
|
459
|
+
total_han = han_count(prose)
|
|
460
|
+
if total_han == 0:
|
|
461
|
+
print("没有检测到汉字。", file=sys.stderr)
|
|
462
|
+
return 2
|
|
463
|
+
|
|
464
|
+
failures = []
|
|
465
|
+
warnings = []
|
|
466
|
+
|
|
467
|
+
fiction = args.genre == "fiction"
|
|
468
|
+
if fiction:
|
|
469
|
+
hard_stops: tuple[str, ...] = ()
|
|
470
|
+
hard_jargon: tuple[str, ...] = ()
|
|
471
|
+
context_jargon: tuple[str, ...] = ()
|
|
472
|
+
soft_markers: tuple[str, ...] = ()
|
|
473
|
+
conjunctions: tuple[str, ...] = ()
|
|
474
|
+
road_sign_patterns: tuple[re.Pattern[str], ...] = ()
|
|
475
|
+
nominalization_patterns: tuple[re.Pattern[str], ...] = ()
|
|
476
|
+
else:
|
|
477
|
+
hard_stops = HARD_STOPS
|
|
478
|
+
hard_jargon = HARD_JARGON
|
|
479
|
+
context_jargon = CONTEXT_JARGON
|
|
480
|
+
soft_markers = SOFT_MARKERS
|
|
481
|
+
conjunctions = CONJUNCTIONS
|
|
482
|
+
road_sign_patterns = ROAD_SIGN_PATTERNS
|
|
483
|
+
nominalization_patterns = NOMINALIZATION_PATTERNS
|
|
484
|
+
|
|
485
|
+
colon_hits = []
|
|
486
|
+
for symbol in (":", ":"):
|
|
487
|
+
for match in re.finditer(re.escape(symbol), prose):
|
|
488
|
+
before = prose[match.start() - 1 : match.start()]
|
|
489
|
+
after = prose[match.end() : match.end() + 1]
|
|
490
|
+
if before.isdigit() and after.isdigit():
|
|
491
|
+
continue
|
|
492
|
+
colon_hits.append(match.start())
|
|
493
|
+
colon_hits.sort()
|
|
494
|
+
|
|
495
|
+
hollow_colons = []
|
|
496
|
+
quote_colons = []
|
|
497
|
+
for position in colon_hits:
|
|
498
|
+
head = prose[max(0, position - 14) : position]
|
|
499
|
+
tail = prose[position + 1 : position + 3].lstrip()
|
|
500
|
+
if any(hollow in head for hollow in HOLLOW_COLON_LABELS):
|
|
501
|
+
hollow_colons.append(position)
|
|
502
|
+
elif tail[:1] in QUOTE_OPENERS:
|
|
503
|
+
quote_colons.append(position)
|
|
504
|
+
|
|
505
|
+
if hollow_colons:
|
|
506
|
+
lines = count_flagged_lines(
|
|
507
|
+
text, [line_number(text, position) for position in hollow_colons]
|
|
508
|
+
)
|
|
509
|
+
failures.append(
|
|
510
|
+
f"提示性抬价冒号共 {len(hollow_colons)} 处,第 {lines} 行。"
|
|
511
|
+
"这种冒号只是把下文抬成结论,改成正面陈述或句号。"
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
colon_allowance = punctuation_allowance(total_han, COLON_ALLOWANCE_PER_1000)
|
|
515
|
+
if len(colon_hits) > colon_allowance:
|
|
516
|
+
lines = count_flagged_lines(
|
|
517
|
+
text, [line_number(text, position) for position in colon_hits]
|
|
518
|
+
)
|
|
519
|
+
failures.append(
|
|
520
|
+
f"冒号共 {len(colon_hits)} 处,超过这份稿子 {total_han} 字允许的 "
|
|
521
|
+
f"{colon_allowance} 处(每千字 {COLON_ALLOWANCE_PER_1000} 处),第 {lines} 行起。"
|
|
522
|
+
"引出原话、列条目、标时间和比例都可以留,超出的改成逗号、句号或直接说。"
|
|
523
|
+
)
|
|
524
|
+
elif colon_hits:
|
|
525
|
+
lines = count_flagged_lines(
|
|
526
|
+
text, [line_number(text, position) for position in colon_hits]
|
|
527
|
+
)
|
|
528
|
+
warnings.append(
|
|
529
|
+
f"冒号 {len(colon_hits)} 处,限额 {colon_allowance} 处,第 {lines} 行"
|
|
530
|
+
f"(其中直接引出原话 {len(quote_colons)} 处)。"
|
|
531
|
+
"确认每一处都在引出原话、列条目或交代时间比例,不是替读者下结论。"
|
|
532
|
+
)
|
|
533
|
+
|
|
534
|
+
dash_runs = dash_marks(prose)
|
|
535
|
+
dash_allowance = punctuation_allowance(total_han, DASH_RUN_ALLOWANCE)
|
|
536
|
+
if len(dash_runs) > dash_allowance:
|
|
537
|
+
lines = count_flagged_lines(
|
|
538
|
+
text, [line_number(text, position) for position, _ in dash_runs]
|
|
539
|
+
)
|
|
540
|
+
failures.append(
|
|
541
|
+
f"长破折号 {len(dash_runs)} 处,超过 {total_han} 字允许的 "
|
|
542
|
+
f"{dash_allowance} 处,第 {lines} 行起。"
|
|
543
|
+
"留两三处真有停顿作用的,其余换成逗号、句号或括号。"
|
|
544
|
+
)
|
|
545
|
+
elif dash_runs:
|
|
546
|
+
lines = count_flagged_lines(
|
|
547
|
+
text, [line_number(text, position) for position, _ in dash_runs]
|
|
548
|
+
)
|
|
549
|
+
warnings.append(
|
|
550
|
+
f"长破折号 {len(dash_runs)} 处,限额 {dash_allowance} 处,第 {lines} 行。"
|
|
551
|
+
"确认每处都是补语、插说或真的停顿,不是拿它替翻案腔断句。"
|
|
552
|
+
)
|
|
553
|
+
|
|
554
|
+
if DASH_AFTER_COMMA.search(prose):
|
|
555
|
+
warnings.append(
|
|
556
|
+
"逗号后面紧跟长破折号。这里多半是在替下文抬价,改成直接说。"
|
|
557
|
+
)
|
|
558
|
+
|
|
559
|
+
quote_styles = [
|
|
560
|
+
name for name, pattern in QUOTE_PAIR_STYLES if pattern.search(prose)
|
|
561
|
+
]
|
|
562
|
+
if len(quote_styles) > 1:
|
|
563
|
+
warnings.append(
|
|
564
|
+
f"同一篇出现 {'、'.join(quote_styles)} 两套以上引号制度。"
|
|
565
|
+
"引号不限数量,但全文只留一套;转述不必加引号。"
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
stop_matches = non_overlapping_terms(prose, hard_stops)
|
|
569
|
+
for position, phrase in stop_matches:
|
|
570
|
+
failures.append(f"硬停词,第 {line_number(text, position)} 行,{phrase}")
|
|
571
|
+
|
|
572
|
+
jargon_matches = non_overlapping_terms(prose, hard_jargon)
|
|
573
|
+
for position, phrase in jargon_matches:
|
|
574
|
+
failures.append(f"黑话,第 {line_number(text, position)} 行,{phrase}")
|
|
575
|
+
|
|
576
|
+
context_jargon_matches = non_overlapping_terms(prose, context_jargon)
|
|
577
|
+
hard_spans = [
|
|
578
|
+
(position, position + len(phrase)) for position, phrase in jargon_matches
|
|
579
|
+
]
|
|
580
|
+
context_jargon_matches = [
|
|
581
|
+
(position, phrase)
|
|
582
|
+
for position, phrase in context_jargon_matches
|
|
583
|
+
if not any(
|
|
584
|
+
position < end and position + len(phrase) > start
|
|
585
|
+
for start, end in hard_spans
|
|
586
|
+
)
|
|
587
|
+
]
|
|
588
|
+
if context_jargon_matches:
|
|
589
|
+
samples = "、".join(
|
|
590
|
+
dict.fromkeys(phrase for _, phrase in context_jargon_matches)
|
|
591
|
+
)
|
|
592
|
+
lines = "、".join(
|
|
593
|
+
dict.fromkeys(
|
|
594
|
+
str(line_number(text, position))
|
|
595
|
+
for position, _ in context_jargon_matches[:8]
|
|
596
|
+
)
|
|
597
|
+
)
|
|
598
|
+
warnings.append(
|
|
599
|
+
f"有 {len(context_jargon_matches)} 处词语需要结合语境判断。"
|
|
600
|
+
f"第 {lines} 行出现 {samples}。本义准确时保留,用来抬价时改写。"
|
|
601
|
+
)
|
|
602
|
+
|
|
603
|
+
road_signs = all_matches(prose, road_sign_patterns)
|
|
604
|
+
for match in road_signs:
|
|
605
|
+
failures.append(
|
|
606
|
+
f"模型路标,第 {line_number(text, match.start())} 行,"
|
|
607
|
+
f"“{excerpt(match.group().lstrip(ROAD_STRIP_CHARS))}”"
|
|
608
|
+
)
|
|
609
|
+
|
|
610
|
+
pivots = all_matches(prose, PIVOT_PATTERNS)
|
|
611
|
+
for match in pivots:
|
|
612
|
+
failures.append(
|
|
613
|
+
f"禁用翻案句,第 {line_number(text, match.start())} 行,"
|
|
614
|
+
f"“{excerpt(match.group())}”"
|
|
615
|
+
)
|
|
616
|
+
|
|
617
|
+
occupied_spans = [match.span() for match in pivots]
|
|
618
|
+
semantic_pivots = []
|
|
619
|
+
for match in all_matches(prose, SEMANTIC_PIVOT_PATTERNS):
|
|
620
|
+
if any(
|
|
621
|
+
match.start() < end and match.end() > start
|
|
622
|
+
for start, end in occupied_spans
|
|
623
|
+
):
|
|
624
|
+
continue
|
|
625
|
+
semantic_pivots.append(match)
|
|
626
|
+
occupied_spans.append(match.span())
|
|
627
|
+
for match in semantic_pivots:
|
|
628
|
+
warnings.append(
|
|
629
|
+
f"疑似翻案腔变形,第 {line_number(text, match.start())} 行,"
|
|
630
|
+
f"“{excerpt(match.group(), 44)}”。先立误解再推翻就改成正面陈述,正常用法保留。"
|
|
631
|
+
)
|
|
632
|
+
|
|
633
|
+
anaphoras = anaphora_runs(prose)
|
|
634
|
+
for match in anaphoras[:4]:
|
|
635
|
+
warnings.append(
|
|
636
|
+
f"三连以上同构排比,第 {line_number(text, match.start())} 行,"
|
|
637
|
+
f"“{excerpt(match.group(), 44)}”。留两项,第三项换说法或删掉。"
|
|
638
|
+
)
|
|
639
|
+
|
|
640
|
+
lyric_matches = non_overlapping_terms(prose, LYRIC_WORDS)
|
|
641
|
+
if len(lyric_matches) >= 2:
|
|
642
|
+
samples = "、".join(dict.fromkeys(term for _, term in lyric_matches))
|
|
643
|
+
warnings.append(
|
|
644
|
+
f"模型偏爱的抒情词 {len(lyric_matches)} 处。{samples}。"
|
|
645
|
+
"写具体事物时保留,给抽象概念穿衣服时删掉。"
|
|
646
|
+
)
|
|
647
|
+
|
|
648
|
+
nominalizations = all_matches(prose, nominalization_patterns)
|
|
649
|
+
for match in nominalizations[:4]:
|
|
650
|
+
warnings.append(
|
|
651
|
+
f"名词化句式,第 {line_number(text, match.start())} 行,"
|
|
652
|
+
f"“{excerpt(match.group(), 36)}”。还原成直接的动词。"
|
|
653
|
+
)
|
|
654
|
+
|
|
655
|
+
conjunction_hits = non_overlapping_terms(prose, conjunctions)
|
|
656
|
+
if total_han >= 600 and len(conjunction_hits) * 1000 / total_han > 7:
|
|
657
|
+
samples = "、".join(
|
|
658
|
+
f"{term} {count} 次"
|
|
659
|
+
for term, count in collections.Counter(
|
|
660
|
+
term for _, term in conjunction_hits
|
|
661
|
+
).most_common(4)
|
|
662
|
+
)
|
|
663
|
+
warnings.append(
|
|
664
|
+
f"连词密度偏高,每千字 {len(conjunction_hits) * 1000 // total_han} 个。{samples}。"
|
|
665
|
+
"中文小句靠语序和事理相接,删掉一半试试。"
|
|
666
|
+
)
|
|
667
|
+
|
|
668
|
+
highlights = bracket_highlights(prose)
|
|
669
|
+
highlight_limit = max(3, total_han // 700)
|
|
670
|
+
if len(highlights) > highlight_limit:
|
|
671
|
+
samples = "、".join(dict.fromkeys(match.group() for match in highlights[:6]))
|
|
672
|
+
warnings.append(
|
|
673
|
+
f"「」括起的短语共 {len(highlights)} 处。{samples}。太密说明在批量造金句。"
|
|
674
|
+
)
|
|
675
|
+
|
|
676
|
+
cv_result = None if fiction else sentence_length_cv(prose)
|
|
677
|
+
if cv_result and cv_result[0] < 0.42:
|
|
678
|
+
warnings.append(
|
|
679
|
+
f"全文 {cv_result[1]} 个句子长度过于接近(变异系数 {cv_result[0]:.2f})。"
|
|
680
|
+
"人写的段落里十个字的句子会挨着四十个字的句子,放开几句,压短几句。"
|
|
681
|
+
)
|
|
682
|
+
|
|
683
|
+
marker_matches = non_overlapping_terms(prose, soft_markers)
|
|
684
|
+
marker_limit = max(2, total_han // 900)
|
|
685
|
+
if len(marker_matches) > marker_limit:
|
|
686
|
+
samples = "、".join(dict.fromkeys(term for _, term in marker_matches))
|
|
687
|
+
warnings.append(
|
|
688
|
+
f"洞察路标共 {len(marker_matches)} 处,当前提醒线为 {marker_limit} 处。"
|
|
689
|
+
f"重点检查 {samples}。"
|
|
690
|
+
)
|
|
691
|
+
|
|
692
|
+
left_branches = all_matches(prose, LEFT_BRANCH_PATTERNS)
|
|
693
|
+
left_limit = max(2, total_han // 1200)
|
|
694
|
+
if len(left_branches) > left_limit:
|
|
695
|
+
samples = ";".join(
|
|
696
|
+
f"第 {line_number(text, match.start())} 行“{excerpt(match.group(), 44)}”"
|
|
697
|
+
for match in left_branches[:4]
|
|
698
|
+
)
|
|
699
|
+
warnings.append(
|
|
700
|
+
f"长前置成分共 {len(left_branches)} 处,可能让主干来得太晚。{samples}"
|
|
701
|
+
)
|
|
702
|
+
|
|
703
|
+
dense_de = heavy_de_sentences(prose)
|
|
704
|
+
dense_de_limit = max(1, total_han // 1500)
|
|
705
|
+
if len(dense_de) > dense_de_limit:
|
|
706
|
+
samples = ";".join(
|
|
707
|
+
f"第 {line_number(text, match.start())} 行“{excerpt(match.group(), 44)}”"
|
|
708
|
+
for match in dense_de[:4]
|
|
709
|
+
)
|
|
710
|
+
warnings.append(
|
|
711
|
+
f"有 {len(dense_de)} 个长句包含四个以上的“的”,可能要先交代人和动作。{samples}"
|
|
712
|
+
)
|
|
713
|
+
|
|
714
|
+
paragraphs = prose_paragraphs(prose)
|
|
715
|
+
if len(paragraphs) >= 10 and not fiction:
|
|
716
|
+
one_sentence = sum(paragraph.sentences <= 1 for paragraph in paragraphs)
|
|
717
|
+
ratio = one_sentence / len(paragraphs)
|
|
718
|
+
if ratio >= 0.75:
|
|
719
|
+
warnings.append(
|
|
720
|
+
f"可识别段落中有 {ratio:.0%} 只有一句话,可能形成统一的短段鼓点。"
|
|
721
|
+
)
|
|
722
|
+
|
|
723
|
+
streak = None if fiction else short_streak(paragraphs)
|
|
724
|
+
if streak:
|
|
725
|
+
first = streak[0]
|
|
726
|
+
warnings.append(
|
|
727
|
+
f"从第 {line_number(text, first.position)} 行起连续出现 {len(streak)} 个短促单句段,"
|
|
728
|
+
"检查是否在排队喊结论。"
|
|
729
|
+
)
|
|
730
|
+
|
|
731
|
+
counts, opener_examples = opener_counts(paragraphs)
|
|
732
|
+
repeated = [(opener, count) for opener, count in counts.items() if count >= 4]
|
|
733
|
+
if repeated:
|
|
734
|
+
details = "、".join(f"{opener} {count} 次" for opener, count in repeated)
|
|
735
|
+
first_position = min(opener_examples[opener] for opener, _ in repeated)
|
|
736
|
+
warnings.append(
|
|
737
|
+
f"段落开场重复,从第 {line_number(text, first_position)} 行附近开始。{details}。"
|
|
738
|
+
)
|
|
739
|
+
|
|
740
|
+
metaphors = None if fiction else metaphor_cluster(prose)
|
|
741
|
+
if metaphors:
|
|
742
|
+
window, fields = metaphors
|
|
743
|
+
samples = "、".join(dict.fromkeys(hit[2] for hit in window))
|
|
744
|
+
warnings.append(
|
|
745
|
+
f"八百字内出现 {len(fields)} 套借喻。{'、'.join(sorted(fields))}。"
|
|
746
|
+
f"例词有 {samples}。"
|
|
747
|
+
)
|
|
748
|
+
|
|
749
|
+
print(f"汉字数 {total_han}")
|
|
750
|
+
if fiction:
|
|
751
|
+
print(
|
|
752
|
+
"体裁 fiction:已跳过商业黑话、硬停词、模型路标、名词化、连词密度,"
|
|
753
|
+
"以及句长变异系数、短段连排、单句段占比、借喻聚类这四类散文化节律警告。"
|
|
754
|
+
)
|
|
755
|
+
print(
|
|
756
|
+
f"翻案句 {len(pivots)},翻案腔变形 {len(semantic_pivots)},"
|
|
757
|
+
f"同构排比 {len(anaphoras)},名词化 {len(nominalizations)},"
|
|
758
|
+
f"黑话 {len(jargon_matches)},硬停词 {len(stop_matches)},"
|
|
759
|
+
f"模型路标 {len(road_signs)},需辨语境词 {len(context_jargon_matches)},"
|
|
760
|
+
f"抒情词 {len(lyric_matches)},洞察路标 {len(marker_matches)},"
|
|
761
|
+
f"长前置成分 {len(left_branches)},重定语句 {len(dense_de)}"
|
|
762
|
+
)
|
|
763
|
+
|
|
764
|
+
if failures:
|
|
765
|
+
print("\n需要修改")
|
|
766
|
+
for item in failures:
|
|
767
|
+
print(f"- {item}")
|
|
768
|
+
|
|
769
|
+
if warnings:
|
|
770
|
+
print("\n需要人工判断")
|
|
771
|
+
for item in warnings:
|
|
772
|
+
print(f"- {item}")
|
|
773
|
+
|
|
774
|
+
if not failures and not warnings:
|
|
775
|
+
print("\n未发现这份检查器覆盖的问题。")
|
|
776
|
+
|
|
777
|
+
return 1 if failures else 0
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
if __name__ == "__main__":
|
|
781
|
+
raise SystemExit(main())
|