dsh-lifecard 0.2.1 → 0.3.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/lib/prose.js ADDED
@@ -0,0 +1,253 @@
1
+ /**
2
+ * 顺手数一下「像 AI 写的」那些地方。
3
+ *
4
+ * 模型审稿(`novel.chapter.review`)问的是「哪里卡住、哪里不信、哪里想跳过」,
5
+ * 那是读者的判断,靠它自己读。但有一类毛病不靠判断也能数出来:
6
+ * 「不是…而是…」连着用了四次、「瞳孔一缩」出现了三次、每五百字五个「似乎」。
7
+ * 这种地方人一眼看不出密度,数出来才知道。
8
+ *
9
+ * 所以这里做的是**统计**,不是评价:只报告「哪个说法出现了几次、举一句原文」,
10
+ * 不替作者改句子,也不说「这段写得不好」。
11
+ *
12
+ * 三条纪律:
13
+ * 1. 只数,不判。这里没有分数,也没有「合格/不合格」。
14
+ * 2. 举原句要举完整的短句,让人能自己判断是不是该改。
15
+ * 3. 查不到就说查不到,不要为了显得有用而凑数。
16
+ */
17
+
18
+ /** 严重程度只是「先看哪个」的顺序,不是错误等级。 */
19
+ const ORDER = { 先看: 0, 顺便看: 1 }
20
+
21
+ /** 一、套话:说出来等于没说,删掉不影响任何信息。 */
22
+ const FILLER_WORDS = [
23
+ ['此外', '删掉,或者直接接着说下一件事'],
24
+ ['总而言之', '删掉,接着写就行'],
25
+ ['综上所述', '删掉'],
26
+ ['不可否认', '改成「确实」,或者直接陈述'],
27
+ ['显而易见', '删掉,把看得见的东西写出来'],
28
+ ['值得注意的是', '删掉,直接写值得注意的那件事'],
29
+ ['需要指出的是', '删掉'],
30
+ ['众所周知', '删掉'],
31
+ ['从某种意义上说', '删掉,直接说'],
32
+ ['不言而喻', '删掉,让读者自己体会'],
33
+ ['意味深长', '用具体的话或表情替代'],
34
+ ]
35
+
36
+ /** 二、句式:不是错,是密度一高就露出「同一个脑子在写」。 */
37
+ const PATTERNS = [
38
+ [/不是[^。!?\n]{1,30}而是/g, '先说什么不是什么,再另起一句说什么', '先看'],
39
+ [/没有[^。!?\n]{1,30}只是/g, '直接陈述事实', '先看'],
40
+ [/让[^。!?\n]{1,15}(?:感到|觉得|意识到|想起)/g, '去掉「让」,写他自己感到的那个动作', '先看'],
41
+ [/令[^。!?\n]{1,15}(?:感到|觉得|想起)/g, '同上', '先看'],
42
+ [/与此同时/g, '「同时」或「这时候」', '先看'],
43
+ [/当[^。!?\n]{1,40}时/g, '拆成两句,别把时间条件套在前面', '顺便看'],
44
+ [/于是[^。!?\n]{1,20}然而/g, '拆成两句', '顺便看'],
45
+ [/随即[^。!?\n]{1,20}紧接着/g, '留一个连接词就够', '顺便看'],
46
+ [/不禁[^。!?\n]{0,8}/g, '直接写动作', '顺便看'],
47
+ ]
48
+
49
+ /** 三、身体模板:情绪一动就用同一套身体反应。 */
50
+ const BODY = [
51
+ [/瞳孔[^。!?\n]{0,5}(?:缩|一缩)/g, '写他眼睛具体在看什么', '顺便看'],
52
+ [/身体[^。!?\n]{0,5}(?:一僵|僵住|僵了)/g, '「他停住了」「动作顿了一下」', '顺便看'],
53
+ [/倒(?:吸|抽)[^。!?\n]{0,5}凉气/g, '写他在那儿看到了什么', '顺便看'],
54
+ [/呼吸[^。!?\n]{0,5}(?:一滞|滞住)/g, '「他屏住呼吸」或者删掉', '顺便看'],
55
+ [/心头[^。!?\n]{0,5}(?:一暖|暖了|暖)/g, '写身上哪儿热了一下', '顺便看'],
56
+ [/心里[^。!?\n]{0,5}(?:一沉|沉了|沉)/g, '「胃里一阵发紧」或「手脚发凉」', '顺便看'],
57
+ [/嘴角[^。!?\n]{0,5}(?:勾起|上扬|翘起)/g, '写他脸上具体的表情', '顺便看'],
58
+ [/眼神[^。!?\n]{0,5}(?:闪烁|游移)/g, '写他在躲什么', '顺便看'],
59
+ ]
60
+
61
+ /** 四、大词:本来要具体写的地方,用一个大词糊过去。 */
62
+ const BIG_WORDS = [
63
+ ['至关重要', '「关键」「要命」'],
64
+ ['深入探讨', '写他们真的说了什么'],
65
+ ['充满活力', '写具体在动的东西'],
66
+ ['不可磨灭', '写那件事本身'],
67
+ ['焕然一新', '写变了什么'],
68
+ ['翻天覆地', '写变了什么'],
69
+ ['命运的齿轮', '删掉'],
70
+ ['无声地诉说', '写它具体是什么样子'],
71
+ ['空气中弥漫着', '写闻到的、看到的'],
72
+ ['交织在一起', '写两件事怎么缠上的'],
73
+ ]
74
+
75
+ /** 五、形容词脱钩:把一个挂在物件上的词,摘下来挂到抽象的东西上(「他做事很平」)。 */
76
+ const DETACHED = [
77
+ [
78
+ /(?:做法|判断|方案|稿子|这话|这句话|逻辑|节奏|关系|思路|风格|口气|语气)(?:很|挺|太|够|有点|特别|十分|非常)?(?:稳|平|沉|轻|重)/g,
79
+ '「稳」是车和地基的属性,「平」是地的属性。写清他做了什么,别把物件上的词摘下来挂到做法上',
80
+ '先看',
81
+ ],
82
+ [
83
+ /(?:做事|做人|办事|下笔|分析|推理)(?:很|挺|太|够|有点|特别)?(?:稳|平|沉|轻|重)/g,
84
+ '同上:把它翻成他到底在做什么动作',
85
+ '先看',
86
+ ],
87
+ ]
88
+
89
+ /** 六、糊词:一个两个是语气,一堆就是没想清楚。 */
90
+ const FUZZY = ['似乎', '也许', '大概', '仿佛', '好像', '隐约', '莫名', '某种', '一丝', '些许']
91
+
92
+ /** 每 500 字允许几个糊词(超过就算「太多」)。 */
93
+ const FUZZY_PER_500 = 3
94
+
95
+ /** 取命中位置前后一小段,人能看出是哪一句。 */
96
+ function excerpt(text, index, length) {
97
+ const start = Math.max(0, index - 10)
98
+ const end = Math.min(text.length, index + length + 10)
99
+ const cut = text.slice(start, end).replace(/\s+/g, ' ').trim()
100
+ return cut.length > 32 ? `${cut.slice(0, 32)}…` : cut
101
+ }
102
+
103
+ function countOf(text, word) {
104
+ let count = 0
105
+ let from = 0
106
+ for (;;) {
107
+ const at = text.indexOf(word, from)
108
+ if (at < 0) return count
109
+ count += 1
110
+ from = at + word.length
111
+ }
112
+ }
113
+
114
+ /**
115
+ * 数一遍。
116
+ * @param {string} text 正文
117
+ * @returns {{chars:number,total:number,byOrder:object,hits:Array,fuzzy:object}}
118
+ */
119
+ export function scanProse(text) {
120
+ const source = String(text ?? '')
121
+ const chars = source.replace(/\s+/g, '').length
122
+ const hits = []
123
+
124
+ for (const [word, advice] of FILLER_WORDS) {
125
+ const count = countOf(source, word)
126
+ if (count === 0) continue
127
+ const at = source.indexOf(word)
128
+ hits.push({ kind: 'filler', label: `「${word}」`, count, advice, sample: excerpt(source, at, word.length), order: '先看' })
129
+ }
130
+
131
+ for (const [pattern, advice, order] of PATTERNS) {
132
+ const found = []
133
+ pattern.lastIndex = 0
134
+ let match = pattern.exec(source)
135
+ while (match !== null) {
136
+ found.push({ index: match.index, text: match[0] })
137
+ if (found.length >= 20) break
138
+ match = pattern.exec(source)
139
+ }
140
+ if (found.length === 0) continue
141
+ hits.push({
142
+ kind: 'pattern',
143
+ label: patternLabel(found[0].text),
144
+ count: found.length,
145
+ advice,
146
+ sample: excerpt(source, found[0].index, found[0].text.length),
147
+ order,
148
+ })
149
+ }
150
+
151
+ for (const [pattern, advice, order] of BODY) {
152
+ const found = []
153
+ pattern.lastIndex = 0
154
+ let match = pattern.exec(source)
155
+ while (match !== null) {
156
+ found.push({ index: match.index, text: match[0] })
157
+ if (found.length >= 20) break
158
+ match = pattern.exec(source)
159
+ }
160
+ if (found.length === 0) continue
161
+ hits.push({
162
+ kind: 'body',
163
+ label: `「${found[0].text}」这类身体反应`,
164
+ count: found.length,
165
+ advice,
166
+ sample: excerpt(source, found[0].index, found[0].text.length),
167
+ order,
168
+ })
169
+ }
170
+
171
+ for (const [pattern, advice, order] of DETACHED) {
172
+ const found = []
173
+ pattern.lastIndex = 0
174
+ let match = pattern.exec(source)
175
+ while (match !== null) {
176
+ found.push({ index: match.index, text: match[0] })
177
+ if (found.length >= 20) break
178
+ match = pattern.exec(source)
179
+ }
180
+ if (found.length === 0) continue
181
+ hits.push({
182
+ kind: 'detached',
183
+ label: `「${found[0].text}」这类说法`,
184
+ count: found.length,
185
+ advice,
186
+ sample: excerpt(source, found[0].index, found[0].text.length),
187
+ order,
188
+ })
189
+ }
190
+
191
+ for (const [word, advice] of BIG_WORDS) {
192
+ const count = countOf(source, word)
193
+ if (count === 0) continue
194
+ const at = source.indexOf(word)
195
+ hits.push({ kind: 'big', label: `「${word}」`, count, advice, sample: excerpt(source, at, word.length), order: '先看' })
196
+ }
197
+
198
+ let fuzzyCount = 0
199
+ for (const word of FUZZY) fuzzyCount += countOf(source, word)
200
+ const per500 = chars === 0 ? 0 : Math.round((fuzzyCount / (chars / 500)) * 10) / 10
201
+ const fuzzy = { count: fuzzyCount, per500, tooMany: chars >= 500 && per500 > FUZZY_PER_500 }
202
+
203
+ hits.sort((a, b) => (ORDER[a.order] ?? 9) - (ORDER[b.order] ?? 9) || b.count - a.count)
204
+ const byOrder = { 先看: 0, 顺便看: 0 }
205
+ for (const hit of hits) byOrder[hit.order] = (byOrder[hit.order] ?? 0) + hit.count
206
+
207
+ return {
208
+ ok: true,
209
+ chars,
210
+ total: hits.reduce((sum, hit) => sum + hit.count, 0),
211
+ byOrder,
212
+ hits,
213
+ fuzzy,
214
+ }
215
+ }
216
+
217
+ /** 正则命中的原句开头几字,用来当标签(「不是…而是」)。 */
218
+ function patternLabel(matched) {
219
+ const text = String(matched ?? '')
220
+ if (text.startsWith('不是')) return '「不是…而是」这种句式'
221
+ if (text.startsWith('没有')) return '「没有…只是」这种句式'
222
+ if (/^让/.test(text)) return '「让某人感到/觉得」这种句式'
223
+ if (/^令/.test(text)) return '「令人感到」这种句式'
224
+ if (text.startsWith('与此同时')) return '「与此同时」'
225
+ if (/^当/.test(text)) return '「当…时」这种句式'
226
+ if (/^于是/.test(text)) return '「于是…然而」连着用'
227
+ if (/^随即/.test(text)) return '「随即…紧接着」连着用'
228
+ if (/^不禁/.test(text)) return '「不禁…」'
229
+ return `「${text.slice(0, 6)}」这类句式`
230
+ }
231
+
232
+ /**
233
+ * 把数出来的结果写成一段人能读的话。
234
+ * 一条都没有时返回空串(调用方就别贴一段「没查出问题」占地方)。
235
+ */
236
+ export function proseReportText(scan) {
237
+ const data = scan && scan.ok === true ? scan : null
238
+ if (data === null) return ''
239
+ const lines = []
240
+
241
+ for (const hit of data.hits) {
242
+ // 只出现一次、篇幅又短:算不上密度问题,别拿一条孤例占版面。
243
+ // 但一章里出现一次「命运的齿轮」也值得说,所以门槛按篇幅走。
244
+ // 套话与大词出现一次就该看见;句式与身体模板要成密度才说,否则一句一个不算毛病。
245
+ if (hit.kind !== 'filler' && hit.kind !== 'big' && hit.kind !== 'detached' && hit.count < 2 && data.chars < 800) continue
246
+ lines.push(`- ${hit.label}用了 ${hit.count} 次,例如「${hit.sample}」——${hit.advice}`)
247
+ }
248
+ if (data.fuzzy.tooMany === true) {
249
+ lines.push(`- 「似乎 / 大概 / 仿佛」这类词每五百字 ${data.fuzzy.per500} 个(一共 ${data.fuzzy.count} 个)——想清楚的地方不用这些词`)
250
+ }
251
+
252
+ return lines.join('\n')
253
+ }