tpmkms_4wp 8.0.0-beta.77 → 8.0.0-beta.78

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ {
2
+ }
@@ -0,0 +1,104 @@
1
+ const { knowledgeModule, where } = require('./runtime').theprogrammablemind
2
+ const gdefaults = require('./gdefaults.js')
3
+ const conjunction_tests = require('./conjunction.test.json')
4
+ const { defaultContextCheck } = require('./helpers')
5
+
6
+ let config = {
7
+ name: 'conjunction',
8
+ operators: [
9
+ "(x [list|and] y)",
10
+ ],
11
+ bridges: [
12
+ // context.instance == variables.instance (unification)
13
+ {
14
+ id: "list",
15
+ level: 0,
16
+ selector: {
17
+ match: "same",
18
+ left: [ { pattern: '($type && context.instance == variables.instance)' } ],
19
+ right: [ { pattern: '($type && context.instance == variables.instance)' } ],
20
+ // left: [ { pattern: '($type)' } ],
21
+ // right: [ { pattern: '($type)' } ],
22
+ passthrough: true
23
+ },
24
+ bridge: "{ ...next(operator), listable: true, isList: true, value: append(before, after) }"
25
+ },
26
+ {
27
+ id: "list",
28
+ level: 1,
29
+ selector: {
30
+ match: "same",
31
+ left: [ { pattern: '($type && context.instance == variables.instance)' } ],
32
+ passthrough: true
33
+ },
34
+ bridge: "{ ...operator, value: append(before, operator.value) }"
35
+ },
36
+ ],
37
+ generators: [
38
+ {
39
+ where: where(),
40
+ notes: 'handle lists with yes no',
41
+ // ({context, hierarchy}) => context.marker == 'list' && context.paraphrase && context.value,
42
+ // ({context, hierarchy}) => context.marker == 'list' && context.value,
43
+ match: ({context, hierarchy}) => context.marker == 'list' && context.paraphrase && context.value && context.value.length > 0 && context.value[0].marker == 'yesno',
44
+ apply: async ({context, g, gs}) => {
45
+ return `${await g(context.value[0])} ${await gs(context.value.slice(1), ', ', ' and ')}`
46
+ }
47
+ },
48
+
49
+ {
50
+ where: where(),
51
+ notes: 'handle lists',
52
+ // ({context, hierarchy}) => context.marker == 'list' && context.paraphrase && context.value,
53
+ // ({context, hierarchy}) => context.marker == 'list' && context.value,
54
+ match: ({context, hierarchy}) => context.marker == 'list' && context.value,
55
+ apply: async ({context, gs}) => {
56
+ if (context.newLinesOnly) {
57
+ return await gs(context.value, '\n')
58
+ } else {
59
+ return await gs(context.value, ', ', ' and ')
60
+ }
61
+ }
62
+ },
63
+ ],
64
+ };
65
+
66
+ const initializer = ({objects, config, isModule}) => {
67
+ config.addArgs(({config, api, isA}) => ({
68
+ isAListable: (context, type) => {
69
+ if (context.marker == 'list' || context.listable) {
70
+ return context.value.every( (element) => isA(element.marker, type) )
71
+ } else {
72
+ return isA(context.marker, type)
73
+ }
74
+ },
75
+ toContext: (v) => {
76
+ if (Array.isArray(v)) {
77
+ return { marker: 'list', level: 1, value: v }
78
+ }
79
+ if (v.marker == 'list') {
80
+ return v
81
+ }
82
+ return v
83
+ },
84
+ }))
85
+ }
86
+
87
+ knowledgeModule( {
88
+ config,
89
+ includes: [gdefaults],
90
+ initializer,
91
+
92
+ module,
93
+ description: 'framework for conjunction',
94
+ newWay: true,
95
+ test: {
96
+ name: './conjunction.test.json',
97
+ contents: conjunction_tests,
98
+ checks: {
99
+ objects: ['idSuffix'],
100
+ context: defaultContextCheck,
101
+ },
102
+
103
+ },
104
+ })
@@ -0,0 +1,322 @@
1
+ [
2
+ {
3
+ "associations": [
4
+ [
5
+ [
6
+ "list",
7
+ 0
8
+ ],
9
+ [
10
+ "unknown",
11
+ 0
12
+ ]
13
+ ],
14
+ [
15
+ [
16
+ "list",
17
+ 0
18
+ ],
19
+ [
20
+ "unknown",
21
+ 0
22
+ ],
23
+ [
24
+ "unknown",
25
+ 1
26
+ ]
27
+ ],
28
+ [
29
+ [
30
+ "list",
31
+ 0
32
+ ],
33
+ [
34
+ "unknown",
35
+ 1
36
+ ]
37
+ ],
38
+ [
39
+ [
40
+ "list",
41
+ 1
42
+ ],
43
+ [
44
+ "unknown",
45
+ 1
46
+ ]
47
+ ]
48
+ ],
49
+ "config": {
50
+ },
51
+ "contexts": [
52
+ {
53
+ "default": true,
54
+ "isList": true,
55
+ "level": 1,
56
+ "listable": true,
57
+ "marker": "list",
58
+ "range": {
59
+ "end": 8,
60
+ "start": 0
61
+ },
62
+ "text": "1 2 and 3",
63
+ "topLevel": true,
64
+ "types": [
65
+ "list",
66
+ "unknown"
67
+ ],
68
+ "value": [
69
+ {
70
+ "dead": true,
71
+ "level": 1,
72
+ "marker": "unknown",
73
+ "range": {
74
+ "end": 0,
75
+ "start": 0
76
+ },
77
+ "text": "1",
78
+ "types": [
79
+ "unknown"
80
+ ],
81
+ "unknown": true,
82
+ "value": "1",
83
+ "word": "1"
84
+ },
85
+ {
86
+ "dead": true,
87
+ "level": 1,
88
+ "marker": "unknown",
89
+ "range": {
90
+ "end": 2,
91
+ "start": 2
92
+ },
93
+ "text": "2",
94
+ "types": [
95
+ "unknown"
96
+ ],
97
+ "unknown": true,
98
+ "value": "2",
99
+ "word": "2"
100
+ },
101
+ {
102
+ "dead": true,
103
+ "level": 1,
104
+ "marker": "unknown",
105
+ "range": {
106
+ "end": 8,
107
+ "start": 8
108
+ },
109
+ "text": "3",
110
+ "types": [
111
+ "unknown"
112
+ ],
113
+ "unknown": true,
114
+ "value": "3",
115
+ "word": "3"
116
+ }
117
+ ],
118
+ "word": "and"
119
+ }
120
+ ],
121
+ "developerTest": false,
122
+ "generatedParenthesized": [
123
+ ""
124
+ ],
125
+ "metadata": {
126
+ "opChoices": [
127
+ {
128
+ "counter": 1,
129
+ "op": [
130
+ "unknown",
131
+ 0
132
+ ],
133
+ "ops": [
134
+ [
135
+ "list",
136
+ 0
137
+ ],
138
+ [
139
+ "unknown",
140
+ 0
141
+ ],
142
+ [
143
+ "unknown",
144
+ 0
145
+ ],
146
+ [
147
+ "unknown",
148
+ 0
149
+ ]
150
+ ]
151
+ },
152
+ {
153
+ "counter": 2,
154
+ "op": [
155
+ "unknown",
156
+ 0
157
+ ],
158
+ "ops": [
159
+ [
160
+ "list",
161
+ 0
162
+ ],
163
+ [
164
+ "unknown",
165
+ 0
166
+ ],
167
+ [
168
+ "unknown",
169
+ 0
170
+ ]
171
+ ]
172
+ },
173
+ {
174
+ "counter": 3,
175
+ "op": [
176
+ "unknown",
177
+ 0
178
+ ],
179
+ "ops": [
180
+ [
181
+ "list",
182
+ 0
183
+ ],
184
+ [
185
+ "unknown",
186
+ 0
187
+ ]
188
+ ]
189
+ },
190
+ {
191
+ "counter": 4,
192
+ "op": [
193
+ "list",
194
+ 0
195
+ ],
196
+ "ops": [
197
+ [
198
+ "list",
199
+ 0
200
+ ]
201
+ ]
202
+ },
203
+ {
204
+ "counter": 5,
205
+ "op": [
206
+ "list",
207
+ 1
208
+ ],
209
+ "ops": [
210
+ [
211
+ "list",
212
+ 1
213
+ ]
214
+ ]
215
+ }
216
+ ]
217
+ },
218
+ "objects": {
219
+ "nameToUUID": {
220
+ "conjunction": "conjunction1",
221
+ "gdefaults": "gdefaults2",
222
+ "tokenize": "tokenize2"
223
+ },
224
+ "namespaced": {
225
+ "conjunction1": {
226
+ },
227
+ "gdefaults2": {
228
+ },
229
+ "tokenize2": {
230
+ }
231
+ },
232
+ "processed": [
233
+ {
234
+ "context": {
235
+ "default": true,
236
+ "isList": true,
237
+ "level": 1,
238
+ "listable": true,
239
+ "marker": "list",
240
+ "range": {
241
+ "end": 8,
242
+ "start": 0
243
+ },
244
+ "text": "1 2 and 3",
245
+ "topLevel": true,
246
+ "types": [
247
+ "list",
248
+ "unknown"
249
+ ],
250
+ "value": [
251
+ {
252
+ "dead": true,
253
+ "level": 1,
254
+ "marker": "unknown",
255
+ "range": {
256
+ "end": 0,
257
+ "start": 0
258
+ },
259
+ "text": "1",
260
+ "types": [
261
+ "unknown"
262
+ ],
263
+ "unknown": true,
264
+ "value": "1",
265
+ "word": "1"
266
+ },
267
+ {
268
+ "dead": true,
269
+ "level": 1,
270
+ "marker": "unknown",
271
+ "range": {
272
+ "end": 2,
273
+ "start": 2
274
+ },
275
+ "text": "2",
276
+ "types": [
277
+ "unknown"
278
+ ],
279
+ "unknown": true,
280
+ "value": "2",
281
+ "word": "2"
282
+ },
283
+ {
284
+ "dead": true,
285
+ "level": 1,
286
+ "marker": "unknown",
287
+ "range": {
288
+ "end": 8,
289
+ "start": 8
290
+ },
291
+ "text": "3",
292
+ "types": [
293
+ "unknown"
294
+ ],
295
+ "unknown": true,
296
+ "value": "3",
297
+ "word": "3"
298
+ }
299
+ ],
300
+ "word": "and"
301
+ },
302
+ "generatedParenthesized": "",
303
+ "paraphrases": "1, 2 and 3",
304
+ "paraphrasesParenthesized": "((1), (2) and (3))",
305
+ "responses": [
306
+ ""
307
+ ]
308
+ }
309
+ ]
310
+ },
311
+ "paraphrases": [
312
+ "1, 2 and 3"
313
+ ],
314
+ "paraphrasesParenthesized": [
315
+ "((1), (2) and (3))"
316
+ ],
317
+ "query": "1 2 and 3",
318
+ "responses": [
319
+ ""
320
+ ]
321
+ }
322
+ ]
@@ -2,6 +2,8 @@ const { knowledgeModule, where, stableId } = require('./runtime').theprogrammabl
2
2
  const meta = require('./meta.js')
