slopless 0.2.15 → 0.2.17
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/dist/presets/everything.js +0 -1
- package/dist/registries/metrics.js +0 -2
- package/dist/rules/words/llm-vocabulary.js +46 -12
- package/dist/rules/words/simplicity.js +45 -21
- package/dist/shared/text/document.js +0 -10
- package/package.json +1 -2
- package/dist/rules/metrics/avg-sentence-length.js +0 -34
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import avgSentenceLength from "../rules/metrics/avg-sentence-length.js";
|
|
2
1
|
import colemanLiau from "../rules/metrics/coleman-liau.js";
|
|
3
2
|
import fleschKincaid from "../rules/metrics/flesch-kincaid.js";
|
|
4
3
|
import gunningFog from "../rules/metrics/gunning-fog.js";
|
|
5
4
|
import paragraphLength from "../rules/metrics/paragraph-length.js";
|
|
6
5
|
import wordRepetition from "../rules/metrics/word-repetition.js";
|
|
7
6
|
export const metricRules = {
|
|
8
|
-
"avg-sentence-length": avgSentenceLength,
|
|
9
7
|
"coleman-liau": colemanLiau,
|
|
10
8
|
"flesch-kincaid": fleschKincaid,
|
|
11
9
|
"gunning-fog": gunningFog,
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { defineTextlintRule } from "../../adapters/textlint/rule.js";
|
|
2
|
+
import { paragraphUnits } from "../../adapters/textlint/units.js";
|
|
3
|
+
import { wordTokens } from "../../shared/text/tokens.js";
|
|
4
|
+
import { isVocabularyContextAllowed } from "./private/vocabulary-context.js";
|
|
5
|
+
const RULE_ID = "words:llm-vocabulary";
|
|
6
|
+
const GROUP = "llm vocabulary";
|
|
7
|
+
const MAX_PARAGRAPH_TOKENS = 90;
|
|
8
|
+
const MAX_WINDOW_TOKENS = 65;
|
|
9
|
+
const MIN_HITS = 3;
|
|
10
|
+
const WINDOW_SENTENCES = 4;
|
|
11
|
+
// Single stock words like "comprehensive" or "moreover" are ordinary in human
|
|
12
|
+
// prose; flag only when stock LLM diction clusters. (Words that are slop on
|
|
13
|
+
// their own, e.g. "delve", are still caught per-instance by prohibited-words.)
|
|
3
14
|
const LLM_VOCABULARY = new Set([
|
|
4
15
|
"delve",
|
|
5
16
|
"vibrant",
|
|
@@ -14,16 +25,39 @@ const LLM_VOCABULARY = new Set([
|
|
|
14
25
|
"moreover",
|
|
15
26
|
"tapestry"
|
|
16
27
|
]);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
function vocabularyDetections(unit) {
|
|
29
|
+
return wordTokens(unit.text)
|
|
30
|
+
.filter((token) => LLM_VOCABULARY.has(token.normalized) &&
|
|
31
|
+
!isVocabularyContextAllowed(unit.text, token.normalized))
|
|
32
|
+
.map((token) => ({
|
|
33
|
+
evidence: unit.text.slice(token.start, token.end),
|
|
34
|
+
group: GROUP,
|
|
35
|
+
label: token.normalized,
|
|
36
|
+
range: { end: token.end, start: token.start },
|
|
37
|
+
ruleId: RULE_ID,
|
|
38
|
+
unitId: unit.id
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
const rule = defineTextlintRule({
|
|
42
|
+
detector: {
|
|
43
|
+
detect: ({ units }) => units.flatMap((unit) => vocabularyDetections(unit)),
|
|
44
|
+
family: "words",
|
|
45
|
+
id: RULE_ID
|
|
46
|
+
},
|
|
47
|
+
formatMessage: (report) => {
|
|
48
|
+
const labels = [...new Set(report.detections.map((hit) => hit.label))];
|
|
49
|
+
return `LLM vocabulary density: ${report.detections.length} stock words in a short span (${labels.join(", ")}). Replace the stock diction with concrete words.`;
|
|
50
|
+
},
|
|
51
|
+
reportPolicy: {
|
|
52
|
+
groups: [GROUP],
|
|
53
|
+
kind: "density",
|
|
54
|
+
maxParagraphTokens: MAX_PARAGRAPH_TOKENS,
|
|
55
|
+
maxWindowTokens: MAX_WINDOW_TOKENS,
|
|
56
|
+
paragraphMinimumHits: MIN_HITS,
|
|
57
|
+
windowMinimumHits: MIN_HITS,
|
|
58
|
+
windowSentences: WINDOW_SENTENCES
|
|
59
|
+
},
|
|
60
|
+
units: (document) => paragraphUnits(document)
|
|
27
61
|
});
|
|
28
62
|
export default rule;
|
|
29
63
|
//# sourceMappingURL=llm-vocabulary.js.map
|
|
@@ -1,26 +1,50 @@
|
|
|
1
1
|
import simplicityPairs from "./data/simplicity-pairs.json" with { type: "json" };
|
|
2
|
+
import { defineTextlintRule } from "../../adapters/textlint/rule.js";
|
|
3
|
+
import { paragraphUnits } from "../../adapters/textlint/units.js";
|
|
2
4
|
import { wordTokens } from "../../shared/text/tokens.js";
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
const RULE_ID = "words:simplicity";
|
|
6
|
+
const GROUP = "complex word";
|
|
7
|
+
const MAX_PARAGRAPH_TOKENS = 90;
|
|
8
|
+
const MAX_WINDOW_TOKENS = 65;
|
|
9
|
+
const MIN_HITS = 2;
|
|
10
|
+
const WINDOW_SENTENCES = 4;
|
|
11
|
+
// A single complex word is not slop; one "numerous" or "utilize" is ordinary.
|
|
12
|
+
// Flag only when complex diction clusters, which is what makes prose feel dense.
|
|
13
|
+
const COMPLEX_WORDS = new Set(simplicityPairs
|
|
14
|
+
.map((pair) => pair[0])
|
|
15
|
+
.filter((word) => word !== undefined));
|
|
16
|
+
function complexDetections(unit) {
|
|
17
|
+
return wordTokens(unit.text)
|
|
18
|
+
.filter((token) => COMPLEX_WORDS.has(token.normalized))
|
|
19
|
+
.map((token) => ({
|
|
20
|
+
evidence: unit.text.slice(token.start, token.end),
|
|
21
|
+
group: GROUP,
|
|
22
|
+
label: token.normalized,
|
|
23
|
+
range: { end: token.end, start: token.start },
|
|
24
|
+
ruleId: RULE_ID,
|
|
25
|
+
unitId: unit.id
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
const rule = defineTextlintRule({
|
|
29
|
+
detector: {
|
|
30
|
+
detect: ({ units }) => units.flatMap((unit) => complexDetections(unit)),
|
|
31
|
+
family: "words",
|
|
32
|
+
id: RULE_ID
|
|
33
|
+
},
|
|
34
|
+
formatMessage: (report) => {
|
|
35
|
+
const labels = [...new Set(report.detections.map((hit) => hit.label))];
|
|
36
|
+
return `Complex word density: ${report.detections.length} complex words in a short span (${labels.join(", ")}). Prefer simpler wording.`;
|
|
37
|
+
},
|
|
38
|
+
reportPolicy: {
|
|
39
|
+
groups: [GROUP],
|
|
40
|
+
kind: "density",
|
|
41
|
+
maxParagraphTokens: MAX_PARAGRAPH_TOKENS,
|
|
42
|
+
maxWindowTokens: MAX_WINDOW_TOKENS,
|
|
43
|
+
paragraphMinimumHits: MIN_HITS,
|
|
44
|
+
windowMinimumHits: MIN_HITS,
|
|
45
|
+
windowSentences: WINDOW_SENTENCES
|
|
46
|
+
},
|
|
47
|
+
units: (document) => paragraphUnits(document)
|
|
24
48
|
});
|
|
25
49
|
export default rule;
|
|
26
50
|
//# sourceMappingURL=simplicity.js.map
|
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
import { allParagraphs } from "./sections.js";
|
|
2
|
-
import { splitSentences } from "./sentences.js";
|
|
3
|
-
import { wordTokens } from "./tokens.js";
|
|
4
2
|
export function documentText(document) {
|
|
5
3
|
return allParagraphs(document)
|
|
6
4
|
.map((paragraph) => paragraph.text.trim())
|
|
7
5
|
.filter((text) => text.length > 0)
|
|
8
6
|
.join("\n\n");
|
|
9
7
|
}
|
|
10
|
-
export function documentMetrics(document) {
|
|
11
|
-
const text = documentText(document);
|
|
12
|
-
return {
|
|
13
|
-
sentenceCount: splitSentences(text).length,
|
|
14
|
-
text,
|
|
15
|
-
wordCount: wordTokens(text).length
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
8
|
//# sourceMappingURL=document.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slopless",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.17",
|
|
4
4
|
"description": "Deterministic textlint rules and CLI for catching prose slop in English Markdown.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"textlint",
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"./rules/academic-slop/academic-boilerplate": "./dist/rules/academic-slop/academic-boilerplate.js",
|
|
53
53
|
"./rules/academic-slop/academic-formula-frames": "./dist/rules/academic-slop/academic-formula-frames.js",
|
|
54
54
|
"./rules/academic-slop/tortured-phrases": "./dist/rules/academic-slop/tortured-phrases.js",
|
|
55
|
-
"./rules/metrics/avg-sentence-length": "./dist/rules/metrics/avg-sentence-length.js",
|
|
56
55
|
"./rules/metrics/coleman-liau": "./dist/rules/metrics/coleman-liau.js",
|
|
57
56
|
"./rules/metrics/flesch-kincaid": "./dist/rules/metrics/flesch-kincaid.js",
|
|
58
57
|
"./rules/metrics/gunning-fog": "./dist/rules/metrics/gunning-fog.js",
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { documentMetrics } from "../../shared/text/document.js";
|
|
2
|
-
import { oneToOneRule } from "../private/textlint-rule-builders.js";
|
|
3
|
-
const MAX_WORDS = 24;
|
|
4
|
-
function isDocumentNode(node) {
|
|
5
|
-
return node.type === "Document" && "children" in node;
|
|
6
|
-
}
|
|
7
|
-
const rule = oneToOneRule({
|
|
8
|
-
detect: (unit) => {
|
|
9
|
-
if (!isDocumentNode(unit.node)) {
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
const metrics = documentMetrics(unit.node);
|
|
13
|
-
if (metrics.sentenceCount === 0) {
|
|
14
|
-
return [];
|
|
15
|
-
}
|
|
16
|
-
const average = Math.floor(metrics.wordCount / metrics.sentenceCount);
|
|
17
|
-
if (average <= MAX_WORDS) {
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
20
|
-
return [
|
|
21
|
-
{
|
|
22
|
-
evidence: String(average),
|
|
23
|
-
label: "average sentence length",
|
|
24
|
-
range: { start: 0, end: 0 }
|
|
25
|
-
}
|
|
26
|
-
];
|
|
27
|
-
},
|
|
28
|
-
family: "metrics",
|
|
29
|
-
formatMessage: (report) => `Average sentence length is ${report.evidence} words. Keep it at ${MAX_WORDS} or fewer.`,
|
|
30
|
-
ruleId: "metrics:avg-sentence-length",
|
|
31
|
-
unitKind: "document"
|
|
32
|
-
});
|
|
33
|
-
export default rule;
|
|
34
|
-
//# sourceMappingURL=avg-sentence-length.js.map
|