dsh-lifecard 0.2.0 → 0.2.2

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,864 @@
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
+ # 形容词脱钩:形容人的词挂到了人和人的做法上。写在 SKILL.md「形容词脱钩」一节。
214
+ # 只查「抽象主语 + 程度副词 + 物理属性形容词」这一种碰撞,正常用法(地很平、车很稳)不命中。
215
+ # 收得紧是故意的:宁可多报几句正常话,也别放过「他做事很平」。
216
+ ABSTRACT_SUBJECTS = (
217
+ "他这个人", "她这个人", "这个人", "那人", "这人",
218
+ "他做事", "她做事", "做事", "做法", "处事",
219
+ "他的判断", "她的判断", "判断", "方案", "稿子", "文字", "句子",
220
+ "这句话", "这话", "这种说法", "说法", "逻辑", "思路", "节奏",
221
+ "关系", "内容", "观点", "态度", "能力", "水平", "表现", "推进",
222
+ )
223
+
224
+ PHYSICAL_ADJECTIVES = (
225
+ "稳", "平", "沉", "轻", "重", "强", "硬", "软", "钝", "脆", "顺", "实", "厚", "薄",
226
+ )
227
+
228
+ DEGREE_ADVERBS = (
229
+ "很", "挺", "真", "太", "比较", "特别", "相当", "还算", "非常", "极其", "蛮", "怪",
230
+ )
231
+
232
+ # 「只有态度、没有对象」的固定短句。写在 SKILL.md「删掉之后什么都没少的句子」一节。
233
+ # 只作提醒,不进失败项:虚构对白里这类短句是正常的对话节奏,由人判断。
234
+ EMPTY_ATTITUDE = (
235
+ "这句话稳",
236
+ "这话我留着",
237
+ "这句话我记着",
238
+ "这句话我不接",
239
+ "我记下了",
240
+ "行,我认",
241
+ "行我认",
242
+ "比之前的都重",
243
+ "比之前的都轻",
244
+ "比之前的都强",
245
+ "我不拦",
246
+ "你这句话我记着",
247
+ )
248
+
249
+ SOFT_MARKERS = (
250
+ "真正",
251
+ "本质上",
252
+ "更深层次",
253
+ "归根结底",
254
+ "换句话说",
255
+ "不可否认",
256
+ "核心是",
257
+ "关键在于",
258
+ "这意味着",
259
+ )
260
+
261
+ REPEATED_OPENERS = (
262
+ "其实",
263
+ "不过",
264
+ "当然",
265
+ "所以",
266
+ "但是",
267
+ "后来",
268
+ "当时",
269
+ "很多人",
270
+ "问题是",
271
+ "更重要的是",
272
+ "说到这里",
273
+ )
274
+
275
+ LEFT_BRANCH_PATTERNS = (
276
+ re.compile(r"(?:^|[。!?]\s*)在[^,。!?\n]{12,70}(?:以后|之后|之前|以前|过程中|情况下|背景下),"),
277
+ re.compile(r"(?:^|[。!?]\s*)那些[^,。!?\n]{10,60}的[^,。!?\n]{2,30}[,。]"),
278
+ re.compile(r"(?:^|[。!?]\s*)(?:真正|最终|最后)让[^,。!?\n]{8,70}的,是"),
279
+ )
280
+
281
+ METAPHOR_FIELDS = {
282
+ "温度": ("降温", "升温", "冷却", "余温", "温度最高"),
283
+ "生死战争": ("杀死", "死因", "枪响", "开火", "战场", "引爆", "弹药"),
284
+ "建筑灾害": ("坍塌", "崩塌", "地基", "砖头", "支柱", "废墟"),
285
+ "仓储租赁": ("仓库", "库房", "租金", "取货", "入库", "库存"),
286
+ "道路竞赛": ("赛道", "跑道", "岔路", "十字路口", "终点线", "门票"),
287
+ "机器器官": ("齿轮", "引擎", "发动机", "血管", "骨架", "肌肉"),
288
+ "海洋航行": ("蓝海", "浪潮", "潮水", "航船", "灯塔", "彼岸"),
289
+ }
290
+
291
+
292
+ @dataclass
293
+ class Paragraph:
294
+ position: int
295
+ text: str
296
+ han: int
297
+ sentences: int
298
+
299
+
300
+ def han_count(text: str) -> int:
301
+ return len(re.findall(r"[\u4e00-\u9fff]", text))
302
+
303
+
304
+ def line_number(text: str, position: int) -> int:
305
+ return text.count("\n", 0, position) + 1
306
+
307
+
308
+ def excerpt(value: str, width: int = 72) -> str:
309
+ value = re.sub(r"\s+", " ", value).strip()
310
+ return value if len(value) <= width else value[: width - 1] + "…"
311
+
312
+
313
+ def mask_non_prose(text: str) -> str:
314
+ """屏蔽代码、网址和机器元数据,同时保留字符位置与换行。"""
315
+
316
+ def mask(match: re.Match[str]) -> str:
317
+ return "".join("\n" if char == "\n" else " " for char in match.group())
318
+
319
+ patterns = (
320
+ re.compile(r"\A---\s*\n.*?\n---\s*(?:\n|\Z)", re.DOTALL),
321
+ re.compile(r"```.*?```", re.DOTALL),
322
+ re.compile(r"`[^`\n]*`"),
323
+ re.compile(r"\]\([^\n)]*\)"),
324
+ re.compile(r"https?://[^\s)>]+"),
325
+ re.compile(r"<[^>\n]+>"),
326
+ )
327
+ masked = text
328
+ for pattern in patterns:
329
+ masked = pattern.sub(mask, masked)
330
+ return masked
331
+
332
+
333
+ def non_overlapping_terms(text: str, terms: tuple[str, ...]):
334
+ matches = []
335
+ occupied = []
336
+ for term in sorted(terms, key=len, reverse=True):
337
+ for match in re.finditer(re.escape(term), text):
338
+ start, end = match.span()
339
+ if any(start < old_end and end > old_start for old_start, old_end in occupied):
340
+ continue
341
+ matches.append((start, term))
342
+ occupied.append((start, end))
343
+ return sorted(matches)
344
+
345
+
346
+ def all_matches(text: str, patterns: tuple[re.Pattern[str], ...]):
347
+ matches = []
348
+ for pattern in patterns:
349
+ matches.extend(pattern.finditer(text))
350
+ return sorted(matches, key=lambda match: match.start())
351
+
352
+
353
+ def heavy_de_sentences(text: str):
354
+ """找出主干可能被多个“的”压到后面的长句。"""
355
+
356
+ matches = []
357
+ pattern = re.compile(r"[^。!?!?\n]+(?:[。!?!?]|$)")
358
+ for match in pattern.finditer(text):
359
+ value = match.group()
360
+ if han_count(value) >= 38 and value.count("的") >= 4:
361
+ matches.append(match)
362
+ return matches
363
+
364
+
365
+ def anaphora_runs(text: str, minimum: int = 3):
366
+ """找出同一句里三个以上小句用同一个开头的排比。"""
367
+
368
+ matches = []
369
+ for sentence in re.finditer(r"[^。!?!?\n]+(?:[。!?!?]|$)", text):
370
+ clauses = [
371
+ clause.strip()
372
+ for clause in re.split(r"[,、;,;]", sentence.group())
373
+ if han_count(clause) >= 3
374
+ ]
375
+ if len(clauses) < minimum:
376
+ continue
377
+ run = 1
378
+ for previous, current in zip(clauses, clauses[1:]):
379
+ if previous[:2] == current[:2] and re.match(r"[一-鿿]{2}", current):
380
+ run += 1
381
+ if run >= minimum:
382
+ matches.append(sentence)
383
+ break
384
+ else:
385
+ run = 1
386
+ return matches
387
+
388
+
389
+ def sentence_length_cv(text: str):
390
+ """句长变异系数。人写的长短句差距大,模型的句长彼此接近。"""
391
+
392
+ lengths = [
393
+ han_count(match.group())
394
+ for match in re.finditer(r"[^。!?!?\n]+[。!?!?]", text)
395
+ if han_count(match.group()) >= 4
396
+ ]
397
+ if len(lengths) < 12:
398
+ return None
399
+ mean = sum(lengths) / len(lengths)
400
+ if mean == 0:
401
+ return None
402
+ variance = sum((value - mean) ** 2 for value in lengths) / len(lengths)
403
+ return (variance ** 0.5) / mean, len(lengths)
404
+
405
+
406
+ def bracket_highlights(text: str):
407
+ """「」括起来的短语。太密说明在批量造金句。"""
408
+
409
+ return list(re.finditer(r"[「『][^」』\n]{1,6}[」』]", text))
410
+
411
+
412
+ def prose_paragraphs(text: str) -> list[Paragraph]:
413
+ paragraphs = []
414
+ cursor = 0
415
+ for block in re.split(r"\n\s*\n", text):
416
+ position = text.find(block, cursor)
417
+ cursor = max(position + len(block), cursor)
418
+ clean = re.sub(r"[>*_`]", "", block).strip()
419
+ if not clean or clean.startswith(("#", "http", "![", "```")):
420
+ continue
421
+ if re.match(r"^(?:[-+*]|\d+[.、])\s", clean):
422
+ continue
423
+ count = han_count(clean)
424
+ if count < 4:
425
+ continue
426
+ sentences = max(1, len(re.findall(r"[。!?!?]", clean)))
427
+ paragraphs.append(Paragraph(position, clean, count, sentences))
428
+ return paragraphs
429
+
430
+
431
+ def metaphor_cluster(text: str, distance: int = 800):
432
+ hits = []
433
+ for field, words in METAPHOR_FIELDS.items():
434
+ for word in words:
435
+ for match in re.finditer(re.escape(word), text):
436
+ hits.append((match.start(), field, word))
437
+ hits.sort()
438
+ for index, (start, _, _) in enumerate(hits):
439
+ window = [hit for hit in hits[index:] if hit[0] - start <= distance]
440
+ fields = {hit[1] for hit in window}
441
+ if len(fields) >= 3:
442
+ return window, fields
443
+ return None
444
+
445
+
446
+ def short_streak(paragraphs: list[Paragraph], limit: int = 4):
447
+ streak = []
448
+ for paragraph in paragraphs:
449
+ if paragraph.han <= 24 and paragraph.sentences <= 1:
450
+ streak.append(paragraph)
451
+ if len(streak) >= limit:
452
+ return streak
453
+ else:
454
+ streak = []
455
+ return None
456
+
457
+
458
+ def opener_counts(paragraphs: list[Paragraph]):
459
+ counts = collections.Counter()
460
+ examples = {}
461
+ for paragraph in paragraphs:
462
+ value = paragraph.text.lstrip("“‘\"((")
463
+ for opener in REPEATED_OPENERS:
464
+ if value.startswith(opener):
465
+ counts[opener] += 1
466
+ examples.setdefault(opener, paragraph.position)
467
+ break
468
+ return counts, examples
469
+
470
+
471
+ def read_text(path: str) -> str:
472
+ if path == "-":
473
+ return sys.stdin.read()
474
+ return Path(path).read_text(encoding="utf-8")
475
+
476
+
477
+ def main() -> int:
478
+ parser = argparse.ArgumentParser(description="检查中文成稿的硬禁令与模型化形状")
479
+ parser.add_argument("path", help="Markdown 或文本文件路径。使用 - 从标准输入读取")
480
+ parser.add_argument(
481
+ "--genre",
482
+ choices=("prose", "fiction"),
483
+ default="prose",
484
+ help="prose(默认)按说明文/观点文判;fiction 走小说口径,跳过说明文专属项",
485
+ )
486
+ args = parser.parse_args()
487
+
488
+ try:
489
+ text = read_text(args.path)
490
+ except (OSError, UnicodeError) as error:
491
+ print(f"无法读取稿件。{error}", file=sys.stderr)
492
+ return 2
493
+
494
+ prose = mask_non_prose(text)
495
+ total_han = han_count(prose)
496
+ if total_han == 0:
497
+ print("没有检测到汉字。", file=sys.stderr)
498
+ return 2
499
+
500
+ failures = []
501
+ warnings = []
502
+
503
+ fiction = args.genre == "fiction"
504
+ if fiction:
505
+ hard_stops: tuple[str, ...] = ()
506
+ hard_jargon: tuple[str, ...] = ()
507
+ context_jargon: tuple[str, ...] = ()
508
+ soft_markers: tuple[str, ...] = ()
509
+ conjunctions: tuple[str, ...] = ()
510
+ road_sign_patterns: tuple[re.Pattern[str], ...] = ()
511
+ nominalization_patterns: tuple[re.Pattern[str], ...] = ()
512
+ else:
513
+ hard_stops = HARD_STOPS
514
+ hard_jargon = HARD_JARGON
515
+ context_jargon = CONTEXT_JARGON
516
+ soft_markers = SOFT_MARKERS
517
+ conjunctions = CONJUNCTIONS
518
+ road_sign_patterns = ROAD_SIGN_PATTERNS
519
+ nominalization_patterns = NOMINALIZATION_PATTERNS
520
+
521
+ colon_hits = []
522
+ for symbol in (":", ":"):
523
+ for match in re.finditer(re.escape(symbol), prose):
524
+ before = prose[match.start() - 1 : match.start()]
525
+ after = prose[match.end() : match.end() + 1]
526
+ if before.isdigit() and after.isdigit():
527
+ continue
528
+ colon_hits.append(match.start())
529
+ colon_hits.sort()
530
+
531
+ hollow_colons = []
532
+ quote_colons = []
533
+ for position in colon_hits:
534
+ head = prose[max(0, position - 14) : position]
535
+ tail = prose[position + 1 : position + 3].lstrip()
536
+ if any(hollow in head for hollow in HOLLOW_COLON_LABELS):
537
+ hollow_colons.append(position)
538
+ elif tail[:1] in QUOTE_OPENERS:
539
+ quote_colons.append(position)
540
+
541
+ if hollow_colons:
542
+ lines = count_flagged_lines(
543
+ text, [line_number(text, position) for position in hollow_colons]
544
+ )
545
+ failures.append(
546
+ f"提示性抬价冒号共 {len(hollow_colons)} 处,第 {lines} 行。"
547
+ "这种冒号只是把下文抬成结论,改成正面陈述或句号。"
548
+ )
549
+
550
+ colon_allowance = punctuation_allowance(total_han, COLON_ALLOWANCE_PER_1000)
551
+ if len(colon_hits) > colon_allowance:
552
+ lines = count_flagged_lines(
553
+ text, [line_number(text, position) for position in colon_hits]
554
+ )
555
+ failures.append(
556
+ f"冒号共 {len(colon_hits)} 处,超过这份稿子 {total_han} 字允许的 "
557
+ f"{colon_allowance} 处(每千字 {COLON_ALLOWANCE_PER_1000} 处),第 {lines} 行起。"
558
+ "引出原话、列条目、标时间和比例都可以留,超出的改成逗号、句号或直接说。"
559
+ )
560
+ elif colon_hits:
561
+ lines = count_flagged_lines(
562
+ text, [line_number(text, position) for position in colon_hits]
563
+ )
564
+ warnings.append(
565
+ f"冒号 {len(colon_hits)} 处,限额 {colon_allowance} 处,第 {lines} 行"
566
+ f"(其中直接引出原话 {len(quote_colons)} 处)。"
567
+ "确认每一处都在引出原话、列条目或交代时间比例,不是替读者下结论。"
568
+ )
569
+
570
+ dash_runs = dash_marks(prose)
571
+ dash_allowance = punctuation_allowance(total_han, DASH_RUN_ALLOWANCE)
572
+ if len(dash_runs) > dash_allowance:
573
+ lines = count_flagged_lines(
574
+ text, [line_number(text, position) for position, _ in dash_runs]
575
+ )
576
+ failures.append(
577
+ f"长破折号 {len(dash_runs)} 处,超过 {total_han} 字允许的 "
578
+ f"{dash_allowance} 处,第 {lines} 行起。"
579
+ "留两三处真有停顿作用的,其余换成逗号、句号或括号。"
580
+ )
581
+ elif dash_runs:
582
+ lines = count_flagged_lines(
583
+ text, [line_number(text, position) for position, _ in dash_runs]
584
+ )
585
+ warnings.append(
586
+ f"长破折号 {len(dash_runs)} 处,限额 {dash_allowance} 处,第 {lines} 行。"
587
+ "确认每处都是补语、插说或真的停顿,不是拿它替翻案腔断句。"
588
+ )
589
+
590
+ empty_hits = []
591
+ for phrase in EMPTY_ATTITUDE:
592
+ for match in re.finditer(re.escape(phrase), prose):
593
+ empty_hits.append((match.start(), phrase))
594
+ if empty_hits:
595
+ empty_hits.sort()
596
+ lines = count_flagged_lines(
597
+ text, [line_number(text, position) for position, _ in empty_hits]
598
+ )
599
+ shown = "、".join(sorted({f"“{phrase}”" for _, phrase in empty_hits}))
600
+ warnings.append(
601
+ f"只有态度没有对象的短句 {len(empty_hits)} 处,第 {lines} 行:{shown}。"
602
+ "单独抄给一个不在场的人看,他知不知道在说什么?删掉它下一句还接得上,就删。"
603
+ "要留就落到一件具体的事上。对白里这类短句是节奏,不用改。"
604
+ )
605
+
606
+ decoupled = []
607
+ degree_alt = "|".join(DEGREE_ADVERBS)
608
+ adjective_alt = "|".join(PHYSICAL_ADJECTIVES)
609
+ for subject in ABSTRACT_SUBJECTS:
610
+ pattern = re.compile(
611
+ re.escape(subject) + r"\s*(?:" + degree_alt + r")\s*(?:" + adjective_alt + r")"
612
+ )
613
+ for match in pattern.finditer(prose):
614
+ decoupled.append((match.start(), match.group(0)))
615
+ if decoupled:
616
+ decoupled.sort()
617
+ # 主体有重叠(「做事很平」是「他做事很平」的一部分),只留最长的那一处
618
+ deduped = []
619
+ for start, piece in decoupled:
620
+ end = start + len(piece)
621
+ if deduped and start < deduped[-1][0] + len(deduped[-1][1]):
622
+ if end - start > len(deduped[-1][1]):
623
+ deduped[-1] = (start, piece)
624
+ continue
625
+ deduped.append((start, piece))
626
+ decoupled = deduped
627
+ lines = count_flagged_lines(
628
+ text, [line_number(text, position) for position, _ in decoupled]
629
+ )
630
+ shown = "、".join(f"“{piece}”" for _, piece in decoupled[:6])
631
+ failures.append(
632
+ f"形容词脱钩 {len(decoupled)} 处,第 {lines} 行:{shown}。"
633
+ "这些形容词属于能用手的实物(车才稳、地才平、箱子才沉),挂在人、做法、判断和方案上就错了。"
634
+ "改法:说清它本来指哪个动作,或者直接删掉这个评价。这一项故意收得紧,宁可多报也别放过。"
635
+ )
636
+
637
+ if DASH_AFTER_COMMA.search(prose):
638
+ warnings.append(
639
+ "逗号后面紧跟长破折号。这里多半是在替下文抬价,改成直接说。"
640
+ )
641
+
642
+ quote_styles = [
643
+ name for name, pattern in QUOTE_PAIR_STYLES if pattern.search(prose)
644
+ ]
645
+ if len(quote_styles) > 1:
646
+ warnings.append(
647
+ f"同一篇出现 {'、'.join(quote_styles)} 两套以上引号制度。"
648
+ "引号不限数量,但全文只留一套;转述不必加引号。"
649
+ )
650
+
651
+ stop_matches = non_overlapping_terms(prose, hard_stops)
652
+ for position, phrase in stop_matches:
653
+ failures.append(f"硬停词,第 {line_number(text, position)} 行,{phrase}")
654
+
655
+ jargon_matches = non_overlapping_terms(prose, hard_jargon)
656
+ for position, phrase in jargon_matches:
657
+ failures.append(f"黑话,第 {line_number(text, position)} 行,{phrase}")
658
+
659
+ context_jargon_matches = non_overlapping_terms(prose, context_jargon)
660
+ hard_spans = [
661
+ (position, position + len(phrase)) for position, phrase in jargon_matches
662
+ ]
663
+ context_jargon_matches = [
664
+ (position, phrase)
665
+ for position, phrase in context_jargon_matches
666
+ if not any(
667
+ position < end and position + len(phrase) > start
668
+ for start, end in hard_spans
669
+ )
670
+ ]
671
+ if context_jargon_matches:
672
+ samples = "、".join(
673
+ dict.fromkeys(phrase for _, phrase in context_jargon_matches)
674
+ )
675
+ lines = "、".join(
676
+ dict.fromkeys(
677
+ str(line_number(text, position))
678
+ for position, _ in context_jargon_matches[:8]
679
+ )
680
+ )
681
+ warnings.append(
682
+ f"有 {len(context_jargon_matches)} 处词语需要结合语境判断。"
683
+ f"第 {lines} 行出现 {samples}。本义准确时保留,用来抬价时改写。"
684
+ )
685
+
686
+ road_signs = all_matches(prose, road_sign_patterns)
687
+ for match in road_signs:
688
+ failures.append(
689
+ f"模型路标,第 {line_number(text, match.start())} 行,"
690
+ f"“{excerpt(match.group().lstrip(ROAD_STRIP_CHARS))}”"
691
+ )
692
+
693
+ pivots = all_matches(prose, PIVOT_PATTERNS)
694
+ for match in pivots:
695
+ failures.append(
696
+ f"禁用翻案句,第 {line_number(text, match.start())} 行,"
697
+ f"“{excerpt(match.group())}”"
698
+ )
699
+
700
+ occupied_spans = [match.span() for match in pivots]
701
+ semantic_pivots = []
702
+ for match in all_matches(prose, SEMANTIC_PIVOT_PATTERNS):
703
+ if any(
704
+ match.start() < end and match.end() > start
705
+ for start, end in occupied_spans
706
+ ):
707
+ continue
708
+ semantic_pivots.append(match)
709
+ occupied_spans.append(match.span())
710
+ for match in semantic_pivots:
711
+ warnings.append(
712
+ f"疑似翻案腔变形,第 {line_number(text, match.start())} 行,"
713
+ f"“{excerpt(match.group(), 44)}”。先立误解再推翻就改成正面陈述,正常用法保留。"
714
+ )
715
+
716
+ anaphoras = anaphora_runs(prose)
717
+ for match in anaphoras[:4]:
718
+ warnings.append(
719
+ f"三连以上同构排比,第 {line_number(text, match.start())} 行,"
720
+ f"“{excerpt(match.group(), 44)}”。留两项,第三项换说法或删掉。"
721
+ )
722
+
723
+ lyric_matches = non_overlapping_terms(prose, LYRIC_WORDS)
724
+ if len(lyric_matches) >= 2:
725
+ samples = "、".join(dict.fromkeys(term for _, term in lyric_matches))
726
+ warnings.append(
727
+ f"模型偏爱的抒情词 {len(lyric_matches)} 处。{samples}。"
728
+ "写具体事物时保留,给抽象概念穿衣服时删掉。"
729
+ )
730
+
731
+ nominalizations = all_matches(prose, nominalization_patterns)
732
+ for match in nominalizations[:4]:
733
+ warnings.append(
734
+ f"名词化句式,第 {line_number(text, match.start())} 行,"
735
+ f"“{excerpt(match.group(), 36)}”。还原成直接的动词。"
736
+ )
737
+
738
+ conjunction_hits = non_overlapping_terms(prose, conjunctions)
739
+ if total_han >= 600 and len(conjunction_hits) * 1000 / total_han > 7:
740
+ samples = "、".join(
741
+ f"{term} {count} 次"
742
+ for term, count in collections.Counter(
743
+ term for _, term in conjunction_hits
744
+ ).most_common(4)
745
+ )
746
+ warnings.append(
747
+ f"连词密度偏高,每千字 {len(conjunction_hits) * 1000 // total_han} 个。{samples}。"
748
+ "中文小句靠语序和事理相接,删掉一半试试。"
749
+ )
750
+
751
+ highlights = bracket_highlights(prose)
752
+ highlight_limit = max(3, total_han // 700)
753
+ if len(highlights) > highlight_limit:
754
+ samples = "、".join(dict.fromkeys(match.group() for match in highlights[:6]))
755
+ warnings.append(
756
+ f"「」括起的短语共 {len(highlights)} 处。{samples}。太密说明在批量造金句。"
757
+ )
758
+
759
+ cv_result = None if fiction else sentence_length_cv(prose)
760
+ if cv_result and cv_result[0] < 0.42:
761
+ warnings.append(
762
+ f"全文 {cv_result[1]} 个句子长度过于接近(变异系数 {cv_result[0]:.2f})。"
763
+ "人写的段落里十个字的句子会挨着四十个字的句子,放开几句,压短几句。"
764
+ )
765
+
766
+ marker_matches = non_overlapping_terms(prose, soft_markers)
767
+ marker_limit = max(2, total_han // 900)
768
+ if len(marker_matches) > marker_limit:
769
+ samples = "、".join(dict.fromkeys(term for _, term in marker_matches))
770
+ warnings.append(
771
+ f"洞察路标共 {len(marker_matches)} 处,当前提醒线为 {marker_limit} 处。"
772
+ f"重点检查 {samples}。"
773
+ )
774
+
775
+ left_branches = all_matches(prose, LEFT_BRANCH_PATTERNS)
776
+ left_limit = max(2, total_han // 1200)
777
+ if len(left_branches) > left_limit:
778
+ samples = ";".join(
779
+ f"第 {line_number(text, match.start())} 行“{excerpt(match.group(), 44)}”"
780
+ for match in left_branches[:4]
781
+ )
782
+ warnings.append(
783
+ f"长前置成分共 {len(left_branches)} 处,可能让主干来得太晚。{samples}"
784
+ )
785
+
786
+ dense_de = heavy_de_sentences(prose)
787
+ dense_de_limit = max(1, total_han // 1500)
788
+ if len(dense_de) > dense_de_limit:
789
+ samples = ";".join(
790
+ f"第 {line_number(text, match.start())} 行“{excerpt(match.group(), 44)}”"
791
+ for match in dense_de[:4]
792
+ )
793
+ warnings.append(
794
+ f"有 {len(dense_de)} 个长句包含四个以上的“的”,可能要先交代人和动作。{samples}"
795
+ )
796
+
797
+ paragraphs = prose_paragraphs(prose)
798
+ if len(paragraphs) >= 10 and not fiction:
799
+ one_sentence = sum(paragraph.sentences <= 1 for paragraph in paragraphs)
800
+ ratio = one_sentence / len(paragraphs)
801
+ if ratio >= 0.75:
802
+ warnings.append(
803
+ f"可识别段落中有 {ratio:.0%} 只有一句话,可能形成统一的短段鼓点。"
804
+ )
805
+
806
+ streak = None if fiction else short_streak(paragraphs)
807
+ if streak:
808
+ first = streak[0]
809
+ warnings.append(
810
+ f"从第 {line_number(text, first.position)} 行起连续出现 {len(streak)} 个短促单句段,"
811
+ "检查是否在排队喊结论。"
812
+ )
813
+
814
+ counts, opener_examples = opener_counts(paragraphs)
815
+ repeated = [(opener, count) for opener, count in counts.items() if count >= 4]
816
+ if repeated:
817
+ details = "、".join(f"{opener} {count} 次" for opener, count in repeated)
818
+ first_position = min(opener_examples[opener] for opener, _ in repeated)
819
+ warnings.append(
820
+ f"段落开场重复,从第 {line_number(text, first_position)} 行附近开始。{details}。"
821
+ )
822
+
823
+ metaphors = None if fiction else metaphor_cluster(prose)
824
+ if metaphors:
825
+ window, fields = metaphors
826
+ samples = "、".join(dict.fromkeys(hit[2] for hit in window))
827
+ warnings.append(
828
+ f"八百字内出现 {len(fields)} 套借喻。{'、'.join(sorted(fields))}。"
829
+ f"例词有 {samples}。"
830
+ )
831
+
832
+ print(f"汉字数 {total_han}")
833
+ if fiction:
834
+ print(
835
+ "体裁 fiction:已跳过商业黑话、硬停词、模型路标、名词化、连词密度,"
836
+ "以及句长变异系数、短段连排、单句段占比、借喻聚类这四类散文化节律警告。"
837
+ )
838
+ print(
839
+ f"翻案句 {len(pivots)},翻案腔变形 {len(semantic_pivots)},"
840
+ f"同构排比 {len(anaphoras)},名词化 {len(nominalizations)},"
841
+ f"黑话 {len(jargon_matches)},硬停词 {len(stop_matches)},"
842
+ f"模型路标 {len(road_signs)},需辨语境词 {len(context_jargon_matches)},"
843
+ f"抒情词 {len(lyric_matches)},洞察路标 {len(marker_matches)},"
844
+ f"长前置成分 {len(left_branches)},重定语句 {len(dense_de)}"
845
+ )
846
+
847
+ if failures:
848
+ print("\n需要修改")
849
+ for item in failures:
850
+ print(f"- {item}")
851
+
852
+ if warnings:
853
+ print("\n需要人工判断")
854
+ for item in warnings:
855
+ print(f"- {item}")
856
+
857
+ if not failures and not warnings:
858
+ print("\n未发现这份检查器覆盖的问题。")
859
+
860
+ return 1 if failures else 0
861
+
862
+
863
+ if __name__ == "__main__":
864
+ raise SystemExit(main())