tpmkms_4wp 8.9.0 → 8.9.1-beta.1
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.
- package/common/animals.instance.json +65 -36
- package/common/articles.js +4 -0
- package/common/colors.instance.json +77 -106
- package/common/comparable.instance.json +15 -0
- package/common/conjunction.js +27 -18
- package/common/countable.js +8 -2
- package/common/countable.test.json +586 -0
- package/common/crew.instance.json +142 -504
- package/common/dialogues.js +16 -11
- package/common/dimension.instance.json +10 -36
- package/common/edible.instance.json +324 -224
- package/common/emotions.instance.json +8 -60
- package/common/fastfood.instance.json +1464 -216
- package/common/formulas.instance.json +10 -0
- package/common/helpers/conjunction.js +75 -0
- package/common/helpers/dialogues.js +14 -8
- package/common/helpers/properties.js +2 -2
- package/common/helpers.js +29 -0
- package/common/hierarchy.js +5 -5
- package/common/hierarchy.test.json +1491 -0
- package/common/kirk.instance.json +5 -0
- package/common/length.instance.json +150 -0
- package/common/math.instance.json +10 -0
- package/common/meta.js +5 -3
- package/common/ordering.instance.json +78 -0
- package/common/people.instance.json +169 -4
- package/common/pipboy.instance.json +203 -177
- package/common/pipboy.js +0 -1
- package/common/pipboy.test.json +494 -251
- package/common/pokemon.instance.json +71 -6
- package/common/pos.js +12 -6
- package/common/pressure.instance.json +40 -0
- package/common/properties.instance.json +5 -44
- package/common/reports.instance.json +21 -1
- package/common/spock.instance.json +5 -0
- package/common/temperature.instance.json +40 -0
- package/common/ui.instance.json +135 -0
- package/common/ui.js +11 -5
- package/common/weight.instance.json +120 -0
- package/common/wp.instance.json +30067 -0
- package/common/wp.js +256 -0
- package/common/wp.test.json +41469 -0
- package/main.js +2 -0
- package/package.json +7 -2
    
        package/common/wp.js
    ADDED
    
    | @@ -0,0 +1,256 @@ | |
| 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 == 'wordComparisonWith_wp') {
         | 
| 96 | 
            +
                  // with or not with that is the question
         | 
| 97 | 
            +
                  const letters = condition.letters.letters.text
         | 
| 98 | 
            +
                  conditions.push({ comparison: condition.comparison, letters })
         | 
| 99 | 
            +
                } else if (condition.marker == 'wordComparison_wp') {
         | 
| 100 | 
            +
                  // with or not with that is the question
         | 
| 101 | 
            +
                  const letters = condition.letters.text
         | 
| 102 | 
            +
                  conditions.push({ comparison: condition.comparison, letters })
         | 
| 103 | 
            +
                }
         | 
| 104 | 
            +
              } else {
         | 
| 105 | 
            +
                scope = context.element.quantity.quantity
         | 
| 106 | 
            +
              }
         | 
| 107 | 
            +
              const update = { unit, scope, conditions }
         | 
| 108 | 
            +
              setUpdate(isA, update, toArray(context.state))
         | 
| 109 | 
            +
              api.changeState(update)
         | 
| 110 | 
            +
            }
         | 
| 111 | 
            +
             | 
