theprogrammablemind_4wp 8.1.0-beta.1 → 8.1.0-beta.2

Sign up to get free protection for your applications and to get access to all the features.
package/client.js CHANGED
@@ -871,7 +871,8 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
871
871
  }
872
872
  */
873
873
  console.log('')
874
- const widths = [60, 10, 72]
874
+ const screen_width = process.stdout.columns
875
+ const widths = [60, 10, Math.max(80, screen_width-71)]
875
876
  const lines = new Lines(widths)
876
877
  lines.setElement(0, 0, '--- The paraphrases are ----------')
877
878
  lines.setElement(0, 2, '--- The response strings are ----------')
package/package.json CHANGED
@@ -65,6 +65,6 @@
65
65
  "sort-json": "^2.0.0",
66
66
  "uuid": "^8.3.2"
67
67
  },
68
- "version": "8.1.0-beta.1",
68
+ "version": "8.1.0-beta.2",
69
69
  "license": "UNLICENSED"
70
70
  }
package/src/config.js CHANGED
@@ -27,6 +27,10 @@ const config_toServer = (config) => {
27
27
  // cant change things because copy breaks something
28
28
  }
29
29
 
30
+ const updateHierarchy = (config) => {
31
+ config.hierarchy = new DigraphInternal(config.config.hierarchy)
32
+ }
33
+
30
34
  const initWords = (words) => {
31
35
  if (!words.literals) {
32
36
  words.literals = {}
@@ -266,7 +270,6 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
266
270
  }
267
271
  if (bridge.children) {
268
272
  for (const child of bridge.children) {
269
- // config.addHierarchy(child, bridge.id)
270
273
  if (child.child) {
271
274
  config.addHierarchy(child.child, bridge.id, child.instance)
272
275
  } else {
@@ -1366,8 +1369,25 @@ class Config {
1366
1369
  }
1367
1370
  }
1368
1371
 
1369
- addHierarchyProperties (edge) {
1370
- const { child, parent, instance } = edge
1372
+ addHierarchyInternal (edge) {
1373
+ debugHierarchy([edge[0], edge[1]])
1374
+ // because this is called from the semantics and internally. in the semantics the config can be a pseudo config
1375
+ // where hierarchy and config.hierarchy do not match
1376
+ if (this.hierarchy) {
1377
+ this.hierarchy.addEdge(edge)
1378
+ // no dups due to sharing
1379
+ if (this.hierarchy._edges != this.config.hierarchy) {
1380
+ this.config.hierarchy.push(edge)
1381
+ this._delta.json.hierarchy.push(edge)
1382
+ }
1383
+ } else {
1384
+ this.config.hierarchy.push(edge)
1385
+ this._delta.json.hierarchy.push(edge)
1386
+ }
1387
+ }
1388
+
1389
+ addHierarchyProperties (properties) {
1390
+ const { child, parent, instance } = properties
1371
1391
  if (typeof child !== 'string') {
1372
1392
  throw new Error(`addHierarchy expected child property to be a string. got ${JSON.stringify(child)}`)
1373
1393
  }
@@ -1377,10 +1397,8 @@ class Config {
1377
1397
  if (instance && typeof instance !== 'boolean') {
1378
1398
  throw new Error(`addHierarchy expected instance property to be a boolean or undefined. got ${JSON.stringify(instance)}`)
1379
1399
  }
1380
- debugHierarchy([child, parent])
1381
- this.config.hierarchy.push(edge)
1382
- // TODO greg11 this.hierarchy.addEdge(edge)
1383
- this._delta.json.hierarchy.push([child, parent, instance || false])
1400
+ const edge = [child, parent, instance || false]
1401
+ this.addHierarchyInternal(edge)
1384
1402
  }
1385
1403
 
1386
1404
  addHierarchyChildParent (child, parent, instance) {
@@ -1403,9 +1421,8 @@ class Config {
1403
1421
  return
1404
1422
  }
1405
1423
 
1406
- this.config.hierarchy.push([child, parent, instance || false])
1407
- // this.hierarchy.addEdge([child, parent])
1408
- this._delta.json.hierarchy.push([child, parent, instance || false])
1424
+ const edge = [child, parent, instance || false]
1425
+ this.addHierarchyInternal(edge)
1409
1426
  }
1410
1427
 
1411
1428
  getBridge (id, level) {
@@ -2116,6 +2133,7 @@ class Config {
2116
2133
  cp.configCounter = this.configCounter
2117
2134
  cp.testConfig = this.testConfig
2118
2135
  cp._server = this._server
2136
+ cp.hierarchy = new DigraphInternal(this.config.hierarchy)
2119
2137
 
2120
2138
  cp.initConfig = _.cloneDeep(this.initConfig)
2121
2139
  cp.defaultConfig()
@@ -2506,6 +2524,7 @@ class Config {
2506
2524
  }
2507
2525
  if (!isSelf) {
2508
2526
  config.config = _.cloneDeep(config.initConfig)
2527
+ config.hierarchy = new DigraphInternal(config.config.hierarchy)
2509
2528
  }
2510
2529
  config.wasInitialized = false
2511
2530
  // TODO change name of config: to baseConfig:
@@ -3132,10 +3151,15 @@ class Config {
3132
3151
 
3133
3152
  // console.log('key', key, 'XXX')
3134
3153
  // console.log('more', JSON.stringify(more, null, 2))
3135
- if (addFirst) {
3136
- this.config[key] = more[key].concat(this.config[key])
3154
+ // hierarchy must update in place and does not care about the list order
3155
+ if (key == 'hierarchy') {
3156
+ this.config[key].push(...more[key])
3137
3157
  } else {
3138
- this.config[key] = this.config[key].concat(more[key])
3158
+ if (addFirst) {
3159
+ this.config[key] = more[key].concat(this.config[key])
3160
+ } else {
3161
+ this.config[key] = this.config[key].concat(more[key])
3162
+ }
3139
3163
  }
3140
3164
  } else {
3141
3165
  if (!(key in this.config)) {
@@ -240,7 +240,8 @@ const setupProcessB = ({ config, initializer, allowDelta = false } = {}) => {
240
240
  delete data.generators
241
241
  // const semantics = new Semantics((data.semantics || []).map((g) => new Semantic(normalizeSemantic(g))))
242
242
  delete data.semantics
243
- const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
243
+ // const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
244
+ const hierarchy = config.hierarchy
244
245
 
245
246
  return {
246
247
  data,
@@ -406,7 +407,8 @@ const loadInstance = async (config, instance) => {
406
407
  }
407
408
  }
408
409
 
409
- const { /* data, generators, semantics, */ hierarchy } = setupProcessB({ config })
410
+ // const { /* data, generators, semantics, */ hierarchy } = setupProcessB({ config })
411
+ const hierarchy = config.hierarchy
410
412
  for (const i in (instance.resultss || [])) {
411
413
  const results = instance.resultss[i]
412
414
  if (results.extraConfig) {
package/src/digraph.js CHANGED
@@ -1,3 +1,5 @@
1
+ const _ = require('lodash')
2
+
1
3
  const toA = (edge) => {
2
4
  if (Array.isArray(edge)) {
3
5
  return edge
@@ -45,6 +47,10 @@ class Digraph {
45
47
  }
46
48
  }
47
49
 
50
+ get length () {
51
+ return this._edges.length
52
+ }
53
+
48
54
  addEdges (edges) {
49
55
  for (const edge of edges) {
50
56
  this.addEdge(edge)
@@ -53,7 +59,11 @@ class Digraph {
53
59
 
54
60
  addEdge (edge) {
55
61
  edge = toA(edge)
62
+ if (this._edges.find((existing) => _.isEqual(edge, existing))) {
63
+ return false
64
+ }
56
65
  this._edges.push(edge)
66
+ return true
57
67
  }
58
68
 
59
69
  get edges () {
@@ -1,3 +1,5 @@
1
+ const _ = require('lodash')
2
+
1
3
  const toA = (edge) => {
2
4
  if (Array.isArray(edge)) {
3
5
  return edge
@@ -21,7 +23,11 @@ class DigraphInternal {
21
23
 
22
24
  addEdge (edge) {
23
25
  edge = toA(edge)
26
+ if (this._edges.find((existing) => _.isEqual(edge, existing))) {
27
+ return false
28
+ }
24
29
  this._edges.push(edge)
30
+ return true
25
31
  }
26
32
 
27
33
  get edges () {
@@ -32,6 +38,10 @@ class DigraphInternal {
32
38
  this._edges = edges
33
39
  }
34
40
 
41
+ get length () {
42
+ return this._edges.length
43
+ }
44
+
35
45
  /*
36
46
  set edges(edges) {
37
47
  this._edges = edges.map( toA )