ekms 8.0.0 → 8.1.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 (122) hide show
  1. package/common/animals.instance.json +3003 -1651
  2. package/common/animals.js +17 -20
  3. package/common/articles.js +103 -0
  4. package/common/articles.test.json +310 -0
  5. package/common/asking.instance.json +2 -0
  6. package/common/asking.js +253 -0
  7. package/common/asking.test.json +2290 -0
  8. package/common/avatar.js +6 -10
  9. package/common/characters.js +23 -30
  10. package/common/colors.instance.json +25513 -0
  11. package/common/colors.js +67 -0
  12. package/common/colors.test.json +4425 -0
  13. package/common/comparable.instance.json +1750 -0
  14. package/common/comparable.js +36 -28
  15. package/common/comparable.test.json +1196 -2
  16. package/common/concept.js +121 -119
  17. package/common/conjunction.instance.json +2 -0
  18. package/common/conjunction.js +104 -0
  19. package/common/conjunction.test.json +322 -0
  20. package/common/countable.js +20 -14
  21. package/common/countable.test.json +1050 -0
  22. package/common/crew.instance.json +16855 -9731
  23. package/common/crew.js +39 -42
  24. package/common/crew.test.json +714 -452
  25. package/common/currency.js +28 -46
  26. package/common/dialogues.js +177 -426
  27. package/common/dialogues.test.json +684 -450
  28. package/common/dimension.instance.json +508 -289
  29. package/common/dimension.js +22 -24
  30. package/common/dimension.test.json +727 -1944
  31. package/common/edible.instance.json +20548 -10848
  32. package/common/edible.js +4 -9
  33. package/common/emotions.instance.json +255 -123
  34. package/common/emotions.js +36 -39
  35. package/common/evaluate.instance.json +2 -0
  36. package/common/evaluate.js +53 -0
  37. package/common/evaluate.test.json +574 -0
  38. package/common/events.js +11 -15
  39. package/common/fastfood.instance.json +223039 -113390
  40. package/common/fastfood.js +77 -87
  41. package/common/fastfood.test.json +8205 -3733
  42. package/common/formulas.instance.json +444 -244
  43. package/common/formulas.js +20 -27
  44. package/common/formulas.test.json +1027 -955
  45. package/common/gdefaults.js +40 -27
  46. package/common/help.js +9 -14
  47. package/common/help.test.json +71 -18
  48. package/common/helpers/concept.js +33 -10
  49. package/common/helpers/dialogues.js +22 -4
  50. package/common/helpers/formulas.js +0 -14
  51. package/common/helpers/meta.js +0 -1
  52. package/common/helpers/properties.js +72 -76
  53. package/common/helpers.js +35 -24
  54. package/common/hierarchy.js +17 -25
  55. package/common/javascript.js +12 -19
  56. package/common/kirk.instance.json +586 -298
  57. package/common/kirk.js +6 -9
  58. package/common/length.instance.json +9158 -5124
  59. package/common/length.js +5 -9
  60. package/common/listener.js +48 -0
  61. package/common/listener.test.json +104 -0
  62. package/common/math.instance.json +409 -1202
  63. package/common/math.js +17 -21
  64. package/common/meta.js +24 -50
  65. package/common/nameable.instance.json +2 -0
  66. package/common/nameable.js +144 -0
  67. package/common/nameable.test.json +3191 -0
  68. package/common/negation.instance.json +2 -0
  69. package/common/negation.js +38 -0
  70. package/common/negation.test.json +308 -0
  71. package/common/numbers.js +28 -32
  72. package/common/ordering.instance.json +449 -273
  73. package/common/ordering.js +81 -87
  74. package/common/ordinals.instance.json +2 -0
  75. package/common/ordinals.js +60 -0
  76. package/common/ordinals.test.json +306 -0
  77. package/common/people.instance.json +2176 -1141
  78. package/common/people.js +9 -14
  79. package/common/percentages.instance.json +2 -0
  80. package/common/percentages.js +53 -0
  81. package/common/percentages.test.json +751 -0
  82. package/common/pipboy.instance.json +12120 -6879
  83. package/common/pipboy.js +53 -62
  84. package/common/pipboy.test.json +2835 -0
  85. package/common/pokemon.instance.json +4415 -2351
  86. package/common/pokemon.js +8 -21
  87. package/common/pos.js +16 -14
  88. package/common/pressure.instance.json +2348 -1373
  89. package/common/pressure.js +5 -9
  90. package/common/properties.instance.json +151 -87
  91. package/common/properties.js +156 -167
  92. package/common/properties.test.json +17605 -4030
  93. package/common/punctuation.js +24 -8
  94. package/common/punctuation.test.json +233 -5
  95. package/common/reports.instance.json +1027 -551
  96. package/common/reports.js +77 -103
  97. package/common/reports.test.json +15623 -10458
  98. package/common/scorekeeper.js +19 -31
  99. package/common/sdefaults.js +17 -8
  100. package/common/sizeable.js +13 -12
  101. package/common/spock.instance.json +585 -297
  102. package/common/spock.js +6 -9
  103. package/common/stgame.js +20 -20
  104. package/common/stm.js +182 -29
  105. package/common/stm.test.json +1734 -1
  106. package/common/tell.js +15 -19
  107. package/common/temperature.instance.json +2480 -1493
  108. package/common/temperature.js +5 -9
  109. package/common/tester.js +15 -4
  110. package/common/testing.js +8 -13
  111. package/common/time.js +21 -26
  112. package/common/tokenize.js +8 -8
  113. package/common/tokenize.test.json +86 -1
  114. package/common/ui.instance.json +151 -460
  115. package/common/ui.js +22 -34
  116. package/common/ui.test.json +641 -5357
  117. package/common/weight.instance.json +8072 -4490
  118. package/common/weight.js +5 -9
  119. package/common/weight.test.json +242 -238
  120. package/common/yesno.js +6 -6
  121. package/main.js +68 -45
  122. package/package.json +44 -6