| 112 | 
            +
            template = {
         | 
| 113 | 
            +
              configs: [
         | 
| 114 | 
            +
                'setidsuffix _wp',
         | 
| 115 | 
            +
                'words are countable and statefulElements',
         | 
| 116 | 
            +
                'characters are countable',
         | 
| 117 | 
            +
                'paragraphs are countable',
         | 
| 118 | 
            +
                'bold, italic, code, capitalize, lowercase and underline are styles',
         | 
| 119 | 
            +
                'underlined means underline',
         | 
| 120 | 
            +
                'capitalized means capitalize',
         | 
| 121 | 
            +
                'uppercase means capitalize',
         | 
| 122 | 
            +
                'italicize means italic',
         | 
| 123 | 
            +
                'italicized means italic',
         | 
| 124 | 
            +
                // 'start end and contain are wordComparisonWiths',
         | 
| 125 | 
            +
                // 'styles are negatable',
         | 
| 126 | 
            +
                "resetIdSuffix",
         | 
| 127 | 
            +
                {
         | 
| 128 | 
            +
                  operators: [
         | 
| 129 | 
            +
                    "([changeState_wp|make] ([statefulElement_wp]) ([stateValue_wp|]))",
         | 
| 130 | 
            +
                    "((style_wp/*) [applyStyle_wp] ([statefulElement_wp|]))",
         | 
| 131 | 
            +
                    "((word_wp/*) [wordComparisonWith_wp] ([comparisonWith_wp|with] (a/0)? (letters)))",
         | 
| 132 | 
            +
                    "((word_wp/*) [wordComparison_wp] (a/0)? (letters))",
         | 
| 133 | 
            +
                  ],
         | 
| 134 | 
            +
                  bridges: [
         | 
| 135 | 
            +
                    { 
         | 
| 136 | 
            +
                      id: 'wordComparisonWith_wp',
         | 
| 137 | 
            +
                      parents: ['verb'],
         | 
| 138 | 
            +
                      words: [ 
         | 
| 139 | 
            +
                        { word: 'start', comparison: 'prefix' }, 
         | 
| 140 | 
            +
                        { word: 'starts', comparison: 'prefix', },
         | 
| 141 | 
            +
                        { word: 'end', comparison: 'suffix' },
         | 
| 142 | 
            +
                        { word: 'ends', comparison: 'suffix' },
         | 
| 143 | 
            +
                      ],
         | 
| 144 | 
            +
                      bridge: "{ ...next(operator), element: before[0], subject: before[0], letters: after[0], verb: operator, generate: ['element', 'verb', 'letters'] }",
         | 
| 145 | 
            +
                    },
         | 
| 146 | 
            +
                    { 
         | 
| 147 | 
            +
                      id: 'wordComparison_wp',
         | 
| 148 | 
            +
                      parents: ['verb'],
         | 
| 149 | 
            +
                      words: [ 
         | 
| 150 | 
            +
                        { word: 'contain', comparison: 'include' }, 
         | 
| 151 | 
            +
                        { word: 'contains', comparison: 'include' },
         | 
| 152 | 
            +
                        { word: 'include', comparison: 'include' }, 
         | 
| 153 | 
            +
                        { word: 'includes', comparison: 'include' },
         | 
| 154 | 
            +
                      ],
         | 
| 155 | 
            +
                      optional: {
         | 
| 156 | 
            +
                        1: "{ marker: 'a' }",
         | 
| 157 | 
            +
                      },
         | 
| 158 | 
            +
                      bridge: "{ ...next(operator), element: before[0], subject: before[0], letters: after[1], verb: operator, generate: ['element', 'verb', 'letters'] }",
         | 
| 159 | 
            +
                    },
         | 
| 160 | 
            +
                    { 
         | 
| 161 | 
            +
                      id: 'comparisonWith_wp',
         | 
| 162 | 
            +
                      parents: ['preposition'],
         | 
| 163 | 
            +
                      optional: {
         | 
| 164 | 
            +
                        1: "{ marker: 'a' }",
         | 
| 165 | 
            +
                      },
         | 
| 166 | 
            +
                      bridge: "{ ...next(operator), operator: operator, letters: after[1], generate: ['operator', 'letters'] }",
         | 
| 167 | 
            +
                    },
         | 
| 168 | 
            +
                    { 
         | 
| 169 | 
            +
                      id: 'applyStyle_wp',
         | 
| 170 | 
            +
                      parents: ['verb'],
         | 
| 171 | 
            +
                      convolution: true,
         | 
| 172 | 
            +
                      bridge: "{ ...next(operator), element: after[0], state: before[0], operator: operator, generate: ['state', 'element'] }",
         | 
| 173 | 
            +
                      localHierarchy: [
         | 
| 174 | 
            +
                        ['thisitthat', 'statefulElement_wp'],
         | 
| 175 | 
            +
                        ['everything', 'statefulElement_wp'],
         | 
| 176 | 
            +
                      ],
         | 
| 177 | 
            +
                      semantic: (args) => {
         | 
| 178 | 
            +
                        changeState({...args, element: args.context.element, state: args.context.state})
         | 
| 179 | 
            +
                      }
         | 
| 180 | 
            +
                    },
         | 
| 181 | 
            +
                    { 
         | 
| 182 | 
            +
                      id: 'changeState_wp',
         | 
| 183 | 
            +
                      parents: ['verb'],
         | 
| 184 | 
            +
                      bridge: "{ ...next(operator), element: after[0], state: after[1], operator: operator, generate: ['operator', 'element', 'state'] }",
         | 
| 185 | 
            +
                      localHierarchy: [
         | 
| 186 | 
            +
                        ['thisitthat', 'statefulElement_wp'],
         | 
| 187 | 
            +
                        ['everything', 'statefulElement_wp'],
         | 
| 188 | 
            +
                      ],
         | 
| 189 | 
            +
                      semantic: (args) => {
         | 
| 190 | 
            +
                        changeState({...args, element: args.context.element, state: args.context.state})
         | 
| 191 | 
            +
                      }
         | 
| 192 | 
            +
                    },
         | 
| 193 | 
            +
                    { 
         | 
| 194 | 
            +
                      id: 'stateValue_wp',
         | 
| 195 | 
            +
                      children: ['color_colors', 'style_wp'],
         | 
| 196 | 
            +
                    },
         | 
| 197 | 
            +
                  ],
         | 
| 198 | 
            +
                  semantics: [
         | 
| 199 | 
            +
                    {
         | 
| 200 | 
            +
                      where: where(),
         | 
| 201 | 
            +
                      match: ({context, isA}) => isA(context, 'style_wp') && !context.same && !context.isResponse && !context.evaluate,
         | 
| 202 | 
            +
                      apply: ({context, api, isA, toArray}) => {
         | 
| 203 | 
            +
                        const update = { scope: 'selection' }
         | 
| 204 | 
            +
                        setUpdate(isA, update, toArray(context))
         | 
| 205 | 
            +
                        api.changeState(update)
         | 
| 206 | 
            +
                      }
         | 
| 207 | 
            +
                    },
         | 
| 208 | 
            +
                    {
         | 
| 209 | 
            +
                      where: where(),
         | 
| 210 | 
            +
                      match: ({context, isA}) => isA(context, 'statefulElement_wp') && !context.same && !context.isResponse && !context.evaluate,
         | 
| 211 | 
            +
                      apply: ({context, api, isA, toArray}) => {
         | 
| 212 | 
            +
                        const unit = root(context.marker)
         | 
| 213 | 
            +
                        let scope
         | 
| 214 | 
            +
                        if (context.quantity) {
         | 
| 215 | 
            +
                          scope = context.quantity.quantity
         | 
| 216 | 
            +
                        }
         | 
| 217 | 
            +
                        // TODO set default scope for "every word bold underlined etc"
         | 
| 218 | 
            +
                      }
         | 
| 219 | 
            +
                    },
         | 
| 220 | 
            +
                  ],
         | 
| 221 | 
            +
                  priorities: [
         | 
| 222 | 
            +
                    { "context": [['changeState_wp',0], ['statefulElement_wp', 0], ['list', 0]], ordered: true, choose: [0] },
         | 
| 223 | 
            +
                    { "context": [['comparisonWith_wp',0], ['unknown', 0], ['list', 1]], ordered: true, choose: [0] },
         | 
| 224 | 
            +
                  ],
         | 
| 225 | 
            +
                },
         | 
| 226 | 
            +
                // "([changeState_wp|make] ([statefulElement_wp]) ([stateValue_wp|]))",
         | 
| 227 | 
            +
                // "((style_wp/*) [applyStyle_wp] ([statefulElement_wp|]))",
         | 
| 228 | 
            +
                // "x statefulElement_wp y means y changeState_wp x",
         | 
| 229 | 
            +
              ]
         | 
| 230 | 
            +
            }
         | 
