ekms 9.6.0-beta.5 → 9.6.0-beta.7

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.
@@ -128,7 +128,7 @@
128
128
  ]
129
129
  ],
130
130
  "generatorp": "async ({context, g}) => `${await g(context.from)} ${context.word} ${await g(context.to)}`",
131
- "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 }"
131
+ "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 = toFinalValue(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 }"
132
132
  },
133
133
  {
134
134
  "id": "unit",
@@ -1,5 +1,5 @@
1
1
  const { debug, knowledgeModule, where, Digraph } = require('./runtime').theprogrammablemind
2
- const { defaultObjectCheck, defaultContextCheck, defaultContextCheckProperties } = require('./helpers')
2
+ const { toFinalValue, 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')
@@ -174,7 +174,7 @@ const config = {
174
174
  let fractionalPart = 0
175
175
  let scale = 1
176
176
  for (const evalue of evalues) {
177
- const value = evalue.value.evalue * scale
177
+ const value = toFinalValue(evalue) * scale
178
178
  const integerPart = Math.trunc(value)
179
179
  fractionalPart = Math.abs(value - integerPart)
180
180
  evalue.value.evalue = integerPart
@@ -6,11 +6,10 @@
6
6
  "point is a concept",
7
7
  "points are nameable orderable and memorable",
8
8
  {
9
- "apply": "(args) => {\n expectDirection(args)\n expectDistanceForMove(args)\n\n args.config.addSemantic({\n match: ({context, isA}) => isA(context.marker, 'quantity') && isA(context.unit.marker, 'unitPerUnit'),\n apply: async ({context, objects, api, gr, fragments, e, say}) => {\n // send a command to the drone\n const instantiation = await fragments(\"quantity in meters per second\", { quantity: context })\n const result = await e(instantiation)\n const desired_speed = result.evalue.amount.evalue.evalue\n const desired_power = objects.current.power * (desired_speed / objects.calibration.speedForward)\n objects.runCommand = true\n objects.current.power = desired_power \n objects.current.speedUnitsOfUser = context.unit\n }\n })\n\n args.config.addSemantic({\n match: ({context, objects, isA}) => objects.current.direction && objects.calibration.isCalibrated && context.marker == 'controlStart',\n apply: ({context, objects, api}) => {\n objects.runCommand = false \n }\n })\n\n args.config.addSemantic({\n // match: ({context, objects, isA}) => objects.current.direction && objects.calibration.isCalibrated && (context.marker == 'controlEnd' || context.marker == 'controlBetween'),\n match: ({context, objects, isA}) => objects.current.direction && objects.calibration.isCalibrated && context.marker == 'controlEnd',\n apply: async ({context, objects, api}) => {\n // send a command to the drone\n if (objects.runCommand) {\n await api.sendCommand()\n }\n }\n })\n }"
9
+ "apply": "(args) => {\n expectDirection(args)\n expectDistanceForMove(args)\n\n args.config.addSemantic({\n match: ({context, isA}) => isA(context.marker, 'quantity') && isA(context.unit.marker, 'unitPerUnit'),\n apply: async ({context, objects, api, gr, fragments, e, say}) => {\n // send a command to the drone\n const instantiation = await fragments(\"quantity in meters per second\", { quantity: context })\n const result = await e(instantiation)\n const desired_speed = result.evalue.amount.evalue.evalue\n objects.runCommand = true\n objects.current.speed = desired_speed\n objects.current.speedUnitsOfUser = context.unit\n }\n })\n\n args.config.addSemantic({\n match: ({context, objects, isA}) => objects.current.direction && context.marker == 'controlStart',\n apply: ({context, objects, api}) => {\n objects.runCommand = false \n }\n })\n\n args.config.addSemantic({\n match: ({context, objects, isA}) => objects.current.direction && context.marker == 'controlEnd',\n apply: async ({context, objects, api}) => {\n // send a command to the drone\n if (objects.runCommand) {\n await api.sendCommand()\n }\n }\n })\n }"
10
10
  },
11
11
  {
12
12
  "operators": [
13
- "([calibrate])",
14
13
  "([back])",
15
14
  "([turn] (direction))",
16
15
  "([pause] ([number]))",
@@ -24,7 +23,7 @@
24
23
  "isA": [
25
24
  "noun"
26
25
  ],
27
- "semantic": "async ({objects, mentions, api, e, context}) => {\n if (api.isCalibrated()) {\n objects.runCommand = true\n const ordinal = objects.current.ordinal - 1\n const lastPoint = mentions({ context: { marker: 'point' }, condition: (context) => context.ordinal == ordinal })\n objects.current.destination = lastPoint\n }\n }"
26
+ "semantic": "async ({objects, mentions, api, e, context}) => {\n objects.runCommand = true\n const ordinal = api.currentOrdinal() - 1\n const lastPoint = mentions({ context: { marker: 'point' }, condition: (context) => context.ordinal == ordinal })\n objects.current.destination = lastPoint\n }"
28
27
  },
29
28
  {
30
29
  "id": "toPoint",
@@ -32,7 +31,7 @@
32
31
  "preposition"
33
32
  ],
34
33
  "bridge": "{ ...next(operator), operator: operator, point: after[0], interpolate: [{ property: 'operator' }, { property: 'point' }] }",
35
- "semantic": "async ({objects, api, e, context}) => {\n if (api.isCalibrated()) {\n objects.runCommand = true\n const point = await e(context.point)\n objects.current.destination = point.evalue\n }\n }"
34
+ "semantic": "async ({objects, api, e, context}) => {\n objects.runCommand = true\n const point = await e(context.point)\n objects.current.destination = point.evalue\n }"
36
35
  },
37
36
  {
38
37
  "id": "go"
@@ -45,17 +44,6 @@
45
44
  "bridge": "{ ...next(operator), direction: after[0], interpolate: [{ context: operator }, { property: 'direction' }] }",
46
45
  "semantic": "({context, objects, api}) => {\n objects.runCommand = true\n objects.current.direction = context.direction.marker\n }"
47
46
  },
48
- {
49
- "id": "calibrate",
50
- "words": [
51
- "configure"
52
- ],
53
- "isA": [
54
- "verb"
55
- ],
56
- "bridge": "{ ...next(operator), interpolate: [{ context: operator }] }",
57
- "semantic": "async ({context, objects, api, mentioned}) => {\n let power = 20\n const moveTimeInSeconds = 0.5\n let distanceInCM = 0\n let startBackward\n for (; power < 30; ++power) {\n const start = await api.sonic();\n await api.forward(power, { batched: true })\n await api.pause(moveTimeInSeconds, { batched: true })\n await api.stop()\n const end = await api.sonic();\n if (end !== start) {\n distanceInCM = start - end\n startBackward = end\n break;\n }\n }\n\n const metersPerSecondForward = (distanceInCM/100)/moveTimeInSeconds\n\n // reset\n\n await api.backward(power, { batched: true })\n await api.pause(moveTimeInSeconds, { batched: true })\n await api.stop()\n const endBackward = await api.sonic();\n\n const metersPerSecondBackward = ((endBackward-startBackward)/100)/moveTimeInSeconds\n \n // console.log(`Distance ${distance} cm`)\n // console.log(`Time ${moveTime} ms`)\n // console.log(`M/S ${metersPerSecond}`)\n\n objects.calibration.minPower = power\n objects.calibration.power = power\n objects.current.power = power\n objects.calibration.speedForward = metersPerSecondForward\n objects.calibration.speedBackward = metersPerSecondBackward\n objects.calibration.isCalibrated = true\n\n const ordinal = api.nextOrdinal()\n mentioned({ marker: 'point', ordinal, point: { x: 0, y: 0 }, description: \"start\" })\n objects.current.ordinal = ordinal\n\n api.saveCalibration(objects.calibration)\n }"
58
- },
59
47
  {
60
48
  "id": "pause",
61
49
  "isA": [
@@ -73,7 +61,7 @@
73
61
  "1": "{ marker: 'drone' }"
74
62
  },
75
63
  "bridge": "{ ...next(operator), object: after[0], interpolate: [{ context: operator }, { property: 'object' }] }",
76
- "semantic": "async ({mentioned, context, objects, api, say}) => {\n if (!objects.calibration.isCalibrated) {\n return // ignore\n }\n if (objects.calibration.speedForward) {\n await api.stop()\n api.markCurrentPoint()\n } else {\n const stopTime = await api.stop()\n objects.calibration.endTime = stopTime\n objects.calibration.duration = (objects.calibration.endTime - objects.calibration.startTime)/1000\n }\n }"
64
+ "semantic": "async ({mentioned, context, objects, api, say}) => {\n await api.stop()\n api.markCurrentPoint()\n }"
77
65
  }
78
66
  ],
79
67
  "generators": [
@@ -15683,12 +15671,11 @@
15683
15671
  }
15684
15672
  },
15685
15673
  {
15686
- "apply": "(args) => {\n expectDirection(args)\n expectDistanceForMove(args)\n\n args.config.addSemantic({\n match: ({context, isA}) => isA(context.marker, 'quantity') && isA(context.unit.marker, 'unitPerUnit'),\n apply: async ({context, objects, api, gr, fragments, e, say}) => {\n // send a command to the drone\n const instantiation = await fragments(\"quantity in meters per second\", { quantity: context })\n const result = await e(instantiation)\n const desired_speed = result.evalue.amount.evalue.evalue\n const desired_power = objects.current.power * (desired_speed / objects.calibration.speedForward)\n objects.runCommand = true\n objects.current.power = desired_power \n objects.current.speedUnitsOfUser = context.unit\n }\n })\n\n args.config.addSemantic({\n match: ({context, objects, isA}) => objects.current.direction && objects.calibration.isCalibrated && context.marker == 'controlStart',\n apply: ({context, objects, api}) => {\n objects.runCommand = false \n }\n })\n\n args.config.addSemantic({\n // match: ({context, objects, isA}) => objects.current.direction && objects.calibration.isCalibrated && (context.marker == 'controlEnd' || context.marker == 'controlBetween'),\n match: ({context, objects, isA}) => objects.current.direction && objects.calibration.isCalibrated && context.marker == 'controlEnd',\n apply: async ({context, objects, api}) => {\n // send a command to the drone\n if (objects.runCommand) {\n await api.sendCommand()\n }\n }\n })\n }"
15674
+ "apply": "(args) => {\n expectDirection(args)\n expectDistanceForMove(args)\n\n args.config.addSemantic({\n match: ({context, isA}) => isA(context.marker, 'quantity') && isA(context.unit.marker, 'unitPerUnit'),\n apply: async ({context, objects, api, gr, fragments, e, say}) => {\n // send a command to the drone\n const instantiation = await fragments(\"quantity in meters per second\", { quantity: context })\n const result = await e(instantiation)\n const desired_speed = result.evalue.amount.evalue.evalue\n objects.runCommand = true\n objects.current.speed = desired_speed\n objects.current.speedUnitsOfUser = context.unit\n }\n })\n\n args.config.addSemantic({\n match: ({context, objects, isA}) => objects.current.direction && context.marker == 'controlStart',\n apply: ({context, objects, api}) => {\n objects.runCommand = false \n }\n })\n\n args.config.addSemantic({\n match: ({context, objects, isA}) => objects.current.direction && context.marker == 'controlEnd',\n apply: async ({context, objects, api}) => {\n // send a command to the drone\n if (objects.runCommand) {\n await api.sendCommand()\n }\n }\n })\n }"
15687
15675
  },
15688
15676
  {
15689
15677
  "extraConfig": true,
15690
15678
  "operators": [
15691
- "([calibrate])",
15692
15679
  "([back])",
15693
15680
  "([turn] (direction))",
15694
15681
  "([pause] ([number]))",
@@ -15720,16 +15707,6 @@
15720
15707
  ],
15721
15708
  "bridge": "{ ...next(operator), direction: after[0], interpolate: [{ context: operator }, { property: 'direction' }] }"
15722
15709
  },
15723
- {
15724
- "id": "calibrate",
15725
- "words": [
15726
- "configure"
15727
- ],
15728
- "isA": [
15729
- "verb"
15730
- ],
15731
- "bridge": "{ ...next(operator), interpolate: [{ context: operator }] }"
15732
- },
15733
15710
  {
15734
15711
  "id": "pause",
15735
15712
  "isA": [
@@ -15927,11 +15904,6 @@
15927
15904
  "verb",
15928
15905
  false
15929
15906
  ],
15930
- [
15931
- "calibrate",
15932
- "verb",
15933
- false
15934
- ],
15935
15907
  [
15936
15908
  "call",
15937
15909
  "verb",
@@ -18718,11 +18690,6 @@
18718
18690
  "verb",
18719
18691
  false
18720
18692
  ],
18721
- [
18722
- "calibrate",
18723
- "verb",
18724
- false
18725
- ],
18726
18693
  [
18727
18694
  "call",
18728
18695
  "verb",
@@ -21780,11 +21747,6 @@
21780
21747
  "verb",
21781
21748
  false
21782
21749
  ],
21783
- [
21784
- "calibrate",
21785
- "verb",
21786
- false
21787
- ],
21788
21750
  [
21789
21751
  "call",
21790
21752
  "verb",
@@ -24762,11 +24724,6 @@
24762
24724
  "verb",
24763
24725
  false
24764
24726
  ],
24765
- [
24766
- "calibrate",
24767
- "verb",
24768
- false
24769
- ],
24770
24727
  [
24771
24728
  "call",
24772
24729
  "verb",