dravoice 0.1.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.md +35 -0
- package/bin/dravoice.js +10 -0
- package/package.json +45 -0
- package/src/index.js +204 -0
- package/src/v2/analyzers/discourse.js +52 -0
- package/src/v2/analyzers/evidence.js +43 -0
- package/src/v2/analyzers/lexical.js +58 -0
- package/src/v2/analyzers/register.js +34 -0
- package/src/v2/analyzers/rhetorical-shape.js +48 -0
- package/src/v2/analyzers/rhythm.js +47 -0
- package/src/v2/analyzers/structure.js +24 -0
- package/src/v2/benchmark.js +702 -0
- package/src/v2/brief.js +146 -0
- package/src/v2/document-model.js +260 -0
- package/src/v2/inspect.js +67 -0
- package/src/v2/profile.js +153 -0
- package/src/v2/prompt.js +64 -0
- package/src/v2/review.js +219 -0
- package/src/v2/text-utils.js +123 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dravoice contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Dravoice
|
|
2
|
+
|
|
3
|
+
Dravoice is a local-first CLI for compiling Markdown, MDX, and plain-text
|
|
4
|
+
writing corpora into reusable voice guidance and deterministic draft review
|
|
5
|
+
notes.
|
|
6
|
+
|
|
7
|
+
It is not an AI-authorship detector, grammar checker, prose linter, or
|
|
8
|
+
third-party author imitation tool. It helps a writer inspect and reuse their
|
|
9
|
+
own measurable rhythm, register, evidence habits, discourse shape, and
|
|
10
|
+
structure.
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx --package dravoice drav learn --examples ./articles --out ./dravoice-voice
|
|
16
|
+
npx --package dravoice drav inspect --voice ./dravoice-voice
|
|
17
|
+
npx --package dravoice drav prompt --voice ./dravoice-voice --format agents --out AGENTS.md
|
|
18
|
+
npx --package dravoice drav brief --voice ./dravoice-voice --topic "A new article topic" --evidence notes.md --out brief.md
|
|
19
|
+
npx --package dravoice drav review draft.md --voice ./dravoice-voice
|
|
20
|
+
npx --package dravoice drav review draft.md --voice ./dravoice-voice --mode strict --format json
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`learn` writes a schemaVersion 2 `profile.json` plus local metadata. `inspect`
|
|
24
|
+
makes the learned feature families visible, `prompt` turns high-confidence
|
|
25
|
+
observations into drafting guidance, `brief` creates an evidence-first article
|
|
26
|
+
plan, and `review` reports family-level drift.
|
|
27
|
+
|
|
28
|
+
## Fresh Install Smoke Test
|
|
29
|
+
|
|
30
|
+
From a packed tarball:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm pack
|
|
34
|
+
npm exec --package ./dravoice-0.1.0.tgz -- drav --help
|
|
35
|
+
```
|
package/bin/dravoice.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dravoice",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Compile article voice profiles into reusable LLM writing context, evidence-first briefs, and deterministic draft review notes.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"drav": "bin/dravoice.js"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"bin/",
|
|
14
|
+
"src/",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"lint": "node ../../scripts/check-js-syntax.js packages/js-cli",
|
|
20
|
+
"test": "node --test test/v2.test.js"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"voice",
|
|
27
|
+
"writing",
|
|
28
|
+
"cli",
|
|
29
|
+
"llm",
|
|
30
|
+
"markdown"
|
|
31
|
+
],
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/hilmimuktitama/dravoice.git",
|
|
35
|
+
"directory": "packages/js-cli"
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/hilmimuktitama/dravoice/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/hilmimuktitama/dravoice#readme",
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT"
|
|
45
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
prepareVoiceBenchmark,
|
|
5
|
+
renderBenchmarkReport,
|
|
6
|
+
scoreVoiceBenchmark,
|
|
7
|
+
} from "./v2/benchmark.js";
|
|
8
|
+
import { renderVoiceBriefV2, voiceArticleBriefV2 } from "./v2/brief.js";
|
|
9
|
+
import { renderInspectV2 } from "./v2/inspect.js";
|
|
10
|
+
import { learnVoicePackV2, loadVoicePackV2 } from "./v2/profile.js";
|
|
11
|
+
import { voicePromptPackV2 } from "./v2/prompt.js";
|
|
12
|
+
import { renderVoiceReviewV2, reviewVoiceDraftV2 } from "./v2/review.js";
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
learnVoicePackV2 as learnVoicePack,
|
|
16
|
+
loadVoicePackV2 as loadVoicePack,
|
|
17
|
+
reviewVoiceDraftV2 as reviewVoiceDraft,
|
|
18
|
+
voicePromptPackV2 as voicePromptPack,
|
|
19
|
+
};
|
|
20
|
+
export { renderInspectV2, renderVoiceReviewV2 as renderVoiceReview };
|
|
21
|
+
export { renderVoiceBriefV2 as renderVoiceBrief, voiceArticleBriefV2 as voiceArticleBrief };
|
|
22
|
+
export { prepareVoiceBenchmark, renderBenchmarkReport, scoreVoiceBenchmark };
|
|
23
|
+
|
|
24
|
+
export async function runCli(args, io) {
|
|
25
|
+
try {
|
|
26
|
+
const [command, ...rest] = args;
|
|
27
|
+
if (!command || command === "--help" || command === "-h") {
|
|
28
|
+
io.stdout.write(helpText());
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (command === "learn") {
|
|
33
|
+
const { options } = parseArgs(rest, ["examples", "out"]);
|
|
34
|
+
const profile = learnVoicePackV2({
|
|
35
|
+
examplesDir: resolvePath(io.cwd, requiredOption(options, "examples")),
|
|
36
|
+
outDir: resolvePath(io.cwd, requiredOption(options, "out")),
|
|
37
|
+
});
|
|
38
|
+
io.stdout.write(`Generated V2 voice pack from ${profile.source.documentCount} document(s). Corpus confidence: ${profile.source.confidence.band}.\n`);
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (command === "review") {
|
|
43
|
+
const { options, positional } = parseArgs(rest, ["voice", "mode", "format"]);
|
|
44
|
+
const file = positional[0];
|
|
45
|
+
if (!file) {
|
|
46
|
+
throw new Error("Missing draft file path for review");
|
|
47
|
+
}
|
|
48
|
+
const result = reviewVoiceDraftV2({
|
|
49
|
+
file: resolvePath(io.cwd, file),
|
|
50
|
+
voice: loadVoicePackV2(resolvePath(io.cwd, options.voice ?? ".")),
|
|
51
|
+
cwd: io.cwd,
|
|
52
|
+
mode: options.mode ?? "balanced",
|
|
53
|
+
});
|
|
54
|
+
if (options.format === "json") {
|
|
55
|
+
io.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
56
|
+
} else {
|
|
57
|
+
io.stdout.write(renderVoiceReviewV2(result));
|
|
58
|
+
}
|
|
59
|
+
return result.exitCode;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (command === "prompt") {
|
|
63
|
+
const { options } = parseArgs(rest, ["voice", "format", "out"]);
|
|
64
|
+
const rendered = voicePromptPackV2({
|
|
65
|
+
voice: loadVoicePackV2(resolvePath(io.cwd, options.voice ?? ".")),
|
|
66
|
+
format: options.format ?? "agents",
|
|
67
|
+
outPath: options.out ? resolvePath(io.cwd, options.out) : undefined,
|
|
68
|
+
});
|
|
69
|
+
if (!options.out) {
|
|
70
|
+
io.stdout.write(rendered);
|
|
71
|
+
}
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (command === "brief") {
|
|
76
|
+
const { options } = parseArgs(rest, ["voice", "topic", "evidence", "format", "out"]);
|
|
77
|
+
const result = voiceArticleBriefV2({
|
|
78
|
+
voice: loadVoicePackV2(resolvePath(io.cwd, options.voice ?? ".")),
|
|
79
|
+
topic: requiredOption(options, "topic"),
|
|
80
|
+
evidence: options.evidence ? resolvePath(io.cwd, options.evidence) : undefined,
|
|
81
|
+
cwd: io.cwd,
|
|
82
|
+
});
|
|
83
|
+
const rendered = options.format === "json" ? `${JSON.stringify(result, null, 2)}\n` : renderVoiceBriefV2(result);
|
|
84
|
+
if (options.out) {
|
|
85
|
+
const outPath = resolvePath(io.cwd, options.out);
|
|
86
|
+
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
87
|
+
fs.writeFileSync(outPath, rendered, "utf8");
|
|
88
|
+
} else {
|
|
89
|
+
io.stdout.write(rendered);
|
|
90
|
+
}
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (command === "inspect") {
|
|
95
|
+
const { options } = parseArgs(rest, ["voice"]);
|
|
96
|
+
const profile = loadVoicePackV2(resolvePath(io.cwd, options.voice ?? "."));
|
|
97
|
+
io.stdout.write(renderInspectV2(profile));
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (command === "benchmark") {
|
|
102
|
+
return runBenchmarkCli(rest, io);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
io.stderr.write(`Unknown command: ${command}\n`);
|
|
106
|
+
return 2;
|
|
107
|
+
} catch (error) {
|
|
108
|
+
io.stderr.write(`${error.message}\n`);
|
|
109
|
+
return 2;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function runBenchmarkCli(args, io) {
|
|
114
|
+
const [benchmarkCommand, ...rest] = args;
|
|
115
|
+
if (benchmarkCommand === "prepare") {
|
|
116
|
+
const { options } = parseArgs(rest, ["examples", "topic", "out", "seed"]);
|
|
117
|
+
const benchmark = prepareVoiceBenchmark({
|
|
118
|
+
examplesDir: resolvePath(io.cwd, requiredOption(options, "examples")),
|
|
119
|
+
topic: requiredOption(options, "topic"),
|
|
120
|
+
outDir: resolvePath(io.cwd, requiredOption(options, "out")),
|
|
121
|
+
seed: options.seed ?? "1",
|
|
122
|
+
});
|
|
123
|
+
io.stdout.write(`Prepared benchmark at ${resolvePath(io.cwd, requiredOption(options, "out"))} with ${benchmark.corpus.fileCount} source article(s).\n`);
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (benchmarkCommand === "score") {
|
|
128
|
+
const { options } = parseArgs(rest, ["run", "judge", "format"]);
|
|
129
|
+
const result = scoreVoiceBenchmark({
|
|
130
|
+
runDir: resolvePath(io.cwd, requiredOption(options, "run")),
|
|
131
|
+
judgePath: options.judge ? resolvePath(io.cwd, options.judge) : undefined,
|
|
132
|
+
});
|
|
133
|
+
if (options.format === "json") {
|
|
134
|
+
io.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
135
|
+
} else {
|
|
136
|
+
io.stdout.write(renderBenchmarkReport(result));
|
|
137
|
+
}
|
|
138
|
+
return result.exitCode;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
throw new Error(`Unknown benchmark command: ${benchmarkCommand ?? ""}`.trim());
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function parseArgs(args, allowedOptionNames) {
|
|
145
|
+
const allowed = new Set(allowedOptionNames);
|
|
146
|
+
const options = {};
|
|
147
|
+
const positional = [];
|
|
148
|
+
let parseOptions = true;
|
|
149
|
+
|
|
150
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
151
|
+
const arg = args[index];
|
|
152
|
+
|
|
153
|
+
if (parseOptions && arg === "--") {
|
|
154
|
+
parseOptions = false;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!parseOptions || !arg.startsWith("--")) {
|
|
159
|
+
positional.push(arg);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const equalsIndex = arg.indexOf("=");
|
|
164
|
+
const key = equalsIndex === -1 ? arg.slice(2) : arg.slice(2, equalsIndex);
|
|
165
|
+
if (!allowed.has(key)) {
|
|
166
|
+
throw new Error(`Unknown option --${key}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const inlineValue = equalsIndex === -1 ? null : arg.slice(equalsIndex + 1);
|
|
170
|
+
const value = inlineValue ?? args[index + 1];
|
|
171
|
+
if (value === undefined || value === "" || (inlineValue === null && value.startsWith("--"))) {
|
|
172
|
+
throw new Error(`Missing value for --${key}`);
|
|
173
|
+
}
|
|
174
|
+
options[key] = value;
|
|
175
|
+
if (inlineValue === null) {
|
|
176
|
+
index += 1;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return { options, positional };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function requiredOption(options, name) {
|
|
183
|
+
if (!options[name]) {
|
|
184
|
+
throw new Error(`Missing required option --${name}`);
|
|
185
|
+
}
|
|
186
|
+
return options[name];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function resolvePath(cwd, value) {
|
|
190
|
+
return path.isAbsolute(value) ? value : path.join(cwd, value);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function helpText() {
|
|
194
|
+
return [
|
|
195
|
+
"drav learn --examples ./articles --out ./dravoice-voice",
|
|
196
|
+
"drav inspect --voice ./dravoice-voice",
|
|
197
|
+
"drav prompt --voice ./dravoice-voice --format agents --out AGENTS.md",
|
|
198
|
+
"drav brief --voice ./dravoice-voice --topic \"New topic\" --evidence notes.md --out brief.md",
|
|
199
|
+
"drav review draft.md --voice ./dravoice-voice --mode balanced --format text",
|
|
200
|
+
"drav benchmark prepare --examples ./articles --topic \"New topic\" --out ./bench-run --seed 42",
|
|
201
|
+
"drav benchmark score --run ./bench-run --judge ./bench-run/judge/judgment.json",
|
|
202
|
+
"",
|
|
203
|
+
].join("\n");
|
|
204
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { rate, topItems } from "../text-utils.js";
|
|
2
|
+
|
|
3
|
+
const TRANSITIONS = {
|
|
4
|
+
additive: /\b(also|and|another|again|plus)\b/i,
|
|
5
|
+
contrast: /\b(but|however|although|yet|instead|still)\b/i,
|
|
6
|
+
causal: /\b(because|so|therefore|since|as a result)\b/i,
|
|
7
|
+
temporal: /\b(then|before|after|while|when|first|second|later)\b/i,
|
|
8
|
+
example: /\b(for example|such as|including|like)\b/i,
|
|
9
|
+
conclusion: /\b(so|therefore|finally|in the end|the lesson)\b/i,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function analyzeDiscourse(documents) {
|
|
13
|
+
const sentences = documents.flatMap((document) => document.sentences);
|
|
14
|
+
const labels = sentences.map((sentence) => transitionLabel(sentence.text));
|
|
15
|
+
const transitionRates = {};
|
|
16
|
+
for (const key of Object.keys(TRANSITIONS)) {
|
|
17
|
+
transitionRates[key] = rate(labels.filter((label) => label === key).length, sentences.length, 2);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
family: "discourse",
|
|
22
|
+
confidence: sentences.length >= 12 ? "medium" : "low",
|
|
23
|
+
features: {
|
|
24
|
+
transitionRates,
|
|
25
|
+
transitionSequence: labels.filter(Boolean).slice(0, 12),
|
|
26
|
+
sentenceCallbacks: callbackRate(sentences),
|
|
27
|
+
},
|
|
28
|
+
examples: topItems(labels.filter(Boolean), 5).map((item) => item.value),
|
|
29
|
+
warnings: sentences.length < 12 ? ["Discourse confidence is limited because the corpus has fewer than 12 sentences."] : [],
|
|
30
|
+
revisionHandles: ["Compare how sentences turn, contrast, explain, and return to earlier ideas."],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function transitionLabel(text) {
|
|
35
|
+
for (const [label, pattern] of Object.entries(TRANSITIONS)) {
|
|
36
|
+
if (pattern.test(text)) {
|
|
37
|
+
return label;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return "plain";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function callbackRate(sentences) {
|
|
44
|
+
let callbacks = 0;
|
|
45
|
+
for (let index = 1; index < sentences.length; index += 1) {
|
|
46
|
+
const previous = new Set(sentences[index - 1].tokens.filter((word) => word.length > 3));
|
|
47
|
+
if (sentences[index].tokens.some((word) => previous.has(word))) {
|
|
48
|
+
callbacks += 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return rate(callbacks, Math.max(1, sentences.length - 1), 2);
|
|
52
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { rate, topItems } from "../text-utils.js";
|
|
2
|
+
|
|
3
|
+
const EVIDENCE_PATTERNS = {
|
|
4
|
+
date: /\b\d{1,2}:\d{2}\s?(?:am|pm)?\b|\b20\d{2}-\d{2}-\d{2}\b|\b(?:monday|tuesday|wednesday|thursday|friday|saturday|sunday)\b/i,
|
|
5
|
+
number: /\b\d+(?:\.\d+)?\b/,
|
|
6
|
+
quote: /"[^"]+"|'[^']+'|^>/,
|
|
7
|
+
url: /https?:\/\/\S+/i,
|
|
8
|
+
citation: /\[[^\]]+\]\([^)]+\)|\([A-Z][A-Za-z]+,\s*\d{4}\)/,
|
|
9
|
+
sourceAttribution: /\b(according to|reported|observed|noted|recorded|quoted|interviewed|surveyed|field notes said|data shows|study found|the memo|the log|the report)\b/i,
|
|
10
|
+
sensory: /\b(cold|warm|hot|cool|quiet|loud|bright|dark|red|blue|green|rough|smooth|sharp|soft|smelled|smell|scent|tasted|heard|sound|noise|flashed|visible|physical|rain|metal|smoke)\b/i,
|
|
11
|
+
specificExample: /\b(for example|for instance|such as|including|included|includes|sample|case in point|specifically|in one case)\b/i,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const ABSTRACT_CLAIM_RE = /\b(always|never|everyone|everything|nothing|best|better|worse|important|obvious|clearly|should|must|need to|have to|all|none|every)\b/i;
|
|
15
|
+
|
|
16
|
+
export function analyzeEvidence(documents) {
|
|
17
|
+
const sentences = documents.flatMap((document) => document.sentences);
|
|
18
|
+
const evidenceSentences = sentences.filter((sentence) => evidenceTypes(sentence.text).length > 0);
|
|
19
|
+
const claimSentences = sentences.filter((sentence) => ABSTRACT_CLAIM_RE.test(sentence.text));
|
|
20
|
+
const typeValues = evidenceSentences.flatMap((sentence) => evidenceTypes(sentence.text));
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
family: "evidence",
|
|
24
|
+
confidence: sentences.length >= 12 ? "medium" : "low",
|
|
25
|
+
features: {
|
|
26
|
+
sentenceCount: sentences.length,
|
|
27
|
+
evidenceSentenceCount: evidenceSentences.length,
|
|
28
|
+
evidenceSentenceRate: rate(evidenceSentences.length, sentences.length, 2),
|
|
29
|
+
claimSentenceRate: rate(claimSentences.length, sentences.length, 2),
|
|
30
|
+
unsupportedClaimRate: rate(Math.max(0, claimSentences.length - evidenceSentences.length), sentences.length, 2),
|
|
31
|
+
evidenceTypes: topItems(typeValues, 8),
|
|
32
|
+
},
|
|
33
|
+
examples: topItems(typeValues, 4).map((item) => `${item.value}: ${item.count}`),
|
|
34
|
+
warnings: sentences.length < 12 ? ["Evidence confidence is limited because the corpus has fewer than 12 sentences."] : [],
|
|
35
|
+
revisionHandles: ["Compare how broad claims are supported by concrete scenes, numbers, quotes, citations, or examples."],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function evidenceTypes(text) {
|
|
40
|
+
return Object.entries(EVIDENCE_PATTERNS)
|
|
41
|
+
.filter(([, pattern]) => pattern.test(text))
|
|
42
|
+
.map(([type]) => type);
|
|
43
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FUNCTION_WORDS,
|
|
3
|
+
characterNgrams,
|
|
4
|
+
contentWords,
|
|
5
|
+
distribution,
|
|
6
|
+
rate,
|
|
7
|
+
tokenizeWords,
|
|
8
|
+
topItems,
|
|
9
|
+
} from "../text-utils.js";
|
|
10
|
+
|
|
11
|
+
export function analyzeLexical(documents) {
|
|
12
|
+
const text = documents.map((document) => document.text).join("\n\n");
|
|
13
|
+
const words = tokenizeWords(text);
|
|
14
|
+
const content = contentWords(text);
|
|
15
|
+
const sentences = documents.flatMap((document) => document.sentences);
|
|
16
|
+
const functionWordSet = new Set(FUNCTION_WORDS);
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
family: "lexical",
|
|
20
|
+
confidence: confidenceFor(words.length),
|
|
21
|
+
features: {
|
|
22
|
+
wordCount: words.length,
|
|
23
|
+
contentWordCount: content.length,
|
|
24
|
+
vocabularyRichness: {
|
|
25
|
+
uniqueContentWords: new Set(content).size,
|
|
26
|
+
contentTypeTokenRatio: rate(new Set(content).size, content.length, 3),
|
|
27
|
+
},
|
|
28
|
+
wordLength: distribution(words.map((word) => word.length)),
|
|
29
|
+
functionWords: topItems(words.filter((word) => functionWordSet.has(word)), 24),
|
|
30
|
+
characterTrigrams: topItems(characterNgrams(text, 3), 24),
|
|
31
|
+
repeatedMotifs: topItems(content, 16).filter((item) => item.count > 1),
|
|
32
|
+
punctuation: {
|
|
33
|
+
commaRate: rate(count(text, /,/g), sentences.length, 2),
|
|
34
|
+
semicolonRate: rate(count(text, /;/g), sentences.length, 2),
|
|
35
|
+
colonRate: rate(count(text, /:/g), sentences.length, 2),
|
|
36
|
+
questionRate: rate(count(text, /\?/g), sentences.length, 2),
|
|
37
|
+
dashRate: rate(count(text, /--|-/g), sentences.length, 2),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
examples: topItems(content, 5).map((item) => item.value),
|
|
41
|
+
warnings: words.length < 200 ? ["Lexical confidence is limited because the corpus has fewer than 200 words."] : [],
|
|
42
|
+
revisionHandles: ["Compare function words, vocabulary richness, motifs, and punctuation habits."],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function confidenceFor(wordCount) {
|
|
47
|
+
if (wordCount >= 2000) {
|
|
48
|
+
return "high";
|
|
49
|
+
}
|
|
50
|
+
if (wordCount >= 120) {
|
|
51
|
+
return "medium";
|
|
52
|
+
}
|
|
53
|
+
return "low";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function count(text, pattern) {
|
|
57
|
+
return Array.from(text.matchAll(pattern)).length;
|
|
58
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { contentWords, rate, topItems } from "../text-utils.js";
|
|
2
|
+
|
|
3
|
+
const REGISTER_MARKERS = {
|
|
4
|
+
narrative: ["scene", "moment", "watched", "waited", "noticed", "remembered", "described", "story"],
|
|
5
|
+
explanatory: ["because", "so", "therefore", "means", "shows", "explains", "reason", "pattern"],
|
|
6
|
+
argumentative: ["should", "must", "better", "important", "claim", "therefore", "argue", "evidence"],
|
|
7
|
+
instructional: ["start", "fix", "use", "avoid", "keep", "write", "revise", "follow"],
|
|
8
|
+
reflective: ["lesson", "pause", "changed", "remember", "noticed", "felt", "learned", "realized"],
|
|
9
|
+
technical: ["file", "test", "system", "code", "api", "build"],
|
|
10
|
+
personal: ["i", "my", "we", "our"],
|
|
11
|
+
formal: ["requires", "outcomes", "process", "alignment", "therefore"],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function analyzeRegister(documents) {
|
|
15
|
+
const text = documents.map((document) => document.text.toLowerCase()).join("\n\n");
|
|
16
|
+
const words = new Set(contentWords(text));
|
|
17
|
+
const scores = Object.entries(REGISTER_MARKERS).map(([value, markers]) => ({
|
|
18
|
+
value,
|
|
19
|
+
score: rate(markers.filter((marker) => text.includes(marker) || words.has(marker)).length, markers.length, 2),
|
|
20
|
+
})).sort((left, right) => right.score - left.score || left.value.localeCompare(right.value));
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
family: "register",
|
|
24
|
+
confidence: documents.length >= 3 ? "medium" : "low",
|
|
25
|
+
features: {
|
|
26
|
+
primary: scores[0] ?? { value: "unknown", score: 0 },
|
|
27
|
+
scores,
|
|
28
|
+
topContentWords: topItems(contentWords(text), 12),
|
|
29
|
+
},
|
|
30
|
+
examples: scores.slice(0, 3).map((item) => `${item.value}: ${item.score}`),
|
|
31
|
+
warnings: documents.length < 3 ? ["Register confidence is limited because the corpus has fewer than 3 documents."] : [],
|
|
32
|
+
revisionHandles: ["Check whether the draft uses the same broad register and genre mix as the corpus."],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { evidenceTypes } from "./evidence.js";
|
|
2
|
+
import { transitionLabel } from "./discourse.js";
|
|
3
|
+
import { topItems } from "../text-utils.js";
|
|
4
|
+
|
|
5
|
+
export function analyzeRhetoricalShape(documents) {
|
|
6
|
+
const documentMoves = documents.map((document) => document.sentences.map((sentence) => moveFor(sentence.text)));
|
|
7
|
+
const sentenceMoves = documentMoves.flat();
|
|
8
|
+
const openingMoves = documents.flatMap((document) => document.sentences.slice(0, 3).map((sentence) => moveFor(sentence.text)));
|
|
9
|
+
const sequences = [];
|
|
10
|
+
for (const moves of documentMoves) {
|
|
11
|
+
for (let index = 0; index < moves.length - 1; index += 1) {
|
|
12
|
+
sequences.push(`${moves[index]} -> ${moves[index + 1]}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
family: "rhetoricalShape",
|
|
18
|
+
confidence: sentenceMoves.length >= 12 ? "medium" : "low",
|
|
19
|
+
features: {
|
|
20
|
+
moveRates: topItems(sentenceMoves, 12),
|
|
21
|
+
openingMoves: openingMoves.slice(0, 9),
|
|
22
|
+
commonSequences: topItems(sequences, 12),
|
|
23
|
+
},
|
|
24
|
+
examples: openingMoves.slice(0, 5),
|
|
25
|
+
warnings: sentenceMoves.length < 12 ? ["Rhetorical-shape confidence is limited because the corpus has fewer than 12 sentences."] : [],
|
|
26
|
+
revisionHandles: ["Compare the draft's opening and move sequence against observed source patterns."],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function moveFor(text) {
|
|
31
|
+
if (evidenceTypes(text).length > 0) {
|
|
32
|
+
return "scene-or-evidence";
|
|
33
|
+
}
|
|
34
|
+
const transition = transitionLabel(text);
|
|
35
|
+
if (transition === "contrast") {
|
|
36
|
+
return "turn";
|
|
37
|
+
}
|
|
38
|
+
if (transition === "causal" || transition === "conclusion") {
|
|
39
|
+
return "implication";
|
|
40
|
+
}
|
|
41
|
+
if (/\b(should|must|rule|lesson|start|fix|avoid|keep)\b/i.test(text)) {
|
|
42
|
+
return "advice";
|
|
43
|
+
}
|
|
44
|
+
if (/\b(always|never|everyone|everything|important|best|better|worse|should|must|all|none|every)\b/i.test(text)) {
|
|
45
|
+
return "abstract-claim";
|
|
46
|
+
}
|
|
47
|
+
return "statement";
|
|
48
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { distribution, rate } from "../text-utils.js";
|
|
2
|
+
|
|
3
|
+
export function analyzeRhythm(documents) {
|
|
4
|
+
const sentences = documents.flatMap((document) => document.sentences);
|
|
5
|
+
const paragraphs = documents.flatMap((document) => document.paragraphs);
|
|
6
|
+
const blocks = documents.flatMap((document) => document.blocks);
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
family: "rhythm",
|
|
10
|
+
confidence: confidenceFor(sentences.length),
|
|
11
|
+
features: {
|
|
12
|
+
documentCount: documents.length,
|
|
13
|
+
sentenceCount: sentences.length,
|
|
14
|
+
paragraphCount: paragraphs.length,
|
|
15
|
+
sentenceWords: distribution(sentences.map((sentence) => sentence.tokens.length)),
|
|
16
|
+
paragraphWords: distribution(paragraphs.map((paragraph) => paragraph.text.split(/\s+/).filter(Boolean).length)),
|
|
17
|
+
paragraphSentences: distribution(paragraphs.map((paragraph) => countParagraphSentences(sentences, paragraph))),
|
|
18
|
+
headingDensity: rate(documents.reduce((sum, document) => sum + document.headings.length, 0), sentences.length, 2),
|
|
19
|
+
listDensity: rate(blocks.filter((block) => block.type === "list").length, paragraphs.length, 2),
|
|
20
|
+
quoteDensity: rate(blocks.filter((block) => block.type === "quote").length, paragraphs.length, 2),
|
|
21
|
+
},
|
|
22
|
+
examples: [
|
|
23
|
+
`sentenceWords.median: ${distribution(sentences.map((sentence) => sentence.tokens.length)).median}`,
|
|
24
|
+
`paragraphWords.median: ${distribution(paragraphs.map((paragraph) => paragraph.text.split(/\s+/).filter(Boolean).length)).median}`,
|
|
25
|
+
],
|
|
26
|
+
warnings: sentences.length < 12 ? ["Rhythm confidence is limited because the corpus has fewer than 12 usable sentences."] : [],
|
|
27
|
+
revisionHandles: ["Compare sentence and paragraph pacing against the learned range."],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function countParagraphSentences(sentences, paragraph) {
|
|
32
|
+
return Math.max(1, sentences.filter((sentence) =>
|
|
33
|
+
sentence.line >= paragraph.line &&
|
|
34
|
+
sentence.line < paragraph.line + 8 &&
|
|
35
|
+
sentence.headingId === paragraph.headingId
|
|
36
|
+
).length);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function confidenceFor(sentenceCount) {
|
|
40
|
+
if (sentenceCount >= 30) {
|
|
41
|
+
return "high";
|
|
42
|
+
}
|
|
43
|
+
if (sentenceCount >= 8) {
|
|
44
|
+
return "medium";
|
|
45
|
+
}
|
|
46
|
+
return "low";
|
|
47
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { distribution, rate } from "../text-utils.js";
|
|
2
|
+
import { moveFor } from "./rhetorical-shape.js";
|
|
3
|
+
|
|
4
|
+
export function analyzeStructure(documents) {
|
|
5
|
+
const sectionLengths = documents.flatMap((document) =>
|
|
6
|
+
document.sections.map((section) => section.blocks.reduce((sum, block) => sum + block.lines.join(" ").split(/\s+/).filter(Boolean).length, 0))
|
|
7
|
+
);
|
|
8
|
+
const openingMoves = documents.flatMap((document) => document.sentences.slice(0, 2).map((sentence) => moveFor(sentence.text)));
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
family: "structure",
|
|
12
|
+
confidence: documents.length >= 3 ? "medium" : "low",
|
|
13
|
+
features: {
|
|
14
|
+
sectionWords: distribution(sectionLengths),
|
|
15
|
+
headingCount: distribution(documents.map((document) => document.headings.length)),
|
|
16
|
+
openingMoves,
|
|
17
|
+
listDocumentRate: rate(documents.filter((document) => document.blocks.some((block) => block.type === "list")).length, documents.length, 2),
|
|
18
|
+
quoteDocumentRate: rate(documents.filter((document) => document.blocks.some((block) => block.type === "quote")).length, documents.length, 2),
|
|
19
|
+
},
|
|
20
|
+
examples: openingMoves.slice(0, 5),
|
|
21
|
+
warnings: documents.length < 3 ? ["Structure confidence is limited because the corpus has fewer than 3 documents."] : [],
|
|
22
|
+
revisionHandles: ["Compare headings, list/quote use, section size, and opening structure."],
|
|
23
|
+
};
|
|
24
|
+
}
|