theprogrammablemind_4wp 7.7.0-beta.0 → 7.7.0-beta.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/client.js CHANGED
@@ -179,11 +179,23 @@ const setupArgs = (args, config, logs, hierarchy) => {
179
179
  args.log = (message) => logs.push(message)
180
180
 
181
181
  args.addAssumedScoped = (args, assumed) => {
182
+ const addAssumed = (args, ...moreAssumed) => {
183
+ return { ...args, assumed: Object.assign({}, (args.assumed || {}), ...moreAssumed) }
184
+ }
185
+
182
186
  args.s = (c) => config.getSemantics(logs).apply(args, c)
183
- args.g = (c) => config.getGenerators(logs).apply(args, c)
184
- args.gp = (c) => config.getGenerators(logs).apply({...args, assumed: {paraphrase: true, isResponse: false, response: false}}, c, {paraphrase: true, isResponse: false, response: false})
185
- args.gr = (c) => config.getGenerators(logs).apply({...args, assumed: {paraphrase: false, isResponse: true}}, { ...c, paraphrase: false, isResponse: true })
186
- args.e = (c) => config.getEvaluator(args.s, args.calls, logs, c)
187
+ args.g = (c, a = {}) => {
188
+ return config.getGenerators(logs).apply(addAssumed(args, a), c, a)
189
+ }
190
+ args.gp = (c, a = {}) => {
191
+ return config.getGenerators(logs).apply(addAssumed(args, a, {paraphrase: true, isResponse: false, response: false}), c, {paraphrase: true, isResponse: false, response: false})
192
+ }
193
+ args.gr = (c, a = {}) => {
194
+ return config.getGenerators(logs).apply(addAssumed(args, a, {paraphrase: false, isResponse: true}), { ...c, paraphrase: false, isResponse: true })
195
+ }
196
+ args.e = (c) => {
197
+ return config.getEvaluator(args.s, args.calls, logs, c)
198
+ }
187
199
  args.gs = gs(args.g)
188
200
  args.gsp = gs(args.gp)
189
201
  args.gsr = gs(args.gr)
@@ -467,8 +479,6 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
467
479
  }
468
480
  // assumed = { paraphrase: true, response: false };
469
481
  assumed = { paraphrase: true, isResponse: false, response: false };
470
- // args.g = (c) => config.getGenerators(json.logs).apply({...args, assumed}, c, assumed)
471
- // args.gs = gs(args.g)
472
482
  if (generateParenthesized) {
473
483
  config.parenthesized = false
474
484
  }
@@ -479,8 +489,6 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
479
489
  paraphrasesParenthesized = config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed)
480
490
  config.parenthesized = false
481
491
  }
482
- // args.g = (c) => config.getGenerators(json.logs).apply(args, c)
483
- // args.gs = gs(args.g)
484
492
  contextsPrime.push(contextPrime)
485
493
  generatedPrime.push(generated)
486
494
  paraphrasesPrime.push(paraphrases)