@@ -1,13 +1,17 @@
1
- const { Config, knowledgeModule, where, stableId } = require('./runtime').theprogrammablemind
1
+ const { knowledgeModule, where, stableId } = require('./runtime').theprogrammablemind
2
2
  const meta = require('./meta.js')
3
3
  const gdefaults = require('./gdefaults.js')
4
4
  const sdefaults = require('./sdefaults.js')
5
+ const asking = require('./asking.js')
6
+ const conjunction = require('./conjunction.js')
7
+ const articles = require('./articles.js')
5
8
  const pos = require('./pos.js')
9
+ const negation = require('./negation.js')
6
10
  const punctuation = require('./punctuation.js')
7
11
  const stm = require('./stm.js')
8
12
  const _ = require('lodash')
9
13
  const { API } = require('./helpers/dialogues')
10
- const { isMany } = require('./helpers')
14
+ const { isMany, propertyToArray, words } = require('./helpers')
11
15
  const dialogues_tests = require('./dialogues.test.json')
12
16
  const { defaultContextCheck, indent, focus } = require('./helpers')
13
17
  const pluralize = require('pluralize')
@@ -33,29 +37,32 @@ const warningSameNotEvaluated = (log, one) => {
33
37
  }
34
38
 
35
39
  // TODO implement what / what did you say ...
