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
|
@@ -1,200 +1,200 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "lexicon.corporate.min",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"language": "en",
|
|
5
|
-
"termSets": {
|
|
6
|
-
"noun.business": {
|
|
7
|
-
"pos": "noun",
|
|
8
|
-
"tags": ["domain:business", "register:formal"],
|
|
9
|
-
"terms": [
|
|
10
|
-
{ "value": "strategy", "weight": 5 },
|
|
11
|
-
{ "value": "initiative", "weight": 4 },
|
|
12
|
-
{ "value": "stakeholder", "weight": 4 },
|
|
13
|
-
{ "value": "synergy", "weight": 3 },
|
|
14
|
-
{ "value": "deliverable", "weight": 3 },
|
|
15
|
-
{ "value": "benchmark", "weight": 3 },
|
|
16
|
-
{ "value": "pipeline", "weight": 2 },
|
|
17
|
-
{ "value": "bandwidth", "weight": 2 },
|
|
18
|
-
{ "value": "ecosystem", "weight": 2 },
|
|
19
|
-
{ "value": "leverage", "weight": 2 }
|
|
20
|
-
]
|
|
21
|
-
},
|
|
22
|
-
"noun.meeting": {
|
|
23
|
-
"pos": "noun",
|
|
24
|
-
"tags": ["domain:business"],
|
|
25
|
-
"terms": [
|
|
26
|
-
{ "value": "meeting", "weight": 5 },
|
|
27
|
-
{ "value": "conference", "weight": 3 },
|
|
28
|
-
{ "value": "summit", "weight": 2 },
|
|
29
|
-
{ "value": "workshop", "weight": 3 },
|
|
30
|
-
{ "value": "briefing", "weight": 2 },
|
|
31
|
-
{ "value": "presentation", "weight": 4 },
|
|
32
|
-
{ "value": "discussion", "weight": 3 }
|
|
33
|
-
]
|
|
34
|
-
},
|
|
35
|
-
"verb.business": {
|
|
36
|
-
"pos": "verb",
|
|
37
|
-
"tags": ["domain:business"],
|
|
38
|
-
"terms": [
|
|
39
|
-
{ "value": "leverage", "weight": 4 },
|
|
40
|
-
{ "value": "optimize", "weight": 4 },
|
|
41
|
-
{ "value": "streamline", "weight": 3 },
|
|
42
|
-
{ "value": "synergize", "weight": 2 },
|
|
43
|
-
{ "value": "facilitate", "weight": 3 },
|
|
44
|
-
{ "value": "implement", "weight": 5 },
|
|
45
|
-
{ "value": "execute", "weight": 4 },
|
|
46
|
-
{ "value": "deliver", "weight": 4 },
|
|
47
|
-
{ "value": "align", "weight": 3 },
|
|
48
|
-
{ "value": "prioritize", "weight": 3 }
|
|
49
|
-
]
|
|
50
|
-
},
|
|
51
|
-
"verb.meeting": {
|
|
52
|
-
"pos": "verb",
|
|
53
|
-
"tags": ["domain:business"],
|
|
54
|
-
"terms": [
|
|
55
|
-
{ "value": "schedule", "weight": 4 },
|
|
56
|
-
{ "value": "convene", "weight": 2 },
|
|
57
|
-
{ "value": "adjourn", "weight": 2 },
|
|
58
|
-
{ "value": "attend", "weight": 4 },
|
|
59
|
-
{ "value": "organize", "weight": 3 },
|
|
60
|
-
{ "value": "chair", "weight": 2 }
|
|
61
|
-
]
|
|
62
|
-
},
|
|
63
|
-
"adj.business": {
|
|
64
|
-
"pos": "adj",
|
|
65
|
-
"tags": ["domain:business", "register:formal"],
|
|
66
|
-
"terms": [
|
|
67
|
-
{ "value": "strategic", "weight": 5 },
|
|
68
|
-
{ "value": "proactive", "weight": 4 },
|
|
69
|
-
{ "value": "scalable", "weight": 3 },
|
|
70
|
-
{ "value": "robust", "weight": 3 },
|
|
71
|
-
{ "value": "agile", "weight": 4 },
|
|
72
|
-
{ "value": "sustainable", "weight": 3 },
|
|
73
|
-
{ "value": "innovative", "weight": 4 },
|
|
74
|
-
{ "value": "competitive", "weight": 3 },
|
|
75
|
-
{ "value": "dynamic", "weight": 3 },
|
|
76
|
-
{ "value": "holistic", "weight": 2 }
|
|
77
|
-
]
|
|
78
|
-
},
|
|
79
|
-
"adv.business": {
|
|
80
|
-
"pos": "adv",
|
|
81
|
-
"tags": ["domain:business"],
|
|
82
|
-
"terms": [
|
|
83
|
-
{ "value": "strategically", "weight": 4 },
|
|
84
|
-
{ "value": "proactively", "weight": 3 },
|
|
85
|
-
{ "value": "effectively", "weight": 5 },
|
|
86
|
-
{ "value": "efficiently", "weight": 4 },
|
|
87
|
-
{ "value": "seamlessly", "weight": 3 },
|
|
88
|
-
{ "value": "holistically", "weight": 2 },
|
|
89
|
-
{ "value": "comprehensively", "weight": 3 }
|
|
90
|
-
]
|
|
91
|
-
},
|
|
92
|
-
"prep.business": {
|
|
93
|
-
"pos": "prep",
|
|
94
|
-
"tags": ["domain:business"],
|
|
95
|
-
"terms": [
|
|
96
|
-
{ "value": "regarding", "weight": 3 },
|
|
97
|
-
{ "value": "concerning", "weight": 2 },
|
|
98
|
-
{ "value": "throughout", "weight": 3 },
|
|
99
|
-
{ "value": "within", "weight": 4 },
|
|
100
|
-
{ "value": "across", "weight": 4 }
|
|
101
|
-
]
|
|
102
|
-
},
|
|
103
|
-
"intj.formal": {
|
|
104
|
-
"pos": "intj",
|
|
105
|
-
"tags": ["register:formal"],
|
|
106
|
-
"terms": [
|
|
107
|
-
{ "value": "indeed", "weight": 4 },
|
|
108
|
-
{ "value": "certainly", "weight": 4 },
|
|
109
|
-
{ "value": "naturally", "weight": 3 },
|
|
110
|
-
{ "value": "accordingly", "weight": 2 },
|
|
111
|
-
{ "value": "importantly", "weight": 3 }
|
|
112
|
-
]
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
"patterns": {
|
|
116
|
-
"sentence.corporate": {
|
|
117
|
-
"type": "sentence",
|
|
118
|
-
"slots": ["NP", "VP", "PUNCT"],
|
|
119
|
-
"tags": ["domain:business"],
|
|
120
|
-
"weight": 2
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
"distributions": {
|
|
124
|
-
"sentenceTypes.corporate": [
|
|
125
|
-
{ "key": "simpleDeclarative", "weight": 50 },
|
|
126
|
-
{ "key": "compound", "weight": 20 },
|
|
127
|
-
{ "key": "introAdverbial", "weight": 15 },
|
|
128
|
-
{ "key": "subordinate", "weight": 12 },
|
|
129
|
-
{ "key": "interjection", "weight": 2 },
|
|
130
|
-
{ "key": "question", "weight": 1 }
|
|
131
|
-
],
|
|
132
|
-
"termSetBias.domain:business": [
|
|
133
|
-
{ "key": "noun.business", "weight": 10 },
|
|
134
|
-
{ "key": "noun.meeting", "weight": 5 },
|
|
135
|
-
{ "key": "verb.business", "weight": 8 },
|
|
136
|
-
{ "key": "verb.meeting", "weight": 4 },
|
|
137
|
-
{ "key": "adj.business", "weight": 8 },
|
|
138
|
-
{ "key": "adv.business", "weight": 5 }
|
|
139
|
-
]
|
|
140
|
-
},
|
|
141
|
-
"correlations": [
|
|
142
|
-
{
|
|
143
|
-
"when": { "chosenTermSet": "noun.business" },
|
|
144
|
-
"thenBoost": [
|
|
145
|
-
{ "termSet": "verb.business", "weightDelta": 5 },
|
|
146
|
-
{ "termSet": "adj.business", "weightDelta": 3 }
|
|
147
|
-
],
|
|
148
|
-
"scope": "sentence"
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
"when": { "chosenTermSet": "noun.meeting" },
|
|
152
|
-
"thenBoost": [
|
|
153
|
-
{ "termSet": "verb.meeting", "weightDelta": 5 }
|
|
154
|
-
],
|
|
155
|
-
"scope": "sentence"
|
|
156
|
-
}
|
|
157
|
-
],
|
|
158
|
-
"constraints": [
|
|
159
|
-
{
|
|
160
|
-
"id": "c.noRepeatNoun",
|
|
161
|
-
"level": "hard",
|
|
162
|
-
"scope": "sentence",
|
|
163
|
-
"type": "noRepeat",
|
|
164
|
-
"target": "pos:noun"
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
"id": "c.maxPP",
|
|
168
|
-
"level": "hard",
|
|
169
|
-
"scope": "phrase",
|
|
170
|
-
"type": "maxCount",
|
|
171
|
-
"target": "PP",
|
|
172
|
-
"value": 2
|
|
173
|
-
}
|
|
174
|
-
],
|
|
175
|
-
"invariants": [
|
|
176
|
-
{ "id": "inv.capitalized", "type": "capitalization", "scope": "sentence" },
|
|
177
|
-
{ "id": "inv.endsWithPunct", "type": "punctuation", "scope": "sentence" },
|
|
178
|
-
{ "id": "inv.noDoubleSpaces", "type": "whitespace", "scope": "text" }
|
|
179
|
-
],
|
|
180
|
-
"archetypes": {
|
|
181
|
-
"corporate": {
|
|
182
|
-
"tags": ["register:formal", "domain:business"],
|
|
183
|
-
"distributions": {
|
|
184
|
-
"sentenceTypes": "sentenceTypes.corporate",
|
|
185
|
-
"termSetBias": "termSetBias.domain:business"
|
|
186
|
-
},
|
|
187
|
-
"overrides": {
|
|
188
|
-
"interjectionRate": 0.02,
|
|
189
|
-
"subordinateClauseRate": 0.12,
|
|
190
|
-
"questionRate": 0.01
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
"relations": [
|
|
195
|
-
{ "from": "strategy", "type": "hasPart", "to": "initiative", "weight": 3 },
|
|
196
|
-
{ "from": "initiative", "type": "requires", "to": "stakeholder", "weight": 2 },
|
|
197
|
-
{ "from": "meeting", "type": "produces", "to": "deliverable", "weight": 2 },
|
|
198
|
-
{ "from": "synergy", "type": "enables", "to": "leverage", "weight": 2 }
|
|
199
|
-
]
|
|
200
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"id": "lexicon.corporate.min",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"language": "en",
|
|
5
|
+
"termSets": {
|
|
6
|
+
"noun.business": {
|
|
7
|
+
"pos": "noun",
|
|
8
|
+
"tags": ["domain:business", "register:formal"],
|
|
9
|
+
"terms": [
|
|
10
|
+
{ "value": "strategy", "weight": 5 },
|
|
11
|
+
{ "value": "initiative", "weight": 4 },
|
|
12
|
+
{ "value": "stakeholder", "weight": 4 },
|
|
13
|
+
{ "value": "synergy", "weight": 3 },
|
|
14
|
+
{ "value": "deliverable", "weight": 3 },
|
|
15
|
+
{ "value": "benchmark", "weight": 3 },
|
|
16
|
+
{ "value": "pipeline", "weight": 2 },
|
|
17
|
+
{ "value": "bandwidth", "weight": 2 },
|
|
18
|
+
{ "value": "ecosystem", "weight": 2 },
|
|
19
|
+
{ "value": "leverage", "weight": 2 }
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"noun.meeting": {
|
|
23
|
+
"pos": "noun",
|
|
24
|
+
"tags": ["domain:business"],
|
|
25
|
+
"terms": [
|
|
26
|
+
{ "value": "meeting", "weight": 5 },
|
|
27
|
+
{ "value": "conference", "weight": 3 },
|
|
28
|
+
{ "value": "summit", "weight": 2 },
|
|
29
|
+
{ "value": "workshop", "weight": 3 },
|
|
30
|
+
{ "value": "briefing", "weight": 2 },
|
|
31
|
+
{ "value": "presentation", "weight": 4 },
|
|
32
|
+
{ "value": "discussion", "weight": 3 }
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"verb.business": {
|
|
36
|
+
"pos": "verb",
|
|
37
|
+
"tags": ["domain:business"],
|
|
38
|
+
"terms": [
|
|
39
|
+
{ "value": "leverage", "weight": 4 },
|
|
40
|
+
{ "value": "optimize", "weight": 4 },
|
|
41
|
+
{ "value": "streamline", "weight": 3 },
|
|
42
|
+
{ "value": "synergize", "weight": 2 },
|
|
43
|
+
{ "value": "facilitate", "weight": 3 },
|
|
44
|
+
{ "value": "implement", "weight": 5 },
|
|
45
|
+
{ "value": "execute", "weight": 4 },
|
|
46
|
+
{ "value": "deliver", "weight": 4 },
|
|
47
|
+
{ "value": "align", "weight": 3 },
|
|
48
|
+
{ "value": "prioritize", "weight": 3 }
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"verb.meeting": {
|
|
52
|
+
"pos": "verb",
|
|
53
|
+
"tags": ["domain:business"],
|
|
54
|
+
"terms": [
|
|
55
|
+
{ "value": "schedule", "weight": 4 },
|
|
56
|
+
{ "value": "convene", "weight": 2 },
|
|
57
|
+
{ "value": "adjourn", "weight": 2 },
|
|
58
|
+
{ "value": "attend", "weight": 4 },
|
|
59
|
+
{ "value": "organize", "weight": 3 },
|
|
60
|
+
{ "value": "chair", "weight": 2 }
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"adj.business": {
|
|
64
|
+
"pos": "adj",
|
|
65
|
+
"tags": ["domain:business", "register:formal"],
|
|
66
|
+
"terms": [
|
|
67
|
+
{ "value": "strategic", "weight": 5 },
|
|
68
|
+
{ "value": "proactive", "weight": 4 },
|
|
69
|
+
{ "value": "scalable", "weight": 3 },
|
|
70
|
+
{ "value": "robust", "weight": 3 },
|
|
71
|
+
{ "value": "agile", "weight": 4 },
|
|
72
|
+
{ "value": "sustainable", "weight": 3 },
|
|
73
|
+
{ "value": "innovative", "weight": 4 },
|
|
74
|
+
{ "value": "competitive", "weight": 3 },
|
|
75
|
+
{ "value": "dynamic", "weight": 3 },
|
|
76
|
+
{ "value": "holistic", "weight": 2 }
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
"adv.business": {
|
|
80
|
+
"pos": "adv",
|
|
81
|
+
"tags": ["domain:business"],
|
|
82
|
+
"terms": [
|
|
83
|
+
{ "value": "strategically", "weight": 4 },
|
|
84
|
+
{ "value": "proactively", "weight": 3 },
|
|
85
|
+
{ "value": "effectively", "weight": 5 },
|
|
86
|
+
{ "value": "efficiently", "weight": 4 },
|
|
87
|
+
{ "value": "seamlessly", "weight": 3 },
|
|
88
|
+
{ "value": "holistically", "weight": 2 },
|
|
89
|
+
{ "value": "comprehensively", "weight": 3 }
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
"prep.business": {
|
|
93
|
+
"pos": "prep",
|
|
94
|
+
"tags": ["domain:business"],
|
|
95
|
+
"terms": [
|
|
96
|
+
{ "value": "regarding", "weight": 3 },
|
|
97
|
+
{ "value": "concerning", "weight": 2 },
|
|
98
|
+
{ "value": "throughout", "weight": 3 },
|
|
99
|
+
{ "value": "within", "weight": 4 },
|
|
100
|
+
{ "value": "across", "weight": 4 }
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
"intj.formal": {
|
|
104
|
+
"pos": "intj",
|
|
105
|
+
"tags": ["register:formal"],
|
|
106
|
+
"terms": [
|
|
107
|
+
{ "value": "indeed", "weight": 4 },
|
|
108
|
+
{ "value": "certainly", "weight": 4 },
|
|
109
|
+
{ "value": "naturally", "weight": 3 },
|
|
110
|
+
{ "value": "accordingly", "weight": 2 },
|
|
111
|
+
{ "value": "importantly", "weight": 3 }
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"patterns": {
|
|
116
|
+
"sentence.corporate": {
|
|
117
|
+
"type": "sentence",
|
|
118
|
+
"slots": ["NP", "VP", "PUNCT"],
|
|
119
|
+
"tags": ["domain:business"],
|
|
120
|
+
"weight": 2
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"distributions": {
|
|
124
|
+
"sentenceTypes.corporate": [
|
|
125
|
+
{ "key": "simpleDeclarative", "weight": 50 },
|
|
126
|
+
{ "key": "compound", "weight": 20 },
|
|
127
|
+
{ "key": "introAdverbial", "weight": 15 },
|
|
128
|
+
{ "key": "subordinate", "weight": 12 },
|
|
129
|
+
{ "key": "interjection", "weight": 2 },
|
|
130
|
+
{ "key": "question", "weight": 1 }
|
|
131
|
+
],
|
|
132
|
+
"termSetBias.domain:business": [
|
|
133
|
+
{ "key": "noun.business", "weight": 10 },
|
|
134
|
+
{ "key": "noun.meeting", "weight": 5 },
|
|
135
|
+
{ "key": "verb.business", "weight": 8 },
|
|
136
|
+
{ "key": "verb.meeting", "weight": 4 },
|
|
137
|
+
{ "key": "adj.business", "weight": 8 },
|
|
138
|
+
{ "key": "adv.business", "weight": 5 }
|
|
139
|
+
]
|
|
140
|
+
},
|
|
141
|
+
"correlations": [
|
|
142
|
+
{
|
|
143
|
+
"when": { "chosenTermSet": "noun.business" },
|
|
144
|
+
"thenBoost": [
|
|
145
|
+
{ "termSet": "verb.business", "weightDelta": 5 },
|
|
146
|
+
{ "termSet": "adj.business", "weightDelta": 3 }
|
|
147
|
+
],
|
|
148
|
+
"scope": "sentence"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"when": { "chosenTermSet": "noun.meeting" },
|
|
152
|
+
"thenBoost": [
|
|
153
|
+
{ "termSet": "verb.meeting", "weightDelta": 5 }
|
|
154
|
+
],
|
|
155
|
+
"scope": "sentence"
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
"constraints": [
|
|
159
|
+
{
|
|
160
|
+
"id": "c.noRepeatNoun",
|
|
161
|
+
"level": "hard",
|
|
162
|
+
"scope": "sentence",
|
|
163
|
+
"type": "noRepeat",
|
|
164
|
+
"target": "pos:noun"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"id": "c.maxPP",
|
|
168
|
+
"level": "hard",
|
|
169
|
+
"scope": "phrase",
|
|
170
|
+
"type": "maxCount",
|
|
171
|
+
"target": "PP",
|
|
172
|
+
"value": 2
|
|
173
|
+
}
|
|
174
|
+
],
|
|
175
|
+
"invariants": [
|
|
176
|
+
{ "id": "inv.capitalized", "type": "capitalization", "scope": "sentence" },
|
|
177
|
+
{ "id": "inv.endsWithPunct", "type": "punctuation", "scope": "sentence" },
|
|
178
|
+
{ "id": "inv.noDoubleSpaces", "type": "whitespace", "scope": "text" }
|
|
179
|
+
],
|
|
180
|
+
"archetypes": {
|
|
181
|
+
"corporate": {
|
|
182
|
+
"tags": ["register:formal", "domain:business"],
|
|
183
|
+
"distributions": {
|
|
184
|
+
"sentenceTypes": "sentenceTypes.corporate",
|
|
185
|
+
"termSetBias": "termSetBias.domain:business"
|
|
186
|
+
},
|
|
187
|
+
"overrides": {
|
|
188
|
+
"interjectionRate": 0.02,
|
|
189
|
+
"subordinateClauseRate": 0.12,
|
|
190
|
+
"questionRate": 0.01
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
"relations": [
|
|
195
|
+
{ "from": "strategy", "type": "hasPart", "to": "initiative", "weight": 3 },
|
|
196
|
+
{ "from": "initiative", "type": "requires", "to": "stakeholder", "weight": 2 },
|
|
197
|
+
{ "from": "meeting", "type": "produces", "to": "deliverable", "weight": 2 },
|
|
198
|
+
{ "from": "synergy", "type": "enables", "to": "leverage", "weight": 2 }
|
|
199
|
+
]
|
|
200
|
+
}
|
package/examples/with-tracing.ts
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example C: Generation with Tracing
|
|
3
|
-
* Demonstrates the tracing/metadata output feature
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { TextGenerator, SimpleFakerAdapter, GeneratedText } from '../src';
|
|
7
|
-
|
|
8
|
-
// Create generator with tracing enabled
|
|
9
|
-
const generator = new TextGenerator({
|
|
10
|
-
fakerAdapter: new SimpleFakerAdapter(),
|
|
11
|
-
enableTrace: true,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
generator.setSeed(42);
|
|
15
|
-
|
|
16
|
-
console.log('=== Text Generation with Tracing ===\n');
|
|
17
|
-
|
|
18
|
-
// Generate a sentence with trace
|
|
19
|
-
const result = generator.sentence() as GeneratedText;
|
|
20
|
-
|
|
21
|
-
console.log('Generated text:', result.text);
|
|
22
|
-
console.log();
|
|
23
|
-
|
|
24
|
-
console.log('Metadata:');
|
|
25
|
-
console.log(' Archetype:', result.meta.archetype);
|
|
26
|
-
console.log(' Seed:', result.meta.seed);
|
|
27
|
-
if (result.meta.lexiconId) {
|
|
28
|
-
console.log(' Lexicon ID:', result.meta.lexiconId);
|
|
29
|
-
console.log(' Lexicon Version:', result.meta.lexiconVersion);
|
|
30
|
-
}
|
|
31
|
-
console.log();
|
|
32
|
-
|
|
33
|
-
if (result.trace) {
|
|
34
|
-
console.log('Trace:');
|
|
35
|
-
const sentence = result.trace.paragraphs[0]?.sentences[0];
|
|
36
|
-
if (sentence) {
|
|
37
|
-
console.log(' Template:', sentence.template);
|
|
38
|
-
console.log(' Retry count:', sentence.retryCount);
|
|
39
|
-
console.log(' Token count:', sentence.tokens.length);
|
|
40
|
-
console.log();
|
|
41
|
-
|
|
42
|
-
console.log(' Tokens:');
|
|
43
|
-
for (const token of sentence.tokens.slice(0, 10)) {
|
|
44
|
-
console.log(` "${token.value}" - source: ${token.source}${token.pos ? `, pos: ${token.pos}` : ''}`);
|
|
45
|
-
}
|
|
46
|
-
if (sentence.tokens.length > 10) {
|
|
47
|
-
console.log(` ... and ${sentence.tokens.length - 10} more tokens`);
|
|
48
|
-
}
|
|
49
|
-
console.log();
|
|
50
|
-
|
|
51
|
-
console.log(' Constraints evaluated:');
|
|
52
|
-
for (const c of sentence.constraintsEvaluated) {
|
|
53
|
-
console.log(` ${c.id}: ${c.passed ? 'PASS' : 'FAIL'}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
console.log();
|
|
58
|
-
console.log(' Invariants checked:');
|
|
59
|
-
for (const inv of result.trace.invariantsChecked) {
|
|
60
|
-
console.log(` ${inv.id}: ${inv.passed ? 'PASS' : 'FAIL'}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (result.trace.correlationsApplied.length > 0) {
|
|
64
|
-
console.log();
|
|
65
|
-
console.log(' Correlations applied:', result.trace.correlationsApplied);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Generate a paragraph with trace
|
|
70
|
-
console.log('\n\n=== Paragraph with Tracing ===\n');
|
|
71
|
-
|
|
72
|
-
const paragraphResult = generator.paragraph({ sentences: 3 }) as GeneratedText;
|
|
73
|
-
|
|
74
|
-
console.log('Generated text:');
|
|
75
|
-
console.log(paragraphResult.text);
|
|
76
|
-
console.log();
|
|
77
|
-
|
|
78
|
-
if (paragraphResult.trace) {
|
|
79
|
-
const sentences = paragraphResult.trace.paragraphs[0]?.sentences || [];
|
|
80
|
-
console.log(`Trace: ${sentences.length} sentences`);
|
|
81
|
-
for (let i = 0; i < sentences.length; i++) {
|
|
82
|
-
const s = sentences[i]!;
|
|
83
|
-
console.log(` Sentence ${i + 1}: template=${s.template}, tokens=${s.tokens.length}, retries=${s.retryCount}`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Example C: Generation with Tracing
|
|
3
|
+
* Demonstrates the tracing/metadata output feature
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { TextGenerator, SimpleFakerAdapter, GeneratedText } from '../src';
|
|
7
|
+
|
|
8
|
+
// Create generator with tracing enabled
|
|
9
|
+
const generator = new TextGenerator({
|
|
10
|
+
fakerAdapter: new SimpleFakerAdapter(),
|
|
11
|
+
enableTrace: true,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
generator.setSeed(42);
|
|
15
|
+
|
|
16
|
+
console.log('=== Text Generation with Tracing ===\n');
|
|
17
|
+
|
|
18
|
+
// Generate a sentence with trace
|
|
19
|
+
const result = generator.sentence() as GeneratedText;
|
|
20
|
+
|
|
21
|
+
console.log('Generated text:', result.text);
|
|
22
|
+
console.log();
|
|
23
|
+
|
|
24
|
+
console.log('Metadata:');
|
|
25
|
+
console.log(' Archetype:', result.meta.archetype);
|
|
26
|
+
console.log(' Seed:', result.meta.seed);
|
|
27
|
+
if (result.meta.lexiconId) {
|
|
28
|
+
console.log(' Lexicon ID:', result.meta.lexiconId);
|
|
29
|
+
console.log(' Lexicon Version:', result.meta.lexiconVersion);
|
|
30
|
+
}
|
|
31
|
+
console.log();
|
|
32
|
+
|
|
33
|
+
if (result.trace) {
|
|
34
|
+
console.log('Trace:');
|
|
35
|
+
const sentence = result.trace.paragraphs[0]?.sentences[0];
|
|
36
|
+
if (sentence) {
|
|
37
|
+
console.log(' Template:', sentence.template);
|
|
38
|
+
console.log(' Retry count:', sentence.retryCount);
|
|
39
|
+
console.log(' Token count:', sentence.tokens.length);
|
|
40
|
+
console.log();
|
|
41
|
+
|
|
42
|
+
console.log(' Tokens:');
|
|
43
|
+
for (const token of sentence.tokens.slice(0, 10)) {
|
|
44
|
+
console.log(` "${token.value}" - source: ${token.source}${token.pos ? `, pos: ${token.pos}` : ''}`);
|
|
45
|
+
}
|
|
46
|
+
if (sentence.tokens.length > 10) {
|
|
47
|
+
console.log(` ... and ${sentence.tokens.length - 10} more tokens`);
|
|
48
|
+
}
|
|
49
|
+
console.log();
|
|
50
|
+
|
|
51
|
+
console.log(' Constraints evaluated:');
|
|
52
|
+
for (const c of sentence.constraintsEvaluated) {
|
|
53
|
+
console.log(` ${c.id}: ${c.passed ? 'PASS' : 'FAIL'}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
console.log();
|
|
58
|
+
console.log(' Invariants checked:');
|
|
59
|
+
for (const inv of result.trace.invariantsChecked) {
|
|
60
|
+
console.log(` ${inv.id}: ${inv.passed ? 'PASS' : 'FAIL'}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (result.trace.correlationsApplied.length > 0) {
|
|
64
|
+
console.log();
|
|
65
|
+
console.log(' Correlations applied:', result.trace.correlationsApplied);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Generate a paragraph with trace
|
|
70
|
+
console.log('\n\n=== Paragraph with Tracing ===\n');
|
|
71
|
+
|
|
72
|
+
const paragraphResult = generator.paragraph({ sentences: 3 }) as GeneratedText;
|
|
73
|
+
|
|
74
|
+
console.log('Generated text:');
|
|
75
|
+
console.log(paragraphResult.text);
|
|
76
|
+
console.log();
|
|
77
|
+
|
|
78
|
+
if (paragraphResult.trace) {
|
|
79
|
+
const sentences = paragraphResult.trace.paragraphs[0]?.sentences || [];
|
|
80
|
+
console.log(`Trace: ${sentences.length} sentences`);
|
|
81
|
+
for (let i = 0; i < sentences.length; i++) {
|
|
82
|
+
const s = sentences[i]!;
|
|
83
|
+
console.log(` Sentence ${i + 1}: template=${s.template}, tokens=${s.tokens.length}, retries=${s.retryCount}`);
|
|
84
|
+
}
|
|
85
|
+
}
|