| 231 | 
            +
             | 
| 232 | 
            +
            knowledgeModule({ 
         | 
| 233 | 
            +
              config,
         | 
| 234 | 
            +
              includes: [ui, countable, colors, errors],
         | 
| 235 | 
            +
              api: () => new API(),
         | 
| 236 | 
            +
             | 
| 237 | 
            +
              module,
         | 
| 238 | 
            +
              description: 'Word processor',
         | 
| 239 | 
            +
              test: {
         | 
| 240 | 
            +
                name: './wp.test.json',
         | 
| 241 | 
            +
                contents: wp_tests,
         | 
| 242 | 
            +
                checks: {
         | 
| 243 | 
            +
                  context: [
         | 
| 244 | 
            +
                    ...defaultContextCheck(), 
         | 
| 245 | 
            +
                  ],
         | 
| 246 | 
            +
                  objects: [
         | 
| 247 | 
            +
                    'changeState', 
         | 
| 248 | 
            +
                    { km: 'ui' },
         | 
| 249 | 
            +
                  ],
         | 
| 250 | 
            +
                },
         | 
| 251 | 
            +
              },
         | 
| 252 | 
            +
              template: {
         | 
| 253 | 
            +
                template,
         | 
| 254 | 
            +
                instance,
         | 
| 255 | 
            +
              }
         | 
| 256 | 
            +
            })
         |