tpmkms_4wp 9.5.1-beta.3 → 9.5.1-beta.31

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 (114) hide show
  1. package/common/animals.instance.json +21 -61
  2. package/common/asking.js +112 -102
  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 +3 -3
  8. package/common/colors.instance.json +10 -10
  9. package/common/comparable.instance.json +2 -2
  10. package/common/concept.js +19 -22
  11. package/common/concept.test.json +54 -40
  12. package/common/conjunction.js +13 -5
  13. package/common/conjunction.test.json +32 -42
  14. package/common/crew.instance.json +164 -150
  15. package/common/crew.js +1 -1
  16. package/common/currency.js +1 -1
  17. package/common/dateTimeSelectors.instance.json +2 -2
  18. package/common/dateTimeSelectors.js +3 -3
  19. package/common/dateTimeSelectors.test.json +76935 -35739
  20. package/common/dates.instance.json +3 -3
  21. package/common/dates.test.json +284 -287
  22. package/common/dialogues.js +41 -119
  23. package/common/dialogues.test.json +1171 -996
  24. package/common/dimension.instance.json +21374 -562
  25. package/common/dimension.js +145 -51
  26. package/common/dimension.test.json +8753 -3495
  27. package/common/drone.instance.json +23710 -0
  28. package/common/drone.js +429 -0
  29. package/common/drone.test.json +61113 -0
  30. package/common/edible.instance.json +23 -95
  31. package/common/emotions.instance.json +53 -80
  32. package/common/emotions.js +1 -1
  33. package/common/english_helpers.js +277 -67
  34. package/common/fastfood.instance.json +180 -372
  35. package/common/fastfood.js +4 -4
  36. package/common/fastfood.test.json +6970 -6829
  37. package/common/formulas.instance.json +1 -1
  38. package/common/gdefaults.js +94 -17
  39. package/common/help.js +11 -11
  40. package/common/help.test.json +65 -11
  41. package/common/helpers/concept.js +1 -1
  42. package/common/helpers/conjunction.js +54 -44
  43. package/common/helpers/dateTimeSelectors.js +2 -2
  44. package/common/helpers/dialogues.js +7 -2
  45. package/common/helpers/formulas.js +13 -11
  46. package/common/helpers/menus.js +12 -12
  47. package/common/helpers/meta.js +8 -8
  48. package/common/helpers/properties.js +104 -23
  49. package/common/helpers.js +114 -48
  50. package/common/hierarchy.js +6 -4
  51. package/common/kirk.instance.json +1 -1
  52. package/common/kirk.test.json +600 -424
  53. package/common/latin.instance.json +10 -10
  54. package/common/latin.js +5 -5
  55. package/common/length.instance.json +27612 -2890
  56. package/common/length.js +6 -1
  57. package/common/length.test.json +45315 -3925
  58. package/common/math.instance.json +20 -20
  59. package/common/math.js +45 -44
  60. package/common/menus.instance.json +6 -9
  61. package/common/menus.js +2 -9
  62. package/common/meta.js +50 -33
  63. package/common/nameable.js +13 -6
  64. package/common/nameable.test.json +436 -0
  65. package/common/numbers.js +1 -1
  66. package/common/ordering.instance.json +20 -30
  67. package/common/ordering.js +1 -1
  68. package/common/ordering.test.json +414 -426
  69. package/common/people.instance.json +82 -348
  70. package/common/people.js +1 -1
  71. package/common/people.test.json +952 -681
  72. package/common/pipboy.instance.json +16 -16
  73. package/common/pokemon.instance.json +8 -8
  74. package/common/pokemon.js +1 -1
  75. package/common/pressure.instance.json +3579 -1610
  76. package/common/pressure.test.json +433 -477
  77. package/common/properties.instance.json +6 -17
  78. package/common/properties.js +19 -6
  79. package/common/properties.test.json +8746 -6638
  80. package/common/rates.instance.json +59 -0
  81. package/common/rates.js +97 -0
  82. package/common/rates.test.json +27702 -0
  83. package/common/reminders.js +1 -1
  84. package/common/reminders.test.json +64635 -25787
  85. package/common/reports.instance.json +3 -3
  86. package/common/reports.js +18 -16
  87. package/common/scorekeeper.js +4 -4
  88. package/common/sdefaults.js +22 -2
  89. package/common/spock.instance.json +1 -1
  90. package/common/spock.test.json +606 -430
  91. package/common/stgame.js +1 -1
  92. package/common/stm.js +15 -4
  93. package/common/tell.js +1 -1
  94. package/common/temperature.instance.json +3786 -1705
  95. package/common/temperature.test.json +433 -477
  96. package/common/tester.js +3 -3
  97. package/common/time.instance.json +24762 -0
  98. package/common/time.js +137 -141
  99. package/common/time.test.json +31876 -3757
  100. package/common/tokenize.js +1 -1
  101. package/common/ui.instance.json +2 -5
  102. package/common/ui.js +1 -8
  103. package/common/weight.instance.json +10359 -4077
  104. package/common/weight.test.json +2601 -2263
  105. package/common/words.instance.json +9 -0
  106. package/common/words.js +53 -0
  107. package/common/words.test.json +2 -0
  108. package/common/wp.instance.json +336 -8
  109. package/common/wp.js +8 -4
  110. package/common/wp.test.json +7385 -6906
  111. package/main.js +4 -2
  112. package/package.json +18 -5
  113. package/common/listener.js +0 -50
  114. package/common/listener.test.json +0 -142
