inkbone 0.0.0-stage → 2.0.0
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/LICENSE +21 -0
- package/README.en.md +318 -0
- package/README.md +333 -2
- package/bin/inkbone.mjs +941 -0
- package/configs/genres.json +570 -0
- package/configs/messages.json +302 -0
- package/configs/platforms.json +62 -0
- package/configs/presets.json +265 -0
- package/configs/severity.json +52 -0
- package/configs/zh-linguistics.json +986 -0
- package/configs/zh-traditional.json +97 -0
- package/examples/claude-code-hooks.json +15 -0
- package/examples/mcp-config.json +12 -0
- package/package.json +61 -4
- package/prompts/00-style-architect.md +42 -0
- package/prompts/01-beat-planner.md +54 -0
- package/prompts/02-paratactic-renderer.md +60 -0
- package/prompts/03-targeted-rewriter.md +39 -0
- package/prompts/04-evidence-reviewer.md +39 -0
- package/prompts/05-reader-simulator.md +54 -0
- package/prompts/06-ledger-importer.md +41 -0
- package/prompts/07-chapter-settler.md +66 -0
- package/resources/bad_vs_good_cases.md +98 -0
- package/resources/eval/blind-read-instructions.md +18 -0
- package/resources/genre_playbooks/classical-xianxia.md +22 -0
- package/resources/genre_playbooks/general-clean.md +19 -0
- package/resources/genre_playbooks/historical-court.md +21 -0
- package/resources/genre_playbooks/light-fantasy.md +21 -0
- package/resources/genre_playbooks/mystery-thriller.md +22 -0
- package/resources/genre_playbooks/romance-emotional.md +20 -0
- package/resources/genre_playbooks/scifi-wasteland.md +21 -0
- package/resources/genre_playbooks/urban-realism.md +22 -0
- package/resources/genre_playbooks/wuxia-jianghu.md +21 -0
- package/resources/micro_techniques.md +77 -0
- package/skills/inkbone/LICENSE +21 -0
- package/skills/inkbone/README.md +334 -0
- package/skills/inkbone/SKILL.md +155 -0
- package/skills/inkbone/benchmarks/eval-set/README.md +49 -0
- package/skills/inkbone/benchmarks/eval-set/public-pairs.json +42 -0
- package/skills/inkbone/benchmarks/eval-set/seeds.json +42 -0
- package/skills/inkbone/bin/inkbone.mjs +941 -0
- package/skills/inkbone/configs/genres.json +570 -0
- package/skills/inkbone/configs/messages.json +302 -0
- package/skills/inkbone/configs/platforms.json +62 -0
- package/skills/inkbone/configs/presets.json +265 -0
- package/skills/inkbone/configs/severity.json +52 -0
- package/skills/inkbone/configs/zh-linguistics.json +986 -0
- package/skills/inkbone/configs/zh-traditional.json +97 -0
- package/skills/inkbone/package.json +63 -0
- package/skills/inkbone/prompts/00-style-architect.md +42 -0
- package/skills/inkbone/prompts/01-beat-planner.md +54 -0
- package/skills/inkbone/prompts/02-paratactic-renderer.md +60 -0
- package/skills/inkbone/prompts/03-targeted-rewriter.md +39 -0
- package/skills/inkbone/prompts/04-evidence-reviewer.md +39 -0
- package/skills/inkbone/prompts/05-reader-simulator.md +54 -0
- package/skills/inkbone/prompts/06-ledger-importer.md +41 -0
- package/skills/inkbone/prompts/07-chapter-settler.md +66 -0
- package/skills/inkbone/resources/bad_vs_good_cases.md +98 -0
- package/skills/inkbone/resources/eval/blind-read-instructions.md +18 -0
- package/skills/inkbone/resources/genre_playbooks/classical-xianxia.md +22 -0
- package/skills/inkbone/resources/genre_playbooks/general-clean.md +19 -0
- package/skills/inkbone/resources/genre_playbooks/historical-court.md +21 -0
- package/skills/inkbone/resources/genre_playbooks/light-fantasy.md +21 -0
- package/skills/inkbone/resources/genre_playbooks/mystery-thriller.md +22 -0
- package/skills/inkbone/resources/genre_playbooks/romance-emotional.md +20 -0
- package/skills/inkbone/resources/genre_playbooks/scifi-wasteland.md +21 -0
- package/skills/inkbone/resources/genre_playbooks/urban-realism.md +22 -0
- package/skills/inkbone/resources/genre_playbooks/wuxia-jianghu.md +21 -0
- package/skills/inkbone/resources/micro_techniques.md +77 -0
- package/skills/inkbone/src/auditor.mjs +24 -0
- package/skills/inkbone/src/benchmark-runner.mjs +71 -0
- package/skills/inkbone/src/boundary-compiler.mjs +54 -0
- package/skills/inkbone/src/browser-doctor.mjs +30 -0
- package/skills/inkbone/src/calibrator.mjs +175 -0
- package/skills/inkbone/src/config-loader.mjs +233 -0
- package/skills/inkbone/src/continuity.mjs +5 -0
- package/skills/inkbone/src/core/auditor.mjs +914 -0
- package/skills/inkbone/src/core/boundary-compiler.mjs +423 -0
- package/skills/inkbone/src/core/browser-doctor.mjs +318 -0
- package/skills/inkbone/src/core/config-compiler.mjs +434 -0
- package/skills/inkbone/src/core/continuity.mjs +158 -0
- package/skills/inkbone/src/core/evidence-validator.mjs +77 -0
- package/skills/inkbone/src/core/exporter.mjs +128 -0
- package/skills/inkbone/src/core/formatter.mjs +241 -0
- package/skills/inkbone/src/core/ledger-manager.mjs +576 -0
- package/skills/inkbone/src/core/normalizer.mjs +517 -0
- package/skills/inkbone/src/core/profiler.mjs +686 -0
- package/skills/inkbone/src/core/rule-engine.mjs +1536 -0
- package/skills/inkbone/src/core/style-profiler.mjs +229 -0
- package/skills/inkbone/src/detector.mjs +270 -0
- package/skills/inkbone/src/doctor.mjs +428 -0
- package/skills/inkbone/src/evaluation.mjs +311 -0
- package/skills/inkbone/src/evidence-validator.mjs +15 -0
- package/skills/inkbone/src/exporter.mjs +106 -0
- package/skills/inkbone/src/formatter.mjs +34 -0
- package/skills/inkbone/src/importer.mjs +230 -0
- package/skills/inkbone/src/index.mjs +116 -0
- package/skills/inkbone/src/ledger-manager.mjs +15 -0
- package/skills/inkbone/src/mcp-server.mjs +861 -0
- package/skills/inkbone/src/normalizer.mjs +73 -0
- package/skills/inkbone/src/profiler.mjs +17 -0
- package/skills/inkbone/src/rule-engine.mjs +73 -0
- package/skills/inkbone/src/rule-stats.mjs +142 -0
- package/skills/inkbone/src/style-profiler.mjs +25 -0
- package/src/auditor.mjs +24 -0
- package/src/benchmark-runner.mjs +71 -0
- package/src/boundary-compiler.mjs +54 -0
- package/src/browser-doctor.mjs +30 -0
- package/src/calibrator.mjs +175 -0
- package/src/config-loader.mjs +233 -0
- package/src/continuity.mjs +5 -0
- package/src/core/auditor.mjs +914 -0
- package/src/core/boundary-compiler.mjs +423 -0
- package/src/core/browser-doctor.mjs +318 -0
- package/src/core/config-compiler.mjs +434 -0
- package/src/core/continuity.mjs +158 -0
- package/src/core/evidence-validator.mjs +77 -0
- package/src/core/exporter.mjs +128 -0
- package/src/core/formatter.mjs +241 -0
- package/src/core/ledger-manager.mjs +576 -0
- package/src/core/normalizer.mjs +517 -0
- package/src/core/profiler.mjs +686 -0
- package/src/core/rule-engine.mjs +1536 -0
- package/src/core/style-profiler.mjs +229 -0
- package/src/detector.mjs +270 -0
- package/src/doctor.mjs +428 -0
- package/src/evaluation.mjs +311 -0
- package/src/evidence-validator.mjs +15 -0
- package/src/exporter.mjs +106 -0
- package/src/formatter.mjs +34 -0
- package/src/importer.mjs +230 -0
- package/src/index.mjs +116 -0
- package/src/ledger-manager.mjs +15 -0
- package/src/mcp-server.mjs +861 -0
- package/src/normalizer.mjs +73 -0
- package/src/profiler.mjs +17 -0
- package/src/rule-engine.mjs +73 -0
- package/src/rule-stats.mjs +142 -0
- package/src/style-profiler.mjs +25 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// 零 Token 确定性排版与标点清洗器(严格零汉字代码,规则词条来自 JSON 配置)
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { collectTextFiles } from "./calibrator.mjs";
|
|
5
|
+
import { loadLinguisticsConfig } from "./config-loader.mjs";
|
|
6
|
+
import {
|
|
7
|
+
normalizeProseText as normalizeProseTextCore,
|
|
8
|
+
stripMarkdownEmphasis as stripMarkdownEmphasisCore,
|
|
9
|
+
} from "./core/normalizer.mjs";
|
|
10
|
+
|
|
11
|
+
// 零 Token 确定性清洗正文中的 Markdown 星号、分隔线与非标省略号/破折号
|
|
12
|
+
export function normalizeProseText(rawContent, options = {}) {
|
|
13
|
+
return normalizeProseTextCore(rawContent, {
|
|
14
|
+
...options,
|
|
15
|
+
lingConfig: options.lingConfig || loadLinguisticsConfig(),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 仅剥离受保护区间之外的 Markdown 加粗与斜体星号,用于边界与锚点匹配
|
|
20
|
+
export function stripMarkdownEmphasis(
|
|
21
|
+
rawContent,
|
|
22
|
+
whitelistLiterals = [],
|
|
23
|
+
lingConfig = null
|
|
24
|
+
) {
|
|
25
|
+
return stripMarkdownEmphasisCore(
|
|
26
|
+
rawContent,
|
|
27
|
+
whitelistLiterals,
|
|
28
|
+
lingConfig || loadLinguisticsConfig()
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 批量检查或清洗目录下所有小说文件(check 模式只读不写回)
|
|
33
|
+
export function normalizeFiles(targetPaths, options = {}) {
|
|
34
|
+
const filePaths = collectTextFiles([].concat(targetPaths || []));
|
|
35
|
+
const lingConfig = options.lingConfig || loadLinguisticsConfig();
|
|
36
|
+
const isCheck = Boolean(options.check);
|
|
37
|
+
let filesChanged = 0;
|
|
38
|
+
let totalFindings = 0;
|
|
39
|
+
const files = [];
|
|
40
|
+
|
|
41
|
+
for (const absPath of filePaths) {
|
|
42
|
+
const raw = fs.readFileSync(absPath, "utf8");
|
|
43
|
+
const res = normalizeProseText(raw, {
|
|
44
|
+
lingConfig,
|
|
45
|
+
whitelistLiterals: options.whitelistLiterals || [],
|
|
46
|
+
stripMarkdownEmphasis: Boolean(options.stripMarkdownEmphasis),
|
|
47
|
+
fixNarrationEmDash: Boolean(options.fixNarrationEmDash),
|
|
48
|
+
});
|
|
49
|
+
totalFindings += res.findingCount;
|
|
50
|
+
if (!isCheck && res.changed) {
|
|
51
|
+
fs.writeFileSync(absPath, res.output, "utf8");
|
|
52
|
+
filesChanged += 1;
|
|
53
|
+
}
|
|
54
|
+
if (res.findingCount > 0) {
|
|
55
|
+
files.push({
|
|
56
|
+
file: path.basename(absPath),
|
|
57
|
+
path: absPath,
|
|
58
|
+
findingCount: res.findingCount,
|
|
59
|
+
changed: !isCheck && res.changed,
|
|
60
|
+
findings: res.findings,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
pass: !(isCheck && totalFindings > 0),
|
|
67
|
+
check: isCheck,
|
|
68
|
+
filesScanned: filePaths.length,
|
|
69
|
+
filesChanged,
|
|
70
|
+
totalFindings,
|
|
71
|
+
files,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { loadLinguisticsConfig } from "./config-loader.mjs";
|
|
2
|
+
import { countHan, profileText as profileTextCore } from "./core/profiler.mjs";
|
|
3
|
+
|
|
4
|
+
export { countHan };
|
|
5
|
+
|
|
6
|
+
// 对输入章节或语料执行全维度计算语言学指纹画像分析
|
|
7
|
+
export function profileText(
|
|
8
|
+
rawContent,
|
|
9
|
+
customLingConfig = null,
|
|
10
|
+
ruleOverrides = null
|
|
11
|
+
) {
|
|
12
|
+
return profileTextCore(
|
|
13
|
+
rawContent,
|
|
14
|
+
customLingConfig || loadLinguisticsConfig(),
|
|
15
|
+
ruleOverrides
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { loadLinguisticsConfig } from "./config-loader.mjs";
|
|
2
|
+
import {
|
|
3
|
+
countVisibleChars,
|
|
4
|
+
maskWhitelistLiterals,
|
|
5
|
+
getQuotedRanges,
|
|
6
|
+
maskQuotedText,
|
|
7
|
+
stripSpokenDialogue,
|
|
8
|
+
dedupContainedHits,
|
|
9
|
+
computeTailStartIndex,
|
|
10
|
+
scanParagraphRuleSet,
|
|
11
|
+
evaluateHitsWithDensity,
|
|
12
|
+
scanCrossParagraphParallel,
|
|
13
|
+
runDensityTics,
|
|
14
|
+
extractBodyParagraphLines as extractBodyParagraphLinesCore,
|
|
15
|
+
runDegenerationChecks,
|
|
16
|
+
checkOutlineCopy as checkOutlineCopyCore,
|
|
17
|
+
parseChineseOrArabicNumber,
|
|
18
|
+
checkCharCountClaims as checkCharCountClaimsCore,
|
|
19
|
+
checkOutlineContract as checkOutlineContractCore,
|
|
20
|
+
} from "./core/rule-engine.mjs";
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
countVisibleChars,
|
|
24
|
+
maskWhitelistLiterals,
|
|
25
|
+
getQuotedRanges,
|
|
26
|
+
maskQuotedText,
|
|
27
|
+
stripSpokenDialogue,
|
|
28
|
+
dedupContainedHits,
|
|
29
|
+
computeTailStartIndex,
|
|
30
|
+
scanParagraphRuleSet,
|
|
31
|
+
evaluateHitsWithDensity,
|
|
32
|
+
scanCrossParagraphParallel,
|
|
33
|
+
runDensityTics,
|
|
34
|
+
runDegenerationChecks,
|
|
35
|
+
parseChineseOrArabicNumber,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// 提取用于语言学画像与规则扫描的含汉字正文自然段
|
|
39
|
+
export function extractBodyParagraphLines(rawContent, customLingConfig = null) {
|
|
40
|
+
return extractBodyParagraphLinesCore(
|
|
41
|
+
rawContent,
|
|
42
|
+
customLingConfig || loadLinguisticsConfig()
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 检测正文是否大段照搬章节细纲文字(支持白名单原话/复沓锚句豁免)
|
|
47
|
+
export function checkOutlineCopy(chapterText, outlineText, options = {}) {
|
|
48
|
+
return checkOutlineCopyCore(chapterText, outlineText, {
|
|
49
|
+
...options,
|
|
50
|
+
lingConfig: options.lingConfig || loadLinguisticsConfig(),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 校验引号相邻句的“短短 X 字 / 这 X 个字”字数宣称是否与引号内实际字数一致
|
|
55
|
+
export function checkCharCountClaims(
|
|
56
|
+
rawContent,
|
|
57
|
+
customLingConfig = null,
|
|
58
|
+
whitelistLiterals = []
|
|
59
|
+
) {
|
|
60
|
+
return checkCharCountClaimsCore(
|
|
61
|
+
rawContent,
|
|
62
|
+
customLingConfig || loadLinguisticsConfig(),
|
|
63
|
+
whitelistLiterals
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 校验章节细纲是否缺失核心情节要素或残留未填占位符
|
|
68
|
+
export function checkOutlineContract(outlineText, options = {}) {
|
|
69
|
+
return checkOutlineContractCore(outlineText, {
|
|
70
|
+
...options,
|
|
71
|
+
lingConfig: options.lingConfig || loadLinguisticsConfig(),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadGenresConfig,
|
|
3
|
+
loadLinguisticsConfig,
|
|
4
|
+
resolveGenre,
|
|
5
|
+
} from "./config-loader.mjs";
|
|
6
|
+
import { profileText } from "./profiler.mjs";
|
|
7
|
+
import { scanParagraphRuleSet } from "./rule-engine.mjs";
|
|
8
|
+
|
|
9
|
+
// 判定阈值:人类文本每万字命中达到 tasteMinPer10k 且 AI/人类比值低于 markerMinRatio,视为口味规则
|
|
10
|
+
const DEFAULTS = {
|
|
11
|
+
markerMinRatio: 3,
|
|
12
|
+
markerMinAiHits: 3,
|
|
13
|
+
tasteMinPer10k: 1,
|
|
14
|
+
minReliableHumanHan: 20000,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// 按审计器同样的顺序合并三层规则,返回带 family 的规则清单
|
|
18
|
+
export function collectRuleFamilies(options = {}) {
|
|
19
|
+
const lingConfig = options.linguisticsConfig || loadLinguisticsConfig();
|
|
20
|
+
const genresConfig = loadGenresConfig(options.genresPath);
|
|
21
|
+
const genrePack = options.genre ? resolveGenre(options.genre, options.genresPath) : null;
|
|
22
|
+
const project = options.projectRules || null;
|
|
23
|
+
const disabled = project ? project.disabledRuleIds : new Set();
|
|
24
|
+
const families = {
|
|
25
|
+
cliche: [
|
|
26
|
+
...lingConfig.compiledRegex.forbiddenCliches,
|
|
27
|
+
...(genrePack ? genrePack.compiledClicheRules : []),
|
|
28
|
+
...(project ? project.clicheRules : []),
|
|
29
|
+
],
|
|
30
|
+
symmetric: [
|
|
31
|
+
...lingConfig.compiledRegex.symmetricSkeletons,
|
|
32
|
+
...(project ? project.symmetricSkeletons : []),
|
|
33
|
+
],
|
|
34
|
+
register: [
|
|
35
|
+
...(genrePack ? genrePack.compiledRegisterRules : []),
|
|
36
|
+
...(project ? project.registerRules : []),
|
|
37
|
+
],
|
|
38
|
+
filler: [
|
|
39
|
+
...genresConfig.compiledUniversalFillers,
|
|
40
|
+
...(genrePack ? genrePack.compiledFillerRules : []),
|
|
41
|
+
...(project ? project.fillerRules : []),
|
|
42
|
+
],
|
|
43
|
+
rhetorical: [
|
|
44
|
+
...(lingConfig.compiledRegex.rhetoricalRules || []),
|
|
45
|
+
...(genrePack ? genrePack.compiledRhetoricalRules || [] : []),
|
|
46
|
+
...(project ? project.rhetoricalRules || [] : []),
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
const rules = [];
|
|
50
|
+
for (const [family, list] of Object.entries(families)) {
|
|
51
|
+
for (const rule of list) {
|
|
52
|
+
if (!rule || !rule.regex || disabled.has(rule.id)) continue;
|
|
53
|
+
rules.push({ family, rule });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { lingConfig, genre: genrePack ? genrePack.id : null, rules };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 统计一组文本里每条规则的命中次数(逐条单独扫描,不做跨规则去重)
|
|
60
|
+
function countCorpus(texts, ruleEntries, lingConfig) {
|
|
61
|
+
const counts = new Map();
|
|
62
|
+
let totalHan = 0;
|
|
63
|
+
const scanOpts = {
|
|
64
|
+
quoteMaskRegexes: lingConfig.compiledRegex.quoteMaskRegexes || [],
|
|
65
|
+
quoteMaskChar: lingConfig.tokens.quoteMaskChar || "?",
|
|
66
|
+
visibleCharRegex: lingConfig.compiledRegex.visibleCharGlobal || lingConfig.compiledRegex.hanCharGlobal,
|
|
67
|
+
};
|
|
68
|
+
for (const text of texts) {
|
|
69
|
+
const { metrics, diagnostics } = profileText(text, lingConfig);
|
|
70
|
+
totalHan += metrics.totalHan;
|
|
71
|
+
for (const { rule } of ruleEntries) {
|
|
72
|
+
// tail600 窗口规则在统计时按全文扫描,避免短样本全部落在窗口外
|
|
73
|
+
const scanRule = rule.window === "tail600" ? { ...rule, window: undefined } : rule;
|
|
74
|
+
const hits = scanParagraphRuleSet(diagnostics.paragraphs, [scanRule], scanOpts);
|
|
75
|
+
if (hits.length > 0) counts.set(rule.id, (counts.get(rule.id) || 0) + hits.length);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { counts, totalHan };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 对比人类文本与 AI 稿,给每条规则打上 ai-marker / taste / inconclusive / silent 判定
|
|
82
|
+
export function computeRuleStats(humanTexts, aiTexts, options = {}) {
|
|
83
|
+
const cfg = { ...DEFAULTS, ...(options.thresholds || {}) };
|
|
84
|
+
const { lingConfig, genre, rules } = collectRuleFamilies(options);
|
|
85
|
+
const human = countCorpus(humanTexts, rules, lingConfig);
|
|
86
|
+
const ai = countCorpus(aiTexts, rules, lingConfig);
|
|
87
|
+
const per10k = (n, han) => (han > 0 ? Math.round((n / han) * 1e5) / 10 : 0);
|
|
88
|
+
const rows = rules.map(({ family, rule }) => {
|
|
89
|
+
const humanHits = human.counts.get(rule.id) || 0;
|
|
90
|
+
const aiHits = ai.counts.get(rule.id) || 0;
|
|
91
|
+
const humanRate = per10k(humanHits, human.totalHan);
|
|
92
|
+
const aiRate = per10k(aiHits, ai.totalHan);
|
|
93
|
+
// 加 0.5 平滑后比较每万字命中率
|
|
94
|
+
const smoothedHuman = ((humanHits + 0.5) / Math.max(human.totalHan, 1)) * 1e4;
|
|
95
|
+
const smoothedAi = ((aiHits + 0.5) / Math.max(ai.totalHan, 1)) * 1e4;
|
|
96
|
+
const ratio = Math.round((smoothedAi / smoothedHuman) * 10) / 10;
|
|
97
|
+
let verdict = "inconclusive";
|
|
98
|
+
if (humanHits === 0 && aiHits === 0) verdict = "silent";
|
|
99
|
+
else if (humanRate >= cfg.tasteMinPer10k && ratio < cfg.markerMinRatio) verdict = "taste";
|
|
100
|
+
else if (ratio >= cfg.markerMinRatio && aiHits >= cfg.markerMinAiHits) verdict = "ai-marker";
|
|
101
|
+
return {
|
|
102
|
+
id: rule.id,
|
|
103
|
+
family,
|
|
104
|
+
layer: rule.layer || "universal",
|
|
105
|
+
humanHits,
|
|
106
|
+
aiHits,
|
|
107
|
+
humanPer10k: humanRate,
|
|
108
|
+
aiPer10k: aiRate,
|
|
109
|
+
ratio,
|
|
110
|
+
verdict,
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
const order = { taste: 0, inconclusive: 1, "ai-marker": 2, silent: 3 };
|
|
114
|
+
rows.sort((a, b) => order[a.verdict] - order[b.verdict] || b.humanHits - a.humanHits || b.aiHits - a.aiHits);
|
|
115
|
+
return {
|
|
116
|
+
kind: "inkbone-rule-stats",
|
|
117
|
+
genre,
|
|
118
|
+
human: { docs: humanTexts.length, han: human.totalHan },
|
|
119
|
+
ai: { docs: aiTexts.length, han: ai.totalHan },
|
|
120
|
+
reliable: human.totalHan >= cfg.minReliableHumanHan,
|
|
121
|
+
thresholds: cfg,
|
|
122
|
+
summary: rows.reduce((acc, r) => ({ ...acc, [r.verdict]: (acc[r.verdict] || 0) + 1 }), {}),
|
|
123
|
+
rules: rows,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 把统计结果渲染成 Markdown 表格(默认隐藏 silent 规则)
|
|
128
|
+
export function formatRuleStatsMarkdown(stats, options = {}) {
|
|
129
|
+
const shown = stats.rules.filter((r) => options.all || r.verdict !== "silent");
|
|
130
|
+
const lines = [
|
|
131
|
+
`human: ${stats.human.docs} docs / ${stats.human.han} han; ai: ${stats.ai.docs} docs / ${stats.ai.han} han; reliable: ${stats.reliable}`,
|
|
132
|
+
`summary: ${JSON.stringify(stats.summary)}`,
|
|
133
|
+
"",
|
|
134
|
+
"| verdict | rule | family | layer | human hits | ai hits | human /10k | ai /10k | ratio |",
|
|
135
|
+
"| :--- | :--- | :--- | :--- | ---: | ---: | ---: | ---: | ---: |",
|
|
136
|
+
...shown.map(
|
|
137
|
+
(r) =>
|
|
138
|
+
`| ${r.verdict} | ${r.id} | ${r.family} | ${r.layer} | ${r.humanHits} | ${r.aiHits} | ${r.humanPer10k} | ${r.aiPer10k} | ${r.ratio} |`
|
|
139
|
+
),
|
|
140
|
+
];
|
|
141
|
+
return lines.join("\n");
|
|
142
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Node 端安全拆书与文风节奏画像入口:自动加载本地语言学、预设与双语文案配置
|
|
2
|
+
import {
|
|
3
|
+
loadLinguisticsConfig,
|
|
4
|
+
loadPresetsConfig,
|
|
5
|
+
loadMessagesConfig,
|
|
6
|
+
} from "./config-loader.mjs";
|
|
7
|
+
import {
|
|
8
|
+
analyzeStyleProfile as analyzeStyleProfileCore,
|
|
9
|
+
formatStyleProfileMarkdown as formatStyleProfileMarkdownCore,
|
|
10
|
+
} from "./core/style-profiler.mjs";
|
|
11
|
+
|
|
12
|
+
// 从一批范文或前文章节计算纯统计节奏画像与建议 customGates(绝不输出原句)
|
|
13
|
+
export function analyzeStyleProfile(texts, options = {}) {
|
|
14
|
+
const lingConfig = options.linguisticsConfig || loadLinguisticsConfig();
|
|
15
|
+
const presetsConfig = options.presetsConfig || loadPresetsConfig(options.presetsPath);
|
|
16
|
+
return analyzeStyleProfileCore(texts, lingConfig, presetsConfig, options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 将风格画像格式化为双语 Markdown 报告
|
|
20
|
+
export function formatStyleProfileMarkdown(profile, options = {}) {
|
|
21
|
+
return formatStyleProfileMarkdownCore(profile, {
|
|
22
|
+
...options,
|
|
23
|
+
messagesConfig: options.messagesConfig || loadMessagesConfig(options.messagesPath),
|
|
24
|
+
});
|
|
25
|
+
}
|
package/src/auditor.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadGenresConfig,
|
|
3
|
+
loadLinguisticsConfig,
|
|
4
|
+
loadPresetsConfig,
|
|
5
|
+
loadSeverityConfig,
|
|
6
|
+
loadTraditionalConfig,
|
|
7
|
+
} from "./config-loader.mjs";
|
|
8
|
+
import { auditChapterText as auditChapterTextCore } from "./core/auditor.mjs";
|
|
9
|
+
|
|
10
|
+
// Node 端审计入口:自动从本地 JSON 加载默认配置后委托给零文件系统依赖的核心引擎
|
|
11
|
+
export function auditChapterText(rawContent, options = {}) {
|
|
12
|
+
return auditChapterTextCore(rawContent, {
|
|
13
|
+
...options,
|
|
14
|
+
linguisticsConfig: options.linguisticsConfig || loadLinguisticsConfig(),
|
|
15
|
+
genresConfig: options.genresConfig || loadGenresConfig(options.genresPath),
|
|
16
|
+
presetsConfig: options.presetsConfig || loadPresetsConfig(options.presetsPath),
|
|
17
|
+
severityConfig:
|
|
18
|
+
options.severityConfig || loadSeverityConfig(options.severityPath),
|
|
19
|
+
traditionalConfig:
|
|
20
|
+
options.traditionalConfig !== undefined
|
|
21
|
+
? options.traditionalConfig
|
|
22
|
+
: loadTraditionalConfig(),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { profileText } from "./profiler.mjs";
|
|
5
|
+
import { loadLinguisticsConfig } from "./config-loader.mjs";
|
|
6
|
+
|
|
7
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
8
|
+
const srcDir = path.dirname(currentFile);
|
|
9
|
+
const defaultCorpusPath = path.resolve(
|
|
10
|
+
srcDir,
|
|
11
|
+
"../benchmarks/master-corpus.json"
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
// 批量运行基准语料库与实战章节对比,生成结构化统计对照结果与 Markdown 表格
|
|
15
|
+
export function runCorpusBenchmark(options = {}) {
|
|
16
|
+
const lingConfig = loadLinguisticsConfig();
|
|
17
|
+
const corpusPath = options.corpusPath
|
|
18
|
+
? path.resolve(options.corpusPath)
|
|
19
|
+
: defaultCorpusPath;
|
|
20
|
+
// 人类语料涉及版权,不随仓库发布;文件缺失时只跑本地章节
|
|
21
|
+
const corpusData = fs.existsSync(corpusPath)
|
|
22
|
+
? JSON.parse(fs.readFileSync(corpusPath, "utf8"))
|
|
23
|
+
: { samples: [] };
|
|
24
|
+
|
|
25
|
+
const rows = [];
|
|
26
|
+
for (const sample of corpusData.samples) {
|
|
27
|
+
const { metrics } = profileText(sample.text, lingConfig);
|
|
28
|
+
rows.push({
|
|
29
|
+
id: sample.id,
|
|
30
|
+
label: sample.label,
|
|
31
|
+
group: sample.group,
|
|
32
|
+
note: sample.detectorNote || "",
|
|
33
|
+
...metrics,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 支持附带外部实战 Markdown 文件一同参与基准对比
|
|
38
|
+
for (const extra of options.extraFiles || []) {
|
|
39
|
+
const resolved = path.resolve(extra.path);
|
|
40
|
+
if (fs.existsSync(resolved)) {
|
|
41
|
+
const content = fs.readFileSync(resolved, "utf8");
|
|
42
|
+
const { metrics } = profileText(content, lingConfig);
|
|
43
|
+
rows.push({
|
|
44
|
+
id: extra.id || path.basename(resolved, ".md"),
|
|
45
|
+
label: extra.label || path.basename(resolved),
|
|
46
|
+
group: extra.group || "benchmark_chapter",
|
|
47
|
+
note: extra.note || "",
|
|
48
|
+
...metrics,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return rows;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 将基准跑分数组渲染为清晰的 Markdown 对比表格
|
|
57
|
+
export function formatBenchmarkMarkdown(rows) {
|
|
58
|
+
const header = [
|
|
59
|
+
"| Sample | Han | SentMean | CV (Burst) | Flow>=4c | Short<=10 | De/100 | MATTR-50 | Anchor% | Dash/1k | Note |",
|
|
60
|
+
"| :--- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | :--- |",
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
const lines = rows.map((r) => {
|
|
64
|
+
const flowPct = `${(r.flowingSentRatio * 100).toFixed(1)}%`;
|
|
65
|
+
const shortPct = `${(r.ultraShortSentRatio * 100).toFixed(1)}%`;
|
|
66
|
+
const anchorPct = `${(r.topicAnchorRatio * 100).toFixed(1)}%`;
|
|
67
|
+
return `| ${r.label} | ${r.totalHan} | ${r.sentLenMean} | **${r.sentLenCV}** | ${flowPct} | ${shortPct} | ${r.dePer100Han} | **${r.mattr50}** | ${anchorPct} | ${r.emDashPer1kHan} | ${r.note} |`;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return [...header, ...lines].join("\n");
|
|
71
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { loadLinguisticsConfig } from "./config-loader.mjs";
|
|
2
|
+
import {
|
|
3
|
+
compileBoundaryPacket,
|
|
4
|
+
computeBoundaryEchoRatio as computeBoundaryEchoRatioCore,
|
|
5
|
+
verifyChapterBoundaries as verifyChapterBoundariesCore,
|
|
6
|
+
checkDeceasedCharacterAppearances as checkDeceasedCharacterAppearancesCore,
|
|
7
|
+
} from "./core/boundary-compiler.mjs";
|
|
8
|
+
|
|
9
|
+
export { compileBoundaryPacket };
|
|
10
|
+
|
|
11
|
+
// 检查已阵亡或退场角色是否在非回忆段落中再次活跃出场
|
|
12
|
+
export function checkDeceasedCharacterAppearances(
|
|
13
|
+
chapterText,
|
|
14
|
+
ledger,
|
|
15
|
+
chapterNumber,
|
|
16
|
+
customLingConfig = null
|
|
17
|
+
) {
|
|
18
|
+
return checkDeceasedCharacterAppearancesCore(
|
|
19
|
+
chapterText,
|
|
20
|
+
ledger,
|
|
21
|
+
chapterNumber,
|
|
22
|
+
customLingConfig || loadLinguisticsConfig()
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 计算本章开篇 500 字与上一章结尾 500 字的 6-gram 重合率(防前情重演)
|
|
27
|
+
export function computeBoundaryEchoRatio(
|
|
28
|
+
chapterText,
|
|
29
|
+
previousChapterText = "",
|
|
30
|
+
customLingConfig = null
|
|
31
|
+
) {
|
|
32
|
+
return computeBoundaryEchoRatioCore(
|
|
33
|
+
chapterText,
|
|
34
|
+
previousChapterText,
|
|
35
|
+
customLingConfig || loadLinguisticsConfig()
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 对已完成章节执行硬边界、防剧透围栏与必达事实锚点的确定性代码校验
|
|
40
|
+
export function verifyChapterBoundaries(
|
|
41
|
+
chapterText,
|
|
42
|
+
ledger,
|
|
43
|
+
chapterNumber,
|
|
44
|
+
previousChapterText = "",
|
|
45
|
+
customLingConfig = null
|
|
46
|
+
) {
|
|
47
|
+
return verifyChapterBoundariesCore(
|
|
48
|
+
chapterText,
|
|
49
|
+
ledger,
|
|
50
|
+
chapterNumber,
|
|
51
|
+
previousChapterText,
|
|
52
|
+
customLingConfig || loadLinguisticsConfig()
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Node 端内存多章整书体检入口:自动加载本地配置并委托给零文件系统核心模块
|
|
2
|
+
import {
|
|
3
|
+
loadGenresConfig,
|
|
4
|
+
loadLinguisticsConfig,
|
|
5
|
+
loadPresetsConfig,
|
|
6
|
+
loadSeverityConfig,
|
|
7
|
+
loadTraditionalConfig,
|
|
8
|
+
} from "./config-loader.mjs";
|
|
9
|
+
import {
|
|
10
|
+
diagnoseChapterEntries as diagnoseChapterEntriesCore,
|
|
11
|
+
parseChapterMetaFromEntry,
|
|
12
|
+
inferGenreFromEntries,
|
|
13
|
+
} from "./core/browser-doctor.mjs";
|
|
14
|
+
|
|
15
|
+
export { parseChapterMetaFromEntry, inferGenreFromEntries };
|
|
16
|
+
|
|
17
|
+
// 对内存中的章节数组执行整书排序体检、高频规则排行与自动台账骨架生成
|
|
18
|
+
export function diagnoseChapterEntries(entries, options = {}) {
|
|
19
|
+
return diagnoseChapterEntriesCore(entries, {
|
|
20
|
+
...options,
|
|
21
|
+
linguisticsConfig: options.linguisticsConfig || loadLinguisticsConfig(),
|
|
22
|
+
genresConfig: options.genresConfig || loadGenresConfig(options.genresPath),
|
|
23
|
+
presetsConfig: options.presetsConfig || loadPresetsConfig(options.presetsPath),
|
|
24
|
+
severityConfig: options.severityConfig || loadSeverityConfig(options.severityPath),
|
|
25
|
+
traditionalConfig:
|
|
26
|
+
options.traditionalConfig !== undefined
|
|
27
|
+
? options.traditionalConfig
|
|
28
|
+
: loadTraditionalConfig(),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { profileText } from "./profiler.mjs";
|
|
4
|
+
import { loadLinguisticsConfig } from "./config-loader.mjs";
|
|
5
|
+
|
|
6
|
+
// 参与参考区间统计的指标(与篇幅关系较小、可在章节之间比较的比率类指标)
|
|
7
|
+
const REFERENCE_METRICS = [
|
|
8
|
+
"sentLenMean",
|
|
9
|
+
"sentLenCV",
|
|
10
|
+
"flowingSentRatio",
|
|
11
|
+
"ultraShortSentRatio",
|
|
12
|
+
"dePer100Han",
|
|
13
|
+
"longModPerClause",
|
|
14
|
+
"mattr50",
|
|
15
|
+
"hapaxRatio",
|
|
16
|
+
"topicAnchorRatio",
|
|
17
|
+
"sentsPerParaMean",
|
|
18
|
+
"paraLenMean",
|
|
19
|
+
"emDashPer1kHan",
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
// 样本数和单样本篇幅达到这两个数,参考区间才标为可靠
|
|
23
|
+
const MIN_RELIABLE_SAMPLES = 20;
|
|
24
|
+
const MIN_RELIABLE_HAN = 2000;
|
|
25
|
+
|
|
26
|
+
// 线性插值求分位数
|
|
27
|
+
function quantile(sorted, q) {
|
|
28
|
+
if (sorted.length === 0) return null;
|
|
29
|
+
const pos = (sorted.length - 1) * q;
|
|
30
|
+
const lo = Math.floor(pos);
|
|
31
|
+
const hi = Math.ceil(pos);
|
|
32
|
+
const v = sorted[lo] + (sorted[hi] - sorted[lo]) * (pos - lo);
|
|
33
|
+
return Math.round(v * 1000) / 1000;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 递归收集目录或文件列表下的全部 .md / .txt 文本(递归时跳过隐藏目录、node_modules 与下划线开头的备份子目录)
|
|
37
|
+
export function collectTextFiles(inputs) {
|
|
38
|
+
const files = [];
|
|
39
|
+
const walkDir = (dirPath) => {
|
|
40
|
+
for (const entry of fs.readdirSync(dirPath, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true }))) {
|
|
41
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
42
|
+
if (entry.isDirectory() && entry.name.startsWith("_")) continue;
|
|
43
|
+
const full = path.join(dirPath, entry.name);
|
|
44
|
+
if (entry.isDirectory()) {
|
|
45
|
+
walkDir(full);
|
|
46
|
+
} else if (entry.isFile() && /\.(md|txt)$/u.test(entry.name)) {
|
|
47
|
+
files.push(full);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
for (const input of inputs) {
|
|
52
|
+
const resolved = path.resolve(input);
|
|
53
|
+
if (!fs.existsSync(resolved)) continue;
|
|
54
|
+
const stat = fs.statSync(resolved);
|
|
55
|
+
if (stat.isDirectory()) {
|
|
56
|
+
walkDir(resolved);
|
|
57
|
+
} else {
|
|
58
|
+
files.push(resolved);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return files;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 从一批人类文本计算各指标的 p10 / 中位数 / p90,只输出统计结果,不输出原文
|
|
65
|
+
export function calibrateReference(texts, options = {}) {
|
|
66
|
+
const lingConfig = options.linguisticsConfig || loadLinguisticsConfig();
|
|
67
|
+
const profiles = texts.map((t) => profileText(t, lingConfig).metrics);
|
|
68
|
+
const hanCounts = profiles.map((p) => p.totalHan).sort((a, b) => a - b);
|
|
69
|
+
const metrics = {};
|
|
70
|
+
for (const key of REFERENCE_METRICS) {
|
|
71
|
+
const values = profiles
|
|
72
|
+
.map((p) => p[key])
|
|
73
|
+
.filter((v) => typeof v === "number" && Number.isFinite(v))
|
|
74
|
+
.sort((a, b) => a - b);
|
|
75
|
+
if (values.length === 0) continue;
|
|
76
|
+
metrics[key] = {
|
|
77
|
+
p10: quantile(values, 0.1),
|
|
78
|
+
median: quantile(values, 0.5),
|
|
79
|
+
p90: quantile(values, 0.9),
|
|
80
|
+
min: values[0],
|
|
81
|
+
max: values[values.length - 1],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const shortSamples = hanCounts.filter((h) => h < MIN_RELIABLE_HAN).length;
|
|
85
|
+
const reliable =
|
|
86
|
+
profiles.length >= MIN_RELIABLE_SAMPLES && shortSamples === 0;
|
|
87
|
+
return {
|
|
88
|
+
kind: "inkbone-human-reference",
|
|
89
|
+
label: options.label || "",
|
|
90
|
+
sampleCount: profiles.length,
|
|
91
|
+
medianSampleHan: quantile(hanCounts, 0.5),
|
|
92
|
+
shortSampleCount: shortSamples,
|
|
93
|
+
reliable,
|
|
94
|
+
reliabilityRule: {
|
|
95
|
+
minSamples: MIN_RELIABLE_SAMPLES,
|
|
96
|
+
minHanPerSample: MIN_RELIABLE_HAN,
|
|
97
|
+
},
|
|
98
|
+
metrics,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 统计纯汉字 n-gram 计数(按标点切成小句,避免跨句拼接)
|
|
103
|
+
function countNgrams(text, n, counts) {
|
|
104
|
+
const clauses = text.split(/[^\p{Script=Han}]+/u);
|
|
105
|
+
let total = 0;
|
|
106
|
+
for (const clause of clauses) {
|
|
107
|
+
const chars = Array.from(clause);
|
|
108
|
+
for (let i = 0; i + n <= chars.length; i += 1) {
|
|
109
|
+
const g = chars.slice(i, i + n).join("");
|
|
110
|
+
counts.set(g, (counts.get(g) || 0) + 1);
|
|
111
|
+
total += 1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return total;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 对比 AI 稿与人类文本,找出在 AI 稿里出现率明显偏高的搭配,作为套话词表候选
|
|
118
|
+
export function mineOverusedPhrases(aiTexts, humanTexts, options = {}) {
|
|
119
|
+
const sizes = options.sizes || [3, 4];
|
|
120
|
+
const minAiCount = options.minAiCount ?? 3;
|
|
121
|
+
const minRatio = options.minRatio ?? 5;
|
|
122
|
+
const top = options.top ?? 80;
|
|
123
|
+
const exclude = new Set(options.exclude || []);
|
|
124
|
+
// 故事词表:设定、大纲、人物卡里出现过的 n-gram 视为本书专名,不当套话
|
|
125
|
+
const vocabTexts = options.vocabTexts || [];
|
|
126
|
+
const results = [];
|
|
127
|
+
for (const n of sizes) {
|
|
128
|
+
const aiCounts = new Map();
|
|
129
|
+
const humanCounts = new Map();
|
|
130
|
+
const aiDocFreq = new Map();
|
|
131
|
+
let aiTotal = 0;
|
|
132
|
+
let humanTotal = 0;
|
|
133
|
+
for (const t of aiTexts) {
|
|
134
|
+
const local = new Map();
|
|
135
|
+
aiTotal += countNgrams(t, n, local);
|
|
136
|
+
for (const [g, c] of local) {
|
|
137
|
+
aiCounts.set(g, (aiCounts.get(g) || 0) + c);
|
|
138
|
+
aiDocFreq.set(g, (aiDocFreq.get(g) || 0) + 1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (const t of humanTexts) humanTotal += countNgrams(t, n, humanCounts);
|
|
142
|
+
const vocabCounts = new Map();
|
|
143
|
+
for (const t of vocabTexts) countNgrams(t, n, vocabCounts);
|
|
144
|
+
if (aiTotal === 0 || humanTotal === 0) continue;
|
|
145
|
+
for (const [g, aiCount] of aiCounts) {
|
|
146
|
+
if (aiCount < minAiCount || exclude.has(g) || vocabCounts.has(g)) continue;
|
|
147
|
+
// 只保留在两篇及以上 AI 稿里都出现的搭配,排除单章专名
|
|
148
|
+
if (aiTexts.length > 1 && (aiDocFreq.get(g) || 0) < 2) continue;
|
|
149
|
+
const humanCount = humanCounts.get(g) || 0;
|
|
150
|
+
// 加 0.5 平滑后比较每万字出现率
|
|
151
|
+
const aiRate = ((aiCount + 0.5) / aiTotal) * 1e4;
|
|
152
|
+
const humanRate = ((humanCount + 0.5) / humanTotal) * 1e4;
|
|
153
|
+
const ratio = aiRate / humanRate;
|
|
154
|
+
if (ratio < minRatio) continue;
|
|
155
|
+
results.push({
|
|
156
|
+
phrase: g,
|
|
157
|
+
n,
|
|
158
|
+
aiCount,
|
|
159
|
+
aiDocs: aiDocFreq.get(g) || 0,
|
|
160
|
+
humanCount,
|
|
161
|
+
aiPer10k: Math.round(aiRate * 100) / 100,
|
|
162
|
+
humanPer10k: Math.round(humanRate * 100) / 100,
|
|
163
|
+
ratio: Math.round(ratio * 10) / 10,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
results.sort((a, b) => b.ratio * Math.log(b.aiCount + 1) - a.ratio * Math.log(a.aiCount + 1));
|
|
168
|
+
return {
|
|
169
|
+
kind: "inkbone-phrase-candidates",
|
|
170
|
+
note: "candidates only; review each phrase in context before adding it to a blocklist",
|
|
171
|
+
aiDocs: aiTexts.length,
|
|
172
|
+
humanDocs: humanTexts.length,
|
|
173
|
+
candidates: results.slice(0, top),
|
|
174
|
+
};
|
|
175
|
+
}
|