-
Notifications
You must be signed in to change notification settings - Fork 19
/
JueJueZiGenerator.ts
436 lines (392 loc) · 11 KB
/
JueJueZiGenerator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
// JueJueZiGenerator
// --- SETUPS ---
const matierailsJSON = `
{
"emotions": {
"emoji": [
"😊",
"🌟",
"🧩",
"✨",
"☀️",
"🌹",
"🌸",
"🌼",
"🥝",
"🥤",
"🍑",
"🍹",
"🥑",
"🙋♀️",
"🎀",
"❤️",
"🧡",
"💛",
"💚",
"💙",
"💜",
"🖤",
"🤍",
"🤎",
"💕",
"💞",
"💓",
"💗",
"💖",
"💝"
],
"xiaohongshu": [
"[微笑R]",
"[害羞R]",
"[失望R]",
"[汗颜R]",
"[哇R]",
"[喝奶茶R]",
"[自拍R]",
"[偷笑R]",
"[飞吻R]",
"[石化R]",
"[笑哭R]",
"[赞R]",
"[暗中观察R]",
"[买爆R]",
"[大笑R]",
"[色色R]",
"[生气R]",
"[哭惹R]",
"[萌萌哒R]",
"[斜眼R]",
"[可怜R]",
"[鄙视R]",
"[皱眉R]",
"[抓狂R]",
"[派对R]",
"[吧唧R]",
"[惊恐R]",
"[抠鼻R]",
"[再见R]",
"[叹气R]",
"[睡觉R]",
"[得意R]",
"[吃瓜R]",
"[扶墙R]",
"[黑薯问号R]",
"[黄金薯R]",
"[吐舌头H]",
"[扯脸H]",
"[doge]"
],
"weibo": []
},
"symbols": [
"!",
"?",
"~",
"❓",
"❔",
"‼️",
"⁉️",
"❗️",
"❕"
],
"auxiliaryWords": [
"鸭",
"呜",
"啦",
"呐",
"呀",
"咩",
"呢",
"哈",
"嘿",
"哒",
"害",
"啊"
],
"dividers": [
" ",
","
],
"beginning": [
"今日份who营业啦",
"who下班啦",
"投递日常",
"今天的who也营业啦",
"今日份甜甜碎片已加载完毕",
"忙里偷闲的生活碎片",
"和someone逛吃的一天",
"分享開心",
"分享今日份開心",
"营业一下"
],
"who": [
"打工人",
"仙女",
"普信男",
"Java男",
"普信女",
"小可爱",
"本公主"
],
"someone": [
"小狗勾",
"小姐姐",
"集美",
"集美们",
"闺蜜",
"闺蜜👭",
"姐妹",
"姐妹们",
"姐妹👭",
"好姐妹",
"好姐妹👭",
"小姐妹",
"小姐妹👭"
],
"todosth": [
"今天去dosth",
"今天去dosth了",
"今天去dosth啦",
"今天去dosth鸭",
"今天去dosth噜",
"今天又又又dosth啦",
"今天又又又dosth鸭",
"又去dosth啦",
"又是dosth的一天啦",
"今天又是dosth的一天啦",
"宝~我今天dosth了",
"宝!我今天dosth了",
"还是去dosth了",
"无聊去dosth",
"今天去体验了dosth"
],
"another": [
"买 小蛋糕",
"买 小布丁",
"喝 奶茶",
"穿 JK",
"吃 迷hotel",
"喝 咖啡",
"买 蜜雪冰城",
"买 喜茶",
"喝 谬可"
],
"ending": [
"也是在逃公主的一天",
"好想谈一场双向奔赴的恋爱",
"星星月亮和我都要睡啦",
"散会",
"我是一面镜子 所以 晚安 我碎啦",
"岁月漫长 那就一起拯救地球与乐趣吧"
],
"collections": [
"路上还看见一个普信男",
"路边捡到了一分钱",
"不小心踩了狗屎",
"路上还看见一个Java男"
],
"attribute": [
"绝绝子",
"无语子",
"真下头",
"yyds",
"奈斯",
"有被惊艳到",
"🉑️",
"太可了",
"太🉑️了",
"真的绝",
"太牛了",
"太🐮了",
"好dosth到跺脚",
"好dosth到爆",
"好dosth到跺jiojio",
"太爱了"
],
"fashion": [
"救命🆘",
"噎死莫拉",
"不管啦",
"就是玩儿",
"无语子",
"我真的哭死",
"冲鸭",
"笑死",
"那我走",
"我都惊了",
"大无语事件",
"就很烦",
"心态炸裂",
"搞快点",
"不是吧",
"不是8⃣️",
"全都给我冲",
"啥也不是"
],
"default": [
"豁 奶茶",
"撸 代码",
"刷 微博",
"买 基金",
"摸 鱼",
"玩 绝绝子生成器"
]
}
`
const ContentLengthConstraint = 300 // 内容长度约束
// --- INTERFACES ---
interface Matierail {
emotions: { // 表情
emoji: string[]
xiaohongshu: string[]
weibo: string[]
}
symbols: string[]
auxiliaryWords: string[]
dividers: string[] // 断句符
fashion: string[] // 潮流
attribute: string[] // 定语
beginning: string[] // 开头
ending: string[] // 结尾
who: string[] // 主语
someone: string[] // 和/跟谁
todosth: string[] // 干什么
another: string[] // 扯另一个淡
collections: string[] // 一些固定搭配
default: string[] // 默认 something
}
// --- UTILITIES ---
function parseMatieraials(matierailsJSON: string): Matierail {
return JSON.parse(matierailsJSON)
}
function randomWord(words: string[], nullable = false, divider = ''): string {
var maxRange = words.length
if (nullable) {
// 增加 1/3 概率
maxRange += maxRange / 3
}
var index = Math.floor(Math.random() * maxRange)
if (index >= words.length) {
return ''
} else {
return words[index] + divider
}
}
function randomWords(words: string[], count: number): string[] {
if (words.length < count) {
return words
}
// Inspired by: https://www.imooc.com/wenda/detail/440036
return words.sort(() => Math.random() - 0.5).slice(0, count)
}
function randomRepeat(word: string, times = -1): string {
if (times > 0) {
var result = ""
for (let index = 0; index < times; index++) {
result += word
}
return result
}
var index = Math.floor(Math.random() * 3)
if (index == 2) {
return randomRepeat(word, 3)
}
if (index == 0) {
return randomRepeat(word, 1)
}
return ''
}
// --- CORE ---
function generateBeginning(matierail: Matierail, divider: string) {
var beginning = randomWord(matierail.beginning)
if (beginning.indexOf('who') != -1) {
// 拼 who
beginning = beginning.replace('who', randomWord(matierail.who))
}
if (beginning.indexOf('someone') != -1) {
// 拼 someone
beginning = beginning.replace('someone', randomWord(matierail.someone))
}
var emotion = randomWord(matierail.emotions.emoji, true)
// if (emotion == '') {
// emotion = divider
// }
return beginning + emotion + divider
}
function generateDoSth(matierail: Matierail, something: string, divider: string): string {
var todosth = randomWord(matierail.todosth)
if (todosth.indexOf('dosth') != -1) {
// 拼 something
if (something.indexOf(' ') != -1) {
something = something.replace(' ', '') // 去间隔
}
todosth = todosth.replace('dosth', something)
}
// 拼 emotions
var emotions = randomRepeat(randomWord(matierail.emotions.emoji))
// if (emotions.length == 0) {
// emotions = divider
// }
return todosth + emotions + divider
}
function praiseSth(something: string, praisedWords: string[], hasAlso = false): string {
var praiseWord = randomWord(praisedWords)
var verb = something.split(' ')[0]
var noun = something.split(' ')[1]
var result = ''
var intro = randomWord(['这家的', '这家店的', '这个', '这件', '这杯'])
var also = hasAlso ? '也' : ''
if (praiseWord.indexOf('dosth') != -1) {
// eg. 好dosth到爆
praiseWord = praiseWord.replace('dosth', verb)
result = intro + noun + also + praiseWord
} else {
// eg. 绝绝子
result = intro + noun + also + praiseWord
}
return result
}
function randomButNotContain(words: string[], already: string): string {
var random = randomWord(words)
// Inspired by: https://www.cnblogs.com/mengff/p/7350005.html
var set = new Set(already.replace(' ', '').split(''))
var intersect = new Set(random.replace(' ', '').split('').filter(x => set.has(x)))
if (Array.from(intersect).length == 0) {
return random
} else {
return randomButNotContain(words, already)
}
}
function generate(matierail: Matierail, something: string): string {
// 开场白
var divider = randomWord(matierail.dividers) // 分隔符
var fashionWords = randomWords(matierail.fashion, matierail.fashion.length) // 不重复的词组
var first = generateBeginning(matierail, divider)
var second = fashionWords[0] + divider
var third = generateDoSth(matierail, something, divider)
var forth = fashionWords[1] + divider
var fifth = randomRepeat(randomWord(matierail.auxiliaryWords), 3) + divider
var sixth = praiseSth(something, matierail.attribute) + randomRepeat(randomWord(matierail.symbols), 3)
var seventh = praiseSth(randomButNotContain(matierail.another, something), matierail.attribute, true) + randomRepeat(randomWord(matierail.symbols), 3)
var eighth = fashionWords[2] + divider
var ninth = randomWord(matierail.collections, true, divider) + fashionWords[3] + divider
var tenth = randomRepeat(randomWord(matierail.auxiliaryWords), 3) + divider
var last = randomWord(matierail.ending) + randomWord(matierail.emotions.emoji)
return first + second + third + forth + fifth + sixth + seventh + eighth + ninth + tenth + last
}
var matierail = parseMatieraials(matierailsJSON)
function randomSetDefaultWord() {
var input = <HTMLInputElement>document.getElementById('keyword_input')
input.value = randomWord(matierail.default)
}
function chongYa() {
var input = <HTMLInputElement>document.getElementById('keyword_input')
var content = generate(matierail, input.value)
var container = <HTMLDivElement>document.getElementById('content_container')
container.style.display = 'flex'
if (container.firstElementChild != null) {
container.firstElementChild.innerHTML = content
}
}
// console.log(generate(matierail, randomWord(matierail.default)))
randomSetDefaultWord()