theprogrammablemind_4wp 8.3.0 → 8.4.0

Sign up to get free protection for your applications and to get access to all the features.
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.3.0",
68
+ "version": "8.4.0",
69
69
  "license": "UNLICENSED"
70
70
  }
package/src/config.js CHANGED
@@ -387,32 +387,53 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
387
387
  config.config.generators.push(addUUID(generator))
388
388
  }
389
389
  }
390
- if (bridge.evaluator) {
391
- const semantic = {
392
- where: bridge.evaluator.where || bridge.where || helpers.where(3),
393
- match: ({ context }) => bridge.id == context.marker && context.evaluate,
394
- apply: (args) => bridge.evaluator(args),
395
- applyWrapped: bridge.evaluator,
396
- property: 'evaluator'
390
+
391
+ const addSemantic = (semantic, evaluate) => {
392
+ const match = semantic.match || (() => true)
393
+ let apply = semantic
394
+ // if I do apply == semantic.apply or semantic there is one function that has apply defined for some reason even though not explicitly set
395
+ if (semantic.apply && typeof semantic !== 'function') {
396
+ apply = semantic.apply
397
+ }
398
+ const semanticDef = {
399
+ where: semantic.where || bridge.where || helpers.where(4),
400
+ match: (args) => bridge.id == args.context.marker && !!args.context.evaluate == evaluate && match(args),
401
+ apply: (args) => apply(args),
402
+ applyWrapped: semantic,
403
+ property: evaluate ? 'evaluator':'semantic',
397
404
  }
398
405
  if (addFirst) {
399
- config.config.semantics.unshift(addUUID(semantic))
406
+ config.config.semantics.unshift(addUUID(semanticDef))
400
407
  } else {
401
- config.config.semantics.push(addUUID(semantic))
408
+ config.config.semantics.push(addUUID(semanticDef))
402
409
  }
403
410
  }
411
+
412
+ if (bridge.evaluator) {
413
+ addSemantic(bridge.evaluator, true)
414
+ }
415
+
404
416
  if (bridge.semantic) {
405
- const semantic = {
406
- where: bridge.semantic.where || bridge.where || helpers.where(3),
407
- match: ({ context }) => bridge.id == context.marker && !context.evaluate,
408
- apply: (args) => bridge.semantic(args),
409
- applyWrapped: bridge.semantic,
410
- property: 'semantic'
417
+ addSemantic(bridge.semantic, false)
418
+ }
419
+
420
+ if (bridge.evaluators) {
421
+ const evaluators = [...bridge.evaluators]
422
+ evaluators.reverse()
423
+ if (evaluators) {
424
+ for (const evaluator of evaluators) {
425
+ addSemantic(evaluator, true)
426
+ }
411
427
  }
412
- if (addFirst) {
413
- config.config.semantics.unshift(addUUID(semantic))
414
- } else {
415
- config.config.semantics.push(addUUID(semantic))
428
+ }
429
+
430
+ if (bridge.semantics) {
431
+ const semantics = [...bridge.semantics]
432
+ semantics.reverse()
433
+ if (semantics) {
434
+ for (const semantic of semantics) {
435
+ addSemantic(semantic, false)
436
+ }
416
437
  }
417
438
  }
418
439
  }
@@ -423,8 +444,8 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
423
444
  if (moreConfig.bridges) {
424
445
  moreConfig.bridges = moreConfig.bridges.map((bridge) => {
425
446
  bridge = { ...bridge }
426
- const valid = ['after', 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'operator', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
427
- 'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid']
447
+ const valid = ['after', 'before', 'bridge', 'development', 'evaluator', 'evaluators', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'operator', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
448
+ 'level', 'optional', 'selector', 'semantic', 'semantics', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid']
428
449
  helpers.validProps(valid, bridge, 'bridge')
429
450
  handleBridgeProps(baseConfig, bridge, { addFirst, uuid })
430
451
  return bridge
@@ -1149,13 +1170,16 @@ class Config {
1149
1170
  delete bridge.generatorr
1150
1171
  delete bridge.generatorpr
1151
1172
  delete bridge.evaluator
1173
+ delete bridge.evaluators
1152
1174
  delete bridge.semantic
1175
+ delete bridge.semantics
1153
1176
  if (!bridge.bridge) {
1154
1177
  bridge.bridge = "{ ...next(operator) }"
1155
1178
  }
1156
1179
  return bridge
1157
1180
  })
1158
1181
  } else {
1182
+ /* done in updateQueries now
1159
1183
  config.generators = (config.generators || []).map((generator) => {
1160
1184
  generator = { ...generator }
1161
1185
  delete generator.where
@@ -1190,6 +1214,7 @@ class Config {
1190
1214
  }
1191
1215
  return bridge
1192
1216
  })
1217
+ */
1193
1218
  }
1194
1219
  return config
1195
1220
  }
@@ -40,17 +40,32 @@ const asList = (context) => {
40
40
  }
41
41
  }
42
42
 
43
- const isA = (hierarchy) => (child, parent) => {
43
+ const isA = (hierarchy) => (child, parent, { extended=false } = {}) => {
44
44
  if (!child || !parent) {
45
45
  return false
46
46
  }
47
- if (child.marker) {
48
- child = child.marker
49
- }
50
- if (parent.marker) {
51
- parent = parent.marker
47
+
48
+ if (extended) {
49
+ if (hierarchy.isA(child.marker || child, parent.marker || parent)) {
50
+ return true
51
+ }
52
+ for (const childT of child.types || [child]) {
53
+ for (const parentT of parent.types || [parent]) {
54
+ if (hierarchy.isA(childT, parentT)) {
55
+ return true
56
+ }
57
+ }
58
+ }
59
+ return false
60
+ } else {
61
+ if (child.marker) {
62
+ child = child.marker
63
+ }
64
+ if (parent.marker) {
65
+ parent = parent.marker
66
+ }
67
+ return hierarchy.isA(child, parent)
52
68
  }
53
- return hierarchy.isA(child, parent)
54
69
  }
55
70
 
56
71
  class ErrorReason extends Error {
@@ -278,7 +293,7 @@ const processContextsB = async ({ config, hierarchy, semantics, generators, json
278
293
  const contexts = setupContexts(json.contexts)
279
294
 
280
295
  const objects = config.get('objects')
281
- const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance }
296
+ const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance, contexts }
282
297
  if (!json.logs) {
283
298
  json.logs = []
284
299
  }
@@ -306,7 +321,6 @@ const processContextsB = async ({ config, hierarchy, semantics, generators, json
306
321
  const mostCalled = semantics.getMostCalled()
307
322
  e.message += `\nThe most called semantic was:\nnotes: ${mostCalled.notes}\nmatch: ${mostCalled.matcher.toString()}\napply: ${mostCalled._apply.toString()}\n`
308
323
  }
309
- // contextPrime = semantics.apply(args, { marker: 'error', context, error: e })
310
324
  if (isInstance) {
311
325
  console.log('error', e.error)
312
326
  }
package/src/helpers.js CHANGED
@@ -312,24 +312,18 @@ const updateQueries = (queryOrConfig) => {
312
312
 
313
313
  const functionsToStrings = (config) => {
314
314
  config = { ...config }
315
- const mapGenerator = (generator) => {
316
- if (generator.apply) {
317
- return { ...generator, match: generator.match.toString(), apply: generator.apply.toString() }
315
+ defToStrings = (def) => {
316
+ if (def.apply) {
317
+ return { ...def, match: def.match.toString(), apply: def.apply.toString() }
318
318
  } else {
319
- return [generator[0].toString(), generator[1].toString()]
319
+ return [def[0].toString(), def[1].toString()]
320
320
  }
321
321
  }
322
322
  if (config.generators) {
323
- config.generators = config.generators.map(mapGenerator)
323
+ config.generators = config.generators.map(defToStrings)
324
324
  }
325
325
  if (config.semantics) {
326
- config.semantics = config.semantics.map((semantic) => {
327
- if (semantic.apply) {
328
- return { ...semantic, match: semantic.match.toString(), apply: semantic.apply.toString() }
329
- } else {
330
- return [semantic[0].toString(), semantic[1].toString()]
331
- }
332
- })
326
+ config.semantics = config.semantics.map(defToStrings)
333
327
  }
334
328
  if (config.bridges) {
335
329
  config.bridges = config.bridges.map((bridge) => {
@@ -338,7 +332,7 @@ const functionsToStrings = (config) => {
338
332
  bridge.generator = bridge.generator.toString()
339
333
  }
340
334
  if (bridge.generators) {
341
- bridge.generators = bridge.generators.map(mapGenerator)
335
+ bridge.generators = bridge.generators.map(defToStrings)
342
336
  }
343
337
  if (bridge.generatorp) {
344
338
  bridge.generatorp = bridge.generatorp.toString()
@@ -349,9 +343,15 @@ const functionsToStrings = (config) => {
349
343
  if (bridge.semantic) {
350
344
  bridge.semantic = bridge.semantic.toString()
351
345
  }
346
+ if (bridge.semantics) {
347
+ bridge.semantics = bridge.semantics.toString()
348
+ }
352
349
  if (bridge.evaluator) {
353
350
  bridge.evaluator = bridge.evaluator.toString()
354
351
  }
352
+ if (bridge.evaluators) {
353
+ bridge.evaluators = bridge.evaluators.toString()
354
+ }
355
355
  return bridge
356
356
  })
357
357
  }