tpmkms 9.5.1-beta.24 → 9.5.1-beta.25

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.
@@ -34693,6 +34693,32 @@
34693
34693
  0
34694
34694
  ]
34695
34695
  ],
34696
+ [
34697
+ [
34698
+ "is",
34699
+ 0
34700
+ ],
34701
+ [
34702
+ "photon_torpedo",
34703
+ 0
34704
+ ],
34705
+ [
34706
+ "propertyOf",
34707
+ 0
34708
+ ],
34709
+ [
34710
+ "status",
34711
+ 0
34712
+ ],
34713
+ [
34714
+ "the",
34715
+ 0
34716
+ ],
34717
+ [
34718
+ "unknown",
34719
+ 0
34720
+ ]
34721
+ ],
34696
34722
  [
34697
34723
  [
34698
34724
  "is",
@@ -50363,6 +50389,40 @@
50363
50389
  0
50364
50390
  ]
50365
50391
  ],
50392
+ [
50393
+ [
50394
+ "disarm",
50395
+ 0
50396
+ ],
50397
+ [
50398
+ "is",
50399
+ 0
50400
+ ],
50401
+ [
50402
+ "means",
50403
+ 0
50404
+ ],
50405
+ [
50406
+ "not",
50407
+ 0
50408
+ ],
50409
+ [
50410
+ "propertyOf",
50411
+ 0
50412
+ ],
50413
+ [
50414
+ "status",
50415
+ 0
50416
+ ],
50417
+ [
50418
+ "the",
50419
+ 0
50420
+ ],
50421
+ [
50422
+ "unknown",
50423
+ 0
50424
+ ]
50425
+ ],
50366
50426
  [
50367
50427
  [
50368
50428
  "disarm",
@@ -52104,6 +52164,40 @@
52104
52164
  0
52105
52165
  ]
52106
52166
  ],
52167
+ [
52168
+ [
52169
+ "disarm",
52170
+ 0
52171
+ ],
52172
+ [
52173
+ "is",
52174
+ 0
52175
+ ],
52176
+ [
52177
+ "means",
52178
+ 0
52179
+ ],
52180
+ [
52181
+ "not",
52182
+ 0
52183
+ ],
52184
+ [
52185
+ "propertyOf",
52186
+ 0
52187
+ ],
52188
+ [
52189
+ "status",
52190
+ 0
52191
+ ],
52192
+ [
52193
+ "the",
52194
+ 0
52195
+ ],
52196
+ [
52197
+ "unknown",
52198
+ 0
52199
+ ]
52200
+ ],
52107
52201
  [
52108
52202
  [
52109
52203
  "disarm",
@@ -52664,6 +52758,32 @@
52664
52758
  0
52665
52759
  ]
52666
52760
  ],
