theprogrammablemind_4wp 9.3.0-beta.5 → 9.3.0-beta.50

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/client.js CHANGED
@@ -260,7 +260,7 @@ const throwErrorHandler = (error) => {
260
260
  throw error
261
261
  }
262
262
 
263
- const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
263
+ const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
264
264
  if (credentials) {
265
265
  config.server(credentials.server, credentials.key)
266
266
  }
@@ -315,7 +315,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
315
315
  if (queries.length === 0) {
316
316
  break
317
317
  }
318
-
318
+ config.updateData(data)
319
319
  data.utterance = queries[0]
320
320
  data.start_counter = startCounter
321
321
  let json = await doWithRetries(retries, url, queryParams, data)
@@ -345,13 +345,14 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
345
345
  throw json
346
346
  } else {
347
347
  let clientSideTime
348
+ let start
348
349
  if (isTest) {
349
- const start = runtime.performance.performance.now()
350
+ start = runtime.performance.performance.now()
350
351
  }
351
352
  const summary = { summaries: json.summaries, length: json.contexts.length }
352
353
  summaries.push(summary)
353
354
  const { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
354
- await processContextsB({ isTest, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
355
+ await processContextsB({ isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
355
356
  if (isTest) {
356
357
  const end = runtime.performance.performance.now()
357
358
  clientSideTime = end - start
@@ -484,7 +485,7 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
484
485
  setupArgs(args, config)
485
486
  await testConfig.initializer(args)
486
487
  }
487
- const result = await _process(config, test, { errorHandler, isTest: true })
488
+ const result = await _process(config, test, { errorHandler, isTest: true, isProcess: true, isModule: false })
488
489
  result.query = test
489
490
  if (debug) {
490
491
  defaultInnerProcess(config, errorHandler, result)
@@ -623,7 +624,7 @@ const saveTest = async (testFile, config, test, expected, testConfig, saveDevelo
623
624
  await config.rebuild()
624
625
  const objects = getObjects(config.config.objects)(config.uuid)
625
626
  console.log(test)
626
- const result = await _process(config, test, { isTest: true })
627
+ const result = await _process(config, test, { isTest: true, isProcess: true, isModule: true })
627
628
  // const actualObjects = config.config.objects
628
629
  const actualConfig = getConfigForTest(config, testConfig)
629
630
  const args = {
@@ -1879,7 +1880,7 @@ const knowledgeModuleImpl = async ({
1879
1880
  global.beforeObjects = _.cloneDeep(objects)
1880
1881
  }
1881
1882
  try {
1882
- await processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
1883
+ await processResults(_process(config, args.query, { commandLineArgs: args, isProcess, isModule: !isProcess, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
1883
1884
  } catch (error) {
1884
1885
  console.log('Error', error)
1885
1886
  }
@@ -1908,8 +1909,18 @@ const knowledgeModuleImpl = async ({
1908
1909
  loadForTesting = true
1909
1910
  }
1910
1911
  }
1912
+ if (template) {
1913
+ try {
1914
+ await config.load(rebuildTemplate, template.template, template.instance)
1915
+ } catch (e) {
1916
+ errorHandler(e)
1917
+ }
1918
+ }
1919
+
1911
1920
  // remove test only stuff
1912
1921
  if (!isProcess && !loadForTesting) {
1922
+ config.removeDevelopmentElements(config.config)
1923
+ /*
1913
1924
  config.config.operators = config.config.operators.filter((operator) => {
1914
1925
  if (operator.development) {
1915
1926
  return false
@@ -1924,21 +1935,14 @@ const knowledgeModuleImpl = async ({
1924
1935
  return true
1925
1936
  }
1926
1937
  })
1927
- }
1928
-
1929
- if (template) {
1930
- try {
1931
- await config.load(rebuildTemplate, template.template, template.instance)
1932
- } catch (e) {
1933
- errorHandler(e)
1934
- }
1938
+ */
1935
1939
  }
1936
1940
  }
1937
1941
 
1938
1942
  // no cache 21 minutes + rebuild fails "node tester_rebuild -m colors"
1939
1943
  // cache okay
1940
- const createConfigExport = async () => {
1941
- if (createConfig.cached) {
1944
+ const createConfigExport = async (useCache = true) => {
1945
+ if (useCache && createConfig.cached) {
1942
1946
  return createConfig.cached
1943
1947
  }
1944
1948
  const config = await createConfig()
package/package.json CHANGED
@@ -69,6 +69,6 @@
69
69
  "sort-json": "^2.0.0",
70
70
  "uuid": "^8.3.2"
71
71
  },
72
- "version": "9.3.0-beta.5",
72
+ "version": "9.3.0-beta.50",
73
73
  "license": "UNLICENSED"
74
74
  }
package/src/config.js CHANGED
@@ -473,7 +473,7 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
473
473
  if (moreConfig.bridges) {
474
474
  moreConfig.bridges = moreConfig.bridges.map((bridge) => {
475
475
  bridge = { ...bridge }
476
- const valid = ['after', 'conditional', 'associations', 'before', 'bridge', 'development', 'skipable', 'return_type_selector', 'evaluator', 'evaluators', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'operator', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
476
+ const valid = ['after', 'conditional', 'associations', 'before', 'bridge', 'disabled', 'development', 'skipable', 'return_type_selector', 'evaluator', 'evaluators', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'operator', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
477
477
  'level', 'optional', 'selector', 'semantic', 'semantics', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid']
478
478
  helpers.validProps(valid, bridge, 'bridge')
479
479
  handleBridgeProps(baseConfig, bridge, { addFirst, uuid })
@@ -1055,8 +1055,8 @@ class Config {
1055
1055
 
1056
1056
  // value is in response field
1057
1057
  // TODO maybe generalize out query+evaluate along the lines of set value and set reference
1058
- async getEvaluator (s, calls, log, context) {
1059
- const instance = await s({ ...context, evaluate: true })
1058
+ async getEvaluator (s, calls, log, context, args) {
1059
+ const instance = await s({ ...args, ...context, evaluate: true })
1060
1060
  calls.touch(instance)
1061
1061
  if (!instance.evalue && !instance.verbatim && !instance.value) {
1062
1062
  this.warningNotEvaluated(log, context)
@@ -1214,43 +1214,6 @@ class Config {
1214
1214
  }
1215
1215
  return bridge
1216
1216
  })
1217
- } else {
1218
- /* done in updateQueries now
1219
- config.generators = (config.generators || []).map((generator) => {
1220
- generator = { ...generator }
1221
- delete generator.where
1222
- generator.match = generator.match.toString()
1223
- generator.apply = generator.apply.toString()
1224
- return generator
1225
- })
1226
- config.semantics = (config.semantics || []).map((semantic) => {
1227
- semantic = { ...semantic }
1228
- delete semantic.where
1229
- semantic.match = semantic.match.toString()
1230
- semantic.apply = semantic.apply.toString()
1231
- return semantic
1232
- })
1233
- config.bridges = (config.bridges || []).map((bridge) => {
1234
- bridge = { ...bridge }
1235
- delete bridge.where
1236
- if (bridge.generatorp) {
1237
- bridge.generatorp = bridge.generatorp.toString()
1238
- }
1239
- if (bridge.generatorr) {
1240
- bridge.generatorr = bridge.generatorr.toString()
1241
- }
1242
- if (bridge.generatorpr) {
1243
- bridge.generatorpr = bridge.generatorpr.toString()
1244
- }
1245
- if (bridge.evaluator) {
1246
- bridge.evaluator = bridge.evaluator.toString()
1247
- }
1248
- if (bridge.semantic) {
1249
- bridge.semantic = bridge.semantic.toString()
1250
- }
1251
- return bridge
1252
- })
1253
- */
1254
1217
  }
1255
1218
  return config
1256
1219
  }
@@ -1328,6 +1291,15 @@ class Config {
1328
1291
  }
1329
1292
  }
1330
1293
 
1294
+ addEnable (key) {
1295
+ this._enable.push(key)
1296
+ }
1297
+
1298
+ updateData (data) {
1299
+ data.enable = this._enable
1300
+ this._enable = []
1301
+ }
1302
+
1331
1303
  toData (data) {
1332
1304
  Object.assign(data, this.config)
1333
1305
  // greg99 delete data.objects
@@ -1577,8 +1549,14 @@ class Config {
1577
1549
  }
1578
1550
 
1579
1551
  removeSemantic (deleteSemantic) {
1580
- const id = deleteSemantic.id || deleteSemantic
1581
- const todo = [id]
1552
+ if (!Array.isArray(deleteSemantic)) {
1553
+ deleteSemantic = [deleteSemantic]
1554
+ }
1555
+ const todo = []
1556
+ for (const ds of deleteSemantic) {
1557
+ const id = ds.id || ds
1558
+ todo.push(id)
1559
+ }
1582
1560
  const seen = new Set()
1583
1561
 
1584
1562
  while (todo.length > 0) {
@@ -1591,6 +1569,7 @@ class Config {
1591
1569
  if (index === -1) {
1592
1570
  continue
1593
1571
  }
1572
+ // TODO change to tiedIs(s)
1594
1573
  for (const tied_id of this.config.semantics[index].tied_ids || []) {
1595
1574
  if (!seen.has(tied_id)) {
1596
1575
  todo.push(tied_id)
@@ -1951,6 +1930,7 @@ class Config {
1951
1930
  config.priorities = config.priorities || []
1952
1931
  }
1953
1932
 
1933
+ this._enable = []
1954
1934
  this._apiKMs = apiKMs
1955
1935
 
1956
1936
  this.clientProcess = clientProcess
@@ -2190,7 +2170,6 @@ class Config {
2190
2170
  this._apiConstructor = constructor
2191
2171
  if (this._apiKMs.length > 0) {
2192
2172
  for (const name of this._apiKMs) {
2193
- debugger
2194
2173
  this.km(name)._api = value[name]
2195
2174
  }
2196
2175
  } else {
@@ -2802,6 +2781,10 @@ class Config {
2802
2781
  }
2803
2782
  }
2804
2783
 
2784
+ if (this.isModule) {
2785
+ this.removeDevelopmentElements(this.config)
2786
+ }
2787
+
2805
2788
  this.valid()
2806
2789
  this.checks()
2807
2790
  }
@@ -3187,7 +3170,7 @@ class Config {
3187
3170
  }
3188
3171
 
3189
3172
  // TODO get rid of useOldVersion arg
3190
- addInternal (more, { uuid, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
3173
+ addInternal (more, { uuid, km, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
3191
3174
  validConfigProps(more)
3192
3175
  if (more instanceof Config) {
3193
3176
  more.initialize({ force: false })
@@ -3204,6 +3187,20 @@ class Config {
3204
3187
  handleCalculatedProps(this, more, { addFirst, uuid })
3205
3188
  applyUUID(more, uuid || this._uuid)
3206
3189
  }
3190
+ if (km) {
3191
+ if (more.semantics) {
3192
+ more.semantics.map((s) => s.km = km)
3193
+ }
3194
+ if (more.generators) {
3195
+ more.generators.map((g) => g.km = km)
3196
+ }
3197
+ }
3198
+ const normalizeIsA = (edge) => {
3199
+ if (edge.length == 3 || edge.parent || edge.child) {
3200
+ return edge
3201
+ }
3202
+ return [...edge, false]
3203
+ }
3207
3204
  for (const key of Object.keys(more)) {
3208
3205
  const value = more[key]
3209
3206
  // TODO remove name and description on the config bag
@@ -3247,9 +3244,9 @@ class Config {
3247
3244
  const hierarchy = this.config.words.hierarchy
3248
3245
  const moreHierarchy = more.words.hierarchy
3249
3246
  if (addFirst) {
3250
- this.config.words.hierarchy = moreHierarchy.concat(hierarchy)
3247
+ this.config.words.hierarchy = moreHierarchy.concat(hierarchy.map(normalizeIsA))
3251
3248
  } else {
3252
- this.config.words.hierarchy = hierarchy.concat(moreHierarchy)
3249
+ this.config.words.hierarchy = hierarchy.concat(moreHierarchy.map(normalizeIsA))
3253
3250
  }
3254
3251
  }
3255
3252
  } else if (key === 'name') {
@@ -3321,7 +3318,9 @@ class Config {
3321
3318
  // console.log('more', JSON.stringify(more, null, 2))
3322
3319
  // hierarchy must update in place and does not care about the list order
3323
3320
  if (key === 'hierarchy') {
3324
- this.config[key].push(...more[key])
3321
+ const moreEdges = more[key].map(normalizeIsA)
3322
+ this.config[key].push(...moreEdges)
3323
+ this.hierarchy.addEdges(moreEdges)
3325
3324
  } else {
3326
3325
  if (addFirst) {
3327
3326
  this.config[key] = more[key].concat(this.config[key])
@@ -86,6 +86,9 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
86
86
  args.objects = config.get('objects')
87
87
  args.getObjects = getObjects(args.objects)
88
88
  }
89
+ args.enable = (key) => {
90
+ config.addEnable(key)
91
+ }
89
92
  if (args.uuid) {
90
93
  args.objects = args.getObjects(args.uuid)
91
94
  }
@@ -140,7 +143,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
140
143
  if (!c) {
141
144
  return
142
145
  }
143
- return config.getEvaluator(args.s, args.calls, logs, c)
146
+ return config.getEvaluator(args.s, args.calls, logs, c, { isModule: args.isModule, isProcess: args.isProcess })
144
147
  }
145
148
  args.gs = gs(args.g)
146
149
  args.gsp = gs(args.gp)
@@ -257,18 +260,18 @@ const setupProcessB = ({ config, initializer, allowDelta = false, rebuildingTemp
257
260
  const setupContexts = (rawContexts) => {
258
261
  let first = true
259
262
  const contexts = []
260
- contexts.push({ marker: 'controlStart', controlRemove: true })
263
+ contexts.push({ marker: 'controlStart', controlRemove: true, isControl: true })
261
264
  let previous
262
265
  for (const context of rawContexts) {
263
266
  if (first) {
264
267
  first = false
265
268
  } else {
266
- contexts.push({ marker: 'controlBetween', controlRemove: true, previous })
269
+ contexts.push({ marker: 'controlBetween', controlRemove: true, isControl: true, previous })
267
270
  }
268
271
  contexts.push(context)
269
272
  previous = context
270
273
  }
271
- contexts.push({ marker: 'controlEnd', controlRemove: true, previous })
274
+ contexts.push({ marker: 'controlEnd', controlRemove: true, isControl: true, previous })
272
275
 
273
276
  let _index = 0
274
277
  const id = (context) => {
@@ -279,7 +282,7 @@ const setupContexts = (rawContexts) => {
279
282
  return contexts
280
283
  }
281
284
 
282
- const processContextsB = async ({ config, hierarchy, semantics, generators, json, isTest, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate }) => {
285
+ const processContextsB = async ({ config, hierarchy, semantics, generators, json, isTest, isProcess, isModule, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate }) => {
283
286
  // TODO fix this name to contextsPrime
284
287
  const contextsPrime = []
285
288
  const generatedPrime = []
@@ -290,7 +293,7 @@ const processContextsB = async ({ config, hierarchy, semantics, generators, json
290
293
  const contexts = setupContexts(json.contexts)
291
294
 
292
295
  const objects = config.get('objects')
293
- const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance, contexts }
296
+ const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance, contexts, isProcess, isModule }
294
297
  if (!json.logs) {
295
298
  json.logs = []
296
299
  }
@@ -441,14 +444,14 @@ const loadInstance = async (config, instance) => {
441
444
  */
442
445
 
443
446
  // const { /* data, generators, semantics, */ hierarchy } = setupProcessB({ config })
444
- const hierarchy = config.hierarchy
445
447
  for (const i in (instance.resultss || [])) {
448
+ const hierarchy = config.hierarchy
446
449
  const results = instance.resultss[i]
447
450
  if (results.extraConfig) {
448
451
  // config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
449
452
  const uuid = config.nameToUUID(instance.name)
450
453
  // used to do a CLONE
451
- config.addInternal(instance.template.configs[i], { uuid, addFirst: true, handleCalculatedProps: true })
454
+ config.addInternal(instance.template.configs[i], { uuid, km: instance.name, addFirst: true, handleCalculatedProps: true })
452
455
  } else if (results.apply) {
453
456
  const objects = getObjects(config.get('objects'))(config.uuid)
454
457
  const args = { objects, getObjects: getObjects(objects) }
@@ -468,6 +471,8 @@ const loadInstance = async (config, instance) => {
468
471
  const args = { config, hierarchy, json: results, commandLineArgs: {}, forTemplate: true }
469
472
  args.isInstance = `instance${i}`
470
473
  args.instance = ''
474
+ args.isProcess = !config.isModule
475
+ args.isModule = !!config.isModule
471
476
  await processContextsB(args)
472
477
  if (results.skipSemantics) {
473
478
  config.config.skipSemantics = null
package/src/debug.js CHANGED
@@ -31,12 +31,12 @@ const wasHit = (name) => {
31
31
  return hits[name]
32
32
  }
33
33
 
34
- const counter = (name, breakAt = [], debugBreak = true) => {
34
+ const counter = (name, { breakAt = [], debugBreak = true, tag = '' } = {}) => {
35
35
  if (!counters[name]) {
36
36
  counters[name] = 0
37
37
  }
38
38
  counters[name] += 1
39
- console.log(`counters[${name}] = ${counters[name]}`)
39
+ console.log(`counters[${name}] = ${counters[name]} ${tag}`)
40
40
  unhit(name)
41
41
  if (Array.isArray(breakAt) && breakAt.includes(counters[name])) {
42
42
  if (debugBreak) {
package/src/helpers.js CHANGED
@@ -310,6 +310,7 @@ const validProps = (valids, object, type) => {
310
310
  }
311
311
  }
312
312
  if (!okay) {
313
+ valids.sort()
313
314
  throw new Error(`Unknown property "${prop}" in the ${type}. Valid properties are ${valids.join(', ')}. The ${type} is ${JSON.stringify(object)}`)
314
315
  }
315
316
  }
package/src/project.js CHANGED
@@ -3,6 +3,9 @@ const project = (object, filter) => {
3
3
  if (!object) {
4
4
  return
5
5
  }
6
+ if (typeof object === 'string' || typeof object === 'number') {
7
+ return object
8
+ }
6
9
 
7
10
  const projection = {}
8
11
  const set = (property, value) => {