ekms 8.0.0 → 8.1.0-beta.1

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 (124) hide show
  1. package/common/animals.instance.json +3055 -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 +25666 -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/concept.test.json +688 -0
  18. package/common/conjunction.instance.json +2 -0
  19. package/common/conjunction.js +104 -0
  20. package/common/conjunction.test.json +322 -0
  21. package/common/countable.js +20 -14
  22. package/common/countable.test.json +1050 -0
  23. package/common/crew.instance.json +16432 -9850
  24. package/common/crew.js +39 -42
  25. package/common/crew.test.json +714 -452
  26. package/common/currency.js +28 -46
  27. package/common/dialogues.js +187 -429
  28. package/common/dialogues.test.json +684 -450
  29. package/common/dimension.instance.json +517 -289
  30. package/common/dimension.js +22 -24
  31. package/common/dimension.test.json +727 -1944
  32. package/common/edible.instance.json +20506 -10664
  33. package/common/edible.js +4 -9
  34. package/common/emotions.instance.json +195 -123
  35. package/common/emotions.js +36 -39
  36. package/common/evaluate.instance.json +2 -0
  37. package/common/evaluate.js +53 -0
  38. package/common/evaluate.test.json +574 -0
  39. package/common/events.js +11 -15
  40. package/common/fastfood.instance.json +223185 -113172
  41. package/common/fastfood.js +77 -87
  42. package/common/fastfood.test.json +8205 -3733
  43. package/common/formulas.instance.json +444 -244
  44. package/common/formulas.js +20 -27
  45. package/common/formulas.test.json +1027 -955
  46. package/common/gdefaults.js +45 -32
  47. package/common/help.js +9 -14
  48. package/common/help.test.json +71 -18
  49. package/common/helpers/concept.js +37 -10
  50. package/common/helpers/dialogues.js +22 -4
  51. package/common/helpers/formulas.js +0 -14
  52. package/common/helpers/meta.js +0 -1
  53. package/common/helpers/properties.js +92 -84
  54. package/common/helpers.js +35 -24
  55. package/common/hierarchy.js +18 -25
  56. package/common/javascript.js +12 -19
  57. package/common/kirk.instance.json +583 -300
  58. package/common/kirk.js +6 -9
  59. package/common/length.instance.json +8995 -4964
  60. package/common/length.js +5 -9
  61. package/common/listener.js +48 -0
  62. package/common/listener.test.json +104 -0
  63. package/common/math.instance.json +409 -1202
  64. package/common/math.js +17 -21
  65. package/common/meta.js +24 -50
  66. package/common/nameable.instance.json +2 -0
  67. package/common/nameable.js +144 -0
  68. package/common/nameable.test.json +3191 -0
  69. package/common/negation.instance.json +2 -0
  70. package/common/negation.js +38 -0
  71. package/common/negation.test.json +308 -0
  72. package/common/numbers.js +28 -32
  73. package/common/ordering.instance.json +459 -274
  74. package/common/ordering.js +81 -87
  75. package/common/ordinals.instance.json +2 -0
  76. package/common/ordinals.js +61 -0
  77. package/common/ordinals.test.json +412 -0
  78. package/common/people.instance.json +2138 -1321
  79. package/common/people.js +9 -14
  80. package/common/people.test.json +1815 -1073
  81. package/common/percentages.instance.json +2 -0
  82. package/common/percentages.js +53 -0
  83. package/common/percentages.test.json +751 -0
  84. package/common/pipboy.instance.json +12261 -6898
  85. package/common/pipboy.js +53 -62
  86. package/common/pipboy.test.json +2835 -0
  87. package/common/pokemon.instance.json +4432 -2351
  88. package/common/pokemon.js +8 -21
  89. package/common/pos.js +16 -14
  90. package/common/pressure.instance.json +2311 -1303
  91. package/common/pressure.js +5 -9
  92. package/common/properties.instance.json +151 -87
  93. package/common/properties.js +164 -167
  94. package/common/properties.test.json +17605 -4030
  95. package/common/punctuation.js +24 -8
  96. package/common/punctuation.test.json +233 -5
  97. package/common/reports.instance.json +1037 -551
  98. package/common/reports.js +77 -103
  99. package/common/reports.test.json +15623 -10458
  100. package/common/scorekeeper.js +19 -31
  101. package/common/sdefaults.js +17 -8
  102. package/common/sizeable.js +13 -12
  103. package/common/spock.instance.json +582 -299
  104. package/common/spock.js +6 -9
  105. package/common/stgame.js +20 -20
  106. package/common/stm.js +182 -29
  107. package/common/stm.test.json +1734 -1
  108. package/common/tell.js +15 -19
  109. package/common/temperature.instance.json +2379 -1355
  110. package/common/temperature.js +5 -9
  111. package/common/tester.js +15 -4
  112. package/common/testing.js +8 -13
  113. package/common/time.js +21 -26
  114. package/common/tokenize.js +8 -8
  115. package/common/tokenize.test.json +86 -1
  116. package/common/ui.instance.json +151 -460
  117. package/common/ui.js +22 -34
  118. package/common/ui.test.json +641 -5357
  119. package/common/weight.instance.json +7957 -4350
  120. package/common/weight.js +5 -9
  121. package/common/weight.test.json +242 -238
  122. package/common/yesno.js +6 -6
  123. package/main.js +68 -45
  124. 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,35 @@ 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|]))])",
