tpmkms_4wp 9.5.1 → 9.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/common/animals.instance.json +21 -61
  2. package/common/asking.js +116 -106
  3. package/common/avatar.test.json +1001 -860
  4. package/common/can.instance.json +2174 -0
  5. package/common/can.js +254 -0
  6. package/common/can.test.json +51307 -0
  7. package/common/characters.js +5 -5
  8. package/common/colors.instance.json +12 -12
  9. package/common/comparable.instance.json +3 -3
  10. package/common/concept.js +25 -27
  11. package/common/concept.test.json +180 -144
  12. package/common/conjunction.js +13 -5
  13. package/common/conjunction.test.json +32 -42
  14. package/common/crew.instance.json +196 -160
  15. package/common/crew.js +1 -1
  16. package/common/crew.test.json +4148 -3324
  17. package/common/currency.js +1 -1
  18. package/common/dateTimeSelectors.instance.json +2 -2
  19. package/common/dateTimeSelectors.js +3 -3
  20. package/common/dateTimeSelectors.test.json +76935 -35739
  21. package/common/dates.instance.json +3 -3
  22. package/common/dates.test.json +284 -287
  23. package/common/dialogues.js +41 -119
  24. package/common/dialogues.test.json +1171 -996
  25. package/common/dimension.instance.json +21369 -557
  26. package/common/dimension.js +148 -54
  27. package/common/dimension.test.json +8753 -3495
  28. package/common/drone.instance.json +23712 -0
  29. package/common/drone.js +448 -0
  30. package/common/drone.test.json +66665 -0
  31. package/common/edible.instance.json +32 -32
  32. package/common/emotions.instance.json +75 -76
  33. package/common/emotions.js +1 -1
  34. package/common/emotions.test.json +242 -174
  35. package/common/english_helpers.js +336 -0
  36. package/common/errors.js +6 -6
  37. package/common/evaluate.js +2 -2
  38. package/common/events.js +8 -8
  39. package/common/fastfood.instance.json +389 -245
  40. package/common/fastfood.js +11 -11
  41. package/common/fastfood.test.json +6970 -6829
  42. package/common/formulas.instance.json +1 -1
  43. package/common/formulas.js +1 -1
  44. package/common/gdefaults.js +111 -17
  45. package/common/help.js +12 -12
  46. package/common/help.test.json +65 -11
  47. package/common/helpers/concept.js +1 -1
  48. package/common/helpers/conjunction.js +54 -44
  49. package/common/helpers/dateTimeSelectors.js +2 -2
  50. package/common/helpers/dialogues.js +7 -2
  51. package/common/helpers/formulas.js +13 -11
  52. package/common/helpers/menus.js +12 -12
  53. package/common/helpers/meta.js +9 -9
  54. package/common/helpers/properties.js +185 -62
  55. package/common/helpers.js +167 -48
  56. package/common/hierarchy.js +6 -4
  57. package/common/kirk.instance.json +1 -1
  58. package/common/kirk.test.json +600 -424
  59. package/common/latin.instance.json +12 -12
  60. package/common/latin.js +9 -9
  61. package/common/length.instance.json +27612 -2890
  62. package/common/length.js +6 -1
  63. package/common/length.test.json +45315 -3925
  64. package/common/math.instance.json +29 -29
  65. package/common/math.js +47 -46
  66. package/common/menus.instance.json +7 -10
  67. package/common/menus.js +2 -9
  68. package/common/meta.js +77 -60
  69. package/common/nameable.js +20 -13
  70. package/common/nameable.test.json +436 -0
  71. package/common/numbers.js +1 -1
  72. package/common/ordering.instance.json +87 -19
  73. package/common/ordering.js +1 -1
  74. package/common/ordering.test.json +835 -417
  75. package/common/people.instance.json +96 -348
  76. package/common/people.js +6 -4
  77. package/common/people.test.json +4135 -3606
  78. package/common/pipboy.instance.json +17 -17
  79. package/common/pipboy.js +2 -3
  80. package/common/pokemon.instance.json +13 -13
  81. package/common/pokemon.js +1 -1
  82. package/common/pressure.instance.json +3579 -1610
  83. package/common/pressure.test.json +433 -477
  84. package/common/properties.instance.json +6 -17
  85. package/common/properties.js +25 -7
  86. package/common/properties.test.json +9565 -6951
  87. package/common/rates.instance.json +59 -0
  88. package/common/rates.js +97 -0
  89. package/common/rates.test.json +27702 -0
  90. package/common/reminders.instance.json +4 -4
  91. package/common/reminders.js +5 -5
  92. package/common/reminders.test.json +64635 -25787
  93. package/common/reports.instance.json +3 -3
  94. package/common/reports.js +18 -16
  95. package/common/scorekeeper.js +6 -6
  96. package/common/sdefaults.js +22 -2
  97. package/common/spock.instance.json +1 -1
  98. package/common/spock.test.json +606 -430
  99. package/common/stgame.js +1 -1
  100. package/common/stm.js +17 -6
  101. package/common/tell.js +1 -1
  102. package/common/temperature.instance.json +3659 -1690
  103. package/common/temperature.test.json +433 -477
  104. package/common/tester.js +3 -3
  105. package/common/time.instance.json +24762 -0
  106. package/common/time.js +137 -141
  107. package/common/time.test.json +31876 -3757
  108. package/common/tokenize.js +5 -2
  109. package/common/ui.instance.json +2 -5
  110. package/common/ui.js +1 -8
  111. package/common/weight.instance.json +10360 -4078
  112. package/common/weight.test.json +2601 -2263
  113. package/common/words.instance.json +9 -0
  114. package/common/words.js +53 -0
  115. package/common/words.test.json +2 -0
  116. package/common/wp.instance.json +408 -8
  117. package/common/wp.js +8 -4
  118. package/common/wp.test.json +7385 -6906
  119. package/main.js +4 -2
  120. package/package.json +20 -5
  121. package/common/listener.js +0 -50
  122. package/common/listener.test.json +0 -142
