tpmkms_4wp 8.9.0 → 8.9.1-beta.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 (44) hide show
  1. package/common/animals.instance.json +65 -36
  2. package/common/articles.js +4 -0
  3. package/common/colors.instance.json +77 -106
  4. package/common/comparable.instance.json +15 -0
  5. package/common/conjunction.js +27 -18
  6. package/common/countable.js +8 -2
  7. package/common/countable.test.json +586 -0
  8. package/common/crew.instance.json +142 -504
  9. package/common/dialogues.js +14 -11
  10. package/common/dimension.instance.json +10 -36
  11. package/common/edible.instance.json +324 -224
  12. package/common/emotions.instance.json +8 -60
  13. package/common/fastfood.instance.json +1464 -216
  14. package/common/formulas.instance.json +10 -0
  15. package/common/helpers/conjunction.js +75 -0
  16. package/common/helpers/dialogues.js +14 -8
  17. package/common/helpers/properties.js +2 -2
  18. package/common/helpers.js +29 -0
  19. package/common/hierarchy.js +5 -5
  20. package/common/hierarchy.test.json +1491 -0
  21. package/common/kirk.instance.json +5 -0
  22. package/common/length.instance.json +150 -0
  23. package/common/math.instance.json +10 -0
  24. package/common/meta.js +5 -3
  25. package/common/ordering.instance.json +78 -0
  26. package/common/people.instance.json +169 -4
  27. package/common/pipboy.instance.json +203 -177
  28. package/common/pipboy.js +0 -1
  29. package/common/pipboy.test.json +494 -251
  30. package/common/pokemon.instance.json +71 -6
  31. package/common/pos.js +9 -6
  32. package/common/pressure.instance.json +40 -0
  33. package/common/properties.instance.json +5 -44
  34. package/common/reports.instance.json +21 -1
  35. package/common/spock.instance.json +5 -0
  36. package/common/temperature.instance.json +40 -0
  37. package/common/ui.instance.json +135 -0
  38. package/common/ui.js +11 -5
  39. package/common/weight.instance.json +120 -0
  40. package/common/wp.instance.json +30067 -0
  41. package/common/wp.js +240 -0
  42. package/common/wp.test.json +41513 -0
  43. package/main.js +2 -0
  44. package/package.json +7 -2
