theprogrammablemind 7.12.3 → 7.12.4

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.
Files changed (3) hide show
  1. package/client.js +39 -24
  2. package/package.json +1 -1
  3. package/src/config.js +71 -52
package/client.js CHANGED
@@ -89,12 +89,12 @@ const sameJSON = (json1, json2) => {
89
89
  return JSON.stringify(sjson1) == JSON.stringify(sjson2)
90
90
  }
91
91
 
92
- const vimdiff = (actualJSON, expectedJSON) => {
92
+ const vimdiff = (actualJSON, expectedJSON, title) => {
93
93
  const path = '.'
94
94
  const actual = sortJson(actualJSON, { depth: 25 })
95
- runtime.fs.writeFileSync(`${path}/actual.json`, JSON.stringify(actual, 0, 2))
95
+ runtime.fs.writeFileSync(`${path}/actual.json`, JSON.stringify({ title, actual}, 0, 2))
96
96
  const expected = sortJson(expectedJSON, { depth: 25 })
97
- runtime.fs.writeFileSync(`${path}/expected.json`, JSON.stringify(expected, 0, 2))
97
+ runtime.fs.writeFileSync(`${path}/expected.json`, JSON.stringify({ title, expected}, 0, 2))
98
98
  // console.log(`vimdiff ${path}/actual.json ${path}/expected.json`)
99
99
  {
100
100
  const editor = runtime.process.env.EDITOR || 'vimdiff'
@@ -196,7 +196,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
196
196
 
197
197
  args.addAssumedScoped = (args, assumed) => {
198
198
  const addAssumed = (args, ...moreAssumed) => {
199
- return { ...args, assumed: Object.assign({}, (args.assumed || {}), ...moreAssumed) }
199
+ return { ...args, assumed: Object.assign({}, assumed, (args.assumed || {}), ...moreAssumed) }
200
200
  }
201
201
 
202
202
  args.s = (c) => config.getSemantics(logs).apply(args, c)
@@ -638,7 +638,9 @@ const loadInstance = (config, instance) => {
638
638
  // config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
639
639
  // config.addInternal(config.template.queries[i], { handleCalculatedProps: true } )
640
640
  const uuid = config.nameToUUID(instance.name)
641
- config.addInternal(_.cloneDeep(instance.template.queries[i]), { uuid, addFirst: true, handleCalculatedProps: true })
641
+ // used to do a CLONE
642
+ // config.addInternal(_.cloneDeep(instance.template.queries[i]), { uuid, addFirst: true, handleCalculatedProps: true })
643
+ config.addInternal(instance.template.queries[i], { uuid, addFirst: true, handleCalculatedProps: true })
642
644
  } else if (results.apply) {
643
645
  const objects = config.get('objects')
644
646
  const args = { objects, getObjects: getObjects(objects) }
@@ -1464,6 +1466,7 @@ const knowledgeModuleImpl = async ({
1464
1466
  errorHandler = defaultErrorHandler,
1465
1467
  process: processResults = defaultProcess,
1466
1468
  stopAtFirstFailure = true,
1469
+ acceptsAdditionalConfig = false,
1467
1470
  ...rest
1468
1471
  } = {}) => {
1469
1472
  /*
@@ -1843,34 +1846,33 @@ const knowledgeModuleImpl = async ({
1843
1846
  if (results.length > 0) {
1844
1847
  let headerShown = false
1845
1848
 
1846
- let errorCount = 0
1849
+ let hasError = false
1847
1850
  for (const result of results) {
1848
- let hasError = false
1849
1851
  if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
1850
- hasError = true
1852
+ result.hasError = true
1851
1853
  }
1852
1854
  if (!args.testNoParenthesized) {
1853
1855
  if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
1854
- hasError = true
1856
+ result.hasError = true
1855
1857
  }
1856
1858
  if (JSON.stringify(result.expected.generatedParenthesized) !== JSON.stringify(result.actual.generatedParenthesized)) {
1857
- hasError = true
1859
+ result.hasError = true
1858
1860
  }
1859
1861
  }
1860
1862
  if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
1861
- hasError = true
1863
+ result.hasError = true
1862
1864
  }
1863
1865
  if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
1864
- hasError = true
1866
+ result.hasError = true
1865
1867
  }
1866
1868
  if (!sameJSON(result.expected.checkedContexts, result.actual.checkedContexts)) {
1867
- hasError = true
1869
+ result.hasError = true
1868
1870
  }
1869
- if (hasError) {
1870
- errorCount += 1
1871
+ if (result.hasError) {
1872
+ hasError = true
1871
1873
  }
1872
1874
  }
1873
- const hasError = errorCount > 0
1875
+
1874
1876
  if (hasError) {
1875
1877
  console.log('**************************** ERRORS ************************')
1876
1878
  for (const result of results) {
@@ -1885,21 +1887,20 @@ const knowledgeModuleImpl = async ({
1885
1887
  newError = true
1886
1888
  headerShown = true
1887
1889
  if (args.vimdiff) {
1888
- vimdiff(result.actual.paraphrasesParenthesized, result.expected.paraphrasesParenthesized)
1890
+ vimdiff(actual, expected, `"${result.utterance}" - ${label}`)
1889
1891
  }
1890
- errorCount += 1
1892
+ result.hasError = true
1891
1893
  }
1892
1894
  }
1893
1895
  show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
1894
1896
  if (!args.testNoParenthesized) {
1895
1897
  show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
1896
1898
  }
1897
- /*
1898
- }
1899
1899
  show('responses', result.expected.responses, result.actual.responses)
1900
1900
  if (!args.testNoParenthesized) {
1901
1901
  show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
1902
1902
  }
1903
+ /*
1903
1904
  if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
1904
1905
  if (!headerShown) {
1905
1906
  console.log(' Failure')
@@ -1972,7 +1973,13 @@ const knowledgeModuleImpl = async ({
1972
1973
  if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
1973
1974
  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.')
1974
1975
  // console.log(JSON.stringify(contexts))
1975
- console.log(`**************************** THERE WERE ${errorCount} ERRORS ************************`)
1976
+ let errorCount = 0
1977
+ for (const result of results) {
1978
+ if (result.hasError) {
1979
+ errorCount += 1
1980
+ }
1981
+ }
1982
+ console.log(`**************************** THERE WERE ${errorCount} TEST FAILURES ************************`)
1976
1983
  }
1977
1984
  }
1978
1985
  }
@@ -2072,11 +2079,16 @@ const knowledgeModuleImpl = async ({
2072
2079
  }
2073
2080
  }
2074
2081
 
2075
- createConfigExport = () => {
2082
+ createConfigExport = (additionalConfig) => {
2076
2083
  if (createConfig.cached) {
2077
2084
  return createConfig.cached
2078
2085
  }
2079
- const config = createConfig()
2086
+ const config = createConfig(acceptsAdditionalConfig ? additionalConfig : null)
2087
+ if (!acceptsAdditionalConfig && additionalConfig) {
2088
+ config.stop_auto_rebuild()
2089
+ additionalConfig(config)
2090
+ config.restart_auto_rebuild()
2091
+ }
2080
2092
  initConfig(config)
2081
2093
  // config.rebuild({ isModule: true })
2082
2094
  createConfig.cached = config
@@ -2132,7 +2144,10 @@ function w (func) {
2132
2144
  }
2133
2145
 
2134
2146
  const knowledgeModule = async (...args) => {
2135
- await knowledgeModuleImpl(...args).catch((e) => console.error(e))
2147
+ await knowledgeModuleImpl(...args).catch((e) => {
2148
+ console.error(e)
2149
+ process.exit(-1)
2150
+ })
2136
2151
  }
2137
2152
 
2138
2153
  module.exports = {
package/package.json CHANGED
@@ -65,6 +65,6 @@
65
65
  "json-stable-stringify": "^1.0.1",
66
66
  "node-fetch": "^2.6.1"
67
67
  },
68
- "version": "7.12.3",
68
+ "version": "7.12.4",
69
69
  "license": "UNLICENSED"
70
70
  }
package/src/config.js CHANGED
@@ -1742,6 +1742,15 @@ class Config {
1742
1742
  this.addedArgss.push(moreArgs)
1743
1743
  }
1744
1744
 
1745
+ stop_auto_rebuild() {
1746
+ this._stop_auto_rebuild = true
1747
+ }
1748
+
1749
+ restart_auto_rebuild() {
1750
+ this._stop_auto_rebuild = false
1751
+ this.rebuild()
1752
+ }
1753
+
1745
1754
  getAddedArgs (args) {
1746
1755
  for (let addedArgs of this.addedArgss) {
1747
1756
  addedArgs = addedArgs(args)
@@ -2250,6 +2259,9 @@ class Config {
2250
2259
 
2251
2260
  // rebuild ({ isModule: mainIsModule = false } = {}) {
2252
2261
  rebuild ({ isModule: mainIsModule } = {}) {
2262
+ if (this._stop_auto_rebuild) {
2263
+ return
2264
+ }
2253
2265
  this.resetDelta()
2254
2266
  const debug = this.config.debug
2255
2267
  this.config = _.cloneDeep(this.initConfig)
@@ -2746,63 +2758,70 @@ class Config {
2746
2758
  }
2747
2759
  }
2748
2760
 
2749
- add (more) {
2750
- if (more === this) {
2751
- throw new Error('Cannot add an object to itself.')
2752
- }
2753
- if (!(more instanceof Config)) {
2754
- more = new Config(more)
2755
- }
2761
+ add (...mores) {
2762
+ mores.forEach((km) => {
2763
+ if (km === this) {
2764
+ throw new Error('Cannot add an object to itself.')
2765
+ }
2766
+ })
2756
2767
 
2757
- this.valid()
2758
- more.valid()
2759
- // copy so i don't have to copy later
2760
- more = more.copy()
2761
- more.server(this._server, this._key, this._queryParams)
2762
-
2763
- this.loadOrder.addList(more.configs.map((km) => km.name || km.uuid))
2764
-
2765
- // get the new ones
2766
- // remove the dups
2767
- // run the initialize one all new ones
2768
- // this.configs = this.configs.concat(new KM({config: more}));
2769
- // only set for the first one the rest have it set
2770
- const namespace = this._namespace.concat(more._namespace)
2771
- const moreKMs1 = [new KM({ config: more, getCounter: (name) => this.getCounter(name), uuid: more.uuid, namespace })]
2772
- const moreKMs2 = more.configs.slice(1).map((km) => {
2768
+ mores = mores.map((km) => {
2769
+ if (!(km instanceof Config)) {
2770
+ km = new Config(km)
2771
+ }
2773
2772
  return km
2774
- // const cp = km.copy()
2775
- // cp.namespace = namespace
2776
- // return cp;
2777
2773
  })
2778
- const moreKMs = moreKMs1.concat(moreKMs2)
2779
- const eqClass = moreKMs.map((km) => km.uuid)
2780
- this._eqClasses.push(eqClass)
2781
- // look for dups and combine them with the eqclasses
2782
- for (const moreKM of moreKMs) {
2783
- const existingKM = this.configs.find((km) => moreKM._name && km.name === moreKM.name)
2784
- if (existingKM) {
2785
- this.addEqClass(existingKM, moreKM)
2786
- } else {
2787
- this.configs.push(moreKM)
2774
+
2775
+ mores.forEach((more) => {
2776
+ this.valid()
2777
+ more.valid()
2778
+ // copy so i don't have to copy later
2779
+ more = more.copy()
2780
+ more.server(this._server, this._key, this._queryParams)
2781
+
2782
+ this.loadOrder.addList(more.configs.map((km) => km.name || km.uuid))
2783
+
2784
+ // get the new ones
2785
+ // remove the dups
2786
+ // run the initialize one all new ones
2787
+ // this.configs = this.configs.concat(new KM({config: more}));
2788
+ // only set for the first one the rest have it set
2789
+ const namespace = this._namespace.concat(more._namespace)
2790
+ const moreKMs1 = [new KM({ config: more, getCounter: (name) => this.getCounter(name), uuid: more.uuid, namespace })]
2791
+ const moreKMs2 = more.configs.slice(1).map((km) => {
2792
+ return km
2793
+ // const cp = km.copy()
2794
+ // cp.namespace = namespace
2795
+ // return cp;
2796
+ })
2797
+ const moreKMs = moreKMs1.concat(moreKMs2)
2798
+ const eqClass = moreKMs.map((km) => km.uuid)
2799
+ this._eqClasses.push(eqClass)
2800
+ // look for dups and combine them with the eqclasses
2801
+ for (const moreKM of moreKMs) {
2802
+ const existingKM = this.configs.find((km) => moreKM._name && km.name === moreKM.name)
2803
+ if (existingKM) {
2804
+ this.addEqClass(existingKM, moreKM)
2805
+ } else {
2806
+ this.configs.push(moreKM)
2807
+ }
2788
2808
  }
2789
- }
2790
- more.resetToOne()
2791
- this.config.eqClasses = this._eqClasses
2792
- // greg
2793
- // setup instances
2794
- this.instances = []
2795
- this.configs.forEach((km) => {
2796
- this.instances = (km._config.instances || this.initInstances.slice()).concat(this.instances)
2797
- })
2798
- const noDups = []
2799
- for (const instance of this.instances) {
2800
- if (!noDups.find((existing) => existing.name == instance.name)) {
2801
- noDups.push(instance)
2809
+ more.resetToOne()
2810
+ this.config.eqClasses = this._eqClasses
2811
+ // greg
2812
+ // setup instances
2813
+ this.instances = []
2814
+ this.configs.forEach((km) => {
2815
+ this.instances = (km._config.instances || this.initInstances.slice()).concat(this.instances)
2816
+ })
2817
+ const noDups = []
2818
+ for (const instance of this.instances) {
2819
+ if (!noDups.find((existing) => existing.name == instance.name)) {
2820
+ noDups.push(instance)
2821
+ }
2802
2822
  }
2803
- }
2804
- this.instances = noDups
2805
-
2823
+ this.instances = noDups
2824
+ })
2806
2825
  this.rebuild()
2807
2826
  this.valid()
2808
2827
  return this