theprogrammablemind_4wp 7.5.8-beta.25 → 7.5.8-beta.27

Sign up to get free protection for your applications and to get access to all the features.
package/client.js CHANGED
@@ -15,14 +15,16 @@ const sortJson = runtime.sortJson
15
15
 
16
16
  const getAsk = (config) => (uuid) => (asks) => {
17
17
  for (let ask of asks) {
18
- config.addMotivation({
18
+ config.addSemantic({
19
19
  uuid,
20
+ oneShot: true,
20
21
  match: (args) => ask.matchr(args),
21
22
  apply: (args) => ask.applyr(args)
22
23
  })
23
24
  }
24
- config.addMotivation({
25
+ config.addSemantic({
25
26
  uuid,
27
+ oneShot: true,
26
28
  match: ({context}) => context.marker == 'controlEnd' || context.marker == 'controlBetween',
27
29
  apply: (args) => {
28
30
  for (let ask of asks) {
@@ -37,7 +39,7 @@ const getAsk = (config) => (uuid) => (asks) => {
37
39
  }
38
40
  }
39
41
  if (matchq(args)) {
40
- args.context.motivationKeep = true
42
+ // args.context.motivationKeep = true
41
43
  args.context.verbatim = applyq(args)
42
44
  args.context.isResponse = true;
43
45
  delete args.context.controlRemove;
@@ -144,7 +146,6 @@ const setupArgs = (args, config, logs, hierarchy) => {
144
146
  apis: getAPIs(uuid)
145
147
  }
146
148
  }
147
- args.motivation = (m) => config.addMotivation(m)
148
149
  args.breakOnSemantics = false
149
150
  args.theDebugger = {
150
151
  breakOnSemantics: (value) => args.breakOnSemantics = value
@@ -420,18 +421,16 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
420
421
  }
421
422
  const generateParenthesized = isTest || (commandLineArgs && commandLineArgs.save)
422
423
  if (!config.get('skipSemantics')) {
423
- if (!config.doMotivations(args, context)) {
424
- const semantics = config.getSemantics(json.logs)
425
- try {
426
- contextPrime = semantics.apply(args, context)
427
- } catch( e ) {
428
- if (e.message == 'Maximum call stack size exceeded') {
429
- const mostCalled = semantics.getMostCalled()
430
- e.message += `\nThe most called semantic was:\nnotes: ${mostCalled.notes}\nmatch: ${mostCalled.matcher.toString()}\napply: ${mostCalled._apply.toString()}\n`
431
- }
432
- // contextPrime = semantics.apply(args, { marker: 'error', context, error: e })
433
- contextPrime = semantics.apply(args, { marker: 'error', context, reason: e.reason })
424
+ const semantics = config.getSemantics(json.logs)
425
+ try {
426
+ contextPrime = semantics.apply(args, context)
427
+ } catch( e ) {
428
+ if (e.message == 'Maximum call stack size exceeded') {
429
+ const mostCalled = semantics.getMostCalled()
430
+ e.message += `\nThe most called semantic was:\nnotes: ${mostCalled.notes}\nmatch: ${mostCalled.matcher.toString()}\napply: ${mostCalled._apply.toString()}\n`
434
431
  }
432
+ // contextPrime = semantics.apply(args, { marker: 'error', context, error: e })
433
+ contextPrime = semantics.apply(args, { marker: 'error', context, reason: e.reason })
435
434
  }
436
435
  }
437
436
  if (contextPrime.controlRemove) {
@@ -767,7 +766,6 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
767
766
  testConfigName = testConfig.testModuleName
768
767
  }
769
768
  config.beforeQuery({ query: test, isModule: false, objects })
770
- // config.resetMotivations()
771
769
  try {
772
770
  const result = await _process(config, test, { errorHandler, isTest: true })
773
771
  result.query = test
@@ -785,12 +783,17 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
785
783
  delete expected_objects.nameToUUID
786
784
  const actual_objects = sortJson(convertToStable(config.config.objects), { depth: 25 })
787
785
  const failed_paraphrases = !matching(result.paraphrases, expected.paraphrases)
788
- const failed_paraphrasesParenthesized = !matching(result.paraphrasesParenthesized, expected.paraphrasesParenthesized)
789
- const failed_generatedParenthesized = !matching(result.generatedParenthesized, expected.generatedParenthesized)
786
+ let failed_paraphrasesParenthesized = !matching(result.paraphrasesParenthesized, expected.paraphrasesParenthesized)
787
+ let failed_generatedParenthesized = !matching(result.generatedParenthesized, expected.generatedParenthesized)
790
788
  const failed_responses = !matching(result.responses, expected.responses)
791
789
  const failed_contexts = !matching(result.contexts, expected.contexts)
792
790
  const failed_objects = !matching(actual_objects, expected_objects)
793
791
 
792
+ if (args.testNoParenthesized) {
793
+ failed_paraphrasesParenthesized = false
794
+ failed_generatedParenthesized = false
795
+ }
796
+
794
797
  const pickEm = (getObjects) => {
795
798
  const picked = {}
796
799
  for (let prop of (testConfig.check || [])) {
@@ -816,6 +819,11 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
816
819
  }
817
820
  return expected.objects.namespaced[expected.objects.nameToUUID[name]]
818
821
  }
822
+ try {
823
+ sortJson(pickEm(expectedGetObjects), { depth: 25 })
824
+ } catch ( e ) {
825
+ debugger
826
+ }
819
827
  const expected_checked = sortJson(pickEm(expectedGetObjects), { depth: 25 })
820
828
  const actualGetObjects = (name) => {
821
829
  if (!name) {
@@ -942,7 +950,6 @@ const runTests = async (config, testFile, juicyBits) => {
942
950
  const saveTest = async (testFile, config, test, expected, testConfig, saveDeveloper) => {
943
951
  config.rebuild()
944
952
  const objects = getObjects(config.config.objects)(config.uuid)
945
- //config.resetMotivations()
946
953
  config.beforeQuery({ query: test, isModule: false, objects })
947
954
  console.log(test)
948
955
  const result = await _process(config, test, { isTest: true })
@@ -1215,7 +1222,7 @@ entodicton.knowledgeModule( {
1215
1222
  `
1216
1223
  */
1217
1224
 
1218
- const build = async ({ config, target, template, errorHandler = defaultErrorHandler }) => {
1225
+ const rebuildTemplate = async ({ config, target, template, errorHandler = defaultErrorHandler }) => {
1219
1226
  const accumulators = {
1220
1227
  resultss: [],
1221
1228
  fragments: [],
@@ -1239,8 +1246,6 @@ const build = async ({ config, target, template, errorHandler = defaultErrorHand
1239
1246
  if (property == 'fragments') {
1240
1247
  global.transitoryMode = true
1241
1248
  }
1242
- // greg32
1243
- // config.addInternal( query )
1244
1249
  if (hierarchy) {
1245
1250
  for (let edge of hierarchy) {
1246
1251
  if (Array.isArray(edge)) {
@@ -1282,6 +1287,12 @@ const build = async ({ config, target, template, errorHandler = defaultErrorHand
1282
1287
  // it will just get added to the config
1283
1288
  const extraConfig = queryOrExtraConfig
1284
1289
  console.log('config', extraConfig)
1290
+ try {
1291
+ config.addInternal(_.cloneDeep(extraConfig), { handleCalculatedProps: true } )
1292
+ } catch ( e ) {
1293
+ const where = extraConfig.where ? ` ${extraConfig.where}` : ''
1294
+ throw new Error(`Error processing extra config${where}: ${e.stack}}`)
1295
+ }
1285
1296
  accumulators[property].push({ extraConfig: true, ...extraConfig })
1286
1297
  await looper(queries)
1287
1298
  }
@@ -1472,6 +1483,7 @@ const knowledgeModule = async ({
1472
1483
  parser.add_argument('-t', '--test', { action: 'store_true', help: 'Run the tests. Create tests by running with the --query + --save flag' })
1473
1484
  parser.add_argument('-tv', '--testVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. Create tests by running with the --query or --loop with the --save flag' })
1474
1485
  parser.add_argument('-tva', '--testAllVerbose', { action: 'store_true', help: 'Run the tests in verbose mode. All the tests will be run instead of stopping at first failure. Create tests by running with the --query or --loop with the --save flag' })
1486
+ parser.add_argument('-tnp', '--testNoParenthesized', { action: 'store_true', help: 'Don\' check parenthesized differences for the tests' })
1475
1487
  parser.add_argument('-n', '--count', { help: 'Number of times to run the tests. Default is one. Use this to check for flakey test. If possible the system will print out a message with the word "hint" suggesting how to fix the problem' })
1476
1488
  // parser.add_argument('-b', '--build', { help: 'Specify the template file name of the form <kmName>. There should be a file called <baseKmName>.<kmName>.template.json with the queries to run. For example { queries: [...] }. The template file will be run and generate an instantiation called <baseKmName>.<kmName>.instance.json and a file called <kmName>.js that will load the template file (this is file generated only if not already existing) and a test file called <KmName>.tests.json. This can then be loaded into an instance of the current knowledge module to setup initial conditions.' })
1477
1489
  parser.add_argument('-rt', '--rebuildTemplate', { action: 'store_true', help: 'Force a template rebuild' })
@@ -1728,11 +1740,13 @@ const knowledgeModule = async ({
1728
1740
  if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
1729
1741
  hasError = true
1730
1742
  }
1731
- if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
1732
- hasError = true
1733
- }
1734
- if (JSON.stringify(result.expected.generatedParenthesized) !== JSON.stringify(result.actual.generatedParenthesized)) {
1735
- hasError = true
1743
+ if (!args.testNoParenthesized) {
1744
+ if (JSON.stringify(result.expected.paraphrasesParenthesized) !== JSON.stringify(result.actual.paraphrasesParenthesized)) {
1745
+ hasError = true
1746
+ }
1747
+ if (JSON.stringify(result.expected.generatedParenthesized) !== JSON.stringify(result.actual.generatedParenthesized)) {
1748
+ hasError = true
1749
+ }
1736
1750
  }
1737
1751
  if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
1738
1752
  hasError = true
@@ -1758,9 +1772,13 @@ const knowledgeModule = async ({
1758
1772
  }
1759
1773
  }
1760
1774
  show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
1761
- show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
1775
+ if (!args.testNoParenthesized) {
1776
+ show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
1777
+ }
1762
1778
  show('responses', result.expected.responses, result.actual.responses)
1763
- show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
1779
+ if (!args.testNoParenthesized) {
1780
+ show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
1781
+ }
1764
1782
  /*
1765
1783
  if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
1766
1784
  if (!headerShown) {
@@ -1934,7 +1952,7 @@ module.exports = {
1934
1952
  w,
1935
1953
  // submitBug,
1936
1954
  ensureTestFile,
1937
- build,
1955
+ rebuildTemplate,
1938
1956
  processContext,
1939
1957
  processContexts,
1940
1958
  runTests,
package/index.js CHANGED
@@ -23,5 +23,6 @@ module.exports = {
23
23
  Generator,
24
24
  Digraph,
25
25
  flattens: flattens.flattens,
26
+ flatten: flattens.flatten,
26
27
  unflatten: unflatten.unflatten
27
28
  }
package/package.json CHANGED
@@ -63,6 +63,6 @@
63
63
  "json-stable-stringify": "^1.0.1",
64
64
  "node-fetch": "^2.6.1"
65
65
  },
66
- "version": "7.5.8-beta.25",
66
+ "version": "7.5.8-beta.27",
67
67
  "license": "ISC"
68
68
  }
package/src/config.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // lookup = (name) => returns <config>
2
2
  const { Semantics, normalizeGenerator } = require('./semantics')
3
3
  const { Generators } = require('./generators')
4
- // const { uuid: uuidv4 } = require('uuidv4')
4
+ const { v4 : uuidv4 } = require('uuid');
5
5
  const client = require('../client')
6
6
  const DigraphInternal = require('./digraph_internal')
7
7
  const helpers = require('./helpers')
@@ -30,6 +30,41 @@ const config_toServer = (config) => {
30
30
  }
31
31
  }
32
32
 
33
+ const validConfigProps = (config) => {
34
+ const valid = [
35
+ 'hierarchy',
36
+ 'objects',
37
+ 'bridges',
38
+ 'operators',
39
+ 'words',
40
+ 'priorities',
41
+ 'contextual_priorities',
42
+ 'associations',
43
+ 'name',
44
+ 'version',
45
+ 'generators',
46
+ 'semantics',
47
+ 'where',
48
+ 'floaters',
49
+ 'debug',
50
+
51
+ // TODO Fix these from the test app
52
+ 'implicits',
53
+ 'convolution',
54
+ 'expected_generated',
55
+ 'expected_results',
56
+ 'skipSemantics',
57
+ 'description',
58
+ 'contexts',
59
+ 'utterances',
60
+ 'flatten',
61
+
62
+ 'namespaces',
63
+ 'eqClasses',
64
+ ]
65
+ helpers.validProps(valid, config, 'config')
66
+ }
67
+
33
68
  const setupInitializerFNArgs = (config, args) => {
34
69
  const aw = (word, def) => config.addWord(word, def, args.uuid)
35
70
  const ag = (generator) => config.addGenerator(generator, args.uuid, config.name)
@@ -169,7 +204,7 @@ const handleBridgeProps = (config, bridge) => {
169
204
  config.addWordInternal(def, {"id": bridge.id, "initial": `{ value: "${def}"}` })
170
205
  } else {
171
206
  const word = def.word
172
- def = { initial: JSON.stringify(def), id: bridge.id, word: undefined }
207
+ def = { initial: JSON.stringify(def), id: bridge.id, word }
173
208
  config.addWordInternal(word, def)
174
209
  }
175
210
  }
@@ -249,7 +284,7 @@ const handleBridgeProps = (config, bridge) => {
249
284
  const handleCalculatedProps = (baseConfig, moreConfig) => {
250
285
  for (let bridge of moreConfig.bridges) {
251
286
  const valid = [ 'after', 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
252
- 'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where' ]
287
+ 'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid' ]
253
288
  helpers.validProps(valid, bridge, 'bridge')
254
289
  handleBridgeProps(baseConfig, bridge)
255
290
  }
@@ -357,6 +392,14 @@ const normalizeConfig = (config) => {
357
392
  }
358
393
  }
359
394
  }
395
+
396
+ if (config.semantics) {
397
+ for (let semantic of config.semantics) {
398
+ if (semantic.oneShot) {
399
+ semantic.id = uuid()
400
+ }
401
+ }
402
+ }
360
403
  }
361
404
  }
362
405
 
@@ -564,8 +607,8 @@ const multiApiImpl = (initializer) => {
564
607
  initializer(config, api)
565
608
  const name = api.getName()
566
609
  multiApi.apis[name] = api
567
- api.objects = config.get('objects')
568
- api.config = () => config
610
+ // api.objects = config.get('objects')
611
+ // api.config = () => config
569
612
  multiApi.current = name
570
613
  },
571
614
 
@@ -576,11 +619,13 @@ const multiApiImpl = (initializer) => {
576
619
  }
577
620
  },
578
621
 
622
+ /*
579
623
  set objects (value) {
580
624
  for (const key in Object.keys(this.apis)) {
581
625
  this.apis[key].objects = value
582
626
  }
583
627
  },
628
+ */
584
629
 
585
630
  // "product1": apiInstance(testData1),
586
631
  apis: {
@@ -598,7 +643,18 @@ class Config {
598
643
  return config_toServer(config)
599
644
  }
600
645
 
601
- getPseudoConfig(uuid, config) {
646
+ base () {
647
+ const base = new Config()
648
+ for (let km of this.configs.reverse()) {
649
+ if (km.isSelf) {
650
+ continue
651
+ }
652
+ base.add(km.config)
653
+ }
654
+ return base
655
+ }
656
+
657
+ getPseudoConfig (uuid, config) {
602
658
  return {
603
659
  description: "this is a pseudo config that has limited functionality due to being available in the initializer function context",
604
660
  addAssociation: (...args) => this.addAssociation(...args),
@@ -612,6 +668,9 @@ class Config {
612
668
  addSemantic: (...args) => this.addSemantic(...args, uuid, config.name),
613
669
  addWord: (...args) => this.addWord(...args, uuid),
614
670
 
671
+ getHierarchy: (...args) => this.config.hierarchy,
672
+ getBridges: (...args) => this.config.bridges,
673
+
615
674
  addArgs: (...args) => this.addArgs(...args),
616
675
  getBridge: (...args) => this.getBridge(...args),
617
676
  fragment: (...args) => this.fragment(...args),
@@ -887,7 +946,7 @@ class Config {
887
946
  // TODO fix beforeQuery
888
947
  template = { fragments: [], queries: [], ...template }
889
948
  template.fragments = template.fragments.concat(this.dynamicFragments)
890
- client.build({ config: this, target: this.name, beforeQuery: () => {}, template, ...options })
949
+ client.rebuildTemplate({ config: this, target: this.name, beforeQuery: () => {}, template, ...options })
891
950
  } else {
892
951
  // no change
893
952
  // this.initInstances.push({ ...instance, name: config.name })
@@ -1094,6 +1153,7 @@ class Config {
1094
1153
  if (!(typeof semantic.match === 'function')) {
1095
1154
  throw new Error('addSemantic: Expected match to be a function')
1096
1155
  }
1156
+
1097
1157
  if (!(typeof semantic.apply === 'function')) {
1098
1158
  throw new Error('addSemantic: Expected apply to be a function')
1099
1159
  }
@@ -1107,10 +1167,17 @@ class Config {
1107
1167
  }
1108
1168
 
1109
1169
  const semantics = this.config.semantics
1110
- Object.assign(semantic, { uuid: uuid || this._uuid, km: name || this.name, index: semantics.length })
1170
+ Object.assign(semantic, { uuid: uuid || this._uuid, km: name || this.name, index: semantics.length, id: uuidv4() })
1111
1171
  semantics.unshift(semantic)
1112
1172
  }
1113
1173
 
1174
+ removeSemantic(deleteSemantic) {
1175
+ const index = this.config.semantics.findIndex( (semantic) => semantic.id === deleteSemantic.id )
1176
+ if (index >= 0) {
1177
+ this.config.semantics.splice(index, 1)
1178
+ }
1179
+ }
1180
+
1114
1181
  addOperator (objectOrPattern, uuid) {
1115
1182
  if (!this.config.operators) {
1116
1183
  this.config.operators = []
@@ -1373,34 +1440,7 @@ class Config {
1373
1440
  }
1374
1441
 
1375
1442
  if (config) {
1376
- const valid = [
1377
- 'hierarchy',
1378
- 'objects',
1379
- 'bridges',
1380
- 'operators',
1381
- 'words',
1382
- 'priorities',
1383
- 'contextual_priorities',
1384
- 'associations',
1385
- 'name',
1386
- 'version',
1387
- 'generators',
1388
- 'semantics',
1389
- 'floaters',
1390
- 'debug',
1391
-
1392
- // TODO Fix these from the test app
1393
- 'implicits',
1394
- 'convolution',
1395
- 'expected_generated',
1396
- 'expected_results',
1397
- 'skipSemantics',
1398
- 'description',
1399
- 'contexts',
1400
- 'utterances',
1401
- 'flatten',
1402
- ]
1403
- helpers.validProps(valid, config, 'config')
1443
+ validConfigProps(config)
1404
1444
 
1405
1445
  config.operators = config.operators || []
1406
1446
  config.bridges = config.bridges || []
@@ -1483,7 +1523,6 @@ class Config {
1483
1523
  if (config) {
1484
1524
  this.name = config.name
1485
1525
  }
1486
- this.motivations = []
1487
1526
  this.loadOrder = new DigraphInternal()
1488
1527
  this.wasInitialized = false
1489
1528
  this.configs = []
@@ -1588,11 +1627,13 @@ class Config {
1588
1627
  this._api.add(this, this._api, value)
1589
1628
  } else {
1590
1629
  this._api = _.cloneDeep(value)
1630
+ /*
1591
1631
  if (this._api) {
1592
- this._api.objects = this.config.objects
1593
- this._api.config = () => this
1594
- this._api.uuid = this._uuid
1632
+ // this._api.objects = this.config.objects
1633
+ // this._api.config = () => this
1634
+ // this._api.uuid = this._uuid
1595
1635
  }
1636
+ */
1596
1637
  this.rebuild()
1597
1638
  }
1598
1639
  }
@@ -1635,40 +1676,6 @@ class Config {
1635
1676
  // this.valid() init was not run because the kms are not all setup yet
1636
1677
  }
1637
1678
 
1638
- // motivation === { match, apply, uuid }
1639
- addMotivation (motivation) {
1640
- if (!motivation.uuid) {
1641
- motivation.uuid = this.uuid
1642
- }
1643
- this.motivations.push(motivation)
1644
- }
1645
-
1646
- resetMotivations () {
1647
- this.motivations = []
1648
- }
1649
-
1650
- doMotivations (args, context) {
1651
- args = Object.assign({}, args, { context, api: this.api })
1652
- // console.log('src/config doMotivations this.uuid', this.uuid)
1653
- // args.objects = args.getObjects(this.uuid)
1654
- const motivations = this.motivations
1655
- this.motivations = []
1656
- let done = false
1657
- for (const motivation of motivations) {
1658
- args.objects = args.getObjects(motivation.uuid)
1659
- if (!done && motivation.match(args)) {
1660
- motivation.apply(args)
1661
- if (args.context.controlKeepMotivation || motivation.repeat) {
1662
- this.motivations.push(motivation)
1663
- }
1664
- done = true
1665
- } else {
1666
- this.motivations.push(motivation)
1667
- }
1668
- }
1669
- return done
1670
- }
1671
-
1672
1679
  // TODO add more details
1673
1680
  equal(config) {
1674
1681
  if (JSON.stringify(this.config) != JSON.stringify(config.config)) {
@@ -1682,6 +1689,9 @@ class Config {
1682
1689
  runtime.fs.writeFileSync(fn, JSON.stringify(this.config, 0, 2))
1683
1690
  }
1684
1691
 
1692
+ copy (options = { callInitializers: true }) {
1693
+ }
1694
+
1685
1695
  copy (options = { callInitializers: true }) {
1686
1696
  this.valid()
1687
1697
  const cp = new Config()
@@ -1699,7 +1709,6 @@ class Config {
1699
1709
  cp.name = this.name
1700
1710
  cp.description = this.description
1701
1711
  cp.tests = this.tests
1702
- cp.motivations = [...this.motivations]
1703
1712
  cp.isModule = this.isModule
1704
1713
  cp.loadedForTesting = this.loadedForTesting
1705
1714
  cp.initInstances = this.initInstances.slice()
@@ -1724,25 +1733,38 @@ class Config {
1724
1733
  }
1725
1734
  cp.mapUUIDs(map)
1726
1735
 
1736
+ if (cp._uuid == 'concept2') {
1737
+ // debugger
1738
+ }
1727
1739
  if (options.callInitializers) {
1728
1740
  cp.rebuild(options)
1729
- }
1730
- if (cp._api) {
1731
- cp._api.objects = cp.config.objects
1732
- cp._api.config = () => (cp instanceof Config) ? cp : cp.config
1733
- cp._api.uuid = cp._uuid
1734
- }
1741
+ } else {
1742
+ // this mess is for duplicate into a KM after resetToOne was called
1743
+ /*
1744
+ if (cp._api) {
1745
+ // cp._api.objects = cp.config.objects
1746
+ // cp._api.config = () => (cp instanceof Config) ? cp : cp.config
1747
+ // cp._api.uuid = cp._uuid
1748
+ }
1749
+ */
1735
1750
 
1736
- if (!cp.config.objects) {
1737
- cp.config.objects = { namespaced: {} }
1738
- } else if (!cp.config.objects.namespaced) {
1739
- cp.config.objects.namespaced = {}
1751
+ if (!cp.config.objects) {
1752
+ cp.config.objects = { namespaced: {} }
1753
+ } else if (!cp.config.objects.namespaced) {
1754
+ cp.config.objects.namespaced = {}
1755
+ }
1756
+ cp.configs.forEach((km) => {
1757
+ // const namespace = km.namespace
1758
+ cp.config.objects.namespaced[km._uuid] = {}
1759
+ })
1760
+ /*
1761
+ if (cp._uuid == 'concept2') {
1762
+ if (!cp.api.objects.defaultTypesForHierarchy) {
1763
+ debugger
1764
+ }
1765
+ }
1766
+ */
1740
1767
  }
1741
- cp.configs.forEach((km) => {
1742
- // const namespace = km.namespace
1743
- cp.config.objects.namespaced[km._uuid] = {}
1744
- })
1745
-
1746
1768
  cp.valid()
1747
1769
  return cp
1748
1770
  }
@@ -1844,17 +1866,21 @@ class Config {
1844
1866
  const objects = {}
1845
1867
  if (config instanceof Config) {
1846
1868
  this.get('objects').namespaced[config._uuid] = objects
1869
+ /*
1847
1870
  if (config._api) {
1848
- config._api.objects = objects
1849
- config._api.config = () => this
1871
+ // config._api.objects = objects
1872
+ // config._api.config = () => this
1850
1873
  }
1874
+ */
1851
1875
  config.initializerFn(setupInitializerFNArgs(this, { testConfig: config, currentConfig: config, objects, namespace, uuid }))
1852
1876
  } else {
1853
1877
  this.get('objects').namespaced[this._uuid] = objects
1878
+ /*
1854
1879
  if (config._api) {
1855
- config._api.objects = objects
1856
- config._api.config = () => this
1880
+ // config._api.objects = objects
1881
+ // config._api.config = () => this
1857
1882
  }
1883
+ */
1858
1884
  this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, namespace, uuid }))
1859
1885
  }
1860
1886
  })
@@ -1885,14 +1911,6 @@ class Config {
1885
1911
  // const baseConfig = args.baseConfig
1886
1912
  const currentConfig = args.currentConfig
1887
1913
 
1888
- if (currentConfig.api) {
1889
- currentConfig.api.objects = args.objects
1890
- // GREG42 currentConfig.api.config = () => this
1891
- currentConfig.api.config = () => args.baseConfig
1892
- currentConfig.api.uuid = currentConfig._uuid
1893
- }
1894
- // this.instances.forEach( (instance) => client.processInstance(this, instance) )
1895
- // greg55
1896
1914
  if (args.isAfterApi) {
1897
1915
  fn(args)
1898
1916
  }
@@ -2062,7 +2080,6 @@ class Config {
2062
2080
  }
2063
2081
  this.config.objects.namespaced = {}
2064
2082
  this.resetWasInitialized()
2065
- this.resetMotivations()
2066
2083
 
2067
2084
  // reorder configs base on load ordering
2068
2085
  {
@@ -2123,19 +2140,20 @@ class Config {
2123
2140
  uuid: config._uuid,
2124
2141
  objects: namespacedObjects,
2125
2142
  namespace,
2126
- motivation: (m) => this.addMotivation(m),
2127
2143
  api: config.api,
2128
2144
  }))
2129
2145
 
2130
2146
  const currentConfig = args.currentConfig
2131
2147
 
2148
+ /*
2132
2149
  if (args.currentConfig.api) {
2133
- args.currentConfig.api.objects = args.objects
2150
+ // args.currentConfig.api.objects = args.objects
2134
2151
  // TODO assign pseudo config?
2135
- args.currentConfig.api.config = () => args.baseConfig
2136
- args.currentConfig.api.uuid = args.currentConfig._uuid
2152
+ // args.currentConfig.api.config = () => args.baseConfig
2153
+ // args.currentConfig.api.uuid = args.currentConfig._uuid
2137
2154
  args.currentConfig.wasInitialized = true
2138
2155
  }
2156
+ */
2139
2157
  // debugger
2140
2158
  // greg55
2141
2159
  config.initializerFn(args, { dontCallFn: true })
@@ -2143,16 +2161,17 @@ class Config {
2143
2161
  if (config._api) {
2144
2162
  if (config._api.initialize) {
2145
2163
  // reverse the list
2146
- inits.unshift( () => config._api.initialize({ config: this, km: kmFn, api: config._api }) )
2164
+ // TODO sync up the args with initialize of config
2165
+ inits.unshift( () => config._api.initialize({ config: this, km: kmFn, ...args, api: config._api }) )
2147
2166
  // config._api.initialize({ config, api: config._api })
2148
2167
  } else {
2149
2168
  if (interleaved) {
2150
2169
  inits.unshift(null)
2151
2170
  }
2152
2171
  }
2153
- config._api.objects = namespacedObjects
2154
- config._api.config = () => this
2155
- config._api.uuid = config._uuid
2172
+ // config._api.objects = namespacedObjects
2173
+ // config._api.config = () => this
2174
+ // config._api.uuid = config._uuid
2156
2175
  } else {
2157
2176
  if (interleaved) {
2158
2177
  inits.unshift(null)
@@ -2240,7 +2259,6 @@ class Config {
2240
2259
  }
2241
2260
  this.hierarchy.edges = this.config.hierarchy
2242
2261
  }
2243
- // this.instances.forEach((instance) => client.processInstance(this, instance))
2244
2262
  }
2245
2263
 
2246
2264
  if (reverseIt) {
@@ -2639,6 +2657,7 @@ class Config {
2639
2657
 
2640
2658
  // TODO get rid of useOldVersion arg
2641
2659
  addInternal (more, { useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps : hcps = false } = {}) {
2660
+ validConfigProps(more)
2642
2661
  if (more instanceof Config) {
2643
2662
  more.initialize({ force: false })
2644
2663
  if (useOldVersion) {
@@ -2736,7 +2755,7 @@ class Config {
2736
2755
  this.config[key].splice(iOldOne, 1)
2737
2756
  break;
2738
2757
  }
2739
- }
2758
+ }
2740
2759
  }
2741
2760
  }
2742
2761
  }
package/src/helpers.js CHANGED
@@ -320,7 +320,7 @@ const ecatch = (where, call) => {
320
320
  try {
321
321
  return call()
322
322
  } catch( e ) {
323
- throw new Error(`${where} ${e}`)
323
+ throw new Error(`${where} ${e.stack}`)
324
324
  }
325
325
  }
326
326
 
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