ekms 7.12.3 → 7.12.4-beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. package/common/animals.instance.json +52 -0
  2. package/common/avatar.js +1 -2
  3. package/common/comparable.js +1 -1
  4. package/common/concept.js +2 -0
  5. package/common/countable.js +1 -1
  6. package/common/crew.instance.json +348 -0
  7. package/common/crew.js +3 -2
  8. package/common/currency.js +2 -0
  9. package/common/dialogues.js +7 -3
  10. package/common/dimension.js +3 -1
  11. package/common/dimension.test.json +170 -26
  12. package/common/dimensionTemplate.instance.json +4 -0
  13. package/common/edible.instance.json +128 -0
  14. package/common/edible.js +1 -2
  15. package/common/emotions.instance.json +4 -0
  16. package/common/emotions.js +2 -0
  17. package/common/fastfood.instance.json +939 -435
  18. package/common/fastfood.js +149 -62
  19. package/common/fastfood.test.json +36474 -985
  20. package/common/formulas.js +3 -1
  21. package/common/formulasTemplate.instance.json +4 -0
  22. package/common/formulasTemplate.js +1 -1
  23. package/common/help.js +2 -0
  24. package/common/hierarchy.js +2 -0
  25. package/common/javascript.js +2 -0
  26. package/common/kirk.instance.json +4 -0
  27. package/common/length.instance.json +60 -0
  28. package/common/math.js +1 -4
  29. package/common/mathTemplate.instance.json +8 -0
  30. package/common/mathTemplate.js +1 -1
  31. package/common/ordering.instance.json +8 -0
  32. package/common/ordering.js +2 -0
  33. package/common/people.instance.json +32 -60
  34. package/common/people.js +2 -0
  35. package/common/pipboy.js +3 -1
  36. package/common/pipboy.test.json +13 -5
  37. package/common/pipboyTemplate.js +1 -1
  38. package/common/pokemon.instance.json +52 -0
  39. package/common/pokemon.js +2 -0
  40. package/common/pressure.instance.json +16 -0
  41. package/common/properties.instance.json +4 -0
  42. package/common/properties.js +3 -3
  43. package/common/reports.instance.json +9 -1
  44. package/common/reports.js +7 -3
  45. package/common/scorekeeper.js +3 -3
  46. package/common/sizeable.js +1 -1
  47. package/common/spock.instance.json +4 -0
  48. package/common/stgame.js +2 -0
  49. package/common/stm.js +21 -6
  50. package/common/tell.js +2 -0
  51. package/common/temperature.instance.json +16 -84
  52. package/common/time.js +2 -0
  53. package/common/ui.instance.json +4 -0
  54. package/common/ui.js +3 -1
  55. package/common/weight.instance.json +48 -0
  56. package/package.json +2 -2