package/common/helpers.js CHANGED
@@ -1,13 +1,14 @@
1
1
  const pluralize = require('pluralize')
2
+ const { flatten } = require('./runtime').theprogrammablemind
2
3
 
3
- const unshiftL = (list, element, max) => {
4
+ function unshiftL(list, element, max) {
4
5
  if (list.length >= max) {
5
6
  list.pop()
6
7
  }
7
8
  list.unshift(element)
8
9
  }
9
10
 
10
- const pushL = (list, element, max) => {
11
+ function pushL(list, element, max) {
11
12
  if (list.length >= max) {
12
13
  list.shift()
13
14
  }
@@ -15,11 +16,11 @@ const pushL = (list, element, max) => {
15
16
  }
16
17
 
17
18
  // X pm today or tomorrow
18
- const millisecondsUntilHourOfDay = (newDate, hour) => {
19
+ function millisecondsUntilHourOfDay(newDate, hour) {
19
20
  const now = newDate()
20
21
  const target = newDate(now)
21
22
 
22
- const addHours = (date, h) => {
23
+ function addHours(date, h) {
23
24
  date.setTime(date.getTime() + (h*60*60*1000));
24
25
  }
25
26
  const hours = target.getHours()
@@ -34,11 +35,11 @@ const millisecondsUntilHourOfDay = (newDate, hour) => {
34
35
  return diff;
35
36
  }
36
37
 
37
- const indent = (string, indent) => {
38
+ function indent(string, indent) {
38
39
  return string.replace(/^/gm, ' '.repeat(indent));
39
40
  }
40
41
 
41
- const getCount = (context) => {
42
+ function getCount(context) {
42
43
  if (context.quantity) {
43
44
  return context.quantity.value
44
45
  }
@@ -47,13 +48,23 @@ const getCount = (context) => {
47
48
  }
48
49
  }
49
50
 
50
- const words = (word, additional = {}) => {
51
+ function words(word, additional = {}) {
51
52
  return [{ word: pluralize.singular(word), number: 'one', ...additional }, { word: pluralize.plural(word), number: 'many', ...additional }]
52
53
  }
53
54
 
54
- const isMany = (context) => {
55
- if (((context || {}).value || {}).marker == 'list' && (((context || {}).value || {}).value || []).length > 1) {
56
- return true
55
+ function isMany(context) {
56
+ if (!context) {
57
+ return
58
+ }
59
+ // if (((context || {}).value || {}).marker == 'list' && (((context || {}).value || {}).value || []).length > 1) {
60
+ const isList = context.marker == 'list' || context.value?.marker == 'list'
61
+ if (isList) {
62
+ if (context.value?.length > 1) {
63
+ return true
64
+ }
65
+ if (context.value?.value?.length > 1) {
66
+ return true
67
+ }
57
68
  }
58
69
 
59
70
  let number = context.number
@@ -77,13 +88,13 @@ const isMany = (context) => {
77
88
  return false
78
89
  }
79
90
 
80
- const requiredArgument = (value, name) => {
91
+ function requiredArgument(value, name) {
81
92
  if (!value) {
82
93
  throw new Error(`${name} is a required argument`)
83
94
  }
84
95
  }
85
96
 
86
- const chooseNumber = (context, one, many) => {
97
+ function chooseNumber(context, one, many) {
87
98
  if (isMany(context)) {
88
99
  return many;
89
100
  } else {
@@ -91,7 +102,7 @@ const chooseNumber = (context, one, many) => {
91
102
  }
92
103
  }
93
104
 
94
- const zip = (...arrays) => {
105
+ function zip(...arrays) {
95
106
  if (arrays == []) {
96
107
  return []
97
108
  }
@@ -107,15 +118,21 @@ const zip = (...arrays) => {
107
118
  }
108
119
 
109
120
 
110
- const focus = (context) => {
111
- const helper = (context) => {
121
+ function focus(context) {
122
+ function helper(context) {
112
123
  if (!context || !context.focusable) {
113
124
  return null
114
125
  }
115
126
  for (const property of context.focusable) {
116
127
  let focus = helper(context[property])
117
- if (!focus && (context[property] || {}).focus) {
118
- focus = context[property]
128
+ if (!focus) {
129
+ const flat = flatten(['list'], context[property])[0]
130
+ for (const element of flat) {
131
+ if (element.focus) {
132
+ focus = context[property]
133
+ break
134
+ }
135
+ }
119
136
  }
120
137
  return focus
121
138
  }
@@ -126,7 +143,7 @@ const focus = (context) => {
126
143
 
127
144
  // if property is a list make array of elements of the list, if not return an array with the property value
128
145
  // fromList
129
- const propertyToArray = (value) => {
146
+ function propertyToArray(value) {
130
147
  if (Array.isArray(value)) {
131
148
  return value
132
149
  } else if (value.marker == 'list') {
@@ -136,7 +153,23 @@ const propertyToArray = (value) => {
136
153
  }
137
154
  }
138
155
 
139
- wordNumber = (word, toPlural) => {
156
+ // values is marker: 'list' or some context
157
+ function concats(values) {
158
+ combined = []
159
+ for (const value of values) {
160
+ if (value.marker == 'list') {
161
+ combined = combined.concat(value.value)
162
+ } else {
163
+ combined.push(value)
164
+ }
165
+ }
166
+ return {
167
+ marker: 'list',
168
+ value: combined
169
+ }
170
+ }
171
+
172
+ function wordNumber(word, toPlural) {
140
173
  if (toPlural) {
141
174
  return pluralize.plural(word)
142
175
  } else {
@@ -144,17 +177,18 @@ wordNumber = (word, toPlural) => {
144
177
  }
145
178
  }
146
179
 
147
- const toEValue = (context) => {
180
+ function toEValue(context) {
148
181
  while( context.evalue ) {
149
182
  context = context.evalue
150
183
  }
151
184
  return context;
152
185
  }
153
186
 
154
- const defaultObjectCheck = (extra = []) => {
187
+ function defaultObjectCheck(extra = []) {
155
188
  return {
156
189
  objects: [
157
190
  {
191
+ extra,
158
192
  match: ({objects}) => true,
159
193
  apply: () => extra
160
194
  },
@@ -162,57 +196,62 @@ const defaultObjectCheck = (extra = []) => {
162
196
  }
163
197
  }
164
198
 
165
- const defaultContextCheckProperties = (extra) => {
199
+ function defaultContextCheckProperties(extra) {
166
200
  return ['marker', 'text', 'verbatim', 'value', 'evalue', 'isResponse', { properties: 'modifiers' }, { properties: 'postModifiers' }, ...extra]
167
201
  }
168
202
 
169
- const defaultContextCheck = ({marker, extra = [], exported = false} = {}) => {
203
+ function defaultContextCheck({marker, extra = [], exported = false} = {}) {
170
204
  let match
171
205
  if (marker) {
172
206
  match = ({context}) => context.marker == marker
173
207
  } else {
174
- match = ({context}) => !Array.isArray(context)
175
208
  }
176
209
  return {
210
+ marker,
177
211
  match,
178
212
  exported,
179
213
  apply: () => ['marker', 'text', 'verbatim', 'value', 'evalue', 'isResponse', { properties: 'modifiers' }, { properties: 'postModifiers' }, ...extra],
180
214
  }
181
215
  }
182
216
 
183
- const isA = (hierarchy) => (child, parent, { strict=false } = {}) => {
184
- if (!child || !parent) {
185
- return false
186
- }
187
-
188
- if (strict) {
189
- if (child.marker) {
190
- child = child.marker
217
+ function isA(hierarchy) {
218
+ return (child, parent, { strict=false } = {}) => {
219
+ if (!child || !parent) {
220
+ return false
191
221
  }
192
- if (parent.marker) {
193
- parent = parent.marker
194
- }
195
- return hierarchy.isA(child, parent)
196
- } else {
197
- if (hierarchy.isA(child.marker || child, parent.marker || parent)) {
198
- return true
199
- }
200
- for (const childT of child.types || [child]) {
201
- for (const parentT of parent.types || [parent]) {
202
- if (hierarchy.isA(childT, parentT)) {
203
- return true
222
+
223
+ if (strict) {
224
+ if (child.marker) {
225
+ child = child.marker
226
+ }
227
+ if (parent.marker) {
228
+ parent = parent.marker
229
+ }
230
+ return hierarchy.isA(child, parent)
231
+ } else {
232
+ if (hierarchy.isA(child.marker || child, parent.marker || parent)) {
233
+ return true
234
+ }
235
+ for (const childT of child.types || [child]) {
236
+ for (const parentT of parent.types || [parent]) {
237
+ if (hierarchy.isA(childT, parentT)) {
238
+ return true
239
+ }
204
240
  }
205
241
  }
242
+ return false
206
243
  }
207
- return false
208
244
  }
209
245
  }
210
246
 
211
- const getValue = (propertyPath, object) => {
247
+ function getValue(propertyPath, object) {
212
248
  if (!propertyPath) {
213
249
  return
214
250
  }
215
- const path = propertyPath.split('.')
251
+ let path = propertyPath
252
+ if (typeof path == 'string') {
253
+ path = propertyPath.split('.')
254
+ }
216
255
  let value = object
217
256
  for (const name of path) {
218
257
  if (!value) {
@@ -223,7 +262,30 @@ const getValue = (propertyPath, object) => {
223
262
  return value
224
263
  }
225
264
 
226
- const processTemplateString = async (template, evaluate) => {
265
+ function setValue(propertyPath, object, newValue) {
266
+ if (!propertyPath) {
267
+ return;
268
+ }
269
+ let path = propertyPath;
270
+ if (typeof path === 'string') {
271
+ path = propertyPath.split('.');
272
+ }
273
+ let current = object;
274
+ for (let i = 0; i < path.length; i++) {
275
+ const name = path[i];
276
+ if (i === path.length - 1) {
277
+ // Set the value at the final step
278
+ current[name] = newValue;
279
+ break;
280
+ }
281
+ if (current[name] === undefined || current[name] === null) {
282
+ current[name] = {}; // Create a plain object for nesting
283
+ }
284
+ current = current[name];
285
+ }
286
+ }
287
+
288
+ async function processTemplateString(template, evaluate) {
227
289
  async function resolveWithCallback(strings, ...keys) {
228
290
  // const resolvedValues = await Promise.all(keys.map(key => lookupVariable(key)));
229
291
  const resolvedValues = await Promise.all(keys.map(async (key) => {
@@ -319,7 +381,10 @@ module.exports = {
319
381
  processTemplateString,
320
382
  unshiftL,
321
383
  pushL,
384
+
322
385
  getValue,
386
+ setValue,
387
+
323
388
  defaultContextCheck,
324
389
  defaultContextCheckProperties,
325
390
  defaultObjectCheck,
@@ -337,4 +402,5 @@ module.exports = {
337
402
  requiredArgument,
338
403
  isA,
339
404
  removeProp,
405
+ concats
340
406
  }
@@ -1,4 +1,4 @@
1
- const { knowledgeModule, where } = require('./runtime').theprogrammablemind
1
+ const { debug, knowledgeModule, where } = require('./runtime').theprogrammablemind
2
2
  const { defaultContextCheck } = require('./helpers')
3
3
  const properties = require('./properties')
4
4
  const hierarchy_tests = require('./hierarchy.test.json')
@@ -6,11 +6,11 @@ const pluralize = require('pluralize')
6
6
  const _ = require('lodash')
7
7
  const { isMany } = require('./helpers')
8
8
 
9
- const getTypes = ( km, concept, instance ) => {
9
+ function getTypes( km, concept, instance ) {
10
10
  const propertiesAPI = km('properties').api;
11
11
  const conceptAPI = km('concept').api;
12
12
  const digraph = propertiesAPI.digraph;
13
- const intersect = (set1, set2) => {
13
+ function intersect(set1, set2) {
14
14
  return new Set([...set1].filter(x => set2.has(x)))
15
15
  }
16
16
  const descendants = digraph.descendants(concept.value)
@@ -253,9 +253,11 @@ const config = {
253
253
  const twoConcepts = asList(context.same);
254
254
  for (const oneConcept of oneConcepts.value) {
255
255
  for (const twoConcept of twoConcepts.value) {
256
+ // debug.counter('greg23', { breakAt: 39 })
256
257
  oneConceptId = await api.makeObject({...args, context: oneConcept})
257
258
  twoConceptId = await api.makeObject({...args, context: twoConcept})
258
259
  api.rememberIsA(oneConceptId, twoConceptId)
260
+ api.seenHierarchyWatcher({ childId: oneConceptId, child: oneConcept, parentId: twoConceptId, parent: twoConcept })
259
261
  context.sameWasProcessed = true
260
262
  }
261
263
  }
@@ -286,7 +288,7 @@ const config = {
286
288
  ]
287
289
  };
288
290
 
289
- const initializer = ({apis, hierarchy}) => {
291
+ function initializer({apis, hierarchy}) {
290
292
  apis('stm').addIsA( (child, parent) => {
291
293
  return hierarchy.isA(child, parent)
292
294
  })
@@ -1666,7 +1666,7 @@
1666
1666
  "dead": true,
1667
1667
  "range": {
1668
1668
  "start": 0,
1669
- "end": 11
1669
+ "end": 2
1670
1670
  },
1671
1671
  "types": [
1672
1672
  "self"