theprogrammablemind 7.5.8-beta.8 → 7.5.8-beta.80

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/src/flatten.js CHANGED
@@ -89,7 +89,15 @@ const flatten = (markers, value) => {
89
89
  const split = markers.includes(marker)
90
90
  if (split) {
91
91
  if ('value' in properties) {
92
- return [properties.value, true]
92
+ flattenedValues = []
93
+ for (let v of properties.value) {
94
+ if (v.flatten) {
95
+ flattenedValues = flattenedValues.concat(flatten(markers, v)[0])
96
+ } else {
97
+ flattenedValues.push(v)
98
+ }
99
+ }
100
+ return [flattenedValues, true]
93
101
  } else {
94
102
  return [[value], false]
95
103
  }
package/src/helpers.js CHANGED
@@ -43,6 +43,16 @@ const appendNoDups = (l1, l2) => {
43
43
  }
44
44
  }
45
45
 
46
+ const safeNoDups = (list) => {
47
+ noDups = []
48
+ for (const element of list) {
49
+ if (!noDups.find((e) => safeEquals(e, element))) {
50
+ noDups.push(element)
51
+ }
52
+ }
53
+ return noDups
54
+ }
55
+
46
56
  const safeEquals = (v1, v2) => {
47
57
  if (typeof v1 !== typeof v2) {
48
58
  return false
@@ -53,6 +63,8 @@ const safeEquals = (v1, v2) => {
53
63
  return v1 == v2
54
64
  } else if (type == 'function') {
55
65
  return v1.toString() == v2.toString()
66
+ } else if (v1 == undefined || v2 == undefined) {
67
+ return v1 == v2
56
68
  } else {
57
69
  if (v1.length != v2.length) {
58
70
  return false
@@ -170,9 +182,6 @@ const isCompound = (value) => {
170
182
  return isArray(value) || isObject(value)
171
183
  }
172
184
 
173
- nextCallId = 0
174
- nextContextId = 0
175
-
176
185
  class InitCalls {
177
186
 
178
187
  constructor(name) {
@@ -196,9 +205,10 @@ class InitCalls {
196
205
  // this.nextCallId += 1
197
206
  // this.stack.push(this.nextCallId)
198
207
  this.stack.push(this.nextCallId)
208
+ // TODO put the nextContextId in the context for debugging
199
209
  const calls = this.stack.map( (call) => `${this.name}#call${call}` )
200
210
  // return `Context#${this.nextContextId}: ${calls}`
201
- return `Context#${nextContextId}: ${calls}`
211
+ return `Context#${this.nextContextId}: ${calls}`
202
212
  }
203
213
 
204
214
  current() {
@@ -320,7 +330,7 @@ const ecatch = (where, call) => {
320
330
  try {
321
331
  return call()
322
332
  } catch( e ) {
323
- throw new Error(`${where} ${e}`)
333
+ throw new Error(`${where} ${e.stack}`)
324
334
  }
325
335
  }
326
336
 
@@ -331,6 +341,7 @@ module.exports = {
331
341
  mapInPlace,
332
342
  validProps,
333
343
  args,
344
+ safeNoDups,
334
345
  safeEquals,
335
346
  appendNoDups,
336
347
  hashIndexesGet,
package/src/project.js ADDED
@@ -0,0 +1,81 @@
1
+
2
+ const project = (object, filter) => {
3
+ if (!object) {
4
+ return
5
+ }
6
+
7
+ let projection = {}
8
+ const set = (property, value) => {
9
+ if (value === null || value === undefined) {
10
+ return
11
+ }
12
+ projection[property] = value
13
+ }
14
+ if (Array.isArray(filter)) {
15
+ if (Array.isArray(object)) {
16
+ return object.map( element => project(element, filter) )
17
+ } else {
18
+ for (let properties of filter) {
19
+ if (typeof properties == 'object') {
20
+ if (properties.propertyLists) {
21
+ for (const propertyList in properties.propertyLists) {
22
+ if (object[propertyList]) {
23
+ for (const property of object[propertyList]) {
24
+ set(property, project(object[property], properties.propertyLists[propertyList]))
25
+ }
26
+ }
27
+ }
28
+ }
29
+ if (properties.valueLists) {
30
+ for (const listProperty in properties.valueLists) {
31
+ const old = object[listProperty]
32
+ if (Array.isArray(old)) {
33
+ set(listProperty, old.map((element) => project(element, properties.valueLists[listProperty])))
34
+ } else {
35
+ set(listProperty, project(old, properties.valueLists[listProperty]))
36
+ }
37
+ }
38
+ }
39
+ if (properties.properties) {
40
+ for (const property in properties.properties) {
41
+ const old = object[property]
42
+ set(property, project(old, properties.properties[property]))
43
+ }
44
+ }
45
+ if (properties.property) {
46
+ const property = properties.property
47
+ if (properties.isPropertyList) {
48
+ debugger
49
+ if (!Array.isArray(object[property])) {
50
+ return projection
51
+ }
52
+ for (const propertyRef of object[property]) {
53
+ const old = object[propertyRef]
54
+ set(propertyRef, project(old, properties.filter))
55
+ }
56
+ } else {
57
+ const old = object[property]
58
+ set(property, project(old, properties.filter))
59
+ }
60
+ }
61
+ } else {
62
+ if (!Array.isArray(properties)) {
63
+ properties = [properties]
64
+ }
65
+ for (const property of properties) {
66
+ set(property, object[property])
67
+ }
68
+ }
69
+ }
70
+ }
71
+ } else if (typeof filter == 'object') {
72
+ for (const property of Object.keys(filter)) {
73
+ set(property, project(object[property], filter[property]))
74
+ }
75
+ }
76
+ return projection
77
+ }
78
+
79
+ module.exports = { project }
80
+
81
+
package/src/semantics.js CHANGED
@@ -6,7 +6,7 @@ class Semantic {
6
6
  // constructor ({match, apply, uuid, index, km, notes}) {
7
7
  constructor (semantic) {
8
8
  semantic = normalizeSemantic(semantic)
9
- const { match, apply, uuid, index, km, notes, priority, debug, where, applyWrapped, property } = semantic
9
+ const { match, apply, uuid, index, km, notes, priority, debug, where, applyWrapped, property, oneShot, id } = semantic
10
10
  this.matcher = match
11
11
  this._apply = apply
12
12
  this._applyWrapped = applyWrapped
@@ -18,6 +18,8 @@ class Semantic {
18
18
  this.notes = notes
19
19
  this.callId = debug
20
20
  this.where = where
21
+ this.oneShot = oneShot
22
+ this.id = id
21
23
  }
22
24
 
23
25
  toLabel () {
@@ -197,6 +199,9 @@ class Semantics {
197
199
  const log = (message) => { this.logs.push(message) }
198
200
  try {
199
201
  contextPrime = semantic.apply(args, context, s, log, options)
202
+ if (!contextPrime.controlKeepMotivation && semantic.oneShot) {
203
+ args.config.removeSemantic(semantic)
204
+ }
200
205
  } catch( e ) {
201
206
  contextPrime = null
202
207
  let errorMessage