@@ -160,7 +160,6 @@ const template = {
160
160
  { "context": [['smoothie_ingredient', 1], ['list', 0], ['smoothie_ingredient', 1], ['smoothie', 1]], ordered: true, choose: [1] },
161
161
 
162
162
  { "context": [['list', 0], ['number', 1], ['combo', 1], ['number', 1]], ordered: true, choose: [2,3] },
163
- { "context": [['withModification', 0], ['modification', 1], ['list', 0], ['modification', 1]], ordered: true, choose: [2] },
164
163
 
165
164
 
166
165
  { context: [['comboNumber', 0], ['counting',0]], choose: [0] },
@@ -224,7 +223,7 @@ const template = {
224
223
  {
225
224
  id: 'withModification',
226
225
  level: 0,
227
- isA: ['preposition'],
226
+ before: ['preposition'],
228
227
  generatorp: ({context, gp}) => `with ${gp(context.modifications)}`,
229
228
  bridge: "{ ...next(operator), modifications: after[0], flatten: false }",
230
229
  },
@@ -250,7 +249,7 @@ const template = {
250
249
  {
251
250
  id: 'comboNumber',
252
251
  convolution: true,
253
- before: ['combo'],
252
+ before: ['combo', 'preposition'],
254
253
  bridge: "{ ...next(before[0]), postModifiers: append(before[0].postModifiers, ['comboNumber']), comboNumber: after[0], instance: true, flatten: true }",
255
254
  },
256
255
  {
@@ -297,17 +296,24 @@ const template = {
297
296
  const naArray = api.getAskedForButNotAvailable()
298
297
  naArray.forEach((f) => f.paraphrase = true)
299
298
  const naContext = toContext(naArray)
300
- /*
301
- naContext.isResponse = true
302
- naContext.marker = 'verbatim'
303
- naContext.verbatim = `The following are not menu items: ${gp(naContext)}`
304
- insert(naContext)
305
- */
306
299
  verbatim(`The following are not menu items: ${gp(naContext)}`)
307
300
  // allow other motivation to run
308
301
  context.cascade = true
309
302
  }
310
303
  },
304
+ {
305
+ where: where(),
306
+ match: ({context, api}) => context.marker == 'controlEnd' && api.hasAskedForButNotAvailableModification(),
307
+ apply: ({context, api, gp, toContext, verbatim}) => {
308
+ const naArray = api.getAskedForButNotAvailableModification().map(({ item, modification }) => {
309
+ // return `${gp(item)} can not be modified with ${gp(modification)}.`
310
+ return `XXX can not be modified with ${gp(modification)}.`
311
+ })
312
+ verbatim(naArray.join(' '))
313
+ // allow other motivation to run
314
+ context.cascade = true
315
+ }
316
+ },
311
317
  ]
312
318
  },
313
319
  ({ask, api}) => {
@@ -342,17 +348,26 @@ const template = {
342
348
  {
343
349
  where: where(),
344
350
  oneShot: false,
345
- matchq: (args) => askAbout(args).length > 0,
351
+ matchq: (args) => askAbout(args).length > 0 && args.context.marker == 'controlEnd',
346
352
  applyq: (args) => {
347
353
  args.context.cascade = true
348
354
  const needsDrink = askAbout(args)
355
+ // const details = args.gp({ marker: 'list', value: needsDrink.map((item) => item.food)})
349
356
  if (needsDrink.length > 1) {
350
357
  return `What drinks do you want?`
351
358
  } else {
352
359
  return `What drink do you want?`
353
360
  }
354
361
  },
355
- matchr: (args) => args.isA(args.context.marker, 'drink') && askAbout(args).length > 0,
362
+ matchr: (args) => {
363
+ if (args.isA(args.context.marker, 'drink') && askAbout(args).length > 0) {
364
+ const needsDrink = askAbout(args)
365
+ if (args.api.isAvailableModification(needsDrink[0].food, { ...args.context , id: args.context.value })) {
366
+ return true
367
+ }
368
+ }
369
+ return false
370
+ },
356
371
  applyr: (args) => {
357
372
  // TODO check for is available for all modifications
358
373
  const needsDrink = askAbout(args)
@@ -375,6 +390,33 @@ const template = {
375
390
  ])
376
391
  },
377
392
  {
393
+ operators: [
394
+ "([change] (meal/* || drink/*) (to/1))",
395
+ ],
396
+ hierarchy: [
397
+ ['meal', 'toAble'],
398
+ ['drink', 'toAble'],
399
+ ],
400
+ bridges: [
401
+ {
402
+ id: "change",
403
+ isA: ['verby'],
404
+ localHierarchy: [ ['thisitthat', 'meal'] ],
405
+ generatorp: ({context, gp}) => `change ${gp(context.from)} to ${gp(context.to)}`,
406
+ bridge: "{ ...next(operator), from: after[0], to: after[1].toObject }",
407
+ semantic: ({context, api, e}) => {
408
+ const state = api.state
409
+ const eFrom = e(context.from).evalue
410
+ const from = state.getIdCombo(eFrom.fromSTM ? eFrom : context.from)
411
+ const to = state.getIdCombo(context.to)
412
+ for (const item of api.items()) {
413
+ if (item.id == from.id) {
414
+ api.modify(item, { id: to.id })
415
+ }
416
+ }
417
+ }
418
+ },
419
+ ],
378
420
  priorities: [
379
421
  { context: [['combo', 0], ['number',1], ['list', 0], ['combo', 0]], ordered: true, choose: [0,1] },
380
422
  { context: [['list', 0], ['combo',0], ['number',1]], ordered: true, choose: [1,2] },
@@ -382,6 +424,12 @@ const template = {
382
424
  { context: [['mango', 0], ['passion',0], ['list', 0]], ordered: true, choose: [0,1] },
383
425
  { context: [['number', 1], ['mango_passion',1], ['list', 0]], ordered: true, choose: [0,1] },
384
426
  { context: [['mango', 0], ['mango_passion',0], ['passion',0], ['list', 0]], ordered: true, choose: [0,1,2] },
427
+
428
+ { context: [['drink', 0], ['list',0], ['combo',0], ['number', 0]], ordered: true, choose: [2,3] },
429
+ { context: [['drink', 1], ['list',0], ['combo',0], ['number', 0]], ordered: true, choose: [2,3] },
430
+ { context: [['withModification', 0], ['modification', 1], ['list', 0], ['modification', 1]], ordered: true, choose: [2] },
431
+ { context: [['withModification', 0], ['modification', 1], ['list', 0], ['combo', 1]], ordered: true, choose: [0] },
432
+ { context: [['combo', 2], ['list', 0], ['combo', 1], ['withModification', 1]], ordered: true, choose: [3] },
385
433
  ],
386
434
  },
387
435
  ],
@@ -392,6 +440,7 @@ class API {
392
440
  this._objects = objects
393
441
  this._objects.items = []
394
442
  this._objects.notAvailable = []
443
+ this._objects.notAvailableModification = []
395
444
  }
396
445
 
397
446
  show() {
@@ -412,8 +461,12 @@ class API {
412
461
  return this._objects.items[item_id]
413
462
  }
414
463
 
464
+ modify(item, changes) {
465
+ Object.assign(this._objects.items[item.item_id], changes)
466
+ }
467
+
415
468
  items() {
416
- return this._objects.items
469
+ return [...this._objects.items]
417
470
  }
418
471
 
419
472
  addDrink(item_id, drink) {
@@ -430,17 +483,40 @@ class API {
430
483
  return this._objects.notAvailable.length > 0
431
484
  }
432
485
 
486
+ hasAskedForButNotAvailableModification(item) {
487
+ return this._objects.notAvailableModification.length > 0
488
+ }
489
+
433
490
  getAskedForButNotAvailable(item) {
434
491
  const na = this._objects.notAvailable
435
492
  this._objects.notAvailable = []
436
493
  return na
437
494
  }
438
495
 
496
+ getAskedForButNotAvailableModification(item) {
497
+ const na = this._objects.notAvailableModification
498
+ this._objects.notAvailableModification = []
499
+ return na
500
+ }
501
+
439
502
  addAskedForButNotAvailable(item) {
440
503
  this._objects.notAvailable.push(item)
441
504
  }
442
505
 
506
+ addAskedForButNotAvailableModification(item, modification) {
507
+ this._objects.notAvailableModification.push({item, modification})
508
+ }
509
+
510
+ isAvailableModification(food, modification) {
511
+ if (this.isAvailable(modification)) {
512
+ if (this.args.isA(modification.id, 'fry') || this.args.isA(modification.id, 'pop')) {
513
+ return true
514
+ }
515
+ }
516
+ }
517
+
443
518
  isAvailable(item) {
519
+ item.id = item.id || item.value
444
520
  if (item.id == 'chicken_nugget') {
445
521
  if (![4,5,6,10].includes(item.pieces)) {
446
522
  return false
@@ -468,6 +544,10 @@ class API {
468
544
  item.id = 'coca_cola'
469
545
  }
470
546
 
547
+ if (item.id == 'fry') {
548
+ item.id = 'french_fry'
549
+ }
550
+
471
551
  return [
472
552
  "hamburger",
473
553
  "cheeseburger",
@@ -567,17 +647,13 @@ class State {
567
647
  this.api = api
568
648
  }
569
649
 
570
- add(food) {
571
- let quantity = 1
572
- if (food.quantity) {
573
- quantity = food.quantity.value
574
- }
650
+ getIdCombo(food) {
575
651
  let id, combo
576
652
  if (food.comboNumber?.marker == 'numberNumberCombo') {
577
653
  id = this.api.getCombo(food.comboNumber.comboNumber.value)
578
654
  if (!id) {
579
655
  this.api.addAskedForButNotAvailable(food)
580
- return
656
+ return { done: true }
581
657
  }
582
658
  combo = true
583
659
  }
@@ -585,7 +661,7 @@ class State {
585
661
  id = this.api.getCombo(food.comboNumber.value)
586
662
  if (!id) {
587
663
  this.api.addAskedForButNotAvailable(food)
588
- return
664
+ return { done: true }
589
665
  }
590
666
  combo = true
591
667
  } else if (food.marker == 'combo') {
@@ -600,6 +676,20 @@ class State {
600
676
  id = 'chicken_nugget'
601
677
  }
602
678
 
679
+ return { id, combo }
680
+ }
681
+
682
+ add(food) {
683
+ let quantity = 1
684
+ if (food.quantity) {
685
+ quantity = food.quantity.value
686
+ }
687
+
688
+ const { id, combo, done } = this.getIdCombo(food)
689
+ if (done) {
690
+ return
691
+ }
692
+
603
693
  const addSize = (item, data) => {
604
694
  if (item.size) {
605
695
  data.size = item.size.value
@@ -607,15 +697,39 @@ class State {
607
697
  return data
608
698
  }
609
699
 
700
+ const getAvailableChildren = (item) => {
701
+ // see if this is a categories of items
702
+ const descendants = this.api.args.hierarchy.descendants(item.id)
703
+ const available = []
704
+ for (const descendant of descendants) {
705
+ if (this.api.isAvailable({ id: descendant})) {
706
+ available.push(descendant)
707
+ }
708
+ }
709
+ return available
710
+ }
711
+
610
712
  let modifications
713
+ const addsInsteadOfModifications = []
611
714
  if (food.modifications) {
612
715
  modifications = []
613
716
  for (const modification of propertyToArray(food.modifications.modifications)) {
614
717
  if (modification.size) {
615
718
  food.size = modification.size
616
719
  }
617
- addSize(modification, { id: modification.value })
618
- modifications.push(addSize(modification, { id: modification.value }))
720
+
721
+ // if not a modification treat as top level request
722
+ if (!this.api.isAvailableModification(food, { ...modification, id: modification.value })) {
723
+ if (this.api.isAvailable(modification)) {
724
+ //this.add(modification)
725
+ addsInsteadOfModifications.push(modification)
726
+ } else {
727
+ this.api.addAskedForButNotAvailable(modification)
728
+ }
729
+ } else {
730
+ addSize(modification, { id: modification.value })
731
+ modifications.push(addSize(modification, { id: modification.value }))
732
+ }
619
733
  }
620
734
  }
621
735
 
@@ -636,42 +750,11 @@ class State {
636
750
  return
637
751
  }
638
752
 
639
- const item_id = this.api.add(item)
640
-
641
- if (false) {
642
- // see if followup for drink is needed
753
+ this.api.add(item)
754
+ this.api.args.mentioned(food)
643
755
 
644
- const hasDrink = (item_id) => {
645
- const item = this.api.get(item_id)
646
- let hasDrink = false
647
- for (let modification of (item.modifications || [])) {
648
- if (!this.api.args.isA(modification.id, 'drink')) {
649
- hasDrink = true
650
- break
651
- }
652
- }
653
- return hasDrink
654
- }
655
- const needsDrink = (item_id) => {
656
- const item = this.api.get(item_id)
657
- return item.needsDrink
658
- }
659
-
660
- if (!hasDrink(item_id) && needsDrink(item_id)) {
661
- this.api.args.ask([
662
- {
663
- where: where(),
664
- matchq: ({objects}) => !hasDrink(item_id) && needsDrink(item_id),
665
- applyq: () => `What drink do you want?`,
666
- matchr: ({context, isA}) => isA(context.marker, 'drink'),
667
- applyr: ({context, objects, api}) => {
668
- // TODO check for is available for all modifications
669
- this.api.addDrink(item_id, { id: context.value })
670
- }
671
- },
672
- ]
673
- )
674
- }
756
+ for (const addIt of addsInsteadOfModifications) {
757
+ this.add(addIt)
675
758
  }
676
759
  }
677
760
  }
@@ -686,7 +769,7 @@ class State {
686
769
  }
687
770
  }
688
771
 
689
- const createConfig = () => {
772
+ const createConfig = (additionalConfig) => {
690
773
  const config = new Config({
691
774
  name: 'fastfood',
692
775
  operators: [
@@ -708,7 +791,7 @@ const createConfig = () => {
708
791
  },
709
792
  {
710
793
  where: where(),
711
- match: ({context, isAListable}) => isAListable(context, 'edible') && context.marker !== 'edible' && !context.same && !context.isResponse,
794
+ match: ({context, isAListable}) => isAListable(context, 'edible') && context.marker !== 'edible' && !context.same && !context.isResponse && !context.evaluate,
712
795
  apply: ({context, km, api, instance}) => {
713
796
  for (const element of propertyToArray(context)) {
714
797
  km('fastfood').api.state.add(element)
@@ -737,14 +820,16 @@ const createConfig = () => {
737
820
  },
738
821
  ],
739
822
  }, module)
740
- config.add(edible())
741
- config.add(countable())
742
- config.add(events())
743
- config.add(sizeable())
823
+ config.stop_auto_rebuild()
824
+ config.add(edible(), countable(), events(), sizeable())
744
825
  config.api = api
745
826
  config.initializer( ({api}) => {
746
827
  api.state = new State(api)
747
828
  })
829
+ if (additionalConfig) {
830
+ additionalConfig(config)
831
+ }
832
+ config.restart_auto_rebuild()
748
833
  return config
749
834
  }
750
835
 
@@ -752,6 +837,7 @@ knowledgeModule( {
752
837
  module,
753
838
  description: 'fastfood related concepts',
754
839
  createConfig,
840
+ acceptsAdditionalConfig: true,
755
841
  test: {
756
842
  name: './fastfood.test.json',
757
843
  contents: fastfood_tests,
@@ -762,6 +848,7 @@ knowledgeModule( {
762
848
  'changes',
763
849
  'response',
764
850
  { property: 'notAvailable', filter: [ 'marker', 'value', 'text' ] },
851
+ { property: 'notAvailableModification', filter: [ 'marker', 'value', 'text' ] },
765
852
  { property: 'quantity', filter: ['marker', 'value', 'text' ] },
766
853
  { property: 'pieces', filter: ['marker', 'value', 'text' ] },
767
854
  ],