tpmkms_4wp 7.12.4-beta.1 → 7.12.4-beta.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,6 +30,8 @@ const fastfood_instance = require('./fastfood.instance.json')
30
30
  double hamburger
31
31
  number 1 and 2
32
32
  number 1 2 and 3
33
+ combo 1 through 5
34
+
33
35
  */
34
36
 
35
37
  const template = {
@@ -348,6 +350,18 @@ const template = {
348
350
  {
349
351
  where: where(),
350
352
  oneShot: false,
353
+ onNevermind: ({verbatim, ...args}) => {
354
+ // this is cross km boundaries from the dialogues km to this one so the api if for dialogs.
355
+ // i need to get the one for fastfood here.
356
+ const api = args.kms.fastfood.api
357
+ const needsDrink = askAbout({ args, api })
358
+ if (needsDrink.length > 1) {
359
+ verbatim("The drinks must be specified")
360
+ } else {
361
+ verbatim("The drink must be specified")
362
+ }
363
+ return false
364
+ },
351
365
  matchq: (args) => askAbout(args).length > 0 && args.context.marker == 'controlEnd',
352
366
  applyq: (args) => {
353
367
  args.context.cascade = true
@@ -411,7 +425,7 @@ const template = {
411
425
  const to = state.getIdCombo(context.to)
412
426
  for (const item of api.items()) {
413
427
  if (item.id == from.id) {
414
- api.modify(item, { id: to.id })
428
+ api.modify(item, { id: to.id, food: context.to })
415
429
  }
416
430
  }
417
431
  }
@@ -432,6 +446,35 @@ const template = {
432
446
  { context: [['combo', 2], ['list', 0], ['combo', 1], ['withModification', 1]], ordered: true, choose: [3] },
433
447
  ],
434
448
  },
449
+ {
450
+ operators: [
451
+ "([remove|remove,delete,drop,ditch,forget,no] (food/*))",
452
+ "([reset|reset,restart,clear])",
453
+ ],
454
+ bridges: [
455
+ {
456
+ id: 'remove',
457
+ isA: ['verby'],
458
+ bridge: "{ ...next(operator), remove: after[0], postModifiers: ['remove'] }",
459
+ semantic: ({context, api}) => {
460
+ const state = api.state
461
+ for (const item of api.items()) {
462
+ if (state.match(context.remove, item)) {
463
+ api.remove(item)
464
+ }
465
+ }
466
+ }
467
+ },
468
+ {
469
+ id: 'reset',
470
+ isA: ['verby'],
471
+ bridge: "{ ...next(operator) }",
472
+ semantic: ({context, api}) => {
473
+ api.reset()
474
+ }
475
+ },
476
+ ],
477
+ },
435
478
  ],
436
479
  }
437
480
 
@@ -441,28 +484,53 @@ class API {
441
484
  this._objects.items = []
442
485
  this._objects.notAvailable = []
443
486
  this._objects.notAvailableModification = []
487
+ this._objects.item_id_counter = 0
444
488
  }
445
489
 
446
490
  show() {
447
491
  this._objects.show = this._objects.items
448
492
  }
449
493
 
494
+ toItem(item_id) {
495
+ if (Array.isArray(item_id)) {
496
+ return this._objects.items[item_id[0]].modifications[item_id[1]]
497
+ } else {
498
+ return this._objects.items[item_id]
499
+ }
500
+ }
501
+
502
+ new_item_id() {
503
+ const item_id = this._objects.item_id_counter
504
+ this._objects.item_id_counter += 1
505
+ return item_id
506
+ }
507
+
450
508
  // returns an item id so things can be updated if needed
451
509
  add(item) {
452
- item.item_id = this._objects.items.length
510
+ item.item_id = this.new_item_id()
453
511
  if (!item.modifications) {
454
512
  item.modifications = []
455
513
  }
514
+ item.modifications.forEach((modification, index) => {
515
+ modification.item_id = [item.item_id, index]
516
+ })
456
517
  this._objects.items.push(item)
457
- return item.item_id
518
+ }
519
+
520
+ reset() {
521
+ this._objects.items = []
458
522
  }
459
523
 
460
524
  get(item_id) {
461
- return this._objects.items[item_id]
525
+ return this.toItem(item_id)
462
526
  }
463
527
 
464
528
  modify(item, changes) {
465
- Object.assign(this._objects.items[item.item_id], changes)
529
+ Object.assign(this.toItem(item.item_id), changes)
530
+ }
531
+
532
+ remove(item) {
533
+ this._objects.items = this._objects.items.filter( (i) => i.item_id !== item.item_id )
466
534
  }
467
535
 
468
536
  items() {
@@ -470,8 +538,9 @@ class API {
470
538
  }
471
539
 
472
540
  addDrink(item_id, drink) {
473
- this._objects.items[item_id].modifications.push(drink)
474
- this._objects.items[item_id].needsDrink = false
541
+ const item = this.toItem(item_id)
542
+ item.modifications.push(drink)
543
+ item.needsDrink = false
475
544
  }
476
545
 
477
546
  say(response) {
@@ -638,6 +707,27 @@ class API {
638
707
  }
639
708
  return map[number]
640
709
  }
710
+
711
+ canBeCombo(id) {
712
+ return this.getComboNumber(id) > 0
713
+ }
714
+
715
+ getComboNumber(id) {
716
+ const combos = [
717
+ 'single',
718
+ 'double',
719
+ 'triple',
720
+ 'baconator',
721
+ 'bacon_deluxe',
722
+ 'spicy',
723
+ 'homestyle',
724
+ 'asiago_range_chicken_club',
725
+ 'ultimate_chicken_grill',
726
+ 'chicken_nugget',
727
+ 'premium_cod',
728
+ ]
729
+ return combos.findIndex((e) => e == id) + 1
730
+ }
641
731
  }
642
732
 
643
733
  const api = new API()
@@ -665,7 +755,7 @@ class State {
665
755
  }
666
756
  combo = true
667
757
  } else if (food.marker == 'combo') {
668
- id = food.type.value
758
+ id = food.type?.value
669
759
  combo = true
670
760
  } else {
671
761
  id = food.value
@@ -679,6 +769,18 @@ class State {
679
769
  return { id, combo }
680
770
  }
681
771
 
772
+ match(pattern, item) {
773
+ Object.assign(pattern, this.getIdCombo(pattern))
774
+ if (pattern.id == item.id) {
775
+ return true
776
+ }
777
+ if (!pattern.id) {
778
+ if (pattern.combo == item.combo) {
779
+ return true
780
+ }
781
+ }
782
+ }
783
+
682
784
  add(food) {
683
785
  let quantity = 1
684
786
  if (food.quantity) {
@@ -746,7 +848,66 @@ class State {
746
848
  for (let i = 0; i < quantity; ++i) {
747
849
  const item = addSize(food, { id, combo, modifications, pieces, food })
748
850
  if (!this.api.isAvailable(item)) {
749
- this.api.addAskedForButNotAvailable(food)
851
+ const available = []
852
+ for (const descendant of this.api.args.hierarchy.descendants(food.marker)) {
853
+ if (this.api.isAvailable({ id: descendant })) {
854
+ available.push(descendant)
855
+ }
856
+ }
857
+
858
+ // this sentence runs but it doesnt setup the hierarchy: 'combo 1, 2, 3, 4, 5, 6, 7, 9, 10, and 11 are combos'
859
+ // i made a wrong design choice when i setup the phrase 'combo 1 etc'. I should have mapped that to the 'single_combo'
860
+ // but instead had it be a combo with a comboNumber property. That means the language layer doesnt know about the mapping
861
+ // so that phrase doesnt work. if I set it up the other way that phrase would work. This is just a demo and I have other
862
+ // demoes to write so i am not fixin that and instead will do || is a combo
863
+
864
+ if (available.length > 0 || food.marker == 'combo') {
865
+ this.api.args.ask([
866
+ {
867
+ where: where(),
868
+ oneShot: true,
869
+ matchq: ({context}) => context.marker == 'controlEnd',
870
+ applyq: () => {
871
+ // args.context.cascade = true
872
+ const word = food.word
873
+ return `What kind of ${word}?`
874
+ },
875
+ semanticsr: [
876
+ // stuipid hack one because i didnt put combo fully into the NLI layer
877
+ {
878
+ where: where(),
879
+ match: ({context, callId, isA, api}) => {
880
+ return api.canBeCombo(context.marker)
881
+ },
882
+ apply: ({context}) => {
883
+ const comboNumber = {
884
+ value: api.getComboNumber(context.marker)
885
+ }
886
+ food.comboNumber = comboNumber
887
+ this.add(food)
888
+ }
889
+ },
890
+ {
891
+ where: where(),
892
+ match: ({context, isA}) => isA(context.marker, food.marker),
893
+ apply: ({context}) => {
894
+ this.add(Object.assign(food, context))
895
+ }
896
+ },
897
+ {
898
+ where: where(),
899
+ match: ({context, isA}) => isA(context.marker, `${food.marker}_modifier`),
900
+ apply: ({context}) => {
901
+ const value = `${context.value}_${food.value}`
902
+ this.add(Object.assign(food, { value }))
903
+ }
904
+ },
905
+ ]
906
+ },
907
+ ])
908
+ } else {
909
+ this.api.addAskedForButNotAvailable(food)
910
+ }
750
911
  return
751
912
  }
752
913
 
@@ -844,7 +1005,19 @@ knowledgeModule( {
844
1005
  checks: {
845
1006
  objects: [
846
1007
  'show',
847
- { property: 'items', filter: ['combo', 'pieces', 'size', 'item_id', 'id', 'modifications', 'needsDrink'] },
1008
+ {
1009
+ property: 'items',
1010
+ filter: [
1011
+ 'combo',
1012
+ 'pieces',
1013
+ 'size',
1014
+ 'item_id',
1015
+ 'id',
1016
+ { property: 'food', filter: [ 'marker', 'value', 'text' ] },
1017
+ { property: 'modifications', filter: [ 'id', 'item_id', 'food' ] },
1018
+ 'needsDrink'
1019
+ ],
1020
+ },
848
1021
  'changes',
849
1022
  'response',
850
1023
  { property: 'notAvailable', filter: [ 'marker', 'value', 'text' ] },