45 lines
1.9 KiB
TypeScript
45 lines
1.9 KiB
TypeScript
// 規則表:標籤 → 數值增減。所有數值集中在這裡;模型只給標籤,不給數值。
|
|
import type { Pad } from './types'
|
|
import { isTag, type Tag } from './tags'
|
|
|
|
export const RULES = {
|
|
thanks: { p: 0.15, a: 0.05, d: 0.05 },
|
|
scold: { p: -0.2, a: 0.15, d: -0.1 },
|
|
success: { p: 0.08, a: 0.03, d: 0.05 },
|
|
toolFail: { p: -0.08, a: 0.1, d: -0.08 },
|
|
return: { p: 0.1, a: 0.08, d: 0 },
|
|
lateNight: { p: -0.05, a: -0.1, d: 0 },
|
|
favorite: { p: 0.12, a: 0.08, d: 0.03 },
|
|
ignored: { p: -0.05, a: -0.03, d: -0.03 },
|
|
praiseSkill: { p: 0.1, a: 0.04, d: 0.06 },
|
|
amused: { p: 0.1, a: 0.06, d: 0.02 },
|
|
cared: { p: 0.08, a: -0.02, d: -0.02 },
|
|
apology: { p: 0.06, a: -0.06, d: 0.03 },
|
|
soothe: { p: 0.05, a: -0.08, d: 0.02 },
|
|
brushOff: { p: -0.06, a: 0.02, d: -0.04 },
|
|
overstep: { p: -0.15, a: 0.12, d: 0.02 },
|
|
remembered: { p: 0.08, a: 0.02, d: 0.02 },
|
|
selfDisclosure: { p: 0.04, a: 0.03, d: -0.02 },
|
|
gladForYou: { p: 0.08, a: 0.05, d: 0 },
|
|
liedCaught: { p: -0.18, a: 0.1, d: -0.05 },
|
|
brokenPromise: { p: -0.12, a: 0.04, d: -0.08 },
|
|
} as const satisfies Record<Tag, Pad>
|
|
|
|
// 正則先判明確的情況;順序即優先序
|
|
const PATTERNS: [Tag, RegExp][] = [
|
|
['scold', /笨|白痴|廢物|爛|你很煩|閉嘴|stupid|useless|idiot/i],
|
|
['thanks', /謝謝|感謝|太棒|好棒|厲害|讚|thanks?|thank you|great job|awesome/i],
|
|
['success', /成功|完成了|通過|搞定|passed|done|fixed/i],
|
|
]
|
|
|
|
/** 以正則判斷使用者文字的標籤;沒有明確情況回 null */
|
|
export function regexTag(text: string): Tag | null {
|
|
for (const [tag, re] of PATTERNS) if (re.test(text)) return tag
|
|
return null
|
|
}
|
|
|
|
/** 正則優先;正則沒判出才用模型補的標籤(須在白名單內),缺失或不合法就是沒有標籤 */
|
|
export function classify(text: string, modelTag?: string | null): Tag | null {
|
|
return regexTag(text) ?? (isTag(modelTag) ? modelTag : null)
|
|
}
|