36
- let configStruct = {
40
+ let config = {
37
41
  name: 'dialogues',
38
42
  operators: [
43
+ "([makeObject] (word))",
44
+ "([setIdSuffix] (word))",
45
+ "([resetIdSuffix])",
46
+
39
47
  "(([queryable]) [is|] ([queryable|]))",
40
48
  "([is:queryBridge|] ([queryable]) ([queryable]))",
41
49
  // "(([queryable]) [is:isEdBridge|is,are] ([isEdAble|]))",
42
50
  "(([queryable]) [(<isEd|> ([isEdAble|]))])",
43
51
 
44
- "([nevermind])",
45
- { pattern: "([nevermindTestSetup] (allowed))", development: true },
52
+ // "([nevermind])",
53
+ // { pattern: "([nevermindTestSetup] (allowed))", development: true },
46
54
  "([why])",
47
55
  "([reason])",
48
- "([thisitthat|])",
49
- "([it])",
50
- "([this])",
51
- "([that])",
56
+ // "([thisitthat|])",
57
+ // "([it])",
58
+ // "([this])",
59
+ // "([that])",
52
60
 
53
61
  "(<what> ([whatAble|]))",
54
62
  "([what:optional])",
55
- "(<the|> ([theAble|]))",
56
- "(<a|a,an> ([theAble|]))",
63
+ // "(<the|> ([theAble|]))",
64
+ // "(<a|a,an> ([theAble|]))",
57
65
  // "([unknown])",
58
- "([not] ([notAble|]))",
59
66
 
60
67
  "([be] ([briefOrWordy|]))",
61
68
 
@@ -70,7 +77,6 @@ let configStruct = {
70
77
  // joe is a person the age of joe ...
71
78
  //"arm them, what, the phasers"
72
79
  //greg is a first name
73
- "(x [list|and] y)",
74
80
  "([yesno|])",
75
81
  "(([isEdee])^ <isEdAble|> ([by] ([isEder])?))",
76
82
  "([isEdee|])",
@@ -98,7 +104,31 @@ let configStruct = {
98
104
  ]
99
105
  },
100
106
  bridges: [
101
- { id: "by", level: 0, bridge: "{ ...next(operator), object: after[0] }", optional: { 'isEder': "{ marker: 'unknown', implicit: true, concept: true }", }, },
107
+ {
108
+ id: 'makeObject',
109
+ bridge: "{ ...next(operator), object: after[0] }",
110
+ generatorp: async ({context, gp}) => `${context.word} ${await gp(context.object)}`,
111
+ semantic: ({config, context, api}) => {
112
+ api.makeObject({ context: context.object, config, types: [] })
113
+ }
114
+ },
115
+ {
116
+ id: 'setIdSuffix',
117
+ bridge: "{ ...next(operator), suffix: after[0] }",
118
+ generatorp: async ({context, gp}) => `${context.word} ${await gp(context.suffix)}`,
119
+ semantic: ({context, api}) => {
120
+ api.setIdSuffix(context.suffix.text)
121
+ }
122
+ },
123
+ {
124
+ id: 'resetIdSuffix',
125
+ bridge: "{ ...next(operator) }",
126
+ semantic: ({context, api}) => {
127
+ api.setIdSuffix('')
128
+ }
129
+ },
130
+
131
+ { id: "by", level: 0, bridge: "{ ...next(operator), object: after[0] }", optional: { 1: "{ marker: 'unknown', implicit: true, concept: true }", }, },
102
132
 
103
133
  { id: "debug23", level: 0, bridge: "{ ...next(operator) }" },
104
134
  // { id: "what", level: 0, bridge: "{ ...next(operator), ...after[0], query: ['what'], determined: true }" },
@@ -106,37 +136,14 @@ let configStruct = {
106
136
  { id: "whatAble", level: 0, bridge: "{ ...next(operator) }" },
107
137
 
108
138
  // context.instance == variables.instance (unification)
109
- {
110
- id: "list",
111
- level: 0,
112
- selector: {
113
- match: "same",
114
- left: [ { pattern: '($type && context.instance == variables.instance)' } ],
115
- right: [ { pattern: '($type && context.instance == variables.instance)' } ],
116
- left: [ { pattern: '($type)' } ],
117
- right: [ { pattern: '($type)' } ],
118
- passthrough: true
119
- },
120
- bridge: "{ ...next(operator), listable: true, isList: true, value: append(before, after) }"
121
- },
122
- {
123
- id: "list",
124
- level: 1,
125
- selector: {
126
- match: "same",
127
- left: [ { pattern: '($type && context.instance == variables.instance)' } ],
128
- passthrough: true
129
- },
130
- bridge: "{ ...operator, value: append(before, operator.value) }"
131
- },
132
139
  {
133
140
  where: where(),
134
141
  id: "to",
135
142
  level: 0,
136
143
  isA: ['preposition'],
137
144
  bridge: "{ ...next(operator), toObject: after[0] }",
138
- generatorp: ({context, gp}) => {
139
- return `to ${gp(context.toObject)}`
145
+ generatorp: async ({context, gp}) => {
146
+ return `to ${await gp(context.toObject)}`
140
147
  },
141
148
  },
142
149
  { id: "toAble", level: 0, bridge: "{ ...next(operator) }" },
@@ -144,15 +151,12 @@ let configStruct = {
144
151
  { id: "be", level: 0, bridge: "{ ...next(operator), type: after[0] }" },
145
152
  { id: "briefOrWordy", level: 0, bridge: "{ ...next(operator) }" },
146
153
 
147
- { id: "notAble", level: 0, bridge: "{ ...next(operator) }" },
148
- { id: "not", level: 0, bridge: "{ ...after, negated: true }" },
149
-
150
154
  { id: "yesno", level: 0, bridge: "{ ...next(operator) }" },
151
155
  { id: "canBeQuestion", level: 0, bridge: "{ ...next(operator) }" },
152
156
  { id: "canBeQuestion", level: 1, bridge: "{ ...next(operator) }" },
153
157
  // { id: "unknown", level: 0, bridge: "{ ...next(operator), unknown: true, dead: true }" },
154
158
  // { id: "unknown", level: 1, bridge: "{ ...next(operator) }" },
155
- { id: "queryable", level: 0, bridge: "{ ...next(operator) }" },
159
+ // { id: "queryable", level: 0, bridge: "{ ...next(operator) }" },
156
160
  { id: "questionMark", level: 0, bridge: "{ ...before[0], query: [before.marker] }" },
157
161
  // { id: "isEd", level: 0, bridge: "{ ...context, query: true }" },
158
162
  // gregbug
@@ -169,7 +173,7 @@ let configStruct = {
169
173
  { id: "isEder", level: 0, bridge: "{ ...next(operator) }" },
170
174
  { id: "is", level: 0,
171
175
  bridge: "{ ...next(operator), one: { number: operator.number, ...before[0] }, two: after[0] }",
172
- isA: ['verby'],
176
+ isA: ['verb'],
173
177
  queryBridge: "{ ...next(operator), one: after[0], two: after[1], query: true }" ,
174
178
  },
175
179
  { id: "is", level: 1, bridge: "{ ...next(operator) }" },
@@ -181,6 +185,7 @@ let configStruct = {
181
185
  { id: "doesAble", level: 1, bridge: "{ ...next(operator), before: before[0] }" },
182
186
  { id: "does", level: 0, bridge: "{ query: true, what: operator.marker, ...context, number: operator.number, object.number: operator.number }*" },
183
187
 
188
+ /*
184
189
  {
185
190
  id: 'the',
186
191
  level: 0,
@@ -192,13 +197,17 @@ let configStruct = {
192
197
  // bridge: "{ ...after[0], pullFromContext: false, instance: true, concept: true, number: 'one', wantsValue: true, determiner: operator, modifiers: append(['determiner'], after[0].modifiers) }"
193
198
  bridge: "{ ...after[0], pullFromContext: false, concept: true, number: 'one', wantsValue: true, determiner: operator, modifiers: append(['determiner'], after[0].modifiers) }"
194
199
  },
200
+ */
201
+ /*
195
202
  {
196
203
  id: "theAble",
197
204
  children: ['noun'],
198
205
  bridge: "{ ...next(operator) }"
199
206
  },
207
+ */
200
208
 
201
209
  // TODO make this hierarchy thing work
210
+ /*
202
211
  {
203
212
  id: "thisitthat",
204
213
  level: 0,
@@ -206,6 +215,8 @@ let configStruct = {
206
215
  before: ['verby'],
207
216
  bridge: "{ ...next(operator) }"
208
217
  },
218
+ */
219
+ /*
209
220
  {
210
221
  id: "nevermind",
211
222
  bridge: "{ ...next(operator) }",
@@ -225,6 +236,8 @@ let configStruct = {
225
236
  }
226
237
  }
227
238
  },
239
+ */
240
+ /*
228
241
  {
229
242
  id: "nevermindTestSetup",
230
243
  development: true,
@@ -235,7 +248,6 @@ let configStruct = {
235
248
  applyq: () => 'the test question?',
236
249
  onNevermind: ({objects, context}) => {
237
250
  objects.onNevermindWasCalled = true
238
- debugger
239
251
  objects.nevermindType = nevermindType
240
252
  return nevermindType == 'accept'
241
253
  },
@@ -244,6 +256,7 @@ let configStruct = {
244
256
  })
245
257
  }
246
258
  },
259
+ */
247
260
  {
248
261
  id: "why",
249
262
  level: 0,
@@ -255,6 +268,7 @@ let configStruct = {
255
268
  isA: ['theAble', 'queryable'],
256
269
  bridge: "{ ...next(operator) }"
257
270
  },
271
+ /*
258
272
  {
259
273
  id: "it",
260
274
  level: 0,
@@ -273,11 +287,12 @@ let configStruct = {
273
287
  isA: ['thisitthat'],
274
288
  bridge: "{ ...next(operator), unknown: true, pullFromContext: true }"
275
289
  },
290
+ */
276
291
  ],
277
292
  words: {
278
293
  "literals": {
279
294
  "?": [{"id": "questionMark", "initial": "{}" }],
280
- "the": [{"id": "the", "initial": "{ modifiers: [] }" }],
295
+ // "the": [{"id": "the", "initial": "{ modifiers: [] }" }],
281
296
  "who": [{"id": "what", "initial": "{ modifiers: [], query: true }" }],
282
297
  "yes": [{"id": "yesno", "initial": "{ value: true }" }],
283
298
  "no": [{"id": "yesno", "initial": "{ value: false }" }],
@@ -303,13 +318,13 @@ let configStruct = {
303
318
  { "context": [['isEdAble', 0], ['is', 1], ], "choose": [0] },
304
319
  ],
305
320
  hierarchy: [
321
+ ['doubleQuote', 'queryable'],
306
322
  ['it', 'pronoun'],
307
323
  ['this', 'pronoun'],
308
324
  ['questionMark', 'punctuation'],
309
325
  // ['questionMark', 'isEd'],
310
326
  ['a', 'articlePOS'],
311
327
  ['the', 'articlePOS'],
312
- ['unknown', 'notAble'],
313
328
  ['unknown', 'theAble'],
314
329
  ['unknown', 'queryable'],
315
330
  ['it', 'queryable'],
@@ -326,10 +341,10 @@ let configStruct = {
326
341
  where: where(),
327
342
  notes: "handle making responses brief",
328
343
  match: ({context, objects}) => (context.topLevel || context.isResponse) && objects.brief && !context.briefWasRun,
329
- apply: ({context, g}) => {
344
+ apply: async ({context, g}) => {
330
345
  const focussed = focus(context)
331
346
  context.briefWasRun = true
332
- return g(focussed)
347
+ return await g(focussed)
333
348
  },
334
349
  priority: -2,
335
350
  },
@@ -384,66 +399,15 @@ let configStruct = {
384
399
  priority: -1,
385
400
  },
386
401
 
387
- {
388
- where: where(),
389
- notes: 'handle lists with yes no',
390
- // ({context, hierarchy}) => context.marker == 'list' && context.paraphrase && context.value,
391
- // ({context, hierarchy}) => context.marker == 'list' && context.value,
392
- match: ({context, hierarchy}) => context.marker == 'list' && context.paraphrase && context.value && context.value.length > 0 && context.value[0].marker == 'yesno',
393
- apply: ({context, g, gs}) => {
394
- return `${g(context.value[0])} ${gs(context.value.slice(1), ', ', ' and ')}`
395
- }
396
- },
397
-
398
- {
399
- where: where(),
400
- notes: 'handle lists',
401
- // ({context, hierarchy}) => context.marker == 'list' && context.paraphrase && context.value,
402
- // ({context, hierarchy}) => context.marker == 'list' && context.value,
403
- match: ({context, hierarchy}) => context.marker == 'list' && context.value,
404
- apply: ({context, gs}) => {
405
- if (context.newLinesOnly) {
406
- return gs(context.value, '\n')
407
- } else {
408
- return gs(context.value, ', ', ' and ')
409
- }
410
- }
411
- },
412
-
413
- {
414
- where: where(),
415
- notes: 'paraphrase a negation',
416
- match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'notAble') && context.negated, // && !context.isQuery && !context.paraphrase && context.value,
417
- apply: ({context, g}) => {
418
- context.negated = false
419
- const result = g(context.value)
420
- context.negated = true
421
- return `not ${result}`
422
- }
423
- },
424
-
425
402
  {
426
403
  where: where(),
427
404
  notes: 'paraphrase a queryable response',
428
405
  // || context.evalue.paraphrase -> when the evalue acts as a paraphrase value
429
406
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'queryable') && !context.isQuery && context.evalue && (!context.paraphrase || context.evalue.paraphrase),
430
- apply: ({context, g}) => {
431
- return g(context.evalue)
432
- }
433
- },
434
- /* dup of one above
435
- {
436
- where: where(),
437
- notes: 'paraphrase a queryable',
438
- match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'queryable') && !context.isQuery && !context.paraphrase && context.evalue,
439
- apply: ({context, g}) => {
440
- const oldValue = context.evalue.paraphrase
441
- const result = g(context.evalue)
442
- context.evalue.paraphrase = oldValue
443
- return result
407
+ apply: async ({context, g}) => {
408
+ return await g(context.evalue)
444
409
  }
445
410
  },
446
- */
447
411
  {
448
412
  where: where(),
449
413
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'queryable') && !context.isQuery && context.isSelf && context.subject == 'my',
@@ -452,7 +416,7 @@ let configStruct = {
452
416
  {
453
417
  where: where(),
454
418
  match: ({context, hierarchy}) => ['it', 'what'].includes(context.marker) && context.paraphrase,
455
- apply: ({g, context}) => `${context.word}`
419
+ apply: ({context}) => `${context.word}`
456
420
  },
457
421
  {
458
422
  where: where(),
@@ -462,15 +426,8 @@ let configStruct = {
462
426
  {
463
427
  where: where(),
464
428
  match: ({context, hierarchy}) => ['my', 'your'].includes(context.subject) && hierarchy.isA(context.marker, 'queryable') && context.paraphrase,
465
- apply: ({g, context}) => `${context.subject} ${context.marker}`
466
- },
467
- /*
468
- {
469
- where: where(),
470
- match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'theAble') && context.paraphrase && context.wantsValue && !context.pullFromContext,
471
- apply: ({g, context}) => `a ${context.word}`
429
+ apply: ({context}) => `${context.subject} ${context.marker}`
472
430
  },
473
- */
474
431
  {
475
432
  where: where(),
476
433
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'queryable') && !context.isQuery && context.subject,
@@ -495,8 +452,8 @@ let configStruct = {
495
452
  {
496
453
  where: where(),
497
454
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'canBeQuestion') && context.paraphrase && context.topLevel && context.query,
498
- apply: ({context, gp}) => {
499
- return `${gp({...context, topLevel: undefined})}?`
455
+ apply: async ({context, gp}) => {
456
+ return `${await gp({...context, topLevel: undefined})}?`
500
457
  },
501
458
  priority: -1,
502
459
  },
@@ -504,27 +461,27 @@ let configStruct = {
504
461
  where: where(),
505
462
  notes: "x is y",
506
463
  match: ({context, hierarchy}) => { return hierarchy.isA(context.marker, 'is') && context.paraphrase },
507
- apply: ({context, g, gp}) => {
508
- return `${g({ ...context.one, paraphrase: true })} ${context.word} ${gp(context.two)}`
464
+ apply: async ({context, g, gp}) => {
465
+ return `${await g({ ...context.one, paraphrase: true })} ${context.word} ${await gp(context.two)}`
509
466
  }
510
467
  },
511
468
  {
512
469
  where: where(),
513
470
  notes: 'is with a response defined',
514
471
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'is') && context.evalue,
515
- apply: ({context, g, gs}) => {
472
+ apply: async ({context, g, gs}) => {
516
473
  const response = context.evalue;
517
474
  const concept = response.concept;
518
475
  if (concept) {
519
476
  concept.paraphrase = true
520
477
  concept.isSelf = true
521
- const instance = g(response.instance)
522
- return `${g(concept)} ${context.word} ${instance}`
478
+ const instance = await g(response.instance)
479
+ return `${await g(concept)} ${context.word} ${instance}`
523
480
  } else {
524
481
  if (Array.isArray(response)) {
525
- return `${gs(response)}`
482
+ return `${await gs(response)}`
526
483
  } else {
527
- return `${g(response)}`
484
+ return `${await g(response)}`
528
485
  }
529
486
  }
530
487
  }
@@ -533,13 +490,13 @@ let configStruct = {
533
490
  where: where(),
534
491
  notes: 'x is y (not a response)',
535
492
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'is') && !context.evalue,
536
- apply: ({context, g, gp, gr, callId}) => {
493
+ apply: async ({context, g, gp, gr, callId}) => {
537
494
  if ((context.two.evalue || {}).marker == 'answerNotKnown') {
538
- return g(context.two.evalue)
495
+ return await g(context.two.evalue)
539
496
  }
540
497
 
541
498
  if (!context.isResponse) {
542
- return `${gp(context.one)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${g(context.two)}`
499
+ return `${await gp(context.one)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${await g(context.two)}`
543
500
  }
544
501
 
545
502
  const hasFocus = (property) => {
@@ -564,17 +521,15 @@ let configStruct = {
564
521
  }
565
522
  // greg101
566
523
  if (focus == 'one') {
567
- return `${g(context.two)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${gp(context.one)}`
524
+ return `${await g(context.two)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${await gp(context.one)}`
568
525
  } else {
569
526
  // TODO fix this using the assumed and that whole mess. change isResponse to useValue
570
527
  if (context.isResponse) {
571
- return `${gp(context.one, { responding: true })} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${g(context.two)}`
528
+ return `${await gp(context.one, { responding: true })} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${await g(context.two)}`
572
529
  } else {
573
- return `${gp(context.one)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${gr(context.two)}`
530
+ return `${await gp(context.one)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${await gr(context.two)}`
574
531
  }
575
- // return `${gp(context.one)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${g(context.two)}`
576
532
  }
577
- // return `${g({...context.one})} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${g(context.two)}`
578
533
  },
579
534
  },
580
535
  ],
@@ -600,108 +555,62 @@ let configStruct = {
600
555
  {
601
556
  where: where(),
602
557
  match: ({context}) => context.marker === 'error',
603
- apply: ({context, gp}) => {
558
+ apply: async ({context, gp}) => {
604
559
  context.evalue = "That is not known"
605
560
  if (context.reason) {
606
- context.evalue += ` because ${gp(context.reason)}`
561
+ context.evalue += ` because ${await gp(context.reason)}`
607
562
  }
608
563
  context.isResponse = true
609
564
  }
610
565
  },
611
- {
612
- where: where(),
613
- notes: 'pull from context',
614
- // match: ({context}) => context.marker == 'it' && context.pullFromContext, // && context.value,
615
- match: ({context, callId}) => context.pullFromContext && !context.same, // && context.value,
616
- apply: ({callId, context, s, kms, e, log, retry}) => {
617
- if (true) {
618
- /*
619
- {
620
- "marker": "unknown",
621
- "range": {
622
- "start": 65,
623
- "end": 73
624
- },
625
- "word": "worth",
626
- "text": "the worth",
627
- "value": "worth",
628
- "unknown": true,
629
- "types": [
630
- "unknown"
631
- ],
632
- "pullFromContext": true,
633
- "concept": true,
634
- "wantsValue": true,
635
- "determiner": "the",
636
- "modifiers": [
637
- "determiner"
638
- ],
639
- "evaluate": true
640
- }
641
-
642
- */
643
- context.value = kms.stm.api.mentions(context)
644
- if (!context.value) {
645
- // retry()
646
- context.value = { marker: 'answerNotKnown' }
647
- return
648
- }
649
-
650
- const instance = e(context.value)
651
- if (instance.evalue && !instance.edefault) {
652
- context.value = instance.evalue
653
- }
654
- if (context.evaluate) {
655
- context.evalue = context.value
656
- }
657
- } else {
658
- /*
659
- {
660
- "marker": "unknown",
661
- "range": {
662
- "start": 24,
663
- "end": 32
664
- },
665
- "word": "price",
666
- "text": "the price",
667
- "value": "price",
668
- "unknown": true,
669
- "types": [
670
- "unknown"
671
- ],
672
- "pullFromContext": true,
673
- "concept": true,
674
- "wantsValue": true,
675
- "determiner": "the",
676
- "modifiers": [
677
- "determiner"
678
- ],
679
- "evaluate": true
680
- }
681
-
682
- */
683
- context.value = kms.stm.api.mentions(context)
684
- // debugger;
685
- if (!context.value) {
686
- // retry()
687
- context.value = { marker: 'answerNotKnown' }
688
- return
689
- }
690
- // avoid loops
691
- if (context.marker != 'unknown') {
692
- if (context.value.marker != context.marker) {
693
- const instance = e(context.value)
694
- if (instance.evalue && !instance.edefault) {
695
- context.value = instance.evalue
696
- }
697
- }
698
- }
699
- if (context.evaluate) {
700
- context.evalue = context.value
701
- }
702
- }
703
- },
704
- },
566
+ // {
567
+ // where: where(),
568
+ // notes: 'pull from context',
569
+ // // match: ({context}) => context.marker == 'it' && context.pullFromContext, // && context.value,
570
+ // match: ({context, callId}) => false && context.pullFromContext && !context.same, // && context.value,
571
+ // apply: async ({callId, context, kms, e, log, retry}) => {
572
+ // if (true) {
573
+ // /*
574
+ // {
575
+ // "marker": "unknown",
576
+ // "range": {
577
+ // "start": 65,
578
+ // "end": 73
579
+ // },
580
+ // "word": "worth",
581
+ // "text": "the worth",
582
+ // "value": "worth",
583
+ // "unknown": true,
584
+ // "types": [
585
+ // "unknown"
586
+ // ],
587
+ // "pullFromContext": true,
588
+ // "concept": true,
589
+ // "wantsValue": true,
590
+ // "determiner": "the",
591
+ // "modifiers": [
592
+ // "determiner"
593
+ // ],
594
+ // "evaluate": true
595
+ // }
596
+
597
+ // */
598
+ // context.value = kms.stm.api.mentions(context)
599
+ // if (!context.value) {
600
+ // // retry()
601
+ // context.value = { marker: 'answerNotKnown' }
602
+ // return
603
+ // }
604
+ //
605
+ // const instance = await e(context.value)
606
+ // if (instance.evalue && !instance.edefault) {
607
+ // context.value = instance.evalue
608
+ // }
609
+ // if (context.evaluate) {
610
+ // context.evalue = context.value
611
+ // }
612
+ // },
613
+ // },
705
614
  {
706
615
  where: where(),
707
616
  notes: 'what x is y?',
@@ -712,7 +621,7 @@ let configStruct = {
712
621
  */
713
622
 
714
623
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'is') && context.query,
715
- apply: ({context, s, log, km, objects, e}) => {
624
+ apply: async ({context, s, log, km, objects, e}) => {
716
625
  const one = context.one;
717
626
  const two = context.two;
718
627
  let concept, value;
@@ -726,9 +635,9 @@ let configStruct = {
726
635
  // km('dialogues').api.mentioned(concept)
727
636
  // TODO wtf is the next line?
728
637
  value = JSON.parse(JSON.stringify(value))
729
- let instance = e(value)
638
+ let instance = await e(value)
730
639
  if (false && instance.evalue) {
731
- km('stm').api.mentioned(value)
640
+ km('stm').api.mentioned({ context: value })
732
641
  }
733
642
  if (instance.verbatim) {
734
643
  context.evalue = { verbatim: instance.verbatim }
@@ -790,14 +699,14 @@ let configStruct = {
790
699
  where: where(),
791
700
  notes: 'x is y. handles x is a kind of y or x = y in the stm',
792
701
  match: ({context}) => context.marker == 'is' && !context.query && context.one && context.two,
793
- apply: ({context, s, log, api, kms, config}) => {
702
+ apply: async ({context, s, log, api, kms, config}) => {
794
703
  // const oneZero = { ...context.one }
795
704
  // const twoZero = { ...context.two }
796
705
 
797
706
  const one = context.one;
798
707
  const two = context.two;
799
708
  one.same = two;
800
- const onePrime = s(one)
709
+ const onePrime = await s(one)
801
710
  if (!onePrime.sameWasProcessed) {
802
711
  warningSameNotEvaluated(log, one)
803
712
  } else {
@@ -810,7 +719,7 @@ let configStruct = {
810
719
  let twoPrime;
811
720
  if (!onePrime.sameWasProcessed) {
812
721
  two.same = one
813
- twoPrime = s(two)
722
+ twoPrime = await s(two)
814
723
  if (!twoPrime.sameWasProcessed) {
815
724
  warningSameNotEvaluated(log, two)
816
725
  } else {
@@ -823,26 +732,14 @@ let configStruct = {
823
732
 
824
733
  // if not isA add to stm
825
734
  if (!onePrime.sameWasProcessed && !twoPrime.sameWasProcessed) {
826
- api.makeObject({ context: one, config, types: context.two.types || [] })
827
- kms.stm.api.setVariable(one.value, two)
828
- kms.stm.api.mentioned(one, two)
735
+ for (const child of propertyToArray(one)) {
736
+ api.makeObject({ context: child, config, types: context.two.types || [] })
737
+ kms.stm.api.setVariable(child.value, two)
738
+ kms.stm.api.mentioned({ context: child, value: two })
739
+ }
829
740
  }
830
741
  }
831
742
  },
832
- /*
833
- {
834
- where: where(),
835
- notes: 'x = y in the stm',
836
- match: ({context}) => context.marker == 'is' && !context.query && context.one && context.two,
837
- apply: ({context, s, log, api, kms, config}) => {
838
- const one = context.one;
839
- const two = context.two;
840
- api.makeObject({ context: one, config, types: context.two.types || [] })
841
- kms.stm.api.setVariable(one.value, two)
842
- kms.stm.api.mentioned(one, two)
843
- }
844
- },
845
- */
846
743
  {
847
744
  where: where(),
848
745
  notes: 'get variable from stm',
@@ -850,206 +747,60 @@ let configStruct = {
850
747
  match: ({context, kms}) => context.evaluate && kms.stm.api.getVariable(context.value) != context.value,
851
748
  // match: ({context, kms}) => context.evaluate,
852
749
  priority: -1,
853
- apply: ({context, kms, e}) => {
750
+ apply: async ({context, kms, e}) => {
854
751
  const api = kms.stm.api
855
752
  context.value = api.getVariable(context.value)
856
- /*
857
- if (!context.value && context.marker !== 'unknown') {
858
- context.value = api.getVariable(context.marker)
859
- }
860
- */
861
753
  if (context.value && context.value.marker) {
862
- context.evalue = e(context.value)
754
+ context.evalue = await e(context.value)
863
755
  }
864
756
  context.focusableForPhrase = true
865
757
  }
866
758
  },
867
- /*
868
- {
869
- where: where(),
870
- notes: 'default handle evaluate',
871
- match: ({context, kms}) => context.evaluate && context.value,
872
- // match: ({context, kms}) => context.evaluate,
873
- // priority: -1,
874
- apply: ({context, kms, e}) => {
875
- if (context.value && context.value.marker) {
876
- context.evalue = e(context.value)
877
- }
878
- }
879
- },
880
- */
881
- /*
882
- {
883
- priority: 2,
884
- notes: 'evaluate top level not already done',
885
- match: ({context}) => false && context.topLevel && !context.evalue,
886
- apply: ({context, e}) => {
887
- const instance = e({ ...context, value: undefined, topLevel: undefined })
888
- if (instance.evalue && !instance.edefault) {
889
- context.evalue = instance
890
- context.isResponse = true
891
- }
892
- }
893
- },
894
- */
895
759
  ],
896
760
  };
897
761
 
898
- // move ask to the KM's since verbatim is called probably in dialogues?
899
- const getAsk = (config) => (uuid) => {
900
- // if (!uuid) {
901
- // debugger
902
- //}
903
- return (asks) => {
904
- const ask = (ask) => {
905
- let oneShot = true // default
906
- if (ask.oneShot === false) {
907
- oneShot = false
762
+ const initializer = ({objects, config, isModule}) => {
763
+ /* TODO add this beck in. some stuff from config needs to be here
764
+ config.addArgs((args) => ({
765
+ e: (context) => config.api.getEvaluator(args.s, args.log, context),
766
+ }))
767
+ */
768
+ config.addArgs(({config, api, isA}) => ({
769
+ toScopedId: (context) => {
770
+ return api('dialogues').toScopedId(context)
771
+ },
772
+ addWords: (id, word, additional) => {
773
+ for (let props of words(word, { ...additional })) {
774
+ config.addWord(props.word, { id, initial: JSON.stringify(props) })
908
775
  }
909
-
910
- const id_q = stableId('semantic')
911
- const id_rs = []
912
- let wasAsked = false
913
- let wasApplied = false
914
- const getWasAsked = () => {
915
- return wasAsked
916
- }
917
- const setWasAsked = (value) => {
918
- wasAsked = value
919
- }
920
- const getWasApplied = () => {
921
- return wasApplied
922
- }
923
- const setWasApplied = (value) => {
924
- wasApplied = value
925
- }
926
-
927
- const semanticsr = ask.semanticsr || []
928
- if (semanticsr.length == 0) {
929
- semanticsr.push({ match: ask.matchr, apply: ask.applyr })
930
- }
931
- for (const semantic of semanticsr) {
932
- const id_r = stableId('semantic')
933
- id_rs.push(id_r)
934
- config.addSemantic({
935
- uuid,
936
- id: id_r,
937
- tied_ids: [id_q],
938
- oneShot,
939
- where: semantic.where || ask.where || where(2),
940
- source: 'response',
941
- match: (args) => semantic.match(args),
942
- apply: (args) => {
943
- setWasApplied(true)
944
- semantic.apply(args)
945
- },
946
- })
947
- }
948
-
949
- config.addSemantic({
950
- uuid,
951
- oneShot,
952
- id: id_q,
953
- tied_ids: id_rs,
954
- where: ask.where,
955
- isQuestion: true, // do one question at a time
956
- getWasAsked,
957
- getWasApplied,
958
- onNevermind: ask.onNevermind,
959
- source: 'question',
960
- match: ({ context }) => context.marker == 'controlEnd' || context.marker == 'controlBetween',
961
- apply: (args) => {
962
- let matchq = ask.matchq
963
- let applyq = ask.applyq
964
- if (!matchq) {
965
- let wasAsked = false
966
- matchq = () => !wasAsked,
967
- applyq = (args) => {
968
- wasAsked = true
969
- return ask.applyq(args)
970
- }
971
- }
972
- if (matchq(args)) {
973
- setWasAsked(true)
974
- setWasApplied(false)
975
- // args.context.motivationKeep = true
976
- args.verbatim(applyq(args))
977
- /*
978
- args.context.verbatim = applyq(args)
979
- args.context.isResponse = true;
980
- delete args.context.controlRemove;
981
- */
982
- args.context.controlKeepMotivation = true
983
- }
984
- args.context.cascade = true
985
- }
986
- })
987
- }
988
- if (!Array.isArray(asks)) {
989
- asks = [asks]
990
- }
991
-
992
- [...asks].reverse().forEach( (a) => ask(a) )
776
+ },
777
+ values: propertyToArray,
778
+ }))
779
+ objects.mentioned = []
780
+ objects.variables = {
781
+ }
782
+ if (isModule) {
783
+ } else {
784
+ config.addWord("canbedoquestion", { id: "canBeDoQuestion", "initial": "{}" })
785
+ config.addWord("doesable", { id: "doesAble", "initial": "{}" })
993
786
  }
994
- }
995
-
996
-
997
- const createConfig = () => {
998
- const config = new Config(configStruct, module)
999
- config.stop_auto_rebuild()
1000
- config.api = api
1001
- config.add(gdefaults(), sdefaults(), pos(), stm(), meta(), punctuation())
1002
- config.initializer( ({objects, config, isModule}) => {
1003
- /* TODO add this beck in. some stuff from config needs to be here
1004
- config.addArgs((args) => ({
1005
- e: (context) => config.api.getEvaluator(args.s, args.log, context),
1006
- }))
1007
- */
1008
- config.addArgs(({config, isA}) => ({
1009
- isAListable: (context, type) => {
1010
- if (context.marker == 'list' || context.listable) {
1011
- return context.value.every( (element) => isA(element.marker, type) )
1012
- } else {
1013
- return isA(context.marker, type)
1014
- }
1015
- },
1016
- toContext: (v) => {
1017
- if (Array.isArray(v)) {
1018
- return { marker: 'list', level: 1, value: v }
1019
- }
1020
- if (v.marker == 'list') {
1021
- return v
1022
- }
1023
- return v
1024
- },
1025
- getUUIDScoped: (uuid) => { return {
1026
- ask: getAsk(config)(uuid),
1027
- }
1028
- },
1029
- }))
1030
- objects.mentioned = []
1031
- objects.variables = {
1032
- }
1033
- if (isModule) {
1034
- } else {
1035
- config.addWord("canbedoquestion", { id: "canBeDoQuestion", "initial": "{}" })
1036
- config.addWord("doesable", { id: "doesAble", "initial": "{}" })
1037
- }
1038
- })
1039
- config.restart_auto_rebuild()
1040
- return config
1041
787
  }
1042
788
 
1043
789
  knowledgeModule( {
790
+ config,
791
+ includes: [articles, gdefaults, sdefaults, conjunction, asking, pos, negation, stm, meta, punctuation],
792
+ initializer,
793
+ api: () => new API(),
794
+
1044
795
  module,
1045
796
  description: 'framework for dialogues',
1046
- createConfig, newWay: true,
797
+ newWay: true,
1047
798
  test: {
1048
799
  name: './dialogues.test.json',
1049
800
  contents: dialogues_tests,
1050
801
  checks: {
1051
- objects: ['onNevermindWasCalled', 'nevermindType'],
1052
- context: defaultContextCheck,
802
+ objects: ['idSuffix'],
803
+ context: defaultContextCheck(),
1053
804
  },
1054
805
 
1055
806
  },