ekms 8.9.0-beta.2 → 8.9.0-beta.21

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