51
+ "(([isEdee])^ <isEdAble|> ([by] ([isEder])?))",
52
+ "([isEdee|])",
53
+ "([isEder|])",
43
54
 
44
- "([nevermind])",
45
- { pattern: "([nevermindTestSetup] (allowed))", development: true },
55
+ // "([nevermind])",
56
+ // { pattern: "([nevermindTestSetup] (allowed))", development: true },
46
57
  "([why])",
47
58
  "([reason])",
48
- "([thisitthat|])",
49
- "([it])",
50
- "([this])",
51
- "([that])",
59
+ // "([thisitthat|])",
60
+ // "([it])",
61
+ // "([this])",
62
+ // "([that])",
52
63
 
53
64
  "(<what> ([whatAble|]))",
54
65
  "([what:optional])",
55
- "(<the|> ([theAble|]))",
56
- "(<a|a,an> ([theAble|]))",
66
+ // "(<the|> ([theAble|]))",
67
+ // "(<a|a,an> ([theAble|]))",
57
68
  // "([unknown])",
58
- "([not] ([notAble|]))",
59
69
 
60
70
  "([be] ([briefOrWordy|]))",
61
71
 
@@ -70,11 +80,7 @@ let configStruct = {
70
80
  // joe is a person the age of joe ...
71
81
  //"arm them, what, the phasers"
72
82
  //greg is a first name
73
- "(x [list|and] y)",
74
83
  "([yesno|])",
75
- "(([isEdee])^ <isEdAble|> ([by] ([isEder])?))",
76
- "([isEdee|])",
77
- "([isEder|])",
78
84
  { pattern: "([debug23])" },
79
85
 
80
86
  "([to] ([toAble|]))",
@@ -98,7 +104,37 @@ 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
+ {
132
+ id: "by",
133
+ level: 0,
134
+ bridge: "{ ...next(operator), object: after[0] }",
135
+ localHierarchy: [['unknown', 'isEder']],
136
+ optional: { 1: "{ marker: 'unknown', implicit: true, concept: true }", },
137
+ },
102
138
 
103
139
  { id: "debug23", level: 0, bridge: "{ ...next(operator) }" },
104
140
  // { id: "what", level: 0, bridge: "{ ...next(operator), ...after[0], query: ['what'], determined: true }" },
@@ -106,37 +142,14 @@ let configStruct = {
106
142
  { id: "whatAble", level: 0, bridge: "{ ...next(operator) }" },
107
143
 
108
144
  // 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
145
  {
133
146
  where: where(),
134
147
  id: "to",
135
148
  level: 0,
136
149
  isA: ['preposition'],
137
150
  bridge: "{ ...next(operator), toObject: after[0] }",
138
- generatorp: ({context, gp}) => {
139
- return `to ${gp(context.toObject)}`
151
+ generatorp: async ({context, gp}) => {
152
+ return `to ${await gp(context.toObject)}`
140
153
  },
141
154
  },
142
155
  { id: "toAble", level: 0, bridge: "{ ...next(operator) }" },
@@ -144,15 +157,12 @@ let configStruct = {
144
157
  { id: "be", level: 0, bridge: "{ ...next(operator), type: after[0] }" },
145
158
  { id: "briefOrWordy", level: 0, bridge: "{ ...next(operator) }" },
146
159
 
147
- { id: "notAble", level: 0, bridge: "{ ...next(operator) }" },
148
- { id: "not", level: 0, bridge: "{ ...after, negated: true }" },
149
-
150
160
  { id: "yesno", level: 0, bridge: "{ ...next(operator) }" },
151
161
  { id: "canBeQuestion", level: 0, bridge: "{ ...next(operator) }" },
152
162
  { id: "canBeQuestion", level: 1, bridge: "{ ...next(operator) }" },
153
163
  // { id: "unknown", level: 0, bridge: "{ ...next(operator), unknown: true, dead: true }" },
154
164
  // { id: "unknown", level: 1, bridge: "{ ...next(operator) }" },
155
- { id: "queryable", level: 0, bridge: "{ ...next(operator) }" },
165
+ // { id: "queryable", level: 0, bridge: "{ ...next(operator) }" },
156
166
  { id: "questionMark", level: 0, bridge: "{ ...before[0], query: [before.marker] }" },
157
167
  // { id: "isEd", level: 0, bridge: "{ ...context, query: true }" },
158
168
  // gregbug
@@ -169,7 +179,7 @@ let configStruct = {
169
179
  { id: "isEder", level: 0, bridge: "{ ...next(operator) }" },
170
180
  { id: "is", level: 0,
171
181
  bridge: "{ ...next(operator), one: { number: operator.number, ...before[0] }, two: after[0] }",
172
- isA: ['verby'],
182
+ isA: ['verb'],
173
183
  queryBridge: "{ ...next(operator), one: after[0], two: after[1], query: true }" ,
174
184
  },
175
185
  { id: "is", level: 1, bridge: "{ ...next(operator) }" },
@@ -181,6 +191,7 @@ let configStruct = {
181
191
  { id: "doesAble", level: 1, bridge: "{ ...next(operator), before: before[0] }" },
182
192
  { id: "does", level: 0, bridge: "{ query: true, what: operator.marker, ...context, number: operator.number, object.number: operator.number }*" },
183
193
 
194
+ /*
184
195
  {
185
196
  id: 'the',
186
197
  level: 0,
@@ -192,13 +203,17 @@ let configStruct = {
192
203
  // bridge: "{ ...after[0], pullFromContext: false, instance: true, concept: true, number: 'one', wantsValue: true, determiner: operator, modifiers: append(['determiner'], after[0].modifiers) }"
193
204
  bridge: "{ ...after[0], pullFromContext: false, concept: true, number: 'one', wantsValue: true, determiner: operator, modifiers: append(['determiner'], after[0].modifiers) }"
194
205
  },
206
+ */
207
+ /*
195
208
  {
196
209
  id: "theAble",
197
210
  children: ['noun'],
198
211
  bridge: "{ ...next(operator) }"
199
212
  },
213
+ */
200
214
 
201
215
  // TODO make this hierarchy thing work
216
+ /*
202
217
  {
203
218
  id: "thisitthat",
204
219
  level: 0,
@@ -206,6 +221,8 @@ let configStruct = {
206
221
  before: ['verby'],
207
222
  bridge: "{ ...next(operator) }"
208
223
  },
224
+ */
225
+ /*
209
226
  {
210
227
  id: "nevermind",
211
228
  bridge: "{ ...next(operator) }",
@@ -225,6 +242,8 @@ let configStruct = {
225
242
  }
226
243
  }
227
244
  },
245
+ */
246
+ /*
228
247
  {
229
248
  id: "nevermindTestSetup",
230
249
  development: true,
@@ -235,7 +254,6 @@ let configStruct = {
235
254
  applyq: () => 'the test question?',
236
255
  onNevermind: ({objects, context}) => {
237
256
  objects.onNevermindWasCalled = true
238
- debugger
239
257
  objects.nevermindType = nevermindType
240
258
  return nevermindType == 'accept'
241
259
  },
@@ -244,6 +262,7 @@ let configStruct = {
244
262
  })
245
263
  }
246
264
  },
265
+ */
247
266
  {
248
267
  id: "why",
249
268
  level: 0,
@@ -255,6 +274,7 @@ let configStruct = {
255
274
  isA: ['theAble', 'queryable'],
256
275
  bridge: "{ ...next(operator) }"
257
276
  },
277
+ /*
258
278
  {
259
279
  id: "it",
260
280
  level: 0,
@@ -273,11 +293,12 @@ let configStruct = {
273
293
  isA: ['thisitthat'],
274
294
  bridge: "{ ...next(operator), unknown: true, pullFromContext: true }"
275
295
  },
296
+ */
276
297
  ],
277
298
  words: {
278
299
  "literals": {
279
300
  "?": [{"id": "questionMark", "initial": "{}" }],
280
- "the": [{"id": "the", "initial": "{ modifiers: [] }" }],
301
+ // "the": [{"id": "the", "initial": "{ modifiers: [] }" }],
281
302
  "who": [{"id": "what", "initial": "{ modifiers: [], query: true }" }],
282
303
  "yes": [{"id": "yesno", "initial": "{ value: true }" }],
283
304
  "no": [{"id": "yesno", "initial": "{ value: false }" }],
@@ -303,14 +324,15 @@ let configStruct = {
303
324
  { "context": [['isEdAble', 0], ['is', 1], ], "choose": [0] },
304
325
  ],
305
326
  hierarchy: [
327
+ ['doubleQuote', 'queryable'],
306
328
  ['it', 'pronoun'],
307
329
  ['this', 'pronoun'],
308
330
  ['questionMark', 'punctuation'],
309
331
  // ['questionMark', 'isEd'],
310
332
  ['a', 'articlePOS'],
311
333
  ['the', 'articlePOS'],
312
- ['unknown', 'notAble'],
313
334
  ['unknown', 'theAble'],
335
+ ['theAble', 'queryable'],
314
336
  ['unknown', 'queryable'],
315
337
  ['it', 'queryable'],
316
338
  ['what', 'queryable'],
@@ -326,10 +348,10 @@ let configStruct = {
326
348
  where: where(),
327
349
  notes: "handle making responses brief",
328
350
  match: ({context, objects}) => (context.topLevel || context.isResponse) && objects.brief && !context.briefWasRun,
329
- apply: ({context, g}) => {
351
+ apply: async ({context, g}) => {
330
352
  const focussed = focus(context)
331
353
  context.briefWasRun = true
332
- return g(focussed)
354
+ return await g(focussed)
333
355
  },
334
356
  priority: -2,
335
357
  },
@@ -384,66 +406,15 @@ let configStruct = {
384
406
  priority: -1,
385
407
  },
386
408
 
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
409
  {
426
410
  where: where(),
427
411
  notes: 'paraphrase a queryable response',
428
412
  // || context.evalue.paraphrase -> when the evalue acts as a paraphrase value
429
413
  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)
414
+ apply: async ({context, g}) => {
415
+ return await g(context.evalue)
432
416
  }
433
417
  },
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
444
- }
445
- },
446
- */
447
418
  {
448
419
  where: where(),
449
420
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'queryable') && !context.isQuery && context.isSelf && context.subject == 'my',
@@ -452,7 +423,7 @@ let configStruct = {
452
423
  {
453
424
  where: where(),
454
425
  match: ({context, hierarchy}) => ['it', 'what'].includes(context.marker) && context.paraphrase,
455
- apply: ({g, context}) => `${context.word}`
426
+ apply: ({context}) => `${context.word}`
456
427
  },
457
428
  {
458
429
  where: where(),
@@ -462,15 +433,8 @@ let configStruct = {
462
433
  {
463
434
  where: where(),
464
435
  match: ({context, hierarchy}) => ['my', 'your'].includes(context.subject) && hierarchy.isA(context.marker, 'queryable') && context.paraphrase,
465
- apply: ({g, context}) => `${context.subject} ${context.marker}`
436
+ apply: ({context}) => `${context.subject} ${context.marker}`
466
437
  },
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}`
472
- },
473
- */
474
438
  {
475
439
  where: where(),
476
440
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'queryable') && !context.isQuery && context.subject,
@@ -495,8 +459,8 @@ let configStruct = {
495
459
  {
496
460
  where: where(),
497
461
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'canBeQuestion') && context.paraphrase && context.topLevel && context.query,
498
- apply: ({context, gp}) => {
499
- return `${gp({...context, topLevel: undefined})}?`
462
+ apply: async ({context, gp}) => {
463
+ return `${await gp({...context, topLevel: undefined})}?`
500
464
  },
501
465
  priority: -1,
502
466
  },
@@ -504,27 +468,27 @@ let configStruct = {
504
468
  where: where(),
505
469
  notes: "x is y",
506
470
  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)}`
471
+ apply: async ({context, g, gp}) => {
472
+ return `${await g({ ...context.one, paraphrase: true })} ${context.word} ${await gp(context.two)}`
509
473
  }
510
474
  },
511
475
  {
512
476
  where: where(),
513
477
  notes: 'is with a response defined',
514
478
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'is') && context.evalue,
515
- apply: ({context, g, gs}) => {
479
+ apply: async ({context, g, gs}) => {
516
480
  const response = context.evalue;
517
481
  const concept = response.concept;
518
482
  if (concept) {
519
483
  concept.paraphrase = true
520
484
  concept.isSelf = true
521
- const instance = g(response.instance)
522
- return `${g(concept)} ${context.word} ${instance}`
485
+ const instance = await g(response.instance)
486
+ return `${await g(concept)} ${context.word} ${instance}`
523
487
  } else {
524
488
  if (Array.isArray(response)) {
525
- return `${gs(response)}`
489
+ return `${await gs(response)}`
526
490
  } else {
527
- return `${g(response)}`
491
+ return `${await g(response)}`
528
492
  }
529
493
  }
530
494
  }
@@ -533,13 +497,13 @@ let configStruct = {
533
497
  where: where(),
534
498
  notes: 'x is y (not a response)',
535
499
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'is') && !context.evalue,
536
- apply: ({context, g, gp, gr, callId}) => {
500
+ apply: async ({context, g, gp, gr, callId}) => {
537
501
  if ((context.two.evalue || {}).marker == 'answerNotKnown') {
538
- return g(context.two.evalue)
502
+ return await g(context.two.evalue)
539
503
  }
540
504
 
541
505
  if (!context.isResponse) {
542
- return `${gp(context.one)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${g(context.two)}`
506
+ return `${await gp(context.one)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${await g(context.two)}`
543
507
  }
544
508
 
545
509
  const hasFocus = (property) => {
@@ -564,17 +528,15 @@ let configStruct = {
564
528
  }
565
529
  // greg101
566
530
  if (focus == 'one') {
567
- return `${g(context.two)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${gp(context.one)}`
531
+ return `${await g(context.two)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${await gp(context.one)}`
568
532
  } else {
569
533
  // TODO fix this using the assumed and that whole mess. change isResponse to useValue
570
534
  if (context.isResponse) {
571
- return `${gp(context.one, { responding: true })} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${g(context.two)}`
535
+ return `${await gp(context.one, { responding: true })} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${await g(context.two)}`
572
536
  } else {
573
- return `${gp(context.one)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${gr(context.two)}`
537
+ return `${await gp(context.one)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${await gr(context.two)}`
574
538
  }
575
- // return `${gp(context.one)} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${g(context.two)}`
576
539
  }
577
- // return `${g({...context.one})} ${isMany(context.one) || isMany(context.two) || isMany(context) ? "are" : "is"} ${g(context.two)}`
578
540
  },
579
541
  },
580
542
  ],
@@ -600,108 +562,62 @@ let configStruct = {
600
562
  {
601
563
  where: where(),
602
564
  match: ({context}) => context.marker === 'error',
603
- apply: ({context, gp}) => {
565
+ apply: async ({context, gp}) => {
604
566
  context.evalue = "That is not known"
605
567
  if (context.reason) {
606
- context.evalue += ` because ${gp(context.reason)}`
568
+ context.evalue += ` because ${await gp(context.reason)}`
607
569
  }
608
570
  context.isResponse = true
609
571
  }
610
572
  },
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
- },
573
+ // {
574
+ // where: where(),
575
+ // notes: 'pull from context',
576
+ // // match: ({context}) => context.marker == 'it' && context.pullFromContext, // && context.value,
577
+ // match: ({context, callId}) => false && context.pullFromContext && !context.same, // && context.value,
578
+ // apply: async ({callId, context, kms, e, log, retry}) => {
579
+ // if (true) {
580
+ // /*
581
+ // {
582
+ // "marker": "unknown",
583
+ // "range": {
584
+ // "start": 65,
585
+ // "end": 73
586
+ // },
587
+ // "word": "worth",
588
+ // "text": "the worth",
589
+ // "value": "worth",
590
+ // "unknown": true,
591
+ // "types": [
592
+ // "unknown"
593
+ // ],
594
+ // "pullFromContext": true,
595
+ // "concept": true,
596
+ // "wantsValue": true,
597
+ // "determiner": "the",
598
+ // "modifiers": [
599
+ // "determiner"
600
+ // ],
601
+ // "evaluate": true
602
+ // }
603
+
604
+ // */
605
+ // context.value = kms.stm.api.mentions(context)
606
+ // if (!context.value) {
607
+ // // retry()
608
+ // context.value = { marker: 'answerNotKnown' }
609
+ // return
610
+ // }
611
+ //
612
+ // const instance = await e(context.value)
613
+ // if (instance.evalue && !instance.edefault) {
614
+ // context.value = instance.evalue
615
+ // }
616
+ // if (context.evaluate) {
617
+ // context.evalue = context.value
618
+ // }
619
+ // },
620
+ // },
705
621
  {
706
622
  where: where(),
707
623
  notes: 'what x is y?',
@@ -712,7 +628,7 @@ let configStruct = {
712
628
  */
713
629
 
714
630
  match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'is') && context.query,
715
- apply: ({context, s, log, km, objects, e}) => {
631
+ apply: async ({context, s, log, km, objects, e}) => {
716
632
  const one = context.one;
717
633
  const two = context.two;
718
634
  let concept, value;
@@ -726,9 +642,9 @@ let configStruct = {
726
642
  // km('dialogues').api.mentioned(concept)
727
643
  // TODO wtf is the next line?
728
644
  value = JSON.parse(JSON.stringify(value))
729
- let instance = e(value)
645
+ let instance = await e(value)
730
646
  if (false && instance.evalue) {
731
- km('stm').api.mentioned(value)
647
+ km('stm').api.mentioned({ context: value })
732
648
  }
733
649
  if (instance.verbatim) {
734
650
  context.evalue = { verbatim: instance.verbatim }
@@ -790,14 +706,14 @@ let configStruct = {
790
706
  where: where(),
791
707
  notes: 'x is y. handles x is a kind of y or x = y in the stm',
792
708
  match: ({context}) => context.marker == 'is' && !context.query && context.one && context.two,
793
- apply: ({context, s, log, api, kms, config}) => {
709
+ apply: async ({context, s, log, api, kms, config}) => {
794
710
  // const oneZero = { ...context.one }
795
711
  // const twoZero = { ...context.two }
796
712
 
797
713
  const one = context.one;
798
714
  const two = context.two;
799
715
  one.same = two;
800
- const onePrime = s(one)
716
+ const onePrime = await s(one)
801
717
  if (!onePrime.sameWasProcessed) {
802
718
  warningSameNotEvaluated(log, one)
803
719
  } else {
@@ -810,7 +726,7 @@ let configStruct = {
810
726
  let twoPrime;
811
727
  if (!onePrime.sameWasProcessed) {
812
728
  two.same = one
813
- twoPrime = s(two)
729
+ twoPrime = await s(two)
814
730
  if (!twoPrime.sameWasProcessed) {
815
731
  warningSameNotEvaluated(log, two)
816
732
  } else {
@@ -823,26 +739,14 @@ let configStruct = {
823
739
 
824
740
  // if not isA add to stm
825
741
  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)
742
+ for (const child of propertyToArray(one)) {
743
+ api.makeObject({ context: child, config, types: context.two.types || [] })
744
+ kms.stm.api.setVariable(child.value, two)
745
+ kms.stm.api.mentioned({ context: child, value: two })
746
+ }
829
747
  }
830
748
  }
831
749
  },
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
750
  {
847
751
  where: where(),
848
752
  notes: 'get variable from stm',
@@ -850,206 +754,60 @@ let configStruct = {
850
754
  match: ({context, kms}) => context.evaluate && kms.stm.api.getVariable(context.value) != context.value,
851
755
  // match: ({context, kms}) => context.evaluate,
852
756
  priority: -1,
853
- apply: ({context, kms, e}) => {
757
+ apply: async ({context, kms, e}) => {
854
758
  const api = kms.stm.api
855
759
  context.value = api.getVariable(context.value)
856
- /*
857
- if (!context.value && context.marker !== 'unknown') {
858
- context.value = api.getVariable(context.marker)
859
- }
860
- */
861
760
  if (context.value && context.value.marker) {
862
- context.evalue = e(context.value)
761
+ context.evalue = await e(context.value)
863
762
  }
864
763
  context.focusableForPhrase = true
865
764
  }
866
765
  },
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
766
  ],
896
767
  };
897
768
 
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
908
- }
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
769
+ const initializer = ({objects, config, isModule}) => {
770
+ /* TODO add this beck in. some stuff from config needs to be here
771
+ config.addArgs((args) => ({
772
+ e: (context) => config.api.getEvaluator(args.s, args.log, context),
773
+ }))
774
+ */
775
+ config.addArgs(({config, api, isA}) => ({
776
+ toScopedId: (context) => {
777
+ return api('dialogues').toScopedId(context)
778
+ },
779
+ addWords: (id, word, additional) => {
780
+ for (let props of words(word, { ...additional })) {
781
+ config.addWord(props.word, { id, initial: JSON.stringify(props) })
922
782
  }
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) )
783
+ },
784
+ values: propertyToArray,
785
+ }))
786
+ objects.mentioned = []
787
+ objects.variables = {
788
+ }
789
+ if (isModule) {
790
+ } else {
791
+ config.addWord("canbedoquestion", { id: "canBeDoQuestion", "initial": "{}" })
792
+ config.addWord("doesable", { id: "doesAble", "initial": "{}" })
993
793
  }
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
794
  }
1042
795
 
1043
796
  knowledgeModule( {
797
+ config,
798
+ includes: [articles, gdefaults, sdefaults, conjunction, asking, pos, negation, stm, meta, punctuation],
799
+ initializer,
800
+ api: () => new API(),
801
+
1044
802
  module,
1045
803
  description: 'framework for dialogues',
1046
- createConfig, newWay: true,
804
+ newWay: true,
1047
805
  test: {
1048
806
  name: './dialogues.test.json',
1049
807
  contents: dialogues_tests,
1050
808
  checks: {
1051
- objects: ['onNevermindWasCalled', 'nevermindType'],
1052
- context: defaultContextCheck,
809
+ objects: ['idSuffix'],
810
+ context: defaultContextCheck(),
1053
811
  },
1054
812
 
1055
813
  },