ekms 8.0.0-beta.9 → 8.0.0-beta.90

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 (112) hide show
  1. package/common/animals.instance.json +2915 -1553
  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 -29
  10. package/common/colors.instance.json +7487 -4114
  11. package/common/colors.js +5 -9
  12. package/common/colors.test.json +345 -780
  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 +13553 -7026
  23. package/common/crew.js +37 -42
  24. package/common/crew.test.json +714 -452
  25. package/common/currency.js +28 -46
  26. package/common/dialogues.js +150 -426
  27. package/common/dialogues.test.json +0 -786
  28. package/common/dimension.instance.json +491 -262
  29. package/common/dimension.js +22 -24
  30. package/common/dimension.test.json +508 -1702
  31. package/common/edible.instance.json +20446 -10806
  32. package/common/edible.js +4 -9
  33. package/common/emotions.instance.json +192 -124
  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 +222642 -113618
  40. package/common/fastfood.js +76 -86
  41. package/common/fastfood.test.json +268 -90
  42. package/common/formulas.instance.json +443 -247
  43. package/common/formulas.js +20 -27
  44. package/common/gdefaults.js +40 -27
  45. package/common/help.js +9 -14
  46. package/common/help.test.json +65 -16
  47. package/common/helpers/concept.js +10 -7
  48. package/common/helpers/dialogues.js +5 -3
  49. package/common/helpers/properties.js +67 -64
  50. package/common/helpers.js +35 -24
  51. package/common/hierarchy.js +17 -25
  52. package/common/javascript.js +12 -19
  53. package/common/kirk.instance.json +583 -299
  54. package/common/kirk.js +6 -9
  55. package/common/length.instance.json +9005 -5001
  56. package/common/length.js +5 -9
  57. package/common/listener.js +48 -0
  58. package/common/listener.test.json +104 -0
  59. package/common/math.instance.json +406 -1178
  60. package/common/math.js +17 -21
  61. package/common/meta.js +24 -48
  62. package/common/nameable.instance.json +2 -0
  63. package/common/nameable.js +144 -0
  64. package/common/nameable.test.json +3191 -0
  65. package/common/negation.js +11 -7
  66. package/common/numbers.js +28 -32
  67. package/common/ordering.instance.json +443 -343
  68. package/common/ordering.js +81 -87
  69. package/common/ordinals.instance.json +2 -0
  70. package/common/ordinals.js +60 -0
  71. package/common/ordinals.test.json +306 -0
  72. package/common/people.instance.json +2210 -1150
  73. package/common/people.js +9 -14
  74. package/common/percentages.instance.json +2 -0
  75. package/common/percentages.js +53 -0
  76. package/common/percentages.test.json +751 -0
  77. package/common/pipboy.instance.json +11845 -6590
  78. package/common/pipboy.js +51 -62
  79. package/common/pokemon.instance.json +4300 -2285
  80. package/common/pokemon.js +8 -21
  81. package/common/pos.js +16 -14
  82. package/common/pressure.instance.json +2325 -1340
  83. package/common/pressure.js +5 -9
  84. package/common/properties.instance.json +148 -88
  85. package/common/properties.js +149 -160
  86. package/common/punctuation.js +16 -8
  87. package/common/reports.instance.json +1019 -551
  88. package/common/reports.js +77 -101
  89. package/common/reports.test.json +15623 -10458
  90. package/common/scorekeeper.js +19 -31
  91. package/common/sdefaults.js +17 -8
  92. package/common/sizeable.js +7 -11
  93. package/common/spock.instance.json +582 -298
  94. package/common/spock.js +6 -9
  95. package/common/stgame.js +20 -20
  96. package/common/stm.js +173 -31
  97. package/common/stm.test.json +1734 -1
  98. package/common/tell.js +15 -19
  99. package/common/temperature.instance.json +2430 -1429
  100. package/common/temperature.js +5 -9
  101. package/common/tester.js +15 -4
  102. package/common/testing.js +8 -12
  103. package/common/time.js +21 -26
  104. package/common/tokenize.js +6 -7
  105. package/common/ui.instance.json +150 -463
  106. package/common/ui.js +22 -33
  107. package/common/ui.test.json +641 -5357
  108. package/common/weight.instance.json +8034 -4503
  109. package/common/weight.js +5 -9
  110. package/common/yesno.js +6 -6
  111. package/main.js +20 -4
  112. package/package.json +37 -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,7 +37,7 @@ 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: [
39
43
  "([makeObject] (word))",
@@ -45,21 +49,20 @@ let configStruct = {
45
49
  // "(([queryable]) [is:isEdBridge|is,are] ([isEdAble|]))",
46
50
  "(([queryable]) [(<isEd|> ([isEdAble|]))])",
47
51
 
48
- "([nevermind])",
49
- { pattern: "([nevermindTestSetup] (allowed))", development: true },
52
+ // "([nevermind])",
53
+ // { pattern: "([nevermindTestSetup] (allowed))", development: true },
50
54
  "([why])",
51
55
  "([reason])",
52
- "([thisitthat|])",
53
- "([it])",
54
- "([this])",
55
- "([that])",
56
+ // "([thisitthat|])",
57
+ // "([it])",
58
+ // "([this])",
59
+ // "([that])",
56
60
 
57
61
  "(<what> ([whatAble|]))",
58
62
  "([what:optional])",
59
- "(<the|> ([theAble|]))",
60
- "(<a|a,an> ([theAble|]))",
63
+ // "(<the|> ([theAble|]))",
64
+ // "(<a|a,an> ([theAble|]))",
61
65
  // "([unknown])",
62
- "([not] ([notAble|]))",
63
66
 
64
67
  "([be] ([briefOrWordy|]))",
65
68
 
@@ -74,7 +77,6 @@ let configStruct = {
74
77
  // joe is a person the age of joe ...
75
78
  //"arm them, what, the phasers"
76
79
  //greg is a first name
77
- "(x [list|and] y)",
78
80
  "([yesno|])",
79
81
  "(([isEdee])^ <isEdAble|> ([by] ([isEder])?))",
80
82
  "([isEdee|])",
@@ -105,7 +107,7 @@ let configStruct = {
105
107
  {
106
108
  id: 'makeObject',
107
109
  bridge: "{ ...next(operator), object: after[0] }",
108
- generatorp: ({context, gp}) => `${context.word} ${gp(context.object)}`,
110
+ generatorp: async ({context, gp}) => `${context.word} ${await gp(context.object)}`,
109
111
  semantic: ({config, context, api}) => {
110
112
  api.makeObject({ context: context.object, config, types: [] })
111
113
  }
@@ -113,7 +115,7 @@ let configStruct = {
113
115
  {
114
116
  id: 'setIdSuffix',
115
117
  bridge: "{ ...next(operator), suffix: after[0] }",
116
- generatorp: ({context, gp}) => `${context.word} ${gp(context.suffix)}`,
118
+ generatorp: async ({context, gp}) => `${context.word} ${await gp(context.suffix)}`,
117
119
  semantic: ({context, api}) => {
118
120
  api.setIdSuffix(context.suffix.text)
119
121
  }
@@ -126,7 +128,7 @@ let configStruct = {
126
128
  }
127
129
  },
128
130
 
129
- { id: "by", level: 0, bridge: "{ ...next(operator), object: after[0] }", optional: { 'isEder': "{ marker: 'unknown', implicit: true, concept: true }", }, },
131
+ { id: "by", level: 0, bridge: "{ ...next(operator), object: after[0] }", optional: { 1: "{ marker: 'unknown', implicit: true, concept: true }", }, },
130
132
 
131
133
  { id: "debug23", level: 0, bridge: "{ ...next(operator) }" },
132
134
  // { id: "what", level: 0, bridge: "{ ...next(operator), ...after[0], query: ['what'], determined: true }" },
@@ -134,37 +136,14 @@ let configStruct = {
134
136
  { id: "whatAble", level: 0, bridge: "{ ...next(operator) }" },
135
137
 
136
138
  // context.instance == variables.instance (unification)
137
- {
138
- id: "list",
139
- level: 0,
140
- selector: {
141
- match: "same",
142
- left: [ { pattern: '($type && context.instance == variables.instance)' } ],
143
- right: [ { pattern: '($type && context.instance == variables.instance)' } ],
144
- left: [ { pattern: '($type)' } ],
145
- right: [ { pattern: '($type)' } ],
146
- passthrough: true
147
- },
148
- bridge: "{ ...next(operator), listable: true, isList: true, value: append(before, after) }"
149
- },
150
- {
151
- id: "list",
152
- level: 1,
153
- selector: {
154
- match: "same",
155
- left: [ { pattern: '($type && context.instance == variables.instance)' } ],
156
- passthrough: true
157
- },
158
- bridge: "{ ...operator, value: append(before, operator.value) }"
159
- },
160
139
  {
161
140
  where: where(),
162
141
  id: "to",
163
142
  level: 0,
164
143
  isA: ['preposition'],
165
144
  bridge: "{ ...next(operator), toObject: after[0] }",
166
- generatorp: ({context, gp}) => {
167
- return `to ${gp(context.toObject)}`
145
+ generatorp: async ({context, gp}) => {
146
+ return `to ${await gp(context.toObject)}`
168
147
  },
169
148
  },
170
149
  { id: "toAble", level: 0, bridge: "{ ...next(operator) }" },
@@ -172,15 +151,12 @@ let configStruct = {
172
151
  { id: "be", level: 0, bridge: "{ ...next(operator), type: after[0] }" },
173
152
  { id: "briefOrWordy", level: 0, bridge: "{ ...next(operator) }" },
174
153
 
175
- { id: "notAble", level: 0, bridge: "{ ...next(operator) }" },
176
- { id: "not", level: 0, bridge: "{ ...after, negated: true }" },
177
-
178
154
  { id: "yesno", level: 0, bridge: "{ ...next(operator) }" },
179
155
  { id: "canBeQuestion", level: 0, bridge: "{ ...next(operator) }" },
180
156
  { id: "canBeQuestion", level: 1, bridge: "{ ...next(operator) }" },
181
157
  // { id: "unknown", level: 0, bridge: "{ ...next(operator), unknown: true, dead: true }" },
182
158
  // { id: "unknown", level: 1, bridge: "{ ...next(operator) }" },
183
- { id: "queryable", level: 0, bridge: "{ ...next(operator) }" },
159
+ // { id: "queryable", level: 0, bridge: "{ ...next(operator) }" },
184
160
  { id: "questionMark", level: 0, bridge: "{ ...before[0], query: [before.marker] }" },
185
161
  // { id: "isEd", level: 0, bridge: "{ ...context, query: true }" },
186
162
  // gregbug
@@ -197,7 +173,7 @@ let configStruct = {
197
173
  { id: "isEder", level: 0, bridge: "{ ...next(operator) }" },
198
174
  { id: "is", level: 0,
199
175
  bridge: "{ ...next(operator), one: { number: operator.number, ...before[0] }, two: after[0] }",
200
- isA: ['verby'],
176
+ isA: ['verb'],
201
177
  queryBridge: "{ ...next(operator), one: after[0], two: after[1], query: true }" ,
202
178
  },
203
179
  { id: "is", level: 1, bridge: "{ ...next(operator) }" },
@@ -209,6 +185,7 @@ let configStruct = {
209
185
  { id: "doesAble", level: 1, bridge: "{ ...next(operator), before: before[0] }" },
210
186
  { id: "does", level: 0, bridge: "{ query: true, what: operator.marker, ...context, number: operator.number, object.number: operator.number }*" },
211
187
 
188
+ /*
212
189
  {
213
190
  id: 'the',
214
191
  level: 0,
@@ -220,13 +197,17 @@ let configStruct = {
220
197
  // bridge: "{ ...after[0], pullFromContext: false, instance: true, concept: true, number: 'one', wantsValue: true, determiner: operator, modifiers: append(['determiner'], after[0].modifiers) }"
221
198
  bridge: "{ ...after[0], pullFromContext: false, concept: true, number: 'one', wantsValue: true, determiner: operator, modifiers: append(['determiner'], after[0].modifiers) }"
222
199
  },
200
+ */
201
+ /*
223
202
  {
224
203
  id: "theAble",
225
204
  children: ['noun'],
226
205
  bridge: "{ ...next(operator) }"
227
206
  },
207
+ */
228
208
 
229
209
  // TODO make this hierarchy thing work
210
+ /*
230
211
  {
231
212
  id: "thisitthat",
232
213
  level: 0,
@@ -234,6 +215,8 @@ let configStruct = {
234
215
  before: ['verby'],
235
216
  bridge: "{ ...next(operator) }"
236
217
  },
218
+ */
219
+ /*
237
220
  {
238
221
  id: "nevermind",
239
222
  bridge: "{ ...next(operator) }",
@@ -253,6 +236,8 @@ let configStruct = {
253
236
  }
254
237
  }
255
238
  },
239
+ */
240
+ /*
256
241
  {
257
242
  id: "nevermindTestSetup",
258
243
  development: true,
@@ -271,6 +256,7 @@ let configStruct = {
271
256
  })
272
257
  }
273
258
  },
259
+ */
274
260
  {
275
261
  id: "why",
276
262
  level: 0,
@@ -282,6 +268,7 @@ let configStruct = {
282
268
  isA: ['theAble', 'queryable'],
283
269
  bridge: "{ ...next(operator) }"
284
270
  },
271
+ /*
285
272
  {
286
273
  id: "it",
287
274
  level: 0,
@@ -300,11 +287,12 @@ let configStruct = {
300
287
  isA: ['thisitthat'],
301
288
  bridge: "{ ...next(operator), unknown: true, pullFromContext: true }"
302
289
  },
290
+ */
303
291
  ],
304
292
  words: {
305
293
  "literals": {
306
294
  "?": [{"id": "questionMark", "initial": "{}" }],
307
- "the": [{"id": "the", "initial": "{ modifiers: [] }" }],
295
+ // "the": [{"id": "the", "initial": "{ modifiers: [] }" }],
308
296
  "who": [{"id": "what", "initial": "{ modifiers: [], query: true }" }],
309
297
  "yes": [{"id": "yesno", "initial": "{ value: true }" }],
310
298
  "no": [{"id": "yesno", "initial": "{ value: false }" }],
@@ -337,7 +325,6 @@ let configStruct = {
337
325
  // ['questionMark', 'isEd'],
338
326
  ['a', 'articlePOS'],
339
327
  ['the', 'articlePOS'],
340
- ['unknown', 'notAble'],
341
328
  ['unknown', 'theAble'],
342
329
  ['unknown', 'queryable'],
343
330
  ['it', 'queryable'],
@@ -354,10 +341,10 @@ let configStruct = {
354
341
  where: where(),
355
342
  notes: "handle making responses brief",
356
343
  match: ({context, objects}) => (context.topLevel || context.isResponse) && objects.brief && !context.briefWasRun,
357
- apply: ({context, g}) => {
344
+ apply: async ({context, g}) => {
358
345
  const focussed = focus(context)
359
346
  context.briefWasRun = true
360
- return g(focussed)
347
+ return await g(focussed)
361
348
  },
362
349
  priority: -2,
363
350
  },
@@ -412,66 +399,15 @@ let configStruct = {
412
399
  priority: -1,
413
400
  },
414
401
 
415
- {
416
- where: where(),
417
- notes: 'handle lists with yes no',
418
- // ({context, hierarchy}) => context.marker == 'list' && context.paraphrase && context.value,
419
- // ({context, hierarchy}) => context.marker == 'list' && context.value,
420
- match: ({context, hierarchy}) => context.marker == 'list' && context.paraphrase && context.value && context.value.length > 0 && context.value[0].marker == 'yesno',
421
- apply: ({context, g, gs}) => {
422
- return `${g(context.value[0])} ${gs(context.value.slice(1), ', ', ' and ')}`
423
- }
424
- },
425
-
426
- {
427
- where: where(),
428
- notes: 'handle lists',
429
- // ({context, hierarchy}) => context.marker == 'list' && context.paraphrase && context.value,
430
- // ({context, hierarchy}) => context.marker == 'list' && context.value,
431
- match: ({context, hierarchy}) => context.marker == 'list' && context.value,
432
- apply: ({context, gs}) => {
433
- if (context.newLinesOnly) {
434
- return gs(context.value, '\n')
435
- } else {
436
- return gs(context.value, ', ', ' and ')
437
- }
438
- }
439
- },
440
-
441
- {
442
- where: where(),
443
- notes: 'paraphrase a negation',
444
- match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'notAble') && context.negated, // && !context.isQuery && !context.paraphrase && context.value,
445
- apply: ({context, g}) => {
446
- context.negated = false
447
- const result = g(context.value)
448
- context.negated = true
449
- return `not ${result}`
450
- }
451
- },
452
-
453
402
  {
454
403
  where: where(),
455
404
  notes: 'paraphrase a queryable response',
456
405
  // || context.evalue.paraphrase -> when the evalue acts as a paraphrase value
457
406
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'queryable') && !context.isQuery && context.evalue && (!context.paraphrase || context.evalue.paraphrase),
458
- apply: ({context, g}) => {
459
- return g(context.evalue)
407
+ apply: async ({context, g}) => {
408
+ return await g(context.evalue)
460
409
  }
461
410
  },
462
- /* dup of one above
463
- {
464
- where: where(),
465
- notes: 'paraphrase a queryable',
466
- match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'queryable') && !context.isQuery && !context.paraphrase && context.evalue,
467
- apply: ({context, g}) => {
468
- const oldValue = context.evalue.paraphrase
469
- const result = g(context.evalue)
470
- context.evalue.paraphrase = oldValue
471
- return result
472
- }
473
- },
474
- */
475
411
  {
476
412
  where: where(),
477
413
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'queryable') && !context.isQuery && context.isSelf && context.subject == 'my',
@@ -480,7 +416,7 @@ let configStruct = {
480
416
  {
481
417
  where: where(),
482
418
  match: ({context, hierarchy}) => ['it', 'what'].includes(context.marker) && context.paraphrase,
483
- apply: ({g, context}) => `${context.word}`
419
+ apply: ({context}) => `${context.word}`
484
420
  },
485
421
  {
486
422
  where: where(),
@@ -490,15 +426,8 @@ let configStruct = {
490
426
  {
491
427
  where: where(),
492
428
  match: ({context, hierarchy}) => ['my', 'your'].includes(context.subject) && hierarchy.isA(context.marker, 'queryable') && context.paraphrase,
493
- apply: ({g, context}) => `${context.subject} ${context.marker}`
429
+ apply: ({context}) => `${context.subject} ${context.marker}`
494
430
  },
495
- /*
496
- {
497
- where: where(),
498
- match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'theAble') && context.paraphrase && context.wantsValue && !context.pullFromContext,
499
- apply: ({g, context}) => `a ${context.word}`
500
- },
501
- */
502
431
  {
503
432
  where: where(),
504
433
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'queryable') && !context.isQuery && context.subject,
@@ -523,8 +452,8 @@ let configStruct = {
523
452
  {
524
453
  where: where(),
525
454
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'canBeQuestion') && context.paraphrase && context.topLevel && context.query,
526
- apply: ({context, gp}) => {
527
- return `${gp({...context, topLevel: undefined})}?`
455
+ apply: async ({context, gp}) => {
456
+ return `${await gp({...context, topLevel: undefined})}?`
528
457
  },
529
458
  priority: -1,
530
459
  },
@@ -532,27 +461,27 @@ let configStruct = {
532
461
  where: where(),
533
462
  notes: "x is y",
534
463
  match: ({context, hierarchy}) => { return hierarchy.isA(context.marker, 'is') && context.paraphrase },
535
- apply: ({context, g, gp}) => {
536
- 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)}`
537
466
  }
538
467
  },
539
468
  {
540
469
  where: where(),
541
470
  notes: 'is with a response defined',
542
471
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'is') && context.evalue,
543
- apply: ({context, g, gs}) => {
472
+ apply: async ({context, g, gs}) => {
544
473
  const response = context.evalue;
545
474
  const concept = response.concept;
546
475
  if (concept) {
547
476
  concept.paraphrase = true
548
477
  concept.isSelf = true
549
- const instance = g(response.instance)
550
- return `${g(concept)} ${context.word} ${instance}`
478
+ const instance = await g(response.instance)
479
+ return `${await g(concept)} ${context.word} ${instance}`
551
480
  } else {
552
481
  if (Array.isArray(response)) {
553
- return `${gs(response)}`
482
+ return `${await gs(response)}`
554
483
  } else {
555
- return `${g(response)}`
484
+ return `${await g(response)}`
556
485
  }
557
486
  }
558
487
  }
@@ -561,13 +490,13 @@ let configStruct = {
561
490
  where: where(),
562
491
  notes: 'x is y (not a response)',
563
492
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'is') && !context.evalue,
564
- apply: ({context, g, gp, gr, callId}) => {
493
+ apply: async ({context, g, gp, gr, callId}) => {
565
494
  if ((context.two.evalue || {}).marker == 'answerNotKnown') {
566
- return g(context.two.evalue)
495
+ return await g(context.two.evalue)
567
496
  }
568
497
 
569
498
  if (!context.isResponse) {
570
- 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)}`
571
500
  }
572
501
 
573
502
  const hasFocus = (property) => {
@@ -592,17 +521,15 @@ let configStruct = {
592
521
  }
593
522
  // greg101
594
523
  if (focus == 'one') {
595
- 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)}`
596
525
  } else {
597
526
  // TODO fix this using the assumed and that whole mess. change isResponse to useValue
598
527
  if (context.isResponse) {
599
- 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)}`
600
529
  } else {
601
- 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)}`
602
531
  }
603
- // return `${gp(context.one)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${g(context.two)}`
604
532
  }
605
- // return `${g({...context.one})} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${g(context.two)}`
606
533
  },
607
534
  },
608
535
  ],
@@ -628,107 +555,62 @@ let configStruct = {
628
555
  {
629
556
  where: where(),
630
557
  match: ({context}) => context.marker === 'error',
631
- apply: ({context, gp}) => {
558
+ apply: async ({context, gp}) => {
632
559
  context.evalue = "That is not known"
633
560
  if (context.reason) {
634
- context.evalue += ` because ${gp(context.reason)}`
561
+ context.evalue += ` because ${await gp(context.reason)}`
635
562
  }
636
563
  context.isResponse = true
637
564
  }
638
565
  },
639
- {
640
- where: where(),
641
- notes: 'pull from context',
642
- // match: ({context}) => context.marker == 'it' && context.pullFromContext, // && context.value,
643
- match: ({context, callId}) => context.pullFromContext && !context.same, // && context.value,
644
- apply: ({callId, context, s, kms, e, log, retry}) => {
645
- if (true) {
646
- /*
647
- {
648
- "marker": "unknown",
649
- "range": {
650
- "start": 65,
651
- "end": 73
652
- },
653
- "word": "worth",
654
- "text": "the worth",
655
- "value": "worth",
656
- "unknown": true,
657
- "types": [
658
- "unknown"
659
- ],
660
- "pullFromContext": true,
661
- "concept": true,
662
- "wantsValue": true,
663
- "determiner": "the",
664
- "modifiers": [
665
- "determiner"
666
- ],
667
- "evaluate": true
668
- }
669
-
670
- */
671
- context.value = kms.stm.api.mentions(context)
672
- if (!context.value) {
673
- // retry()
674
- context.value = { marker: 'answerNotKnown' }
675
- return
676
- }
677
-
678
- const instance = e(context.value)
679
- if (instance.evalue && !instance.edefault) {
680
- context.value = instance.evalue
681
- }
682
- if (context.evaluate) {
683
- context.evalue = context.value
684
- }
685
- } else {
686
- /*
687
- {
688
- "marker": "unknown",
689
- "range": {
690
- "start": 24,
691
- "end": 32
692
- },
693
- "word": "price",
694
- "text": "the price",
695
- "value": "price",
696
- "unknown": true,
697
- "types": [
698
- "unknown"
699
- ],
700
- "pullFromContext": true,
701
- "concept": true,
702
- "wantsValue": true,
703
- "determiner": "the",
704
- "modifiers": [
705
- "determiner"
706
- ],
707
- "evaluate": true
708
- }
709
-
710
- */
711
- context.value = kms.stm.api.mentions(context)
712
- if (!context.value) {
713
- // retry()
714
- context.value = { marker: 'answerNotKnown' }
715
- return
716
- }
717
- // avoid loops
718
- if (context.marker != 'unknown') {
719
- if (context.value.marker != context.marker) {
720
- const instance = e(context.value)
721
- if (instance.evalue && !instance.edefault) {
722
- context.value = instance.evalue
723
- }
724
- }
725
- }
726
- if (context.evaluate) {
727
- context.evalue = context.value
728
- }
729
- }
730
- },
731
- },
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
+ // },
732
614
  {
733
615
  where: where(),
734
616
  notes: 'what x is y?',
@@ -739,7 +621,7 @@ let configStruct = {
739
621
  */
740
622
 
741
623
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'is') && context.query,
742
- apply: ({context, s, log, km, objects, e}) => {
624
+ apply: async ({context, s, log, km, objects, e}) => {
743
625
  const one = context.one;
744
626
  const two = context.two;
745
627
  let concept, value;
@@ -753,9 +635,9 @@ let configStruct = {
753
635
  // km('dialogues').api.mentioned(concept)
754
636
  // TODO wtf is the next line?
755
637
  value = JSON.parse(JSON.stringify(value))
756
- let instance = e(value)
638
+ let instance = await e(value)
757
639
  if (false && instance.evalue) {
758
- km('stm').api.mentioned(value)
640
+ km('stm').api.mentioned({ context: value })
759
641
  }
760
642
  if (instance.verbatim) {
761
643
  context.evalue = { verbatim: instance.verbatim }
@@ -817,14 +699,14 @@ let configStruct = {
817
699
  where: where(),
818
700
  notes: 'x is y. handles x is a kind of y or x = y in the stm',
819
701
  match: ({context}) => context.marker == 'is' && !context.query && context.one && context.two,
820
- apply: ({context, s, log, api, kms, config}) => {
702
+ apply: async ({context, s, log, api, kms, config}) => {
821
703
  // const oneZero = { ...context.one }
822
704
  // const twoZero = { ...context.two }
823
705
 
824
706
  const one = context.one;
825
707
  const two = context.two;
826
708
  one.same = two;
827
- const onePrime = s(one)
709
+ const onePrime = await s(one)
828
710
  if (!onePrime.sameWasProcessed) {
829
711
  warningSameNotEvaluated(log, one)
830
712
  } else {
@@ -837,7 +719,7 @@ let configStruct = {
837
719
  let twoPrime;
838
720
  if (!onePrime.sameWasProcessed) {
839
721
  two.same = one
840
- twoPrime = s(two)
722
+ twoPrime = await s(two)
841
723
  if (!twoPrime.sameWasProcessed) {
842
724
  warningSameNotEvaluated(log, two)
843
725
  } else {
@@ -850,26 +732,14 @@ let configStruct = {
850
732
 
851
733
  // if not isA add to stm
852
734
  if (!onePrime.sameWasProcessed && !twoPrime.sameWasProcessed) {
853
- api.makeObject({ context: one, config, types: context.two.types || [] })
854
- kms.stm.api.setVariable(one.value, two)
855
- 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
+ }
856
740
  }
857
741
  }
858
742
  },
859
- /*
860
- {
861
- where: where(),
862
- notes: 'x = y in the stm',
863
- match: ({context}) => context.marker == 'is' && !context.query && context.one && context.two,
864
- apply: ({context, s, log, api, kms, config}) => {
865
- const one = context.one;
866
- const two = context.two;
867
- api.makeObject({ context: one, config, types: context.two.types || [] })
868
- kms.stm.api.setVariable(one.value, two)
869
- kms.stm.api.mentioned(one, two)
870
- }
871
- },
872
- */
873
743
  {
874
744
  where: where(),
875
745
  notes: 'get variable from stm',
@@ -877,206 +747,60 @@ let configStruct = {
877
747
  match: ({context, kms}) => context.evaluate && kms.stm.api.getVariable(context.value) != context.value,
878
748
  // match: ({context, kms}) => context.evaluate,
879
749
  priority: -1,
880
- apply: ({context, kms, e}) => {
750
+ apply: async ({context, kms, e}) => {
881
751
  const api = kms.stm.api
882
752
  context.value = api.getVariable(context.value)
883
- /*
884
- if (!context.value && context.marker !== 'unknown') {
885
- context.value = api.getVariable(context.marker)
886
- }
887
- */
888
753
  if (context.value && context.value.marker) {
889
- context.evalue = e(context.value)
754
+ context.evalue = await e(context.value)
890
755
  }
891
756
  context.focusableForPhrase = true
892
757
  }
893
758
  },
894
- /*
895
- {
896
- where: where(),
897
- notes: 'default handle evaluate',
898
- match: ({context, kms}) => context.evaluate && context.value,
899
- // match: ({context, kms}) => context.evaluate,
900
- // priority: -1,
901
- apply: ({context, kms, e}) => {
902
- if (context.value && context.value.marker) {
903
- context.evalue = e(context.value)
904
- }
905
- }
906
- },
907
- */
908
- /*
909
- {
910
- priority: 2,
911
- notes: 'evaluate top level not already done',
912
- match: ({context}) => false && context.topLevel && !context.evalue,
913
- apply: ({context, e}) => {
914
- const instance = e({ ...context, value: undefined, topLevel: undefined })
915
- if (instance.evalue && !instance.edefault) {
916
- context.evalue = instance
917
- context.isResponse = true
918
- }
919
- }
920
- },
921
- */
922
759
  ],
923
760
  };
924
761
 
925
- // move ask to the KM's since verbatim is called probably in dialogues?
926
- const getAsk = (config) => (uuid) => {
927
- return (asks) => {
928
- const ask = (ask) => {
929
- let oneShot = true // default
930
- if (ask.oneShot === false) {
931
- oneShot = false
932
- }
933
-
934
- const id_q = stableId('semantic')
935
- const id_rs = []
936
- let wasAsked = false
937
- let wasApplied = false
938
- const getWasAsked = () => {
939
- return wasAsked
940
- }
941
- const setWasAsked = (value) => {
942
- wasAsked = value
943
- }
944
- const getWasApplied = () => {
945
- return wasApplied
946
- }
947
- const setWasApplied = (value) => {
948
- wasApplied = value
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) })
949
775
  }
950
-
951
- const semanticsr = ask.semanticsr || []
952
- if (semanticsr.length == 0) {
953
- semanticsr.push({ match: ask.matchr, apply: ask.applyr })
954
- }
955
- for (const semantic of semanticsr) {
956
- const id_r = stableId('semantic')
957
- id_rs.push(id_r)
958
- config.addSemantic({
959
- uuid,
960
- id: id_r,
961
- tied_ids: [id_q],
962
- oneShot,
963
- where: semantic.where || ask.where || where(2),
964
- source: 'response',
965
- match: (args) => semantic.match(args),
966
- apply: (args) => {
967
- setWasApplied(true)
968
- semantic.apply(args)
969
- },
970
- })
971
- }
972
-
973
- config.addSemantic({
974
- uuid,
975
- oneShot,
976
- id: id_q,
977
- tied_ids: id_rs,
978
- where: ask.where,
979
- isQuestion: true, // do one question at a time
980
- getWasAsked,
981
- getWasApplied,
982
- onNevermind: ask.onNevermind,
983
- source: 'question',
984
- match: ({ context }) => context.marker == 'controlEnd' || context.marker == 'controlBetween',
985
- apply: (args) => {
986
- let matchq = ask.matchq
987
- let applyq = ask.applyq
988
- if (!matchq) {
989
- let wasAsked = false
990
- matchq = () => !wasAsked,
991
- applyq = (args) => {
992
- wasAsked = true
993
- return ask.applyq(args)
994
- }
995
- }
996
- if (matchq(args)) {
997
- setWasAsked(true)
998
- setWasApplied(false)
999
- // args.context.motivationKeep = true
1000
- args.verbatim(applyq(args))
1001
- /*
1002
- args.context.verbatim = applyq(args)
1003
- args.context.isResponse = true;
1004
- delete args.context.controlRemove;
1005
- */
1006
- args.context.controlKeepMotivation = true
1007
- }
1008
- args.context.cascade = true
1009
- }
1010
- })
1011
- }
1012
- if (!Array.isArray(asks)) {
1013
- asks = [asks]
1014
- }
1015
-
1016
- [...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": "{}" })
1017
786
  }
1018
- }
1019
-
1020
-
1021
- const createConfig = () => {
1022
- const config = new Config(configStruct, module)
1023
- config.stop_auto_rebuild()
1024
- config.api = api
1025
- config.add(gdefaults(), sdefaults(), pos(), stm(), meta(), punctuation())
1026
- config.initializer( ({objects, config, isModule}) => {
1027
- /* TODO add this beck in. some stuff from config needs to be here
1028
- config.addArgs((args) => ({
1029
- e: (context) => config.api.getEvaluator(args.s, args.log, context),
1030
- }))
1031
- */
1032
- config.addArgs(({config, api, isA}) => ({
1033
- isAListable: (context, type) => {
1034
- if (context.marker == 'list' || context.listable) {
1035
- return context.value.every( (element) => isA(element.marker, type) )
1036
- } else {
1037
- return isA(context.marker, type)
1038
- }
1039
- },
1040
- toContext: (v) => {
1041
- if (Array.isArray(v)) {
1042
- return { marker: 'list', level: 1, value: v }
1043
- }
1044
- if (v.marker == 'list') {
1045
- return v
1046
- }
1047
- return v
1048
- },
1049
- getUUIDScoped: (uuid) => { return {
1050
- ask: getAsk(config)(uuid),
1051
- }
1052
- },
1053
- toScopedId: (context) => {
1054
- return api('dialogues').toScopedId(context)
1055
- },
1056
- }))
1057
- objects.mentioned = []
1058
- objects.variables = {
1059
- }
1060
- if (isModule) {
1061
- } else {
1062
- config.addWord("canbedoquestion", { id: "canBeDoQuestion", "initial": "{}" })
1063
- config.addWord("doesable", { id: "doesAble", "initial": "{}" })
1064
- }
1065
- })
1066
- config.restart_auto_rebuild()
1067
- return config
1068
787
  }
1069
788
 
1070
789
  knowledgeModule( {
790
+ config,
791
+ includes: [articles, gdefaults, sdefaults, conjunction, asking, pos, negation, stm, meta, punctuation],
792
+ initializer,
793
+ api: () => new API(),
794
+
1071
795
  module,
1072
796
  description: 'framework for dialogues',
1073
- createConfig, newWay: true,
797
+ newWay: true,
1074
798
  test: {
1075
799
  name: './dialogues.test.json',
1076
800
  contents: dialogues_tests,
1077
801
  checks: {
1078
- objects: ['onNevermindWasCalled', 'nevermindType', 'idSuffix'],
1079
- context: defaultContextCheck,
802
+ objects: ['idSuffix'],
803
+ context: defaultContextCheck(),
1080
804
  },
1081
805
 
1082
806
  },