theprogrammablemind_4wp 7.6.0-beta.6 → 7.6.0-beta.7
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +21 -19
- package/package.json +1 -1
- package/src/generators.js +112 -118
package/client.js
CHANGED
@@ -175,8 +175,8 @@ const setupArgs = (args, config, logs, hierarchy) => {
|
|
175
175
|
}
|
176
176
|
args.s = (c) => config.getSemantics(logs).apply(args, c)
|
177
177
|
args.g = (c) => config.getGenerators(logs).apply(args, c)
|
178
|
-
args.gp = (c) => config.getGenerators(logs).apply(args, {
|
179
|
-
args.gr = (c) => config.getGenerators(logs).apply(args, { ...c, paraphrase: false, isResponse: true })
|
178
|
+
args.gp = (c) => config.getGenerators(logs).apply({...args, assumed: {paraphrase: true, isResponse: false, response: false}}, c, {paraphrase: true, isResponse: false, response: false})
|
179
|
+
args.gr = (c) => config.getGenerators(logs).apply({...args, assumed: {paraphrase: false, isResponse: true}}, { ...c, paraphrase: false, isResponse: true })
|
180
180
|
if (!logs) {
|
181
181
|
debugger
|
182
182
|
}
|
@@ -189,6 +189,11 @@ const setupArgs = (args, config, logs, hierarchy) => {
|
|
189
189
|
}
|
190
190
|
|
191
191
|
const gs = (g) => (contexts, separator, lastSeparator) => {
|
192
|
+
if (!Array.isArray(contexts)) {
|
193
|
+
debugger
|
194
|
+
throw new Error("Expected a list")
|
195
|
+
}
|
196
|
+
|
192
197
|
let s = ''
|
193
198
|
if (!separator) {
|
194
199
|
separator = ' '
|
@@ -276,8 +281,9 @@ const processContext = (context, { objects = {}, config, logs = [] }) => {
|
|
276
281
|
setupArgs(args, config, logs, hierarchy)
|
277
282
|
|
278
283
|
context = semantics.apply(args, context)
|
279
|
-
const generated = generators.apply(args, context)
|
280
|
-
const
|
284
|
+
const generated = generators.apply(args, context)
|
285
|
+
const assumed = { paraphrase: true, response: false, isResponse: false }
|
286
|
+
const paraphrases = generators.apply({...args, assumed}, context, { paraphrase: true, response: false, isResponse: false })
|
281
287
|
let responses = []
|
282
288
|
if (context.isResponse) {
|
283
289
|
responses = generated
|
@@ -447,37 +453,29 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
447
453
|
continue
|
448
454
|
}
|
449
455
|
let assumed = { isResponse: true };
|
450
|
-
const generated = contextPrime.isResponse ? config.getGenerators(json.logs).apply(args, contextPrime, assumed)
|
456
|
+
const generated = contextPrime.isResponse ? config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed) : ''
|
451
457
|
let generatedParenthesized = []
|
452
458
|
if (generateParenthesized) {
|
453
459
|
config.parenthesized = true
|
454
|
-
generatedParenthesized = contextPrime.isResponse ? config.getGenerators(json.logs).apply(args, contextPrime, assumed)
|
460
|
+
generatedParenthesized = contextPrime.isResponse ? config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed) : ''
|
455
461
|
config.parenthesized = false
|
456
462
|
}
|
457
463
|
// assumed = { paraphrase: true, response: false };
|
458
|
-
assumed = { paraphrase: true };
|
459
|
-
args.g = (c) => config.getGenerators(json.logs).apply(args, c, assumed)
|
460
|
-
args.gp = (c) => config.getGenerators(json.logs).apply(args, {...c, paraphrase: true, isResponse: false, response: false }, assumed)
|
461
|
-
args.gr = (c) => config.getGenerators(json.logs).apply(args, {...c, paraphrase: false }, assumed)
|
464
|
+
assumed = { paraphrase: true, isResponse: false, response: false };
|
465
|
+
args.g = (c) => config.getGenerators(json.logs).apply({...args, assumed}, c, assumed)
|
462
466
|
args.gs = gs(args.g)
|
463
|
-
args.gsp = gs(args.gsp)
|
464
|
-
args.gsr = gs(args.gr)
|
465
467
|
if (generateParenthesized) {
|
466
468
|
config.parenthesized = false
|
467
469
|
}
|
468
|
-
const paraphrases = config.getGenerators(json.logs).apply(args, contextPrime, assumed)
|
470
|
+
const paraphrases = config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed)
|
469
471
|
let paraphrasesParenthesized = []
|
470
472
|
if (generateParenthesized) {
|
471
473
|
config.parenthesized = true
|
472
|
-
paraphrasesParenthesized = config.getGenerators(json.logs).apply(args, contextPrime, assumed)
|
474
|
+
paraphrasesParenthesized = config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed)
|
473
475
|
config.parenthesized = false
|
474
476
|
}
|
475
477
|
args.g = (c) => config.getGenerators(json.logs).apply(args, c)
|
476
|
-
args.gp = (c) => config.getGenerators(json.logs).apply(args, {...c, paraphrase: true, isResponse: false, response: false })
|
477
|
-
args.gr = (c) => config.getGenerators(json.logs).apply(args, {...c, paraphrase: false })
|
478
478
|
args.gs = gs(args.g)
|
479
|
-
args.gsp = gs(args.gp)
|
480
|
-
args.gsr = gs(args.gr)
|
481
479
|
contextsPrime.push(contextPrime)
|
482
480
|
generatedPrime.push(generated)
|
483
481
|
paraphrasesPrime.push(paraphrases)
|
@@ -1794,12 +1792,16 @@ const knowledgeModule = async ({
|
|
1794
1792
|
show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
|
1795
1793
|
if (!args.testNoParenthesized) {
|
1796
1794
|
show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
|
1795
|
+
if (args.vimdiff) {
|
1796
|
+
vimdiff(result.actual.paraphrasesParenthesized, result.expected.paraphrasesParenthesized)
|
1797
|
+
}
|
1798
|
+
}
|
1799
|
+
/*
|
1797
1800
|
}
|
1798
1801
|
show('responses', result.expected.responses, result.actual.responses)
|
1799
1802
|
if (!args.testNoParenthesized) {
|
1800
1803
|
show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
|
1801
1804
|
}
|
1802
|
-
/*
|
1803
1805
|
if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
|
1804
1806
|
if (!headerShown) {
|
1805
1807
|
console.log(' Failure')
|
package/package.json
CHANGED
package/src/generators.js
CHANGED
@@ -165,136 +165,130 @@ class Generators {
|
|
165
165
|
this.logs = logs
|
166
166
|
};
|
167
167
|
|
168
|
-
// assumed - properties added to
|
169
|
-
apply (args,
|
168
|
+
// assumed - properties added to context before the generators are called. For setting paraphrase property
|
169
|
+
apply (args, context, assumed = {}, options = {}) {
|
170
|
+
if (Array.isArray(context)) {
|
171
|
+
return new Error("Expected a context not an array")
|
172
|
+
}
|
173
|
+
if (typeof context !== 'object') {
|
174
|
+
return String(context)
|
175
|
+
}
|
176
|
+
|
170
177
|
const config = args.config
|
171
178
|
const objects = args.objects
|
172
179
|
const hierarchy = args.hierarchy
|
173
180
|
const response = args.response
|
174
|
-
if (Array.isArray(contexts)) {
|
175
|
-
// no-op
|
176
|
-
} else if (typeof contexts === 'object') {
|
177
|
-
contexts = [contexts]
|
178
|
-
} else {
|
179
|
-
return String(contexts)
|
180
|
-
}
|
181
181
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
if (Array.isArray(r)) {
|
196
|
-
return r.join(' ')
|
197
|
-
} else {
|
198
|
-
return r
|
199
|
-
}
|
200
|
-
}
|
201
|
-
const log = (message) => { this.logs.push(message) }
|
202
|
-
// this.logs.push(`Generators: applied ${generator.toString()}\n to\n ${JSON.stringify(context)}`)
|
203
|
-
let errorMessage = 'The apply function did not return a value'
|
204
|
-
try {
|
205
|
-
generated= generator.apply(args, objects, g, args.gs, context, hierarchy, config, response, log)
|
206
|
-
} catch( e ) {
|
207
|
-
// the next if handle this
|
208
|
-
generated = null
|
209
|
-
e.retryCall = () => generator.apply(args, objects, g, args.gs, context, hierarchy, config, response, log)
|
210
|
-
const help = 'The error has a retryCall property that will recall the function that failed.'
|
211
|
-
if (e.stack && e.message) {
|
212
|
-
const info = `${generator.notes ? generator.notes : ''}${generator.where ? generator.where : ''}`
|
213
|
-
errorMessage = `Error applying generator '${info}. Error is ${e.toString()} stack is ${e.stack}. Generator is ${generator.toString()}. ${help}`
|
214
|
-
} else if (e.error) {
|
215
|
-
const info = `${generator.notes ? generator.notes : ''}${generator.where ? generator.where : ''}`
|
216
|
-
errorMessage = `Error applying generator '${info}. Error is ${e.error.join()}. Generator is ${generator.toString()}. ${help}`
|
217
|
-
} else {
|
218
|
-
errorMessage = e.toString()
|
219
|
-
}
|
182
|
+
context = Object.assign({}, context, args.assumed)
|
183
|
+
let generated = ''
|
184
|
+
let applied = false
|
185
|
+
const stack = args.calls.push()
|
186
|
+
for (let igenerator = 0; igenerator < this.generators.length; ++igenerator) {
|
187
|
+
const generator = this.generators[igenerator]
|
188
|
+
if (generator.matches(args, objects, context, hierarchy, config, options)) {
|
189
|
+
const g = (context, options) => {
|
190
|
+
const r = this.apply(args, context, Object.assign({}, ((options||{}).assumed || {}), assumed), options)
|
191
|
+
if (Array.isArray(r)) {
|
192
|
+
return r.join(' ')
|
193
|
+
} else {
|
194
|
+
return r
|
220
195
|
}
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
lines.setElement(0, 1, 'ERROR')
|
241
|
-
lines.setElement(0, 2, errorMessage)
|
242
|
-
this.logs.push(lines.toString())
|
243
|
-
const message = `ERROR while applying (${source}) ${generator.toLabel()}\n to\n ${JSON.stringify(context, null, 2)}.\n${errorMessage}'`
|
244
|
-
// this.logs.push(message)
|
245
|
-
// return [message]
|
246
|
-
args.calls.pop()
|
247
|
-
throw { error: [message], logs: this.logs }
|
196
|
+
}
|
197
|
+
const log = (message) => { this.logs.push(message) }
|
198
|
+
// this.logs.push(`Generators: applied ${generator.toString()}\n to\n ${JSON.stringify(context)}`)
|
199
|
+
let errorMessage = 'The apply function did not return a value'
|
200
|
+
try {
|
201
|
+
generated= generator.apply(args, objects, g, args.gs, context, hierarchy, config, response, log)
|
202
|
+
} catch( e ) {
|
203
|
+
// the next if handle this
|
204
|
+
generated = null
|
205
|
+
e.retryCall = () => generator.apply(args, objects, g, args.gs, context, hierarchy, config, response, log)
|
206
|
+
const help = 'The error has a retryCall property that will recall the function that failed.'
|
207
|
+
if (e.stack && e.message) {
|
208
|
+
const info = `${generator.notes ? generator.notes : ''}${generator.where ? generator.where : ''}`
|
209
|
+
errorMessage = `Error applying generator '${info}. Error is ${e.toString()} stack is ${e.stack}. Generator is ${generator.toString()}. ${help}`
|
210
|
+
} else if (e.error) {
|
211
|
+
const info = `${generator.notes ? generator.notes : ''}${generator.where ? generator.where : ''}`
|
212
|
+
errorMessage = `Error applying generator '${info}. Error is ${e.error.join()}. Generator is ${generator.toString()}. ${help}`
|
213
|
+
} else {
|
214
|
+
errorMessage = e.toString()
|
248
215
|
}
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
216
|
+
}
|
217
|
+
if (!generated && generated !== '') {
|
218
|
+
const widths = [10, 10, 90]
|
219
|
+
const lines = new Lines(widths)
|
220
|
+
lines.setElement(0, 0, 'Generator')
|
221
|
+
const source = `${generator.km}/#${generator.index}`
|
222
|
+
lines.setElement(0, 2, `ERROR while applying (${source}) ${generator.toLabel()}`)
|
223
|
+
lines.newRow()
|
224
|
+
lines.setElement(0, 2, generator.toString())
|
225
|
+
lines.newRow()
|
226
|
+
lines.setElement(0, 1, 'TO')
|
227
|
+
lines.setElement(0, 2, `(HASHCODE ${helpers.hashCode(JSON.stringify(helpers.sortJson(context, { depth: 25 })))})`)
|
228
|
+
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
229
|
+
lines.newRow()
|
230
|
+
lines.setElement(0, 1, 'STACK')
|
231
|
+
lines.setElement(0, 2, stack)
|
232
|
+
lines.newRow()
|
233
|
+
lines.setElement(0, 1, 'DEBUG')
|
234
|
+
lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
|
235
|
+
lines.newRow()
|
236
|
+
lines.setElement(0, 1, 'ERROR')
|
237
|
+
lines.setElement(0, 2, errorMessage)
|
238
|
+
this.logs.push(lines.toString())
|
239
|
+
const message = `ERROR while applying (${source}) ${generator.toLabel()}\n to\n ${JSON.stringify(context, null, 2)}.\n${errorMessage}'`
|
240
|
+
// this.logs.push(message)
|
241
|
+
// return [message]
|
242
|
+
args.calls.pop()
|
243
|
+
throw { error: [message], logs: this.logs }
|
244
|
+
}
|
245
|
+
if (((config || {}).config || {}).debug) {
|
246
|
+
const widths = [10, 10, 90]
|
247
|
+
const lines = new Lines(widths)
|
248
|
+
lines.setElement(0, 0, 'Generator')
|
249
|
+
if (generator.index > -1 && generator.km) {
|
250
|
+
// lines.setElement(0, 2, `KM '${generator.km}' ordinal: ${generator.index}`)
|
259
251
|
lines.setElement(0, 2, generator.toLabel())
|
260
|
-
lines.newRow()
|
261
|
-
lines.setElement(0, 2, generator.toString())
|
262
|
-
lines.newRow()
|
263
|
-
lines.setElement(0, 1, 'RESULT')
|
264
|
-
lines.setElement(0, 2, generated)
|
265
|
-
lines.newRow()
|
266
|
-
lines.setElement(0, 1, 'STACK')
|
267
|
-
lines.setElement(0, 2, stack)
|
268
|
-
lines.newRow()
|
269
|
-
lines.setElement(0, 1, 'DEBUG')
|
270
|
-
lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
|
271
|
-
lines.newRow()
|
272
|
-
lines.setElement(0, 1, 'TO')
|
273
|
-
lines.setElement(0, 2, `(HASHCODE ${helpers.hashCode(JSON.stringify(helpers.sortJson(context, { depth: 25 })))})`)
|
274
|
-
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
275
|
-
this.logs.push(lines.toString())
|
276
252
|
}
|
277
|
-
|
278
|
-
|
253
|
+
lines.newRow()
|
254
|
+
lines.setElement(0, 1, 'APPLIED')
|
255
|
+
lines.setElement(0, 2, generator.toLabel())
|
256
|
+
lines.newRow()
|
257
|
+
lines.setElement(0, 2, generator.toString())
|
258
|
+
lines.newRow()
|
259
|
+
lines.setElement(0, 1, 'RESULT')
|
260
|
+
lines.setElement(0, 2, generated)
|
261
|
+
lines.newRow()
|
262
|
+
lines.setElement(0, 1, 'STACK')
|
263
|
+
lines.setElement(0, 2, stack)
|
264
|
+
lines.newRow()
|
265
|
+
lines.setElement(0, 1, 'DEBUG')
|
266
|
+
lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
|
267
|
+
lines.newRow()
|
268
|
+
lines.setElement(0, 1, 'TO')
|
269
|
+
lines.setElement(0, 2, `(HASHCODE ${helpers.hashCode(JSON.stringify(helpers.sortJson(context, { depth: 25 })))})`)
|
270
|
+
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
271
|
+
this.logs.push(lines.toString())
|
279
272
|
}
|
273
|
+
applied = true
|
274
|
+
break
|
280
275
|
}
|
281
|
-
args.calls.pop()
|
282
|
-
if (!applied && ((config || {}).config || {}).debug) {
|
283
|
-
const widths = [10, 10, 90]
|
284
|
-
const lines = new Lines(widths)
|
285
|
-
lines.setElement(0, 0, 'Generator')
|
286
|
-
lines.setElement(0, 2, 'No generator applied')
|
287
|
-
lines.newRow()
|
288
|
-
lines.setElement(0, 1, 'STACK')
|
289
|
-
lines.setElement(0, 2, stack)
|
290
|
-
lines.newRow()
|
291
|
-
lines.setElement(0, 1, 'TO')
|
292
|
-
lines.setElement(0, 2, JSON.stringify(context, null, 2))
|
293
|
-
this.logs.push(lines.toString())
|
294
|
-
}
|
295
|
-
contextsPrime.push((config || {}).parenthesized ? "(" + generated + ")" : generated)
|
296
276
|
}
|
297
|
-
|
277
|
+
args.calls.pop()
|
278
|
+
if (!applied && ((config || {}).config || {}).debug) {
|
279
|
+
const widths = [10, 10, 90]
|
280
|
+
const lines = new Lines(widths)
|
281
|
+
lines.setElement(0, 0, 'Generator')
|
282
|
+
lines.setElement(0, 2, 'No generator applied')
|
283
|
+
lines.newRow()
|
284
|
+
lines.setElement(0, 1, 'STACK')
|
285
|
+
lines.setElement(0, 2, stack)
|
286
|
+
lines.newRow()
|
287
|
+
lines.setElement(0, 1, 'TO')
|
288
|
+
lines.setElement(0, 2, JSON.stringify(context, null, 2))
|
289
|
+
this.logs.push(lines.toString())
|
290
|
+
}
|
291
|
+
return ((config || {}).parenthesized ? "(" + generated + ")" : generated)
|
298
292
|
}
|
299
293
|
}
|
300
294
|
|