52761
+ [
52762
+ [
52763
+ "is",
52764
+ 0
52765
+ ],
52766
+ [
52767
+ "photon_torpedo",
52768
+ 0
52769
+ ],
52770
+ [
52771
+ "propertyOf",
52772
+ 0
52773
+ ],
52774
+ [
52775
+ "status",
52776
+ 0
52777
+ ],
52778
+ [
52779
+ "the",
52780
+ 0
52781
+ ],
52782
+ [
52783
+ "unknown",
52784
+ 0
52785
+ ]
52786
+ ],
52667
52787
  [
52668
52788
  [
52669
52789
  "is",
@@ -7,11 +7,11 @@
7
7
  {
8
8
  "name": "dimension",
9
9
  "operators": [
10
- "([dimension])",
10
+ "([quantity])",
11
11
  "([unit])",
12
- "((amount/* || number/*) [amountOfDimension|] ([unit]))",
12
+ "((amount/* || number/*) [amountOfCoordinate|] ([unit]))",
13
13
  "(([amount]) [unit])",
14
- "((dimension) [convertToUnits|in] (unit))",
14
+ "((@<=quantity || context.possession == true) [convertToUnits|in] (unit))",
15
15
  "(([number]) [degree])",
16
16
  {
17
17
  "pattern": "([length])",
@@ -22,7 +22,7 @@
22
22
  {
23
23
  "context": [
24
24
  [
25
- "amountOfDimension",
25
+ "amountOfCoordinate",
26
26
  0
27
27
  ],
28
28
  [
@@ -50,10 +50,16 @@
50
50
  ],
51
51
  "bridges": [
52
52
  {
53
- "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:82",
54
- "id": "dimension",
55
- "bridge": "{ ...next(operator) }",
56
- "generatorpr": {}
53
+ "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:92",
54
+ "id": "dimension"
55
+ },
56
+ {
57
+ "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:96",
58
+ "id": "quantity",
59
+ "isA": [
60
+ "noun"
61
+ ],
62
+ "bridge": "{ ...next(operator) }"
57
63
  },
58
64
  {
59
65
  "id": "length",
@@ -67,7 +73,7 @@
67
73
  "id": "amount"
68
74
  },
69
75
  {
70
- "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:107",
76
+ "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:119",
71
77
  "id": "degree",
72
78
  "words": [
73
79
  {
@@ -82,12 +88,12 @@
82
88
  "bridge": "{ ...next(operator), value: before[0].value, amount: before[0] }"
83
89
  },
84
90
  {
85
- "id": "amountOfDimension",
91
+ "id": "amountOfCoordinate",
86
92
  "convolution": true,
87
- "bridge": "{ marker: next(catch(operator(after[0].dimension), operator('dimension'))), dead: true, unit: after[0], value: before[0].value, amount: before[0] }"
93
+ "bridge": "{ marker: next(operator('quantity')), dead: true, unit: after[0], value: before[0].value, amount: before[0] }"
88
94
  },
89
95
  {
90
- "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:121",
96
+ "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:134",
91
97
  "id": "convertToUnits",
92
98
  "bridge": "{ ...next(operator), from: before[0], to: after[0] }",
93
99
  "isA": [
@@ -111,7 +117,7 @@
111
117
  ]
112
118
  ],
113
119
  "generatorp": "async ({context, g}) => `${await g(context.from)} ${context.word} ${await g(context.to)}`",
114
- "evaluator": "async ({context, kms, e, error}) => {\n const from = context.from;\n const to = context.to;\n let evalue;\n let efrom = from\n if (!from.unit) {\n efrom = (await e(from)).evalue\n }\n if (to.value == efrom.unit.value) {\n evalue = efrom.amount\n } else {\n const formula = kms.formulas.api.get(to, [efrom.unit])\n if (!formula) {\n const reason = { marker: 'reason', focusableForPhrase: true, evalue: { marker: 'noconversion', from: efrom.unit, to } }\n kms.stm.api.mentioned({ context: reason })\n error(reason)\n }\n kms.stm.api.setVariable(efrom.unit.value, efrom.amount)\n evalue = await e(formula)\n }\n /*\n '{\n \"marker\":\"dimension\",\n \"unit\":{\"marker\":\"unit\",\"range\":{\"start\":19,\"end\":25},\"word\":\"celcius\",\"text\":\"celcius\",\"value\":\"celcius\",\"unknown\":true,\"types\":[\"unit\",\"unknown\"]},\n \"value\":10,\n \"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\"]}},\n \"text\":\"10 degrees celcius\",\"range\":{\"start\":8,\"end\":25}}'\n */\n context.evalue = { \n paraphrase: true,\n marker: 'dimension',\n level: 1,\n unit: to,\n amount: { evalue, paraphrase: undefined }\n }\n }"
120
+ "evaluator": "async ({context, kms, e, error, toArray, gp, gr, toList}) => {\n const from = context.from;\n const tos = toArray(context.to);\n let evalue;\n let efrom = from\n if (!from.unit) {\n efrom = (await e(from)).evalue\n }\n async function convert(to) {\n if (to.value == efrom.unit.value) {\n evalue = efrom.amount\n evalue.evalue = efrom.amount.value\n } else {\n const formula = kms.formulas.api.get(to, [efrom.unit])\n if (!formula) {\n const reason = { marker: 'reason', focusableForPhrase: true, evalue: { marker: 'noconversion', from: efrom.unit, to } }\n kms.stm.api.mentioned({ context: reason })\n error(reason)\n }\n kms.stm.api.setVariable(efrom.unit.value, efrom.amount)\n evalue = await e(formula)\n }\n return evalue\n }\n\n let evalues = []\n for (const to of tos) {\n evalues.push({ value: await convert(to), to: structuredClone(to) })\n }\n evalues.sort((a, b) => a.evalue - b.evalue )\n\n let fractionalPart = 0\n let scale = 1\n for (const evalue of evalues) {\n const value = evalue.value.evalue * scale\n const integerPart = Math.trunc(value)\n fractionalPart = Math.abs(value - integerPart)\n evalue.value.evalue = integerPart\n scale = fractionalPart / value * scale\n }\n // evalues[evalues.length-1].value.evalue = Number((integerPart * (1+scale)).toFixed(4))\n evalues[evalues.length-1].value.evalue += fractionalPart\n evalues[evalues.length-1].value.evalue = Number(evalues[evalues.length-1].value.evalue.toFixed(4))\n\n // remove the zeros\n evalues = evalues.filter( (evalue) => evalue.value.evalue )\n\n /*\n '{\n \"marker\":\"dimension\",\n \"unit\":{\"marker\":\"unit\",\"range\":{\"start\":19,\"end\":25},\"word\":\"celcius\",\"text\":\"celcius\",\"value\":\"celcius\",\"unknown\":true,\"types\":[\"unit\",\"unknown\"]},\n \"value\":10,\n \"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\"]}},\n \"text\":\"10 degrees celcius\",\"range\":{\"start\":8,\"end\":25}}'\n */\n evalues = evalues.map((evalue) => {\n const number = evalue.value.evalue == 1 ? 'one' : 'many'\n evalue.to.number = number\n return { \n paraphrase: true,\n marker: 'quantity',\n level: 1,\n unit: evalue.to,\n amount: { evalue: evalue.value, paraphrase: undefined }\n }\n })\n if (evalues.length > 1) {\n context.evalue = toList(evalues)\n } else {\n context.evalue = evalues[0]\n }\n }"
115
121
  },
116
122
  {
117
123
  "id": "unit",
@@ -1555,11 +1561,11 @@
1555
1561
  "extraConfig": true,
1556
1562
  "name": "dimension",
1557
1563
  "operators": [
1558
- "([dimension])",
1564
+ "([quantity])",
1559
1565
  "([unit])",
1560
- "((amount/* || number/*) [amountOfDimension|] ([unit]))",
1566
+ "((amount/* || number/*) [amountOfCoordinate|] ([unit]))",
1561
1567
  "(([amount]) [unit])",
1562
- "((dimension) [convertToUnits|in] (unit))",
1568
+ "((@<=quantity || context.possession == true) [convertToUnits|in] (unit))",
1563
1569
  "(([number]) [degree])",
1564
1570
  {
1565
1571
  "pattern": "([length])",
@@ -1570,7 +1576,7 @@
1570
1576
  {
1571
1577
  "context": [
1572
1578
  [
1573
- "amountOfDimension",
1579
+ "amountOfCoordinate",
1574
1580
  0
1575
1581
  ],
1576
1582
  [
@@ -1592,15 +1598,21 @@
1592
1598
  ],
1593
1599
  "generators": [
1594
1600
  {
1595
- "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:75"
1601
+ "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:85"
1596
1602
  }
1597
1603
  ],
1598
1604
  "bridges": [
1599
1605
  {
1600
- "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:82",
1601
- "id": "dimension",
1602
- "bridge": "{ ...next(operator) }",
1603
- "generatorpr": {}
1606
+ "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:92",
1607
+ "id": "dimension"
1608
+ },
1609
+ {
1610
+ "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:96",
1611
+ "id": "quantity",
1612
+ "isA": [
1613
+ "noun"
1614
+ ],
1615
+ "bridge": "{ ...next(operator) }"
1604
1616
  },
1605
1617
  {
1606
1618
  "id": "length",
@@ -1614,7 +1626,7 @@
1614
1626
  "id": "amount"
1615
1627
  },
1616
1628
  {
1617
- "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:107",
1629
+ "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:119",
1618
1630
  "id": "degree",
1619
1631
  "words": [
1620
1632
  {
@@ -1628,12 +1640,12 @@
1628
1640
  "bridge": "{ ...next(operator), value: before[0].value, amount: before[0] }"
1629
1641
  },
1630
1642
  {
1631
- "id": "amountOfDimension",
1643
+ "id": "amountOfCoordinate",
1632
1644
  "convolution": true,
1633
- "bridge": "{ marker: next(catch(operator(after[0].dimension), operator('dimension'))), dead: true, unit: after[0], value: before[0].value, amount: before[0] }"
1645
+ "bridge": "{ marker: next(operator('quantity')), dead: true, unit: after[0], value: before[0].value, amount: before[0] }"
1634
1646
  },
1635
1647
  {
1636
- "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:121",
1648
+ "where": "/home/dev/code/theprogrammablemind/kms/common/dimension.js:134",
1637
1649
  "id": "convertToUnits",
1638
1650
  "bridge": "{ ...next(operator), from: before[0], to: after[0] }",
1639
1651
  "isA": [
@@ -58,22 +58,24 @@ class API {
58
58
  }
59
59
  }
60
60
 
61
+ // eg, dimension == length; meters == unit; 2 meters == quantity
62
+
61
63
  const config = {
62
64
  name: 'dimension',
63
65
  operators: [
64
- "([dimension])",
66
+ "([quantity])",
65
67
  "([unit])",
66
68
  // "(([unit]) [kindOfDimension|of] ([dimension]))",
67
- "((amount/* || number/*) [amountOfDimension|] ([unit]))",
69
+ "((amount/* || number/*) [amountOfCoordinate|] ([unit]))",
68
70
  "(([amount]) [unit])",
69
- "((dimension) [convertToUnits|in] (unit))",
71
+ "((@<=quantity || context.possession == true) [convertToUnits|in] (unit))",
70
72
 
71
73
  "(([number]) [degree])",
72
74
  { pattern: "([length])", scope: "testing" },
73
75
  ],
74
76
  priorities: [
75
77
  // TODO this should have been calculated
76
- { "context": [['amountOfDimension', 0], ['convertToUnits', 0], ], "choose": [0] },
78
+ { "context": [['amountOfCoordinate', 0], ['convertToUnits', 0], ], "choose": [0] },
77
79
  ],
78
80
  hierarchy: [
79
81
  { child: 'convertToUnits', parent: 'testingValue', scope: "testing" },
@@ -89,11 +91,13 @@ const config = {
89
91
  {
90
92
  where: where(),
91
93
  id: "dimension",
94
+ },
95
+ {
96
+ where: where(),
97
+ id: "quantity",
98
+ isA: ["noun"],
92
99
  bridge: "{ ...next(operator) }",
93
- generatorpr: {
94
- match: ({context}) => context.amount,
95
- apply: async ({context, gp, gr}) => `${await gr(context.amount)} ${await gp(context.unit)}`,
96
- },
100
+ generatorpr: async ({context, gp, gr}) => `${await gr(context.amount)} ${await gp(context.unit)}`,
97
101
  },
98
102
  {
99
103
  id: "length",
@@ -120,9 +124,10 @@ const config = {
120
124
  bridge: "{ ...next(operator), value: before[0].value, amount: before[0] }",
121
125
  },
122
126
  {
123
- id: "amountOfDimension",
127
+ id: "amountOfCoordinate",
124
128
  convolution: true,
125
- bridge: "{ marker: next(catch(operator(after[0].dimension), operator('dimension'))), dead: true, unit: after[0], value: before[0].value, amount: before[0] }"
129
+ // bridge: "{ marker: next(catch(operator(after[0].dimension), operator('dimension'))), dead: true, unit: after[0], value: before[0].value, amount: before[0] }"
130
+ bridge: "{ marker: next(operator('quantity')), dead: true, unit: after[0], value: before[0].value, amount: before[0] }"
126
131
  // bridge: "{ marker: operator('dimension'), unit: after[0], value: before[0].value, amount: before[0] }"
127
132
  },
128
133
  {
@@ -134,27 +139,53 @@ const config = {
134
139
  after: [['possession', 0], ['possession', 1]],
135
140
  generatorp: async ({context, g}) => `${await g(context.from)} ${context.word} ${await g(context.to)}`,
136
141
  // evaluator: ({context, kms, error}) => {
137
- evaluator: async ({context, kms, e, error}) => {
142
+ evaluator: async ({context, kms, e, error, toArray, gp, gr, toList}) => {
138
143
  const from = context.from;
139
- const to = context.to;
144
+ const tos = toArray(context.to);
140
145
  let evalue;
141
146
  let efrom = from
142
147
  if (!from.unit) {
143
148
  efrom = (await e(from)).evalue
144
149
  }
145
- if (to.value == efrom.unit.value) {
146
- evalue = efrom.amount
147
- evalue.evalue = efrom.amount.value
148
- } else {
149
- const formula = kms.formulas.api.get(to, [efrom.unit])
150
- if (!formula) {
151
- const reason = { marker: 'reason', focusableForPhrase: true, evalue: { marker: 'noconversion', from: efrom.unit, to } }
152
- kms.stm.api.mentioned({ context: reason })
153
- error(reason)
150
+ async function convert(to) {
151
+ if (to.value == efrom.unit.value) {
152
+ evalue = efrom.amount
153
+ evalue.evalue = efrom.amount.value
154
+ } else {
155
+ const formula = kms.formulas.api.get(to, [efrom.unit])
156
+ if (!formula) {
157
+ const reason = { marker: 'reason', focusableForPhrase: true, evalue: { marker: 'noconversion', from: efrom.unit, to } }
158
+ kms.stm.api.mentioned({ context: reason })
159
+ error(reason)
160
+ }
161
+ kms.stm.api.setVariable(efrom.unit.value, efrom.amount)
162
+ evalue = await e(formula)
154
163
  }
155
- kms.stm.api.setVariable(efrom.unit.value, efrom.amount)
156
- evalue = await e(formula)
164
+ return evalue
157
165
  }
166
+
167
+ let evalues = []
168
+ for (const to of tos) {
169
+ evalues.push({ value: await convert(to), to: structuredClone(to) })
170
+ }
171
+ evalues.sort((a, b) => a.evalue - b.evalue )
172
+
173
+ let fractionalPart = 0
174
+ let scale = 1
175
+ for (const evalue of evalues) {
176
+ const value = evalue.value.evalue * scale
177
+ const integerPart = Math.trunc(value)
178
+ fractionalPart = Math.abs(value - integerPart)
179
+ evalue.value.evalue = integerPart
180
+ scale = fractionalPart / value * scale
181
+ }
182
+ // evalues[evalues.length-1].value.evalue = Number((integerPart * (1+scale)).toFixed(4))
183
+ evalues[evalues.length-1].value.evalue += fractionalPart
184
+ evalues[evalues.length-1].value.evalue = Number(evalues[evalues.length-1].value.evalue.toFixed(4))
185
+
186
+ // remove the zeros
187
+ evalues = evalues.filter( (evalue) => evalue.value.evalue )
188
+
158
189
  /*
159
190
  '{
160
191
  "marker":"dimension",
@@ -163,12 +194,21 @@ const config = {
163
194
  "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"]}},
164
195
  "text":"10 degrees celcius","range":{"start":8,"end":25}}'
165
196
  */
166
- context.evalue = {
167
- paraphrase: true,
168
- marker: 'dimension',
169
- level: 1,
170
- unit: to,
171
- amount: { evalue, paraphrase: undefined }
197
+ evalues = evalues.map((evalue) => {
198
+ const number = evalue.value.evalue == 1 ? 'one' : 'many'
199
+ evalue.to.number = number
200
+ return {
201
+ paraphrase: true,
202
+ marker: 'quantity',
203
+ level: 1,
204
+ unit: evalue.to,
205
+ amount: { evalue: evalue.value, paraphrase: undefined }
206
+ }
207
+ })
208
+ if (evalues.length > 1) {
209
+ context.evalue = toList(evalues)
210
+ } else {
211
+ context.evalue = evalues[0]
172
212
  }
173
213
  },
174
214
  },
@@ -221,12 +261,13 @@ knowledgeModule({
221
261
  checks: {
222
262
  objects: [{ km: 'properties' }],
223
263
  context: [
264
+ defaultContextCheck({ marker: 'convertToUnits', exported: true, extra: ['from', 'to'] }),
224
265
  defaultContextCheck({
225
266
  match: ({context, isA}) => isA(context.marker, 'unit'),
226
267
  exported: true,
227
268
  extra: ['dimension'],
228
269
  }),
229
- defaultContextCheck(['dimension']),
270
+ defaultContextCheck(['dimension', 'response']),
230
271
  ],
231
272
  },
232
273
  },