3
3
  const gdefaults = require('./gdefaults.js')
4
4
  const sdefaults = require('./sdefaults.js')
5
+ const asking = require('./asking.js')
6
+ const conjunction = require('./conjunction.js')
5
7
  const articles = require('./articles.js')
6
8
  const pos = require('./pos.js')
7
9
  const negation = require('./negation.js')
@@ -47,8 +49,8 @@ let config = {
47
49
  // "(([queryable]) [is:isEdBridge|is,are] ([isEdAble|]))",
48
50
  "(([queryable]) [(<isEd|> ([isEdAble|]))])",
49
51
 
50
- "([nevermind])",
51
- { pattern: "([nevermindTestSetup] (allowed))", development: true },
52
+ // "([nevermind])",
53
+ // { pattern: "([nevermindTestSetup] (allowed))", development: true },
52
54
  "([why])",
53
55
  "([reason])",
54
56
  // "([thisitthat|])",
@@ -75,7 +77,6 @@ let config = {
75
77
  // joe is a person the age of joe ...
76
78
  //"arm them, what, the phasers"
77
79
  //greg is a first name
78
- "(x [list|and] y)",
79
80
  "([yesno|])",
80
81
  "(([isEdee])^ <isEdAble|> ([by] ([isEder])?))",
81
82
  "([isEdee|])",
@@ -135,29 +136,6 @@ let config = {
135
136
  { id: "whatAble", level: 0, bridge: "{ ...next(operator) }" },
136
137
 
137
138
  // context.instance == variables.instance (unification)
138
- {
139
- id: "list",
140
- level: 0,
141
- selector: {
142
- match: "same",
143
- left: [ { pattern: '($type && context.instance == variables.instance)' } ],
144
- right: [ { pattern: '($type && context.instance == variables.instance)' } ],
145
- // left: [ { pattern: '($type)' } ],
146
- // right: [ { pattern: '($type)' } ],
147
- passthrough: true
148
- },
149
- bridge: "{ ...next(operator), listable: true, isList: true, value: append(before, after) }"
150
- },
151
- {
152
- id: "list",
153
- level: 1,
154
- selector: {
155
- match: "same",
156
- left: [ { pattern: '($type && context.instance == variables.instance)' } ],
157
- passthrough: true
158
- },
159
- bridge: "{ ...operator, value: append(before, operator.value) }"
160
- },
161
139
  {
162
140
  where: where(),
163
141
  id: "to",
@@ -238,6 +216,7 @@ let config = {
238
216
  bridge: "{ ...next(operator) }"
239
217
  },
240
218
  */
219
+ /*
241
220
  {
242
221
  id: "nevermind",
243
222
  bridge: "{ ...next(operator) }",
@@ -257,6 +236,8 @@ let config = {
257
236
  }
258
237
  }
259
238
  },
239
+ */
240
+ /*
260
241
  {
261
242
  id: "nevermindTestSetup",
262
243
  development: true,
@@ -275,6 +256,7 @@ let config = {
275
256
  })
276
257
  }
277
258
  },
259
+ */
278
260
  {
279
261
  id: "why",
280
262
  level: 0,
@@ -417,32 +399,6 @@ let config = {
417
399
  priority: -1,
418
400
  },
419
401
 
420
- {
421
- where: where(),
422
- notes: 'handle lists with yes no',
423
- // ({context, hierarchy}) => context.marker == 'list' && context.paraphrase && context.value,
424
- // ({context, hierarchy}) => context.marker == 'list' && context.value,
425
- match: ({context, hierarchy}) => context.marker == 'list' && context.paraphrase && context.value && context.value.length > 0 && context.value[0].marker == 'yesno',
426
- apply: async ({context, g, gs}) => {
427
- return `${await g(context.value[0])} ${await gs(context.value.slice(1), ', ', ' and ')}`
428
- }
429
- },
430
-
431
- {
432
- where: where(),
433
- notes: 'handle lists',
434
- // ({context, hierarchy}) => context.marker == 'list' && context.paraphrase && context.value,
435
- // ({context, hierarchy}) => context.marker == 'list' && context.value,
436
- match: ({context, hierarchy}) => context.marker == 'list' && context.value,
437
- apply: async ({context, gs}) => {
438
- if (context.newLinesOnly) {
439
- return await gs(context.value, '\n')
440
- } else {
441
- return await gs(context.value, ', ', ' and ')
442
- }
443
- }
444
- },
445
-
446
402
  {
447
403
  where: where(),
448
404
  notes: 'paraphrase a queryable response',
@@ -803,102 +759,6 @@ let config = {
803
759
  ],
804
760
  };
805
761
 
806
- // move ask to the KM's since verbatim is called probably in dialogues?
807
- const getAsk = (config) => (uuid) => {
808
- return (asks) => {
809
- const ask = (ask) => {
810
- let oneShot = true // default
811
- if (ask.oneShot === false) {
812
- oneShot = false
813
- }
814
-
815
- const id_q = stableId('semantic')
816
- const id_rs = []
817
- let wasAsked = false
818
- let wasApplied = false
819
- const getWasAsked = () => {
820
- return wasAsked
821
- }
822
- const setWasAsked = (value) => {
823
- wasAsked = value
824
- }
825
- const getWasApplied = () => {
826
- return wasApplied
827
- }
828
- const setWasApplied = (value) => {
829
- wasApplied = value
830
- }
831
-
832
- const semanticsr = ask.semanticsr || []
833
- if (semanticsr.length == 0) {
834
- semanticsr.push({ match: ask.matchr, apply: ask.applyr })
835
- }
836
- for (const semantic of semanticsr) {
837
- const id_r = stableId('semantic')
838
- id_rs.push(id_r)
839
- config.addSemantic({
840
- uuid,
841
- id: id_r,
842
- tied_ids: [id_q],
843
- oneShot,
844
- where: semantic.where || ask.where || where(2),
845
- source: 'response',
846
- match: (args) => semantic.match(args),
847
- apply: async (args) => {
848
- setWasApplied(true)
849
- await semantic.apply(args)
850
- },
851
- })
852
- }
853
-
854
- config.addSemantic({
855
- uuid,
856
- oneShot,
857
- id: id_q,
858
- tied_ids: id_rs,
859
- where: ask.where,
860
- isQuestion: true, // do one question at a time
861
- getWasAsked,
862
- getWasApplied,
863
- onNevermind: ask.onNevermind,
864
- source: 'question',
865
- match: ({ context }) => context.marker == 'controlEnd' || context.marker == 'controlBetween',
866
- apply: async (args) => {
867
- let matchq = ask.matchq
868
- let applyq = ask.applyq
869
- if (!matchq) {
870
- let wasAsked = false
871
- matchq = () => !wasAsked,
872
- applyq = (args) => {
873
- wasAsked = true
874
- return ask.applyq(args)
875
- }
876
- }
877
- if (await matchq(args)) {
878
- setWasAsked(true)
879
- setWasApplied(false)
880
- // args.context.motivationKeep = true
881
- args.verbatim(await applyq(args))
882
- /*
883
- args.context.verbatim = applyq(args)
884
- args.context.isResponse = true;
885
- delete args.context.controlRemove;
886
- */
887
- args.context.controlKeepMotivation = true
888
- }
889
- args.context.cascade = true
890
- }
891
- })
892
- }
893
- if (!Array.isArray(asks)) {
894
- asks = [asks]
895
- }
896
-
897
- [...asks].reverse().forEach( (a) => ask(a) )
898
- }
899
- }
900
-
901
-
902
762
  const initializer = ({objects, config, isModule}) => {
903
763
  /* TODO add this beck in. some stuff from config needs to be here
904
764
  config.addArgs((args) => ({
@@ -906,34 +766,15 @@ const initializer = ({objects, config, isModule}) => {
906
766
  }))
907
767
  */
908
768
  config.addArgs(({config, api, isA}) => ({
909
- isAListable: (context, type) => {
910
- if (context.marker == 'list' || context.listable) {
911
- return context.value.every( (element) => isA(element.marker, type) )
912
- } else {
913
- return isA(context.marker, type)
914
- }
915
- },
916
- toContext: (v) => {
917
- if (Array.isArray(v)) {
918
- return { marker: 'list', level: 1, value: v }
919
- }
920
- if (v.marker == 'list') {
921
- return v
922
- }
923
- return v
924
- },
925
- getUUIDScoped: (uuid) => { return {
926
- ask: getAsk(config)(uuid),
927
- }
928
- },
929
769
  toScopedId: (context) => {
930
770
  return api('dialogues').toScopedId(context)
931
771
  },
932
772
  addWords: (id, word, additional) => {
933
- for (let props of words(word, additional)) {
934
- config.addWord(id, props)
773
+ for (let props of words(word, { ...additional })) {
774
+ config.addWord(props.word, { id, initial: JSON.stringify(props) })
935
775
  }
936
- }
776
+ },
777
+ values: propertyToArray,
937
778
  }))
938
779
  objects.mentioned = []
939
780
  objects.variables = {
@@ -947,7 +788,7 @@ const initializer = ({objects, config, isModule}) => {
947
788
 
948
789
  knowledgeModule( {
949
790
  config,
950
- includes: [articles, gdefaults, sdefaults, pos, negation, stm, meta, punctuation],
791
+ includes: [articles, gdefaults, sdefaults, conjunction, asking, pos, negation, stm, meta, punctuation],
951
792
  initializer,
952
793
  api: () => new API(),
953
794
 
@@ -958,7 +799,7 @@ knowledgeModule( {
958
799
  name: './dialogues.test.json',
959
800
  contents: dialogues_tests,
960
801
  checks: {
961
- objects: ['onNevermindWasCalled', 'nevermindType', 'idSuffix'],
802
+ objects: ['idSuffix'],
962
803
  context: defaultContextCheck,
963
804
  },
964
805