package/common/wp.js ADDED
@@ -0,0 +1,240 @@
1
+ const { knowledgeModule, where, Digraph } = require('./runtime').theprogrammablemind
2
+ const { defaultContextCheck } = require('./helpers')
3
+ const helpers = require("./helpers")
4
+ const ui = require("./ui")
5
+ const countable = require("./countable")
6
+ const colors = require("./colors")
7
+ const errors = require("./errors")
8
+ const wp_tests = require('./wp.test.json')
9
+ const instance = require('./wp.instance.json')
10
+
11
+ /*
12
+ start inserting text until I say banana
13
+ ...
14
+ or
15
+ stop inserting text
16
+
17
+ make the text of the 1st to 3rd paragraphs blue
18
+
19
+
20
+ make every word bold and underlines and blue -> weirdly "bold underlined and blue" works
21
+
22
+ make the font ...
23
+ make the color blue
24
+ make the color of the first paragraph blue
25
+
26
+ words that start with a
27
+ make all the bold text uppercase
28
+ underline all the bold text
29
+ underline all the text
30
+ underline everything
31
+ 4 letter word
32
+ 4 to 6 letter word
33
+ word with 'a' in it
34
+ words containing a
35
+ every 5th word
36
+
37
+ in the first paragraph make the words that start with abc bold
38
+ bold the first three words that start with t
39
+ bold much and many
40
+ make the words that start with t bold and underlined
41
+ */
42
+
43
+ class API {
44
+ initialize({ objects }) {
45
+ this._objects = objects
46
+ this._objects.changeState = []
47
+ }
48
+
49
+ changeState(value) {
50
+ this._objects.changeState.push(value)
51
+ }
52
+ }
53
+
54
+ const root = (id) => {
55
+ return id.split('_')[0]
56
+ }
57
+
58
+ const setUpdate = (isA, update, states) => {
59
+ let color;
60
+ const styles = []
61
+ for (const state of states) {
62
+ if (isA(state, 'style_wp')) {
63
+ if (!update.styles) {
64
+ update.styles = []
65
+ }
66
+ let style = root(state.value)
67
+ /*
68
+ if (style == 'underlined') {
69
+ style = 'underline'
70
+ } else if (style == 'italicize') {
71
+ style = 'italic'
72
+ }
73
+ */
74
+ update.styles.push(style)
75
+ } else {
76
+ update.color = root(state.value)
77
+ }
78
+ }
79
+ }
80
+
81
+ const api = new API()
82
+
83
+ let config = {
84
+ name: 'wp',
85
+ };
86
+
87
+ const changeState = ({api, isA, context, toArray, element, state}) => {
88
+ let unit = root(context.element.marker)
89
+ let scope
90
+ let conditions = []
91
+ if (isA(context.element, 'everything')) {
92
+ scope = 'all'
93
+ } else if (context.element.condition) {
94
+ const condition = context.element.condition
95
+ if (condition.marker == 'wordComparison_wp') {
96
+ const letters = condition.letters.letters.text
97
+ conditions.push({ comparison: condition.comparison, letters })
98
+ }
99
+ } else {
100
+ scope = context.element.quantity.quantity
101
+ }
102
+ const update = { unit, scope, conditions }
103
+ setUpdate(isA, update, toArray(context.state))
104
+ api.changeState(update)
105
+ }
106
+
107
+ template = {
108
+ configs: [
109
+ 'setidsuffix _wp',
110
+ 'words are countable and statefulElements',
111
+ 'characters are countable',
112
+ 'paragraphs are countable',
113
+ 'bold, italic, code, capitalize, lowercase and underline are styles',
114
+ 'underlined means underline',
115
+ 'capitalized means capitalize',
116
+ 'uppercase means capitalize',
117
+ 'italicize means italic',
118
+ 'italicized means italic',
119
+ // 'start end and contain are wordComparisons',
120
+ // 'styles are negatable',
121
+ "resetIdSuffix",
122
+ {
123
+ operators: [
124
+ "([changeState_wp|make] ([statefulElement_wp]) ([stateValue_wp|]))",
125
+ "((style_wp/*) [applyStyle_wp] ([statefulElement_wp|]))",
126
+ "((word_wp/*) [wordComparison_wp] ([startsWith_wp|with] (a/0)? (letters)))",
127
+ ],
128
+ bridges: [
129
+ {
130
+ id: 'wordComparison_wp',
131
+ parents: ['verb'],
132
+ words: [
133
+ { word: 'start', comparison: 'prefix' },
134
+ { word: 'starts', comparison: 'prefix', },
135
+ { word: 'end', comparison: 'suffix' },
136
+ { word: 'ends', comparison: 'suffix' },
137
+ { word: 'contain', comparison: 'include' },
138
+ { word: 'contains', comparison: 'include' },
139
+ { word: 'include', comparison: 'include' },
140
+ { word: 'includes', comparison: 'include' },
141
+ ],
142
+ bridge: "{ ...next(operator), element: before[0], subject: before[0], letters: after[0], verb: operator, generate: ['element', 'verb', 'letters'] }",
143
+ },
144
+ {
145
+ id: 'startsWith_wp',
146
+ parents: ['preposition'],
147
+ optional: {
148
+ 1: "{ marker: 'a' }",
149
+ },
150
+ bridge: "{ ...next(operator), operator: operator, letters: after[1], generate: ['operator', 'letters'] }",
151
+ },
152
+ {
153
+ id: 'applyStyle_wp',
154
+ parents: ['verb'],
155
+ convolution: true,
156
+ bridge: "{ ...next(operator), element: after[0], state: before[0], operator: operator, generate: ['state', 'element'] }",
157
+ localHierarchy: [
158
+ ['thisitthat', 'statefulElement_wp'],
159
+ ['everything', 'statefulElement_wp'],
160
+ ],
161
+ semantic: (args) => {
162
+ changeState({...args, element: args.context.element, state: args.context.state})
163
+ }
164
+ },
165
+ {
166
+ id: 'changeState_wp',
167
+ parents: ['verb'],
168
+ bridge: "{ ...next(operator), element: after[0], state: after[1], operator: operator, generate: ['operator', 'element', 'state'] }",
169
+ localHierarchy: [
170
+ ['thisitthat', 'statefulElement_wp'],
171
+ ['everything', 'statefulElement_wp'],
172
+ ],
173
+ semantic: (args) => {
174
+ changeState({...args, element: args.context.element, state: args.context.state})
175
+ }
176
+ },
177
+ {
178
+ id: 'stateValue_wp',
179
+ children: ['color_colors', 'style_wp'],
180
+ },
181
+ ],
182
+ semantics: [
183
+ {
184
+ where: where(),
185
+ match: ({context, isA}) => isA(context, 'style_wp') && !context.same && !context.isResponse && !context.evaluate,
186
+ apply: ({context, api, isA, toArray}) => {
187
+ const update = { scope: 'selection' }
188
+ setUpdate(isA, update, toArray(context))
189
+ api.changeState(update)
190
+ }
191
+ },
192
+ {
193
+ where: where(),
194
+ match: ({context, isA}) => isA(context, 'statefulElement_wp') && !context.same && !context.isResponse && !context.evaluate,
195
+ apply: ({context, api, isA, toArray}) => {
196
+ const unit = root(context.marker)
197
+ let scope
198
+ if (context.quantity) {
199
+ scope = context.quantity.quantity
200
+ }
201
+ // TODO set default scope for "every word bold underlined etc"
202
+ }
203
+ },
204
+ ],
205
+ priorities: [
206
+ { "context": [['changeState_wp',0], ['statefulElement_wp', 0], ['list', 0]], ordered: true, choose: [0] },
207
+ { "context": [['startsWith_wp',0], ['unknown', 0], ['list', 1]], ordered: true, choose: [0] },
208
+ ],
209
+ },
210
+ // "([changeState_wp|make] ([statefulElement_wp]) ([stateValue_wp|]))",
211
+ // "((style_wp/*) [applyStyle_wp] ([statefulElement_wp|]))",
212
+ // "x statefulElement_wp y means y changeState_wp x",
213
+ ]
214
+ }
215
+
216
+ knowledgeModule({
217
+ config,
218
+ includes: [ui, countable, colors, errors],
219
+ api: () => new API(),
220
+
221
+ module,
222
+ description: 'Word processor',
223
+ test: {
224
+ name: './wp.test.json',
225
+ contents: wp_tests,
226
+ checks: {
227
+ context: [
228
+ ...defaultContextCheck(),
229
+ ],
230
+ objects: [
231
+ 'changeState',
232
+ { km: 'ui' },
233
+ ],
234
+ },
235
+ },
236
+ template: {
237
+ template,
238
+ instance,
239
+ }
240
+ })