tpmkms_4wp 8.0.0-beta.31 → 8.0.0-beta.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. package/common/animals.instance.json +325 -0
  2. package/common/articles.js +108 -0
  3. package/common/articles.test.json +310 -0
  4. package/common/colors.instance.json +340 -0
  5. package/common/crew.instance.json +525 -0
  6. package/common/dialogues.js +66 -102
  7. package/common/dimension.instance.json +20 -0
  8. package/common/edible.instance.json +650 -28
  9. package/common/emotions.instance.json +25 -0
  10. package/common/evaluate.instance.json +2 -0
  11. package/common/evaluate.js +55 -0
  12. package/common/evaluate.test.json +574 -0
  13. package/common/fastfood.instance.json +1989 -329
  14. package/common/formulas.instance.json +20 -0
  15. package/common/gdefaults.js +6 -6
  16. package/common/help.test.json +16 -4
  17. package/common/helpers.js +1 -1
  18. package/common/kirk.instance.json +20 -0
  19. package/common/length.instance.json +300 -0
  20. package/common/math.instance.json +25 -0
  21. package/common/nameable.instance.json +2 -0
  22. package/common/nameable.js +137 -0
  23. package/common/nameable.test.json +1545 -0
  24. package/common/ordering.instance.json +50 -0
  25. package/common/people.instance.json +165 -0
  26. package/common/pipboy.instance.json +340 -0
  27. package/common/pokemon.instance.json +265 -0
  28. package/common/pressure.instance.json +80 -0
  29. package/common/properties.instance.json +25 -0
  30. package/common/reports.instance.json +41 -1
  31. package/common/spock.instance.json +20 -0
  32. package/common/stm.js +109 -3
  33. package/common/stm.test.json +1702 -1
  34. package/common/temperature.instance.json +192 -0
  35. package/common/ui.instance.json +20 -0
  36. package/common/weight.instance.json +240 -0
  37. package/main.js +6 -0
  38. package/package.json +13 -2
@@ -0,0 +1,137 @@
1
+ const { Config, knowledgeModule, where } = require('./runtime').theprogrammablemind
2
+ const { defaultContextCheck } = require('./helpers')
3
+ const helpers = require('./helpers')
4
+ const stm = require('./stm')
5
+ const nameable_tests = require('./nameable.test.json')
6
+
7
+ class API {
8
+ initialize({ objects, km, kms }) {
9
+ this.objects = objects
10
+ this.objects.named = {}
11
+ }
12
+
13
+ // report is a context
14
+ setName(context, name) {
15
+ if (!context.nameable_names) {
16
+ context.nameable_names = []
17
+ }
18
+ context.nameable_names.push(name)
19
+ }
20
+
21
+ get(name) {
22
+ return this.objects.named[name]
23
+ }
24
+
25
+ getNamesByType(type) {
26
+ debugger
27
+ const contexts = this.args.kms.stm.api.getByType(type)
28
+ const names = new Set()
29
+ for (const context of contexts) {
30
+ if (context.nameable_names) {
31
+ for (const name of context.nameable_names) {
32
+ names.add(name)
33
+ }
34
+ }
35
+ }
36
+ return [...names]
37
+ }
38
+
39
+ getNames() {
40
+ const current = this.current()
41
+ console.log('getReportNames current', JSON.stringify(current, null, 2))
42
+ return Object.keys(this.objects.namedReports).map( (name) => {
43
+ const selected = (current.names || []).includes(name)
44
+ return { name, selected, id: name }
45
+ })
46
+ }
47
+
48
+ setCurrent(name) {
49
+ const context = this.objects.named[name]
50
+ if (context) {
51
+ this.args.km('stm').api.mentioned(context)
52
+ }
53
+ }
54
+ }
55
+
56
+ const api = new API()
57
+
58
+ const configStruct = {
59
+ name: 'nameable',
60
+ operators: [
61
+ "([call] ([nameable]) (name))",
62
+ { pattern: "([getNamesByType] (type))", development: true },
63
+ { pattern: "([m1])", development: true },
64
+ // { pattern: "([testPullFromContext] ([memorable]))", development: true }
65
+ ],
66
+ words: {
67
+ literals: {
68
+ // "m1": [{"id": "memorable", development: true, "initial": "{ value: 'm1' }" }],
69
+ // "m2": [{"id": "memorable", development: true, "initial": "{ value: 'm2' }" }],
70
+ },
71
+ },
72
+ bridges: [
73
+ {
74
+ id: 'm1',
75
+ isA: ['memorable', 'nameable'],
76
+ },
77
+ {
78
+ id: 'getNamesByType',
79
+ development: true,
80
+ isA: ['verby'],
81
+ bridge: "{ ...next(operator), type: after[0] }",
82
+ semantic: async ({context, api}) => {
83
+ context.response = api.getNamesByType(context.type.value).join(" ")
84
+ context.isResponse = true
85
+ }
86
+ },
87
+ {
88
+ id: 'call',
89
+ isA: ['verby'],
90
+ bridge: "{ ...next(operator), nameable: after[0], name: after[1] }",
91
+ generatorp: async ({context, g}) => `call ${await g(context.nameable)} ${await g(context.name)}`,
92
+ semantic: async ({config, context, api, e}) => {
93
+ // TODO find report being referred to
94
+ const nameable = (await e(context.nameable)).evalue
95
+ const name = context.name.text
96
+ config.addWord(name, { id: nameable.marker, initial: `{ value: "${nameable.marker}", nameable_named: true }` })
97
+ api.setName(nameable, name)
98
+ }
99
+ },
100
+ { id: 'nameable', words: helpers.words('nameable')},
101
+ ]
102
+ }
103
+
104
+ let createConfig = async () => {
105
+ const config = new Config(configStruct, module)
106
+ config.stop_auto_rebuild()
107
+
108
+ await config.initializer( ({config}) => {
109
+ config.addArgs(({kms}) => ({
110
+ mentioned: (context) => {
111
+ kms.nameable.api.mentioned(context)
112
+ },
113
+ mentions: (context) => {
114
+ return kms.nameable.api.mentions(context)
115
+ },
116
+ }))
117
+ })
118
+ await config.setApi(api)
119
+ await config.add(stm)
120
+
121
+ await config.restart_auto_rebuild()
122
+ return config
123
+ }
124
+
125
+ knowledgeModule( {
126
+ module,
127
+ description: 'namable objects',
128
+ createConfig,
129
+ test: {
130
+ name: './nameable.test.json',
131
+ contents: nameable_tests,
132
+ checks: {
133
+ context: [...defaultContextCheck, 'pullFromContext'],
134
+ objects: ['mentioned', { km: 'stm' }],
135
+ },
136
+ },
137
+ })