theprogrammablemind 7.12.3 → 7.12.4-beta.0

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 +61 -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) }
@@ -775,6 +777,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
775
777
  response.trace = response.trace.concat(json.trace)
776
778
  response.version = json.version
777
779
  response.explain_priorities = json.explain_priorities
780
+ response.contextual_priorities_ambiguities = json.contextual_priorities_ambiguities
778
781
 
779
782
  response.contexts = response.contexts.concat(contextsPrime)
780
783
  response.generated = response.generated.concat(generatedPrime)
@@ -1153,6 +1156,24 @@ const defaultErrorHandler = async (error) => {
1153
1156
  throw error
1154
1157
  }
1155
1158
 
1159
+ const printContextualPrioritiesAmbiguities = (cpa) => {
1160
+ console.log('Contextual Priorities Ambiguities')
1161
+ for (const counter in cpa) {
1162
+ console.log(` Counter ${counter}`)
1163
+ for (const choices of cpa[counter]) {
1164
+ console.log(' [')
1165
+ for (const choice of choices) {
1166
+ console.log(' [')
1167
+ for (const element of choice) {
1168
+ console.log(` ${JSON.stringify(element)},`)
1169
+ }
1170
+ console.log(' ],')
1171
+ }
1172
+ console.log(' ],')
1173
+ }
1174
+ }
1175
+ }
1176
+
1156
1177
  const defaultInnerProcess = (config, errorHandler, responses) => {
1157
1178
  if (responses.errors) {
1158
1179
  console.log('Errors')
@@ -1171,6 +1192,9 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
1171
1192
  console.log('Logs')
1172
1193
  responses.logs.forEach((log) => console.log(` ${log}`))
1173
1194
  }
1195
+ if (responses.contextual_priorities_ambiguities) {
1196
+ printContextualPrioritiesAmbiguities(responses.contextual_priorities_ambiguities)
1197
+ }
1174
1198
  console.log(responses.trace)
1175
1199
 
1176
1200
  if (global.beforeObjects) {
@@ -1464,6 +1488,7 @@ const knowledgeModuleImpl = async ({
1464
1488
  errorHandler = defaultErrorHandler,
1465
1489
  process: processResults = defaultProcess,
1466
1490
  stopAtFirstFailure = true,
1491
+ acceptsAdditionalConfig = false,
1467
1492
  ...rest
1468
1493
  } = {}) => {
1469
1494
  /*
@@ -1843,34 +1868,33 @@ const knowledgeModuleImpl = async ({
1843
1868
  if (results.length > 0) {
1844
1869
  let headerShown = false
1845
1870
 
1846
- let errorCount = 0
1871
+ let hasError = false
1847
1872
  for (const result of results) {
1848
- let hasError = false
1849
1873
  if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
1850
- hasError = true
1874
+ result.hasError = true
1851
1875
  }
1852
1876
  if (!args.testNoParenthesized) {
1853
1877
  if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
1854
- hasError = true
1878
+ result.hasError = true
1855
1879
  }
1856
1880
  if (JSON.stringify(result.expected.generatedParenthesized) !== JSON.stringify(result.actual.generatedParenthesized)) {
1857
- hasError = true
1881
+ result.hasError = true
1858
1882
  }
1859
1883
  }
1860
1884
  if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
1861
- hasError = true
1885
+ result.hasError = true
1862
1886
  }
1863
1887
  if (JSON.stringify(result.expected.checked) !== JSON.stringify(result.actual.checked)) {
1864
- hasError = true
1888
+ result.hasError = true
1865
1889
  }
1866
1890
  if (!sameJSON(result.expected.checkedContexts, result.actual.checkedContexts)) {
1867
- hasError = true
1891
+ result.hasError = true
1868
1892
  }
1869
- if (hasError) {
1870
- errorCount += 1
1893
+ if (result.hasError) {
1894
+ hasError = true
1871
1895
  }
1872
1896
  }
1873
- const hasError = errorCount > 0
1897
+
1874
1898
  if (hasError) {
1875
1899
  console.log('**************************** ERRORS ************************')
1876
1900
  for (const result of results) {
@@ -1885,21 +1909,20 @@ const knowledgeModuleImpl = async ({
1885
1909
  newError = true
1886
1910
  headerShown = true
1887
1911
  if (args.vimdiff) {
1888
- vimdiff(result.actual.paraphrasesParenthesized, result.expected.paraphrasesParenthesized)
1912
+ vimdiff(actual, expected, `"${result.utterance}" - ${label}`)
1889
1913
  }
1890
- errorCount += 1
1914
+ result.hasError = true
1891
1915
  }
1892
1916
  }
1893
1917
  show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
1894
1918
  if (!args.testNoParenthesized) {
1895
1919
  show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
1896
1920
  }
1897
- /*
1898
- }
1899
1921
  show('responses', result.expected.responses, result.actual.responses)
1900
1922
  if (!args.testNoParenthesized) {
1901
1923
  show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
1902
1924
  }
1925
+ /*
1903
1926
  if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
1904
1927
  if (!headerShown) {
1905
1928
  console.log(' Failure')
@@ -1972,7 +1995,13 @@ const knowledgeModuleImpl = async ({
1972
1995
  if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
1973
1996
  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
1997
  // console.log(JSON.stringify(contexts))
1975
- console.log(`**************************** THERE WERE ${errorCount} ERRORS ************************`)
1998
+ let errorCount = 0
1999
+ for (const result of results) {
2000
+ if (result.hasError) {
2001
+ errorCount += 1
2002
+ }
2003
+ }
2004
+ console.log(`**************************** THERE WERE ${errorCount} TEST FAILURES ************************`)
1976
2005
  }
1977
2006
  }
1978
2007
  }
@@ -2072,11 +2101,16 @@ const knowledgeModuleImpl = async ({
2072
2101
  }
2073
2102
  }
2074
2103
 
2075
- createConfigExport = () => {
2104
+ createConfigExport = (additionalConfig) => {
2076
2105
  if (createConfig.cached) {
2077
2106
  return createConfig.cached
2078
2107
  }
2079
- const config = createConfig()
2108
+ const config = createConfig(acceptsAdditionalConfig ? additionalConfig : null)
2109
+ if (!acceptsAdditionalConfig && additionalConfig) {
2110
+ config.stop_auto_rebuild()
2111
+ additionalConfig(config)
2112
+ config.restart_auto_rebuild()
2113
+ }
2080
2114
  initConfig(config)
2081
2115
  // config.rebuild({ isModule: true })
2082
2116
  createConfig.cached = config
@@ -2132,7 +2166,10 @@ function w (func) {
2132
2166
  }
2133
2167
 
2134
2168
  const knowledgeModule = async (...args) => {
2135
- await knowledgeModuleImpl(...args).catch((e) => console.error(e))
2169
+ await knowledgeModuleImpl(...args).catch((e) => {
2170
+ console.error(e)
2171
+ process.exit(-1)
2172
+ })
2136
2173
  }
2137
2174
 
2138
2175
  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-beta.0",
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