theprogrammablemind_4wp 7.12.3-beta.0 → 7.12.3-beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/client.js +27 -21
  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) }
@@ -1843,34 +1845,33 @@ const knowledgeModuleImpl = async ({
1843
1845
  if (results.length > 0) {
1844
1846
  let headerShown = false
1845
1847
 
1846
- let errorCount = 0
1848
+ let hasError = false
1847
1849
  for (const result of results) {
1848
- let hasError = false
1849
1850
  if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
1850
- hasError = true
1851
+ result.hasError = true
1851
1852
  }
1852
1853
  if (!args.testNoParenthesized) {
1853
1854
  if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
1854
- hasError = true
1855
+ result.hasError = true
1855
1856
  }
1856
1857
  if (JSON.stringify(result.expected.generatedParenthesized) !== JSON.stringify(result.actual.generatedParenthesized)) {
1857
- hasError = true
1858
+ result.hasError = true
1858
1859
  }
1859
1860
  }
1860
1861
  if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
1861
- hasError = true
1862
+ result.hasError = true
1862
1863
  }
1863
1864
  if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
1864
- hasError = true
1865
+ result.hasError = true
1865
1866
  }
1866
1867
  if (!sameJSON(result.expected.checkedContexts, result.actual.checkedContexts)) {
1867
- hasError = true
1868
+ result.hasError = true
1868
1869
  }
1869
- if (hasError) {
1870
- errorCount += 1
1870
+ if (result.hasError) {
1871
+ hasError = true
1871
1872
  }
1872
1873
  }
1873
- const hasError = errorCount > 0
1874
+
1874
1875
  if (hasError) {
1875
1876
  console.log('**************************** ERRORS ************************')
1876
1877
  for (const result of results) {
@@ -1885,21 +1886,20 @@ const knowledgeModuleImpl = async ({
1885
1886
  newError = true
1886
1887
  headerShown = true
1887
1888
  if (args.vimdiff) {
1888
- vimdiff(result.actual.paraphrasesParenthesized, result.expected.paraphrasesParenthesized)
1889
+ vimdiff(actual, expected, `"${result.utterance}" - ${label}`)
1889
1890
  }
1890
- errorCount += 1
1891
+ result.hasError = true
1891
1892
  }
1892
1893
  }
1893
1894
  show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
1894
1895
  if (!args.testNoParenthesized) {
1895
1896
  show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
1896
1897
  }
1897
- /*
1898
- }
1899
1898
  show('responses', result.expected.responses, result.actual.responses)
1900
1899
  if (!args.testNoParenthesized) {
1901
1900
  show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
1902
1901
  }
1902
+ /*
1903
1903
  if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
1904
1904
  if (!headerShown) {
1905
1905
  console.log(' Failure')
@@ -1972,7 +1972,13 @@ const knowledgeModuleImpl = async ({
1972
1972
  if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
1973
1973
  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
1974
  // console.log(JSON.stringify(contexts))
1975
- console.log(`**************************** THERE WERE ${errorCount} ERRORS ************************`)
1975
+ let errorCount = 0
1976
+ for (const result of results) {
1977
+ if (result.hasError) {
1978
+ errorCount += 1
1979
+ }
1980
+ }
1981
+ console.log(`**************************** THERE WERE ${errorCount} TEST FAILURES ************************`)
1976
1982
  }
1977
1983
  }
1978
1984
  }
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-beta.0",
68
+ "version": "7.12.3-beta.1",
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.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