marlarky 1.0.1 → 1.0.2
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/README.md +503 -495
- package/dist/cli.js +139 -139
- package/examples/basic-usage.ts +48 -48
- package/examples/corporate-lexicon.ts +71 -71
- package/examples/lexicons/corporate-min.json +200 -200
- package/examples/with-tracing.ts +85 -85
- package/package.json +70 -70
package/dist/cli.js
CHANGED
|
@@ -23,150 +23,150 @@ function getVersion() {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
// ---------- Help text ----------
|
|
26
|
-
const MAIN_HELP = `
|
|
27
|
-
marlarky - Generate syntactically plausible English text
|
|
28
|
-
|
|
29
|
-
Usage:
|
|
30
|
-
marlarky <command> [options]
|
|
31
|
-
|
|
32
|
-
Commands:
|
|
33
|
-
sentence Generate one or more sentences
|
|
34
|
-
paragraph Generate one or more paragraphs
|
|
35
|
-
text Generate a text block (multiple paragraphs)
|
|
36
|
-
validate Validate a lexicon JSON file
|
|
37
|
-
list List available transforms or sentence types
|
|
38
|
-
|
|
39
|
-
Global Options:
|
|
40
|
-
-s, --seed <n> RNG seed for deterministic output
|
|
41
|
-
-l, --lexicon <path> Path to a lexicon JSON file
|
|
42
|
-
-a, --archetype <name> Archetype to activate from the lexicon
|
|
43
|
-
-x, --transform <id> Apply an output transform (repeatable, comma-separated)
|
|
44
|
-
-t, --trace Output JSON trace to stderr
|
|
45
|
-
-j, --json Output full result as JSON to stdout
|
|
46
|
-
-n, --count <n> Number of units to generate (default: 1)
|
|
47
|
-
-h, --help Show help
|
|
48
|
-
-v, --version Show version
|
|
49
|
-
|
|
50
|
-
Examples:
|
|
51
|
-
marlarky sentence
|
|
52
|
-
marlarky sentence --seed 42 --type question
|
|
53
|
-
marlarky paragraph --sentences 5 --lexicon ./corp.json
|
|
54
|
-
marlarky text --paragraphs 3 --archetype corporate
|
|
55
|
-
marlarky sentence --transform pigLatin
|
|
56
|
-
marlarky sentence --transform leet,uwu --json
|
|
57
|
-
marlarky validate ./my-lexicon.json
|
|
58
|
-
marlarky list transforms
|
|
26
|
+
const MAIN_HELP = `
|
|
27
|
+
marlarky - Generate syntactically plausible English text
|
|
28
|
+
|
|
29
|
+
Usage:
|
|
30
|
+
marlarky <command> [options]
|
|
31
|
+
|
|
32
|
+
Commands:
|
|
33
|
+
sentence Generate one or more sentences
|
|
34
|
+
paragraph Generate one or more paragraphs
|
|
35
|
+
text Generate a text block (multiple paragraphs)
|
|
36
|
+
validate Validate a lexicon JSON file
|
|
37
|
+
list List available transforms or sentence types
|
|
38
|
+
|
|
39
|
+
Global Options:
|
|
40
|
+
-s, --seed <n> RNG seed for deterministic output
|
|
41
|
+
-l, --lexicon <path> Path to a lexicon JSON file
|
|
42
|
+
-a, --archetype <name> Archetype to activate from the lexicon
|
|
43
|
+
-x, --transform <id> Apply an output transform (repeatable, comma-separated)
|
|
44
|
+
-t, --trace Output JSON trace to stderr
|
|
45
|
+
-j, --json Output full result as JSON to stdout
|
|
46
|
+
-n, --count <n> Number of units to generate (default: 1)
|
|
47
|
+
-h, --help Show help
|
|
48
|
+
-v, --version Show version
|
|
49
|
+
|
|
50
|
+
Examples:
|
|
51
|
+
marlarky sentence
|
|
52
|
+
marlarky sentence --seed 42 --type question
|
|
53
|
+
marlarky paragraph --sentences 5 --lexicon ./corp.json
|
|
54
|
+
marlarky text --paragraphs 3 --archetype corporate
|
|
55
|
+
marlarky sentence --transform pigLatin
|
|
56
|
+
marlarky sentence --transform leet,uwu --json
|
|
57
|
+
marlarky validate ./my-lexicon.json
|
|
58
|
+
marlarky list transforms
|
|
59
59
|
`.trimStart();
|
|
60
|
-
const SENTENCE_HELP = `
|
|
61
|
-
marlarky sentence - Generate one or more sentences
|
|
62
|
-
|
|
63
|
-
Usage:
|
|
64
|
-
marlarky sentence [options]
|
|
65
|
-
|
|
66
|
-
Options:
|
|
67
|
-
--type <type> Sentence type: simpleDeclarative, compound,
|
|
68
|
-
introAdverbial, subordinate, interjection, question
|
|
69
|
-
--hints <tags> Comma-separated hint tags (e.g. domain:tech,register:formal)
|
|
70
|
-
--min-words <n> Minimum word count per sentence
|
|
71
|
-
--max-words <n> Maximum word count per sentence
|
|
72
|
-
-x, --transform <id> Apply an output transform (repeatable, comma-separated)
|
|
73
|
-
-s, --seed <n> RNG seed for deterministic output
|
|
74
|
-
-l, --lexicon <path> Path to a lexicon JSON file
|
|
75
|
-
-a, --archetype <name> Archetype to activate from the lexicon
|
|
76
|
-
-t, --trace Output JSON trace to stderr
|
|
77
|
-
-j, --json Output full result as JSON to stdout
|
|
78
|
-
-n, --count <n> Number of sentences to generate (default: 1)
|
|
79
|
-
-h, --help Show this help
|
|
80
|
-
|
|
81
|
-
Examples:
|
|
82
|
-
marlarky sentence
|
|
83
|
-
marlarky sentence --seed 42 --type question
|
|
84
|
-
marlarky sentence --count 5 --lexicon ./corp.json --archetype corporate
|
|
85
|
-
marlarky sentence --transform pigLatin --seed 42
|
|
86
|
-
marlarky sentence --min-words 10 --max-words 20
|
|
60
|
+
const SENTENCE_HELP = `
|
|
61
|
+
marlarky sentence - Generate one or more sentences
|
|
62
|
+
|
|
63
|
+
Usage:
|
|
64
|
+
marlarky sentence [options]
|
|
65
|
+
|
|
66
|
+
Options:
|
|
67
|
+
--type <type> Sentence type: simpleDeclarative, compound,
|
|
68
|
+
introAdverbial, subordinate, interjection, question
|
|
69
|
+
--hints <tags> Comma-separated hint tags (e.g. domain:tech,register:formal)
|
|
70
|
+
--min-words <n> Minimum word count per sentence
|
|
71
|
+
--max-words <n> Maximum word count per sentence
|
|
72
|
+
-x, --transform <id> Apply an output transform (repeatable, comma-separated)
|
|
73
|
+
-s, --seed <n> RNG seed for deterministic output
|
|
74
|
+
-l, --lexicon <path> Path to a lexicon JSON file
|
|
75
|
+
-a, --archetype <name> Archetype to activate from the lexicon
|
|
76
|
+
-t, --trace Output JSON trace to stderr
|
|
77
|
+
-j, --json Output full result as JSON to stdout
|
|
78
|
+
-n, --count <n> Number of sentences to generate (default: 1)
|
|
79
|
+
-h, --help Show this help
|
|
80
|
+
|
|
81
|
+
Examples:
|
|
82
|
+
marlarky sentence
|
|
83
|
+
marlarky sentence --seed 42 --type question
|
|
84
|
+
marlarky sentence --count 5 --lexicon ./corp.json --archetype corporate
|
|
85
|
+
marlarky sentence --transform pigLatin --seed 42
|
|
86
|
+
marlarky sentence --min-words 10 --max-words 20
|
|
87
87
|
`.trimStart();
|
|
88
|
-
const PARAGRAPH_HELP = `
|
|
89
|
-
marlarky paragraph - Generate one or more paragraphs
|
|
90
|
-
|
|
91
|
-
Usage:
|
|
92
|
-
marlarky paragraph [options]
|
|
93
|
-
|
|
94
|
-
Options:
|
|
95
|
-
--sentences <n> Exact number of sentences per paragraph
|
|
96
|
-
--min-sentences <n> Minimum sentences per paragraph
|
|
97
|
-
--max-sentences <n> Maximum sentences per paragraph
|
|
98
|
-
--hints <tags> Comma-separated hint tags
|
|
99
|
-
-x, --transform <id> Apply an output transform (repeatable, comma-separated)
|
|
100
|
-
-s, --seed <n> RNG seed for deterministic output
|
|
101
|
-
-l, --lexicon <path> Path to a lexicon JSON file
|
|
102
|
-
-a, --archetype <name> Archetype to activate from the lexicon
|
|
103
|
-
-t, --trace Output JSON trace to stderr
|
|
104
|
-
-j, --json Output full result as JSON to stdout
|
|
105
|
-
-n, --count <n> Number of paragraphs to generate (default: 1)
|
|
106
|
-
-h, --help Show this help
|
|
107
|
-
|
|
108
|
-
Examples:
|
|
109
|
-
marlarky paragraph --sentences 5 --seed 42
|
|
110
|
-
marlarky paragraph --count 3 --lexicon ./corp.json
|
|
111
|
-
marlarky paragraph --transform pirate
|
|
88
|
+
const PARAGRAPH_HELP = `
|
|
89
|
+
marlarky paragraph - Generate one or more paragraphs
|
|
90
|
+
|
|
91
|
+
Usage:
|
|
92
|
+
marlarky paragraph [options]
|
|
93
|
+
|
|
94
|
+
Options:
|
|
95
|
+
--sentences <n> Exact number of sentences per paragraph
|
|
96
|
+
--min-sentences <n> Minimum sentences per paragraph
|
|
97
|
+
--max-sentences <n> Maximum sentences per paragraph
|
|
98
|
+
--hints <tags> Comma-separated hint tags
|
|
99
|
+
-x, --transform <id> Apply an output transform (repeatable, comma-separated)
|
|
100
|
+
-s, --seed <n> RNG seed for deterministic output
|
|
101
|
+
-l, --lexicon <path> Path to a lexicon JSON file
|
|
102
|
+
-a, --archetype <name> Archetype to activate from the lexicon
|
|
103
|
+
-t, --trace Output JSON trace to stderr
|
|
104
|
+
-j, --json Output full result as JSON to stdout
|
|
105
|
+
-n, --count <n> Number of paragraphs to generate (default: 1)
|
|
106
|
+
-h, --help Show this help
|
|
107
|
+
|
|
108
|
+
Examples:
|
|
109
|
+
marlarky paragraph --sentences 5 --seed 42
|
|
110
|
+
marlarky paragraph --count 3 --lexicon ./corp.json
|
|
111
|
+
marlarky paragraph --transform pirate
|
|
112
112
|
`.trimStart();
|
|
113
|
-
const TEXT_HELP = `
|
|
114
|
-
marlarky text - Generate a text block (multiple paragraphs)
|
|
115
|
-
|
|
116
|
-
Usage:
|
|
117
|
-
marlarky text [options]
|
|
118
|
-
|
|
119
|
-
Options:
|
|
120
|
-
--paragraphs <n> Exact number of paragraphs
|
|
121
|
-
--min-paragraphs <n> Minimum paragraphs
|
|
122
|
-
--max-paragraphs <n> Maximum paragraphs
|
|
123
|
-
--hints <tags> Comma-separated hint tags
|
|
124
|
-
-x, --transform <id> Apply an output transform (repeatable, comma-separated)
|
|
125
|
-
-s, --seed <n> RNG seed for deterministic output
|
|
126
|
-
-l, --lexicon <path> Path to a lexicon JSON file
|
|
127
|
-
-a, --archetype <name> Archetype to activate from the lexicon
|
|
128
|
-
-t, --trace Output JSON trace to stderr
|
|
129
|
-
-j, --json Output full result as JSON to stdout
|
|
130
|
-
-n, --count <n> Number of text blocks to generate (default: 1)
|
|
131
|
-
-h, --help Show this help
|
|
132
|
-
|
|
133
|
-
Examples:
|
|
134
|
-
marlarky text --paragraphs 3 --seed 42
|
|
135
|
-
marlarky text --lexicon ./corp.json --archetype corporate
|
|
136
|
-
marlarky text --transform bizJargon
|
|
113
|
+
const TEXT_HELP = `
|
|
114
|
+
marlarky text - Generate a text block (multiple paragraphs)
|
|
115
|
+
|
|
116
|
+
Usage:
|
|
117
|
+
marlarky text [options]
|
|
118
|
+
|
|
119
|
+
Options:
|
|
120
|
+
--paragraphs <n> Exact number of paragraphs
|
|
121
|
+
--min-paragraphs <n> Minimum paragraphs
|
|
122
|
+
--max-paragraphs <n> Maximum paragraphs
|
|
123
|
+
--hints <tags> Comma-separated hint tags
|
|
124
|
+
-x, --transform <id> Apply an output transform (repeatable, comma-separated)
|
|
125
|
+
-s, --seed <n> RNG seed for deterministic output
|
|
126
|
+
-l, --lexicon <path> Path to a lexicon JSON file
|
|
127
|
+
-a, --archetype <name> Archetype to activate from the lexicon
|
|
128
|
+
-t, --trace Output JSON trace to stderr
|
|
129
|
+
-j, --json Output full result as JSON to stdout
|
|
130
|
+
-n, --count <n> Number of text blocks to generate (default: 1)
|
|
131
|
+
-h, --help Show this help
|
|
132
|
+
|
|
133
|
+
Examples:
|
|
134
|
+
marlarky text --paragraphs 3 --seed 42
|
|
135
|
+
marlarky text --lexicon ./corp.json --archetype corporate
|
|
136
|
+
marlarky text --transform bizJargon
|
|
137
137
|
`.trimStart();
|
|
138
|
-
const VALIDATE_HELP = `
|
|
139
|
-
marlarky validate - Validate a lexicon JSON file
|
|
140
|
-
|
|
141
|
-
Usage:
|
|
142
|
-
marlarky validate <file.json> [options]
|
|
143
|
-
|
|
144
|
-
Options:
|
|
145
|
-
--json Output validation result as JSON
|
|
146
|
-
-h, --help Show this help
|
|
147
|
-
|
|
148
|
-
Examples:
|
|
149
|
-
marlarky validate ./my-lexicon.json
|
|
150
|
-
marlarky validate ./my-lexicon.json --json
|
|
138
|
+
const VALIDATE_HELP = `
|
|
139
|
+
marlarky validate - Validate a lexicon JSON file
|
|
140
|
+
|
|
141
|
+
Usage:
|
|
142
|
+
marlarky validate <file.json> [options]
|
|
143
|
+
|
|
144
|
+
Options:
|
|
145
|
+
--json Output validation result as JSON
|
|
146
|
+
-h, --help Show this help
|
|
147
|
+
|
|
148
|
+
Examples:
|
|
149
|
+
marlarky validate ./my-lexicon.json
|
|
150
|
+
marlarky validate ./my-lexicon.json --json
|
|
151
151
|
`.trimStart();
|
|
152
|
-
const LIST_HELP = `
|
|
153
|
-
marlarky list - List available transforms or sentence types
|
|
154
|
-
|
|
155
|
-
Usage:
|
|
156
|
-
marlarky list <category>
|
|
157
|
-
|
|
158
|
-
Categories:
|
|
159
|
-
transforms List all registered output transforms
|
|
160
|
-
types List all sentence types
|
|
161
|
-
|
|
162
|
-
Options:
|
|
163
|
-
--json Output as JSON
|
|
164
|
-
-h, --help Show this help
|
|
165
|
-
|
|
166
|
-
Examples:
|
|
167
|
-
marlarky list transforms
|
|
168
|
-
marlarky list types
|
|
169
|
-
marlarky list transforms --json
|
|
152
|
+
const LIST_HELP = `
|
|
153
|
+
marlarky list - List available transforms or sentence types
|
|
154
|
+
|
|
155
|
+
Usage:
|
|
156
|
+
marlarky list <category>
|
|
157
|
+
|
|
158
|
+
Categories:
|
|
159
|
+
transforms List all registered output transforms
|
|
160
|
+
types List all sentence types
|
|
161
|
+
|
|
162
|
+
Options:
|
|
163
|
+
--json Output as JSON
|
|
164
|
+
-h, --help Show this help
|
|
165
|
+
|
|
166
|
+
Examples:
|
|
167
|
+
marlarky list transforms
|
|
168
|
+
marlarky list types
|
|
169
|
+
marlarky list transforms --json
|
|
170
170
|
`.trimStart();
|
|
171
171
|
// ---------- Constants ----------
|
|
172
172
|
const GLOBAL_OPTIONS = {
|
package/examples/basic-usage.ts
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example A: Basic Usage (No Lexicon)
|
|
3
|
-
* Demonstrates text generation using only the built-in word lists
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { TextGenerator, SimpleFakerAdapter } from '../src';
|
|
7
|
-
|
|
8
|
-
// Create a generator with just the simple faker adapter
|
|
9
|
-
const generator = new TextGenerator({
|
|
10
|
-
fakerAdapter: new SimpleFakerAdapter(),
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
// Set a seed for reproducible output
|
|
14
|
-
generator.setSeed(42);
|
|
15
|
-
|
|
16
|
-
console.log('=== Basic Text Generation (No Lexicon) ===\n');
|
|
17
|
-
|
|
18
|
-
// Generate a single sentence
|
|
19
|
-
console.log('Single sentence:');
|
|
20
|
-
console.log(generator.sentence());
|
|
21
|
-
console.log();
|
|
22
|
-
|
|
23
|
-
// Generate different sentence types
|
|
24
|
-
console.log('Different sentence types:');
|
|
25
|
-
console.log('Simple declarative:', generator.sentence({ type: 'simpleDeclarative' }));
|
|
26
|
-
console.log('Question:', generator.sentence({ type: 'question' }));
|
|
27
|
-
console.log('Compound:', generator.sentence({ type: 'compound' }));
|
|
28
|
-
console.log('With intro adverbial:', generator.sentence({ type: 'introAdverbial' }));
|
|
29
|
-
console.log();
|
|
30
|
-
|
|
31
|
-
// Generate a paragraph
|
|
32
|
-
console.log('Paragraph (5 sentences):');
|
|
33
|
-
console.log(generator.paragraph({ sentences: 5 }));
|
|
34
|
-
console.log();
|
|
35
|
-
|
|
36
|
-
// Generate multiple paragraphs
|
|
37
|
-
console.log('Text block (2 paragraphs):');
|
|
38
|
-
console.log(generator.textBlock({ paragraphs: 2 }));
|
|
39
|
-
console.log();
|
|
40
|
-
|
|
41
|
-
// Demonstrate determinism
|
|
42
|
-
console.log('=== Determinism Test ===\n');
|
|
43
|
-
generator.setSeed(12345);
|
|
44
|
-
const text1 = generator.sentence();
|
|
45
|
-
generator.setSeed(12345);
|
|
46
|
-
const text2 = generator.sentence();
|
|
47
|
-
console.log('Same seed produces same output:', text1 === text2);
|
|
48
|
-
console.log('Output:', text1);
|
|
1
|
+
/**
|
|
2
|
+
* Example A: Basic Usage (No Lexicon)
|
|
3
|
+
* Demonstrates text generation using only the built-in word lists
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { TextGenerator, SimpleFakerAdapter } from '../src';
|
|
7
|
+
|
|
8
|
+
// Create a generator with just the simple faker adapter
|
|
9
|
+
const generator = new TextGenerator({
|
|
10
|
+
fakerAdapter: new SimpleFakerAdapter(),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Set a seed for reproducible output
|
|
14
|
+
generator.setSeed(42);
|
|
15
|
+
|
|
16
|
+
console.log('=== Basic Text Generation (No Lexicon) ===\n');
|
|
17
|
+
|
|
18
|
+
// Generate a single sentence
|
|
19
|
+
console.log('Single sentence:');
|
|
20
|
+
console.log(generator.sentence());
|
|
21
|
+
console.log();
|
|
22
|
+
|
|
23
|
+
// Generate different sentence types
|
|
24
|
+
console.log('Different sentence types:');
|
|
25
|
+
console.log('Simple declarative:', generator.sentence({ type: 'simpleDeclarative' }));
|
|
26
|
+
console.log('Question:', generator.sentence({ type: 'question' }));
|
|
27
|
+
console.log('Compound:', generator.sentence({ type: 'compound' }));
|
|
28
|
+
console.log('With intro adverbial:', generator.sentence({ type: 'introAdverbial' }));
|
|
29
|
+
console.log();
|
|
30
|
+
|
|
31
|
+
// Generate a paragraph
|
|
32
|
+
console.log('Paragraph (5 sentences):');
|
|
33
|
+
console.log(generator.paragraph({ sentences: 5 }));
|
|
34
|
+
console.log();
|
|
35
|
+
|
|
36
|
+
// Generate multiple paragraphs
|
|
37
|
+
console.log('Text block (2 paragraphs):');
|
|
38
|
+
console.log(generator.textBlock({ paragraphs: 2 }));
|
|
39
|
+
console.log();
|
|
40
|
+
|
|
41
|
+
// Demonstrate determinism
|
|
42
|
+
console.log('=== Determinism Test ===\n');
|
|
43
|
+
generator.setSeed(12345);
|
|
44
|
+
const text1 = generator.sentence();
|
|
45
|
+
generator.setSeed(12345);
|
|
46
|
+
const text2 = generator.sentence();
|
|
47
|
+
console.log('Same seed produces same output:', text1 === text2);
|
|
48
|
+
console.log('Output:', text1);
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example B: Lexicon-Steered Corporate Text
|
|
3
|
-
* Demonstrates text generation using a corporate lexicon
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { readFileSync } from 'fs';
|
|
7
|
-
import { join, dirname } from 'path';
|
|
8
|
-
import { fileURLToPath } from 'url';
|
|
9
|
-
import { TextGenerator, SimpleFakerAdapter, loadLexiconFromString } from '../src';
|
|
10
|
-
|
|
11
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
|
|
13
|
-
// Load the corporate lexicon
|
|
14
|
-
const lexiconPath = join(__dirname, 'lexicons', 'corporate-min.json');
|
|
15
|
-
const lexiconJson = readFileSync(lexiconPath, 'utf-8');
|
|
16
|
-
const lexicon = loadLexiconFromString(lexiconJson);
|
|
17
|
-
|
|
18
|
-
console.log('=== Lexicon-Steered Corporate Text ===\n');
|
|
19
|
-
console.log(`Loaded lexicon: ${lexicon.id} v${lexicon.version}\n`);
|
|
20
|
-
|
|
21
|
-
// Create generator with lexicon
|
|
22
|
-
const generator = new TextGenerator({
|
|
23
|
-
fakerAdapter: new SimpleFakerAdapter(),
|
|
24
|
-
lexicon,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// Set archetype to "corporate"
|
|
28
|
-
generator.setArchetype('corporate');
|
|
29
|
-
generator.setSeed(42);
|
|
30
|
-
|
|
31
|
-
// Generate corporate sentences
|
|
32
|
-
console.log('Corporate sentences:');
|
|
33
|
-
for (let i = 0; i < 5; i++) {
|
|
34
|
-
console.log(`${i + 1}. ${generator.sentence()}`);
|
|
35
|
-
}
|
|
36
|
-
console.log();
|
|
37
|
-
|
|
38
|
-
// Generate a corporate paragraph
|
|
39
|
-
console.log('Corporate paragraph:');
|
|
40
|
-
console.log(generator.paragraph({ sentences: 4 }));
|
|
41
|
-
console.log();
|
|
42
|
-
|
|
43
|
-
// Generate corporate text block
|
|
44
|
-
console.log('Corporate text block (3 paragraphs):');
|
|
45
|
-
console.log(generator.textBlock({ paragraphs: 3 }));
|
|
46
|
-
console.log();
|
|
47
|
-
|
|
48
|
-
// Compare with non-lexicon output
|
|
49
|
-
console.log('=== Comparison: With vs Without Lexicon ===\n');
|
|
50
|
-
|
|
51
|
-
const withLexicon = new TextGenerator({
|
|
52
|
-
fakerAdapter: new SimpleFakerAdapter(),
|
|
53
|
-
lexicon,
|
|
54
|
-
});
|
|
55
|
-
withLexicon.setArchetype('corporate');
|
|
56
|
-
withLexicon.setSeed(100);
|
|
57
|
-
|
|
58
|
-
const withoutLexicon = new TextGenerator({
|
|
59
|
-
fakerAdapter: new SimpleFakerAdapter(),
|
|
60
|
-
});
|
|
61
|
-
withoutLexicon.setSeed(100);
|
|
62
|
-
|
|
63
|
-
console.log('With corporate lexicon:');
|
|
64
|
-
for (let i = 0; i < 3; i++) {
|
|
65
|
-
console.log(` ${withLexicon.sentence()}`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
console.log('\nWithout lexicon (same seed):');
|
|
69
|
-
for (let i = 0; i < 3; i++) {
|
|
70
|
-
console.log(` ${withoutLexicon.sentence()}`);
|
|
71
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Example B: Lexicon-Steered Corporate Text
|
|
3
|
+
* Demonstrates text generation using a corporate lexicon
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
import { join, dirname } from 'path';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
import { TextGenerator, SimpleFakerAdapter, loadLexiconFromString } from '../src';
|
|
10
|
+
|
|
11
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
|
|
13
|
+
// Load the corporate lexicon
|
|
14
|
+
const lexiconPath = join(__dirname, 'lexicons', 'corporate-min.json');
|
|
15
|
+
const lexiconJson = readFileSync(lexiconPath, 'utf-8');
|
|
16
|
+
const lexicon = loadLexiconFromString(lexiconJson);
|
|
17
|
+
|
|
18
|
+
console.log('=== Lexicon-Steered Corporate Text ===\n');
|
|
19
|
+
console.log(`Loaded lexicon: ${lexicon.id} v${lexicon.version}\n`);
|
|
20
|
+
|
|
21
|
+
// Create generator with lexicon
|
|
22
|
+
const generator = new TextGenerator({
|
|
23
|
+
fakerAdapter: new SimpleFakerAdapter(),
|
|
24
|
+
lexicon,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Set archetype to "corporate"
|
|
28
|
+
generator.setArchetype('corporate');
|
|
29
|
+
generator.setSeed(42);
|
|
30
|
+
|
|
31
|
+
// Generate corporate sentences
|
|
32
|
+
console.log('Corporate sentences:');
|
|
33
|
+
for (let i = 0; i < 5; i++) {
|
|
34
|
+
console.log(`${i + 1}. ${generator.sentence()}`);
|
|
35
|
+
}
|
|
36
|
+
console.log();
|
|
37
|
+
|
|
38
|
+
// Generate a corporate paragraph
|
|
39
|
+
console.log('Corporate paragraph:');
|
|
40
|
+
console.log(generator.paragraph({ sentences: 4 }));
|
|
41
|
+
console.log();
|
|
42
|
+
|
|
43
|
+
// Generate corporate text block
|
|
44
|
+
console.log('Corporate text block (3 paragraphs):');
|
|
45
|
+
console.log(generator.textBlock({ paragraphs: 3 }));
|
|
46
|
+
console.log();
|
|
47
|
+
|
|
48
|
+
// Compare with non-lexicon output
|
|
49
|
+
console.log('=== Comparison: With vs Without Lexicon ===\n');
|
|
50
|
+
|
|
51
|
+
const withLexicon = new TextGenerator({
|
|
52
|
+
fakerAdapter: new SimpleFakerAdapter(),
|
|
53
|
+
lexicon,
|
|
54
|
+
});
|
|
55
|
+
withLexicon.setArchetype('corporate');
|
|
56
|
+
withLexicon.setSeed(100);
|
|
57
|
+
|
|
58
|
+
const withoutLexicon = new TextGenerator({
|
|
59
|
+
fakerAdapter: new SimpleFakerAdapter(),
|
|
60
|
+
});
|
|
61
|
+
withoutLexicon.setSeed(100);
|
|
62
|
+
|
|
63
|
+
console.log('With corporate lexicon:');
|
|
64
|
+
for (let i = 0; i < 3; i++) {
|
|
65
|
+
console.log(` ${withLexicon.sentence()}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.log('\nWithout lexicon (same seed):');
|
|
69
|
+
for (let i = 0; i < 3; i++) {
|
|
70
|
+
console.log(` ${withoutLexicon.sentence()}`);
|
|
71
|
+
}
|