@@ -1,5 +1,5 @@
1
- const { knowledgeModule, where, Digraph } = require('./runtime').theprogrammablemind
2
- const { defaultObjectCheck, defaultContextCheck } = require('./helpers')
1
+ const { debug, knowledgeModule, where, Digraph } = require('./runtime').theprogrammablemind
2
+ const { defaultObjectCheck, defaultContextCheck, defaultContextCheckProperties } = require('./helpers')
3
3
  const hierarchy = require('./hierarchy.js')
4
4
  const formulas = require('./formulas.js')
5
5
  const testing = require('./testing.js')
@@ -11,6 +11,14 @@ const instance = require('./dimension.instance.json')
11
11
  x fahrenheit equals (x-32)*5/9 + 32 fahrenheit
12
12
  10 celcius + 5
13
13
 
14
+ 1 meter 10 centimeters
15
+
16
+ 1 meter in feet and inches
17
+ 10 feet in meters and inches
18
+
19
+ show length in feet and inches
20
+ show length in meters and millimeters
21
+
14
22
  10 C
15
23
 
16
24
  use a digraph for calculating convertions
@@ -24,8 +32,21 @@ const instance = require('./dimension.instance.json')
24
32
  */
25
33
  class API {
26
34
 
27
- initialize({ config }) {
35
+ initialize({ config, objects }) {
28
36
  this._config = config
37
+ this._objects = objects
38
+ }
39
+
40
+ setMeasurementSystem(measurementSystem) {
41
+ this._objects.measurementSystem = measurementSystem
42
+ }
43
+
44
+ // if the user says 2 feet deduce english etc
45
+ deduceMeasurementSystem(utterance) {
46
+ }
47
+
48
+ getMeasurementSystem() {
49
+ return this._objects.measurementSystem
29
50
  }
30
51
 
31
52
  setup( {dimension, units} ) {
@@ -50,27 +71,26 @@ class API {
50
71
  }
51
72
  }
52
73
 
53
- const api = new API()
74
+ // eg, dimension == length; meters == unit; 2 meters == quantity
54
75
 
55
76
  const config = {
56
77
  name: 'dimension',
57
78
  operators: [
58
- "([dimension])",
79
+ "([quantity])",
59
80
  "([unit])",
60
- // "(([unit]) [kindOfDimension|of] ([dimension]))",
61
- "((amount/1 || number/1) [amountOfDimension|] ([unit]))",
81
+ "((amount/* || number/*) [amountOfCoordinate|] ([unit]))",
62
82
  "(([amount]) [unit])",
63
- "((dimension) [convertToUnits|in] (unit))",
83
+ "((@<=quantity || context.possession == true) [convertToUnits|in] (unit))",
64
84
 
65
85
  "(([number]) [degree])",
66
- { pattern: "([length])", development: true },
86
+ { pattern: "([length])", scope: "testing" },
67
87
  ],
68
88
  priorities: [
69
89
  // TODO this should have been calculated
70
- { "context": [['amountOfDimension', 0], ['convertToUnits', 0], ], "choose": [0] },
90
+ { "context": [['amountOfCoordinate', 0], ['convertToUnits', 0], ], "choose": [0] },
71
91
  ],
72
92
  hierarchy: [
73
- { child: 'convertToUnits', parent: 'testingValue', development: true },
93
+ { child: 'convertToUnits', parent: 'testingValue', scope: "testing" },
74
94
  ],
75
95
  generators: [
76
96
  {
@@ -83,29 +103,21 @@ const config = {
83
103
  {
84
104
  where: where(),
85
105
  id: "dimension",
106
+ },
107
+ {
108
+ where: where(),
109
+ id: "quantity",
110
+ isA: ["noun"],
86
111
  bridge: "{ ...next(operator) }",
87
- isA: [],
88
- generatorpr: {
89
- match: ({context}) => context.amount,
90
- apply: async ({context, gp, gr}) => `${await gr(context.amount)} ${await gp(context.unit)}`,
91
- },
112
+ generatorpr: async ({context, gp, gr}) => `${await gr(context.amount)} ${await gp(context.unit)}`,
92
113
  },
93
114
  {
94
115
  id: "length",
95
116
  isA: ['dimension'],
96
117
  bridge: "{ ...next(operator) }",
97
- development: true
118
+ scope: "testing"
98
119
  },
99
120
  { id: "amount", },
100
- /*
101
- {
102
- id: "kindOfDimension",
103
- bridge: "{ ...next(operator), subclass: before[0], class: after[0], value: concat(before[0].marker.id, after[0].marker.id) }",
104
- // bridge: "{ ...next(operator), subclass: before[0], class: after[0], value: concat(before[0].marker, after[0].marker) }",
105
- isA: ['preposition'],
106
- generatorp: ({context, gp}) => `${gp(context.subclass)} ${context.word} ${gp(context.class)}`,
107
- },
108
- */
109
121
  {
110
122
  where: where(),
111
123
  id: "degree",
@@ -115,9 +127,9 @@ const config = {
115
127
  bridge: "{ ...next(operator), value: before[0].value, amount: before[0] }",
116
128
  },
117
129
  {
118
- id: "amountOfDimension",
130
+ id: "amountOfCoordinate",
119
131
  convolution: true,
120
- bridge: "{ marker: operator('dimension'), unit: after[0], value: before[0].value, amount: before[0] }"
132
+ bridge: "{ marker: next(operator('quantity')), dead: true, unit: after[0], value: before[0].value, amount: before[0] }"
121
133
  },
122
134
  {
123
135
  where: where(),
@@ -128,31 +140,53 @@ const config = {
128
140
  after: [['possession', 0], ['possession', 1]],
129
141
  generatorp: async ({context, g}) => `${await g(context.from)} ${context.word} ${await g(context.to)}`,
130
142
  // evaluator: ({context, kms, error}) => {
131
- evaluator: async ({context, kms, e, error}) => {
132
- /*
133
- error(({context, e}) => {
134
- context.evalue = 'dont know...'
135
- })
136
- */
143
+ evaluator: async ({context, kms, e, error, toArray, gp, gr, toList}) => {
137
144
  const from = context.from;
138
- const to = context.to;
145
+ const tos = toArray(context.to);
139
146
  let evalue;
140
147
  let efrom = from
141
148
  if (!from.unit) {
142
149
  efrom = (await e(from)).evalue
143
150
  }
144
- if (to.value == efrom.unit.value) {
145
- evalue = efrom.amount
146
- } else {
147
- const formula = kms.formulas.api.get(to, [efrom.unit])
148
- if (!formula) {
149
- const reason = { marker: 'reason', focusableForPhrase: true, evalue: { marker: 'noconversion', from: efrom.unit, to } }
150
- kms.stm.api.mentioned({ context: reason })
151
- error(reason)
151
+ async function convert(to) {
152
+ if (to.value == efrom.unit.value) {
153
+ evalue = efrom.amount
154
+ evalue.evalue = efrom.amount.value
155
+ } else {
156
+ const formula = kms.formulas.api.get(to, [efrom.unit])
157
+ if (!formula) {
158
+ const reason = { marker: 'reason', focusableForPhrase: true, evalue: { marker: 'noconversion', from: efrom.unit, to } }
159
+ kms.stm.api.mentioned({ context: reason })
160
+ error(reason)
161
+ }
162
+ kms.stm.api.setVariable(efrom.unit.value, efrom.amount)
163
+ evalue = await e(formula)
152
164
  }
153
- kms.stm.api.setVariable(efrom.unit.value, efrom.amount)
154
- evalue = await e(formula)
165
+ return evalue
166
+ }
167
+
168
+ let evalues = []
169
+ for (const to of tos) {
170
+ evalues.push({ value: await convert(to), to: structuredClone(to) })
171
+ }
172
+ evalues.sort((a, b) => a.evalue - b.evalue )
173
+
174
+ let fractionalPart = 0
175
+ let scale = 1
176
+ for (const evalue of evalues) {
177
+ const value = evalue.value.evalue * scale
178
+ const integerPart = Math.trunc(value)
179
+ fractionalPart = Math.abs(value - integerPart)
180
+ evalue.value.evalue = integerPart
181
+ scale = fractionalPart / value * scale
155
182
  }
183
+ // evalues[evalues.length-1].value.evalue = Number((integerPart * (1+scale)).toFixed(4))
184
+ evalues[evalues.length-1].value.evalue += fractionalPart
185
+ evalues[evalues.length-1].value.evalue = Number(evalues[evalues.length-1].value.evalue.toFixed(4))
186
+
187
+ // remove the zeros
188
+ evalues = evalues.filter( (evalue) => evalue.value.evalue )
189
+
156
190
  /*
157
191
  '{
158
192
  "marker":"dimension",
@@ -161,12 +195,21 @@ const config = {
161
195
  "amount":{"word":"degrees","number":"many","text":"10 degrees","marker":"degree","range":{"start":8,"end":17},"value":10,"amount":{"value":10,"text":"10","marker":"number","word":"10","range":{"start":8,"end":9},"types":["number"]}},
162
196
  "text":"10 degrees celcius","range":{"start":8,"end":25}}'
163
197
  */
164
- context.evalue = {
165
- paraphrase: true,
166
- marker: 'dimension',
167
- level: 1,
168
- unit: to,
169
- amount: { evalue, paraphrase: undefined }
198
+ evalues = evalues.map((evalue) => {
199
+ const number = evalue.value.evalue == 1 ? 'one' : 'many'
200
+ evalue.to.number = number
201
+ return {
202
+ paraphrase: true,
203
+ marker: 'quantity',
204
+ level: 1,
205
+ unit: evalue.to,
206
+ amount: { evalue: evalue.value, paraphrase: undefined }
207
+ }
208
+ })
209
+ if (evalues.length > 1) {
210
+ context.evalue = toList(evalues)
211
+ } else {
212
+ context.evalue = evalues[0]
170
213
  }
171
214
  },
172
215
  },
@@ -179,8 +222,49 @@ const config = {
179
222
 
180
223
  const template = {
181
224
  configs: [
182
- "dimension and unit are concepts",
225
+ "measurement modifies unit",
226
+ "dimension and measurement unit are concepts",
227
+ "unit means measurement unit",
228
+ ({apis}) => {
229
+ apis('properties').addHierarchyWatcher({
230
+ match: ({parentId, isA}) => isA(parentId, 'unit') && parentId.startsWith('unit_'),
231
+ apply: ({config, childId, parent, parentId}) => {
232
+ config.updateBridge(childId, ({ bridge }) => {
233
+ if (!bridge.init) {
234
+ bridge.init = {}
235
+ }
236
+ // bridge.init['dimension'] = parent.object.marker
237
+ bridge.init['dimension'] = parent.object.value
238
+ })
239
+ }
240
+ })
241
+ },
242
+ "metric modifies system",
243
+ "imperial modifies system",
244
+ "measurement modifies system",
245
+ "the metric system is a measurement system",
246
+ "the imperial system is a measurement system",
247
+ "imperial modifies unit",
248
+ "metric modifies unit",
249
+ "imperial unit is a unit",
250
+ "metric unit is a unit",
183
251
  config,
252
+ {
253
+ operators: [
254
+ "([useMeasurementSystem|use] (measurement_system))",
255
+ ],
256
+ bridges: [
257
+ {
258
+ id: 'useMeasurementSystem',
259
+ isA: ['verb'],
260
+ bridge: "{ ...next(operator), system: after[0], interpolate: [ { context: operator }, { property: 'system' } ] }",
261
+ semantic: ({context, api}) => {
262
+ api.setMeasurementSystem(context.system.value)
263
+ },
264
+ check: defaultContextCheckProperties(['system']),
265
+ },
266
+ ],
267
+ },
184
268
  ],
185
269
  }
186
270
 
@@ -196,9 +280,19 @@ knowledgeModule({
196
280
  name: './dimension.test.json',
197
281
  contents: tests,
198
282
  checks: {
199
- objects: [{ km: 'properties' }],
283
+ objects: [
284
+ { km: 'properties' },
285
+ { path: ['measurementSystem'] },
286
+ ],
200
287
  context: [
201
- defaultContextCheck(),
288
+ defaultContextCheck({ marker: 'metric_system', exported: true }),
289
+ defaultContextCheck({ marker: 'convertToUnits', exported: true, extra: ['from', 'to'] }),
290
+ defaultContextCheck({
291
+ match: ({context, isA}) => isA(context.marker, 'unit'),
292
+ exported: true,
293
+ extra: ['dimension'],
294
+ }),
295
+ // defaultContextCheck(['dimension', 'response']),
202
296
  ],
203
297
  },
204
298
  },