@@ -617,7 +625,12 @@ const loadInstance = (config, instance) => {
617
625
  if (results.skipSemantics) {
618
626
  config.config.skipSemantics = results.skipSemantics
619
627
  }
620
- processContextsB({ config, hierarchy, json: results/*, generators, semantics */, commandLineArgs: {}, isInstance: `instance${i}`, instance: instance.queries[i] })
628
+ const args = { config, hierarchy, json: results, commandLineArgs: {} }
629
+ if (instance.queries) {
630
+ args.isInstance = `instance${i}`
631
+ args.instance = instance.queries[i]
632
+ }
633
+ processContextsB(args)
621
634
  if (results.skipSemantics) {
622
635
  config.config.skipSemantics = null
623
636
  }
@@ -1241,7 +1254,7 @@ const defaultProcess = ({ config, errorHandler }) => async (promise) => {
1241
1254
  }
1242
1255
 
1243
1256
  // builtTemplate saveInstance
1244
- const rebuildTemplate = async ({ config, target, template, errorHandler = defaultErrorHandler }) => {
1257
+ const rebuildTemplate = async ({ config, target, previousResultss, startOfChanges, template, errorHandler = defaultErrorHandler }) => {
1245
1258
  const accumulators = {
1246
1259
  resultss: [],
1247
1260
  fragments: [],
@@ -1254,7 +1267,7 @@ const rebuildTemplate = async ({ config, target, template, errorHandler = defaul
1254
1267
  finish()
1255
1268
  return
1256
1269
  }
1257
- const { property, hierarchy, query: queryOrExtraConfig, initializer, skipSemantics } = queries.shift()
1270
+ const { property, hierarchy, query: queryOrExtraConfig, previousResults, initializer, skipSemantics } = queries.shift()
1258
1271
  // queries are strings or { query: "blah", development: true/false }
1259
1272
  if (typeof queryOrExtraConfig === 'string' || queryOrExtraConfig.query) {
1260
1273
  let query = queryOrExtraConfig;
@@ -1276,7 +1289,15 @@ const rebuildTemplate = async ({ config, target, template, errorHandler = defaul
1276
1289
  }
1277
1290
  }
1278
1291
  try {
1279
- const results = await _process(config, query.query, {initializer, rebuildingTemplate: true})
1292
+ let results
1293
+ let prMessage = ''
1294
+ if (previousResults && previousResults.query == query.query) {
1295
+ results = previousResults
1296
+ prMessage = ' Using previous results. use -rtf for a hard rebuild of everything on the server side.'
1297
+ loadInstance(config, { resultss: [results] })
1298
+ } else {
1299
+ results = await _process(config, query.query, {initializer, rebuildingTemplate: true})
1300
+ }
1280
1301
  if (config.config.debug) {
1281
1302
  // TODO pass in the error handler like the other ones
1282
1303
  defaultInnerProcess(config, defaultErrorHandler, results)
@@ -1285,9 +1306,9 @@ const rebuildTemplate = async ({ config, target, template, errorHandler = defaul
1285
1306
  console.log(`query "${query.query}". There is ${results.contexts.length} contexts in the results. Make sure its producing the results that you expect.`)
1286
1307
  throw new Error(`query "${query.query}". There is ${results.contexts.length} contexts in the results. Make sure its producing the results that you expect.`)
1287
1308
  } else if (results.paraphrases[0] != query.query) {
1288
- console.log(`query "${query.query}". The paraphrase is different from the query "${results.paraphrases[0]}".`)
1309
+ console.log(`query "${query.query}". The paraphrase is different from the query "${results.paraphrases[0]}".${prMessage}`)
1289
1310
  } else {
1290
- console.log(`query ${query.query}`)
1311
+ console.log(`query "${query.query}".${prMessage}`)
1291
1312
  }
1292
1313
  global.transitoryMode = transitoryMode
1293
1314
  config.config.skipSemantics = null
@@ -1375,7 +1396,13 @@ const rebuildTemplate = async ({ config, target, template, errorHandler = defaul
1375
1396
  }
1376
1397
  let todo = []
1377
1398
  todo = todo.concat((template.initializers || []).map((query) => { return { initializer: true, property: 'resultss', query, skipSemantics: false || query.skipSemantics } }))
1378
- todo = todo.concat((template.queries || []).map((query) => { return { property: 'resultss', query, skipSemantics: false || query.skipSemantics} }))
1399
+ todo = todo.concat((template.queries || []).map((query, index) => {
1400
+ let pr
1401
+ if (index < startOfChanges) {
1402
+ pr = previousResultss[index]
1403
+ }
1404
+ return { property: 'resultss', query, previousResults: pr, skipSemantics: false || query.skipSemantics}
1405
+ }))
1379
1406
  todo = todo.concat((template.fragments || []).map((query) => { return Object.assign({}, toProperties(query), { property: 'fragments', skipSemantics: false }) }))
1380
1407
  todo = todo.concat((template.semantics || []).map((definition) => { return { property: 'semantics', query: `${definition.from}\n${definition.to}`, skipSemantics: true } }))
1381
1408
  await looper(Object.assign([], todo))
@@ -1490,13 +1517,14 @@ const knowledgeModuleImpl = async ({
1490
1517
  parser.add_argument('-tnp', '--testNoParenthesized', { action: 'store_true', help: 'Don\' check parenthesized differences for the tests' })
1491
1518
  parser.add_argument('-n', '--count', { help: 'Number of times to run the tests. Default is one. Use this to check for flakey test. If possible the system will print out a message with the word "hint" suggesting how to fix the problem' })
1492
1519
  // parser.add_argument('-b', '--build', { help: 'Specify the template file name of the form <kmName>. There should be a file called <baseKmName>.<kmName>.template.json with the queries to run. For example { queries: [...] }. The template file will be run and generate an instantiation called <baseKmName>.<kmName>.instance.json and a file called <kmName>.js that will load the template file (this is file generated only if not already existing) and a test file called <KmName>.tests.json. This can then be loaded into an instance of the current knowledge module to setup initial conditions.' })
1493
- parser.add_argument('-rt', '--rebuildTemplate', { action: 'store_true', help: 'Force a template rebuild' })
1520
+ parser.add_argument('-rt', '--rebuildTemplate', { action: 'store_true', help: 'Force a template rebuild. Using optimization where if the query/config has not changed it will use the previous value. One there is a change all subsequence query/configs will be run.' })
1521
+ parser.add_argument('-rtf', '--rebuildTemplateFull', { action: 'store_true', help: 'Force a template rebuild. Skip the optimization' })
1494
1522
  parser.add_argument('-l', '--loop', { action: 'store_true', help: 'Run a loop so that multiply queries may be run' })
1495
1523
  parser.add_argument('-i', '--info', { action: 'store_true', help: 'Print meta-data for the module' })
1496
1524
  parser.add_argument('-v', '--vimdiff', { action: 'store_true', help: 'For failures run vimdiff' })
1497
1525
  parser.add_argument('-g', '--greg', { action: 'store_true', help: 'Set the server to be localhost so I can debug stuff' })
1498
1526
  parser.add_argument('-cl', '--checkForLoop', { nargs: "?", help: 'Check for loops in the priorities, Optional argument is list of operator keys to consider. For example [["banana", 0], ["food", 1]]' })
1499
- parser.add_argument('-r', '--retrain', { action: 'store_true', help: 'Get the server to retrain the neural nets' })
1527
+ parser.add_argument('-r', '--reset', { action: 'store_true', help: 'Get the server to bypass the cache and rebuild everything' })
1500
1528
  parser.add_argument('-q', '--query', { help: 'Run the specified query' })
1501
1529
  parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
1502
1530
  parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
@@ -1521,6 +1549,10 @@ const knowledgeModuleImpl = async ({
1521
1549
  const args = parser.parse_args()
1522
1550
  args.count = args.count || 1
1523
1551
 
1552
+ if (args.rebuildTemplateFull) {
1553
+ args.rebuildTemplate = true
1554
+ }
1555
+
1524
1556
  if (args.parenthesized) {
1525
1557
  config.parenthesized = true
1526
1558
  }
@@ -1711,23 +1743,33 @@ const knowledgeModuleImpl = async ({
1711
1743
  checkTemplate(template)
1712
1744
 
1713
1745
  if (template) {
1714
- const needsRebuild = config.needsRebuild(template.template, template.instance, options)
1715
- if (needsRebuild) {
1746
+ let needsRebuild
1747
+ if (args.rebuildTemplate && !args.rebuildTemplateFull) {
1748
+ // get the startOfChanges for the partial rebuild
1749
+ needsRebuild = config.needsRebuild(template.template, template.instance, { ...options, rebuild: false })
1750
+ } else {
1751
+ // do a check or full rebuild
1752
+ needsRebuild = config.needsRebuild(template.template, template.instance, options)
1753
+ }
1754
+
1755
+ if (needsRebuild.needsRebuild) {
1756
+ if (needsRebuild.previousResultss) {
1757
+ console.log("Rebuild using the optimization to use previous results until a change is hit. For a full rebuild use -rtf")
1758
+ }
1716
1759
  console.log(`This module "${config.name}" needs rebuilding all other arguments will be ignored. Try again after the template is rebuilt.`)
1717
1760
  options.rebuild = true
1718
1761
  config.config.rebuild = true
1719
1762
  }
1720
1763
  try {
1721
- config.load(template.template, template.instance, { rebuild: needsRebuild })
1764
+ config.load(template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
1722
1765
  } catch( e ) {
1723
- debugger
1724
1766
  console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}`)
1725
1767
  runtime.process.exit(-1)
1726
1768
  }
1727
1769
  if (!args.query) {
1728
1770
  printConfig()
1729
1771
  }
1730
- if (needsRebuild) {
1772
+ if (needsRebuild.needsRebuild) {
1731
1773
  return
1732
1774
  }
1733
1775
  }
@@ -1890,7 +1932,7 @@ const knowledgeModuleImpl = async ({
1890
1932
  if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
1891
1933
  console.log('use -v arg to write files expected.json and actual.json in the current directory for detailed comparison. Or do -s and then git diff the changes.')
1892
1934
  // console.log(JSON.stringify(contexts))
1893
- console.log('**************************** ERRORS ************************')
1935
+ console.log('**************************** THERE WERE ERRORS ************************')
1894
1936
  }
1895
1937
  }
1896
1938
  }
@@ -1976,7 +2018,7 @@ const knowledgeModuleImpl = async ({
1976
2018
  }
1977
2019
 
1978
2020
  if (template) {
1979
- if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess })) {
2021
+ if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess }).needsRebuild) {
1980
2022
  const error = `This module "${config.name}" cannot be used because the instance file needs rebuilding. Run on the command line with no arguments or the -rt argument to rebuild.`
1981
2023
  throw new Error(error)
1982
2024
  }
package/package.json CHANGED
@@ -12,6 +12,7 @@
12
12
  "scripts": {
13
13
  "to:debug": "node inspect node_modules/.bin/jest --runInBand -t NEO23",
14
14
  "test:debug": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
15
+ "td": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
15
16
  "tod": "node inspect node_modules/.bin/jest --runInBand -t NEO23",
16
17
  "lint:fix": "eslint \"**/*.js\" --fix",
17
18
  "lint": "eslint \"**/*.js\"",
@@ -64,6 +65,6 @@
64
65
  "json-stable-stringify": "^1.0.1",
65
66
  "node-fetch": "^2.6.1"
66
67
  },
67
- "version": "7.7.0-beta.0",
68
+ "version": "7.7.0-beta.2",
68
69
  "license": "ISC"
69
70
  }
package/src/config.js CHANGED
@@ -965,7 +965,7 @@ class Config {
965
965
  }
966
966
 
967
967
  // { rebuild: false, isModule: false }
968
- needsRebuild(template, instance, options) {
968
+ needsRebuild (template, instance, options) {
969
969
  if (options.rebuild) {
970
970
  return true
971
971
  }
@@ -1058,7 +1058,21 @@ class Config {
1058
1058
  return elements.map( toCanonicalQuery )
1059
1059
  }
1060
1060
 
1061
- const sameQueries = helpers.safeEquals(toCanonicalQueries(template.queries || []).map(helpers.updateQueries), toCanonicalQueries(instance.queries || []))
1061
+ const templateQueries = toCanonicalQueries(template.queries || []).map(helpers.updateQueries)
1062
+ const instanceQueries = toCanonicalQueries(instance.queries || [])
1063
+ let sameQueries = true
1064
+ let startOfChanges;
1065
+ for (let iq = 0; iq < templateQueries.length; ++iq) {
1066
+ if (!helpers.safeEquals(templateQueries[iq], instanceQueries[iq])) {
1067
+ sameQueries = false
1068
+ startOfChanges = iq
1069
+ }
1070
+ }
1071
+ // things were deleted case
1072
+ if (templateQueries.length < instanceQueries.length) {
1073
+ startOfChanges = instanceQueries.length
1074
+ }
1075
+ // const sameQueries = helpers.safeEquals(toCanonicalQueries(template.queries || []).map(helpers.updateQueries), toCanonicalQueries(instance.queries || []))
1062
1076
 
1063
1077
  const debug = false
1064
1078
  if (debug) {
@@ -1067,16 +1081,20 @@ class Config {
1067
1081
  debugger
1068
1082
  debugger
1069
1083
  }
1070
- console.log("instance", instance)
1084
+ // console.log("instance", instance)
1071
1085
  console.log("sameQueries", sameQueries)
1072
1086
  console.log("sameFragments", sameFragments)
1073
- console.log("templateFragments", templateFragments)
1074
- console.log("instanceFragments", instanceFragments)
1075
- console.log('template.queries', JSON.stringify(toCanonicalQueries(template.queries || []).map(helpers.updateQueries), null, 2))
1076
- console.log("instance.queries", JSON.stringify(toCanonicalQueries(instance.queries || []), null, 2))
1087
+ // console.log("templateFragments", templateFragments)
1088
+ // console.log("instanceFragments", instanceFragments)
1089
+ // console.log('template.queries', JSON.stringify(toCanonicalQueries(template.queries || []).map(helpers.updateQueries), null, 2))
1090
+ // console.log("instance.queries", JSON.stringify(toCanonicalQueries(instance.queries || []), null, 2))
1077
1091
  }
1078
1092
  }
1079
- return !(instance && sameQueries && sameFragments)
1093
+ if (startOfChanges || instance.resultss) {
1094
+ return { needsRebuild: !(instance && sameQueries && sameFragments), startOfChanges, previousResultss: instance.resultss }
1095
+ } else {
1096
+ return { needsRebuild: !(instance && sameQueries && sameFragments) }
1097
+ }
1080
1098
  }
1081
1099
 
1082
1100
  validifyTemplate (template) {
@@ -1097,7 +1115,7 @@ class Config {
1097
1115
  }
1098
1116
 
1099
1117
  // loadTemplate
1100
- load (template, instance, options = { rebuild: false } ) {
1118
+ load (template, instance, options = { rebuild: false, previousResultss: undefined, startOfChanges: undefined } ) {
1101
1119
  this.validifyTemplate(template)
1102
1120
  instance.template = template
1103
1121
  this.logs.push(`loading template for ${this.name}`)
@@ -1105,7 +1123,7 @@ class Config {
1105
1123
  // TODO fix beforeQuery
1106
1124
  template = { fragments: [], queries: [], ...template }
1107
1125
  template.fragments = template.fragments.concat(this.dynamicFragments)
1108
- client.rebuildTemplate({ config: this, target: this.name, beforeQuery: () => {}, template, ...options })
1126
+ client.rebuildTemplate({ config: this, target: this.name, previousResultss: options.previousResultss, startOfChanges: options.startOfChanges, beforeQuery: () => {}, template, ...options })
1109
1127
  } else {
1110
1128
  // no change
1111
1129
  // this.initInstances.push({ ...instance, name: config.name })
package/src/generators.js CHANGED
@@ -179,7 +179,6 @@ class Generators {
179
179
  const objects = args.objects
180
180
  const hierarchy = args.hierarchy
181
181
  const response = args.response
182
-
183
182
 
184
183
  // args = { ...args, ...args.getAssumedScoped(assumed) }
185
184
  args.addAssumedScoped(args, assumed)