dravoice 0.1.2 → 0.1.4
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 -21
- package/README.md +126 -37
- package/bin/dravoice.js +11 -10
- package/package.json +47 -45
- package/src/index.js +967 -197
- package/src/v2/analyzers/discourse.js +69 -63
- package/src/v2/analyzers/evidence.js +82 -82
- package/src/v2/analyzers/lexical.js +114 -114
- package/src/v2/analyzers/register.js +70 -34
- package/src/v2/analyzers/rhetorical-shape.js +65 -59
- package/src/v2/analyzers/rhythm.js +39 -47
- package/src/v2/analyzers/structure.js +41 -24
- package/src/v2/benchmark.js +657 -568
- package/src/v2/brief.js +154 -146
- package/src/v2/config.js +78 -0
- package/src/v2/doctor.js +308 -0
- package/src/v2/document-model.js +422 -260
- package/src/v2/inspect.js +67 -67
- package/src/v2/io-utils.js +51 -0
- package/src/v2/profile.js +342 -203
- package/src/v2/prompt.js +65 -64
- package/src/v2/review.js +303 -173
- package/src/v2/revise-plan.js +540 -433
- package/src/v2/stylometry.js +346 -332
- package/src/v2/text-utils.js +123 -123
|
@@ -1,59 +1,65 @@
|
|
|
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
|
|
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
|
-
if (
|
|
53
|
-
return "
|
|
54
|
-
}
|
|
55
|
-
if (
|
|
56
|
-
return "
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
import { evidenceTypes } from "./evidence.js";
|
|
2
|
+
import { transitionLabel } from "./discourse.js";
|
|
3
|
+
import { splitSentences, 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 paragraphMovePatterns = documents.flatMap((document) =>
|
|
10
|
+
document.paragraphs
|
|
11
|
+
.map((paragraph) => splitSentences(paragraph.text).map((sentence) => moveFor(sentence)).join(" -> "))
|
|
12
|
+
.filter(Boolean)
|
|
13
|
+
);
|
|
14
|
+
const bigrams = [];
|
|
15
|
+
const trigrams = [];
|
|
16
|
+
const openingMovePatterns = [];
|
|
17
|
+
for (const moves of documentMoves) {
|
|
18
|
+
if (moves.length > 0) {
|
|
19
|
+
openingMovePatterns.push(moves.slice(0, 3).join(" -> "));
|
|
20
|
+
}
|
|
21
|
+
for (let index = 0; index < moves.length - 1; index += 1) {
|
|
22
|
+
bigrams.push(`${moves[index]} -> ${moves[index + 1]}`);
|
|
23
|
+
}
|
|
24
|
+
for (let index = 0; index < moves.length - 2; index += 1) {
|
|
25
|
+
trigrams.push(`${moves[index]} -> ${moves[index + 1]} -> ${moves[index + 2]}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
family: "rhetoricalShape",
|
|
31
|
+
confidence: sentenceMoves.length >= 12 ? "medium" : "low",
|
|
32
|
+
features: {
|
|
33
|
+
moveRates: topItems(sentenceMoves, 12),
|
|
34
|
+
openingMoves: openingMoves.slice(0, 9),
|
|
35
|
+
openingMovePatterns: topItems(openingMovePatterns, 8),
|
|
36
|
+
paragraphMovePatterns: topItems(paragraphMovePatterns, 12),
|
|
37
|
+
moveBigrams: topItems(bigrams, 12),
|
|
38
|
+
moveTrigrams: topItems(trigrams, 12),
|
|
39
|
+
commonSequences: topItems(bigrams, 12),
|
|
40
|
+
},
|
|
41
|
+
examples: openingMoves.slice(0, 5),
|
|
42
|
+
warnings: sentenceMoves.length < 12 ? ["Rhetorical-shape confidence is limited because the corpus has fewer than 12 sentences."] : [],
|
|
43
|
+
revisionHandles: ["Compare the draft's opening and move sequence against observed source patterns."],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function moveFor(text) {
|
|
48
|
+
if (evidenceTypes(text).length > 0) {
|
|
49
|
+
return "scene-or-evidence";
|
|
50
|
+
}
|
|
51
|
+
const transition = transitionLabel(text);
|
|
52
|
+
if (transition === "contrast") {
|
|
53
|
+
return "turn";
|
|
54
|
+
}
|
|
55
|
+
if (transition === "causal" || transition === "conclusion") {
|
|
56
|
+
return "implication";
|
|
57
|
+
}
|
|
58
|
+
if (/\b(should|must|rule|lesson|start|fix|avoid|keep)\b/i.test(text)) {
|
|
59
|
+
return "advice";
|
|
60
|
+
}
|
|
61
|
+
if (/\b(always|never|everyone|everything|important|best|better|worse|should|must|all|none|every)\b/i.test(text)) {
|
|
62
|
+
return "abstract-claim";
|
|
63
|
+
}
|
|
64
|
+
return "statement";
|
|
65
|
+
}
|
|
@@ -1,47 +1,39 @@
|
|
|
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) =>
|
|
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
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (sentenceCount >= 30) {
|
|
41
|
-
return "high";
|
|
42
|
-
}
|
|
43
|
-
if (sentenceCount >= 8) {
|
|
44
|
-
return "medium";
|
|
45
|
-
}
|
|
46
|
-
return "low";
|
|
47
|
-
}
|
|
1
|
+
import { distribution, rate, splitSentences } 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) => Math.max(1, splitSentences(paragraph.text).length))),
|
|
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 confidenceFor(sentenceCount) {
|
|
32
|
+
if (sentenceCount >= 30) {
|
|
33
|
+
return "high";
|
|
34
|
+
}
|
|
35
|
+
if (sentenceCount >= 8) {
|
|
36
|
+
return "medium";
|
|
37
|
+
}
|
|
38
|
+
return "low";
|
|
39
|
+
}
|
|
@@ -1,24 +1,41 @@
|
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
import { distribution, rate, topItems } 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
|
+
const sectionOrderPatterns = documents
|
|
10
|
+
.map((document) => document.headings.map((heading) => `h${heading.depth}`).join(" -> "))
|
|
11
|
+
.filter(Boolean);
|
|
12
|
+
const listPlacementPatterns = documents.flatMap((document) =>
|
|
13
|
+
document.blocks
|
|
14
|
+
.filter((block) => block.type === "list")
|
|
15
|
+
.map((block) => `h${block.headingDepth || 0}:list`)
|
|
16
|
+
);
|
|
17
|
+
const quotePlacementPatterns = documents.flatMap((document) =>
|
|
18
|
+
document.blocks
|
|
19
|
+
.filter((block) => block.type === "quote")
|
|
20
|
+
.map((block) => `h${block.headingDepth || 0}:quote`)
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
family: "structure",
|
|
25
|
+
confidence: documents.length >= 3 ? "medium" : "low",
|
|
26
|
+
features: {
|
|
27
|
+
sectionWords: distribution(sectionLengths),
|
|
28
|
+
headingCount: distribution(documents.map((document) => document.headings.length)),
|
|
29
|
+
maxHeadingDepth: distribution(documents.map((document) => Math.max(0, ...document.headings.map((heading) => heading.depth)))),
|
|
30
|
+
sectionOrderPatterns: topItems(sectionOrderPatterns, 12),
|
|
31
|
+
listPlacementPatterns: topItems(listPlacementPatterns, 12),
|
|
32
|
+
quotePlacementPatterns: topItems(quotePlacementPatterns, 12),
|
|
33
|
+
openingMoves,
|
|
34
|
+
listDocumentRate: rate(documents.filter((document) => document.blocks.some((block) => block.type === "list")).length, documents.length, 2),
|
|
35
|
+
quoteDocumentRate: rate(documents.filter((document) => document.blocks.some((block) => block.type === "quote")).length, documents.length, 2),
|
|
36
|
+
},
|
|
37
|
+
examples: openingMoves.slice(0, 5),
|
|
38
|
+
warnings: documents.length < 3 ? ["Structure confidence is limited because the corpus has fewer than 3 documents."] : [],
|
|
39
|
+
revisionHandles: ["Compare headings, list/quote use, section size, and opening structure."],
|
|
40
|
+
};
|
|
41
|
+
}
|