ekms 8.0.0 → 8.1.0-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 +3055 -1651
- package/common/animals.js +17 -20
- package/common/articles.js +103 -0
- package/common/articles.test.json +310 -0
- package/common/asking.instance.json +2 -0
- package/common/asking.js +253 -0
- package/common/asking.test.json +2290 -0
- package/common/avatar.js +6 -10
- package/common/characters.js +23 -30
- package/common/colors.instance.json +25666 -0
- package/common/colors.js +67 -0
- package/common/colors.test.json +4425 -0
- package/common/comparable.instance.json +1750 -0
- package/common/comparable.js +36 -28
- package/common/comparable.test.json +1196 -2
- package/common/concept.js +121 -119
- package/common/concept.test.json +688 -0
- package/common/conjunction.instance.json +2 -0
- package/common/conjunction.js +104 -0
- package/common/conjunction.test.json +322 -0
- package/common/countable.js +20 -14
- package/common/countable.test.json +1050 -0
- package/common/crew.instance.json +16432 -9850
- package/common/crew.js +39 -42
- package/common/crew.test.json +714 -452
- package/common/currency.js +28 -46
- package/common/dialogues.js +187 -429
- package/common/dialogues.test.json +684 -450
- package/common/dimension.instance.json +517 -289
- package/common/dimension.js +22 -24
- package/common/dimension.test.json +727 -1944
- package/common/edible.instance.json +20506 -10664
- package/common/edible.js +4 -9
- package/common/emotions.instance.json +195 -123
- package/common/emotions.js +36 -39
- package/common/evaluate.instance.json +2 -0
- package/common/evaluate.js +53 -0
- package/common/evaluate.test.json +574 -0
- package/common/events.js +11 -15
- package/common/fastfood.instance.json +223185 -113172
- package/common/fastfood.js +77 -87
- package/common/fastfood.test.json +8205 -3733
- package/common/formulas.instance.json +444 -244
- package/common/formulas.js +20 -27
- package/common/formulas.test.json +1027 -955
- package/common/gdefaults.js +45 -32
- package/common/help.js +9 -14
- package/common/help.test.json +71 -18
- package/common/helpers/concept.js +37 -10
- package/common/helpers/dialogues.js +22 -4
- package/common/helpers/formulas.js +0 -14
- package/common/helpers/meta.js +0 -1
- package/common/helpers/properties.js +92 -84
- package/common/helpers.js +35 -24
- package/common/hierarchy.js +18 -25
- package/common/javascript.js +12 -19
- package/common/kirk.instance.json +583 -300
- package/common/kirk.js +6 -9
- package/common/length.instance.json +8995 -4964
- package/common/length.js +5 -9
- package/common/listener.js +48 -0
- package/common/listener.test.json +104 -0
- package/common/math.instance.json +409 -1202
- package/common/math.js +17 -21
- package/common/meta.js +24 -50
- package/common/nameable.instance.json +2 -0
- package/common/nameable.js +144 -0
- package/common/nameable.test.json +3191 -0
- package/common/negation.instance.json +2 -0
- package/common/negation.js +38 -0
- package/common/negation.test.json +308 -0
- package/common/numbers.js +28 -32
- package/common/ordering.instance.json +459 -274
- package/common/ordering.js +81 -87
- package/common/ordinals.instance.json +2 -0
- package/common/ordinals.js +61 -0
- package/common/ordinals.test.json +412 -0
- package/common/people.instance.json +2138 -1321
- package/common/people.js +9 -14
- package/common/people.test.json +1815 -1073
- package/common/percentages.instance.json +2 -0
- package/common/percentages.js +53 -0
- package/common/percentages.test.json +751 -0
- package/common/pipboy.instance.json +12261 -6898
- package/common/pipboy.js +53 -62
- package/common/pipboy.test.json +2835 -0
- package/common/pokemon.instance.json +4432 -2351
- package/common/pokemon.js +8 -21
- package/common/pos.js +16 -14
- package/common/pressure.instance.json +2311 -1303
- package/common/pressure.js +5 -9
- package/common/properties.instance.json +151 -87
- package/common/properties.js +164 -167
- package/common/properties.test.json +17605 -4030
- package/common/punctuation.js +24 -8
- package/common/punctuation.test.json +233 -5
- package/common/reports.instance.json +1037 -551
- package/common/reports.js +77 -103
- package/common/reports.test.json +15623 -10458
- package/common/scorekeeper.js +19 -31
- package/common/sdefaults.js +17 -8
- package/common/sizeable.js +13 -12
- package/common/spock.instance.json +582 -299
- package/common/spock.js +6 -9
- package/common/stgame.js +20 -20
- package/common/stm.js +182 -29
- package/common/stm.test.json +1734 -1
- package/common/tell.js +15 -19
- package/common/temperature.instance.json +2379 -1355
- package/common/temperature.js +5 -9
- package/common/tester.js +15 -4
- package/common/testing.js +8 -13
- package/common/time.js +21 -26
- package/common/tokenize.js +8 -8
- package/common/tokenize.test.json +86 -1
- package/common/ui.instance.json +151 -460
- package/common/ui.js +22 -34
- package/common/ui.test.json +641 -5357
- package/common/weight.instance.json +7957 -4350
- package/common/weight.js +5 -9
- package/common/weight.test.json +242 -238
- package/common/yesno.js +6 -6
- package/main.js +68 -45
- package/package.json +44 -6
@@ -45,6 +45,10 @@ class API {
|
|
45
45
|
}
|
46
46
|
|
47
47
|
if (km('concept')) {
|
48
|
+
if (!km('concept').api) {
|
49
|
+
debugger
|
50
|
+
debugger
|
51
|
+
}
|
48
52
|
km('concept').api.addDefaultTypesForObjectHierarchy([
|
49
53
|
'theAble',
|
50
54
|
'queryable',
|
@@ -81,7 +85,6 @@ class API {
|
|
81
85
|
match: ({context}) => context[tm.to],
|
82
86
|
apply: ({context}) => {
|
83
87
|
// Object.assign(context[tm.to], from[tm.from])
|
84
|
-
// debugger;
|
85
88
|
context[tm.to] = from[tm.from]
|
86
89
|
if (context[tm.to]) {
|
87
90
|
context[tm.to].instantiated = true
|
@@ -101,6 +104,7 @@ class API {
|
|
101
104
|
localHierarchy,
|
102
105
|
bridge: `{
|
103
106
|
...before,
|
107
|
+
marker: '${after[0].tag}',
|
104
108
|
constraints: [
|
105
109
|
{
|
106
110
|
property: '${after[0].tag}',
|
@@ -137,7 +141,7 @@ class API {
|
|
137
141
|
notes: 'semantic for setting value with constraint',
|
138
142
|
match: ({context, isA}) => isA(context.marker, after[0].tag) && context.evaluate && context.constraints,
|
139
143
|
// match: ({context, isA}) => context.marker == after[0].tag && context.evaluate,
|
140
|
-
apply: ({km, context, e, log, isA
|
144
|
+
apply: async ({km, context, e, log, isA}) => {
|
141
145
|
const constraint = context.constraints[0];
|
142
146
|
const value = constraint.constraint;
|
143
147
|
let property = constraint.property;
|
@@ -152,7 +156,7 @@ class API {
|
|
152
156
|
// value.greg = true
|
153
157
|
// value.ownee.query = true
|
154
158
|
value.query = true
|
155
|
-
let instance = e(value)
|
159
|
+
let instance = await e(value)
|
156
160
|
if (instance.verbatim) {
|
157
161
|
context.evalue = { verbatim: instance.verbatim }
|
158
162
|
return
|
@@ -169,13 +173,13 @@ class API {
|
|
169
173
|
config.addGenerator({
|
170
174
|
notes: 'generator for constraint',
|
171
175
|
match: ({context}) => context.marker == edAble.operator && context.paraphrase && context.constrained,
|
172
|
-
apply: ({context, g}) => {
|
176
|
+
apply: async ({context, g}) => {
|
173
177
|
if (context[before[0].tag].marker == 'by') {
|
174
178
|
// the cat wendy owned
|
175
|
-
return `${g({...context[after[0].tag], paraphrase: true})} ${edAble.word} ${g({...context[before[0].tag], paraphrase: true})}`
|
179
|
+
return `${await g({...context[after[0].tag], paraphrase: true})} ${edAble.word} ${await g({...context[before[0].tag], paraphrase: true})}`
|
176
180
|
} else {
|
177
181
|
// the cat owned by wendy
|
178
|
-
return `${g({...context[after[0].tag], paraphrase: true})} ${edAble.word} ${['by', g({...context[before[0].tag], paraphrase: true})].filter((t) => t).join(' ')}`
|
182
|
+
return `${await g({...context[after[0].tag], paraphrase: true})} ${edAble.word} ${['by', await g({...context[before[0].tag], paraphrase: true})].filter((t) => t).join(' ')}`
|
179
183
|
}
|
180
184
|
},
|
181
185
|
})
|
@@ -195,19 +199,19 @@ class API {
|
|
195
199
|
|
196
200
|
return false;
|
197
201
|
},
|
198
|
-
apply: ({context, g}) => {
|
202
|
+
apply: async ({context, g}) => {
|
199
203
|
const chosen = chooseNumber(context, word.singular, word.plural)
|
200
|
-
return `${g(context[before[0].tag])} ${chosen} ${g(context[after[0].tag])}`
|
204
|
+
return `${await g(context[before[0].tag])} ${chosen} ${await g(context[after[0].tag])}`
|
201
205
|
}
|
202
206
|
})
|
203
207
|
config.addGenerator({
|
204
208
|
match: ({context}) => context.marker == edAble.operator && context.isEd,
|
205
|
-
apply: ({context, g}) => {
|
209
|
+
apply: async ({context, g}) => {
|
206
210
|
const chosen = chooseNumber(context[after[0].tag], 'is', 'are')
|
207
211
|
if (context[before[0].tag].evalue && context[before[0].tag].evalue.marker == 'answerNotKnown') {
|
208
|
-
return g(context[before[0].tag])
|
212
|
+
return await g(context[before[0].tag])
|
209
213
|
}
|
210
|
-
return `${g(context[after[0].tag])} ${chosen} ${edAble.word} by ${g(context[before[0].tag])}`
|
214
|
+
return `${await g(context[after[0].tag])} ${chosen} ${edAble.word} by ${await g(context[before[0].tag])}`
|
211
215
|
}
|
212
216
|
})
|
213
217
|
/*
|
@@ -251,12 +255,10 @@ class API {
|
|
251
255
|
notes: `generator for who/what is X owned by`,
|
252
256
|
// match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'is') && context.one && context.one.marker == 'ownee' && context.one.constraints && context.one.constraints[0] && context.one.constraints[0].constraint.marker == 'owned' && context.one.constraints[0].constraint.owner.implicit,
|
253
257
|
match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'is') && context.one && context.one.marker == after[0].tag && context.one.constraints && context.one.constraints[0] && context.one.constraints[0].constraint.marker == edAble.operator && context.one.constraints[0].constraint[before[0].tag].implicit,
|
254
|
-
apply: ({context, g, gs, callId}) => {
|
258
|
+
apply: async ({context, fragments, g, gs, callId}) => {
|
255
259
|
const isToFromM = [{"from":["one"],"to":["two"]},{"from":["two"],"to":["one"]}]
|
256
|
-
const fromF =
|
257
|
-
|
258
|
-
// const toF = config.fragment("owneeVar is owned by ownerVar")
|
259
|
-
const toF = config.fragment(thisIsVerbedByThat)
|
260
|
+
const fromF = fragments(whoIsWhatVerbedBy).contexts()[0]
|
261
|
+
const toF = fragments(thisIsVerbedByThat)
|
260
262
|
const to = toF.contexts()[0]
|
261
263
|
const tm = translationMapping(fromF, to)
|
262
264
|
/*
|
@@ -270,11 +272,11 @@ class API {
|
|
270
272
|
// const from = context.one.constraints[0].constraint
|
271
273
|
const from = context
|
272
274
|
const im = translationMappingToInstantiatorMappings(tmPrime, from, to)
|
273
|
-
const translation = toF.instantiate(im)
|
275
|
+
const translation = await toF.instantiate(im)
|
274
276
|
if (Array.isArray(translation)) {
|
275
|
-
return gs(translation)
|
277
|
+
return await gs(translation)
|
276
278
|
} else {
|
277
|
-
return g(translation)
|
279
|
+
return await g(translation)
|
278
280
|
}
|
279
281
|
}
|
280
282
|
}
|
@@ -315,7 +317,12 @@ class API {
|
|
315
317
|
allowDups: true,
|
316
318
|
})
|
317
319
|
// config.addOperator({ id: operator, level: 1, words: [operator] })
|
318
|
-
config.addBridge({
|
320
|
+
config.addBridge({
|
321
|
+
id: operator,
|
322
|
+
level: 1,
|
323
|
+
bridge: '{ ...next(operator) }',
|
324
|
+
allowDups: true,
|
325
|
+
})
|
319
326
|
config.addPriority({ "context": [['does', 0], [operator, 1], ], "choose": [0] })
|
320
327
|
config.addPriority({ "context": [['doesnt', 0], [operator, 1], ], "choose": [0] })
|
321
328
|
config.addPriority({ "context": [[operator, 0], ['does', 0], ], "choose": [0] })
|
@@ -323,14 +330,25 @@ class API {
|
|
323
330
|
} else {
|
324
331
|
config.addOperator({ pattern: `(${beforeOperators} [${operator}|] ${afterOperators})`, allowDups: true })
|
325
332
|
}
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
333
|
+
|
334
|
+
if (false) {
|
335
|
+
for (let argument of before.concat(after)) {
|
336
|
+
if (create.includes(argument.id)) {
|
337
|
+
// config.addHierarchy('unknown', argument.id)
|
338
|
+
// config.addHierarchy('what', argument.id)
|
339
|
+
// greg23 <<<<<<<<<<<< doing this
|
340
|
+
config.addHierarchy(argument.id, 'unknown')
|
341
|
+
config.addHierarchy(argument.id, 'what')
|
342
|
+
}
|
343
|
+
}
|
344
|
+
} else {
|
345
|
+
for (let argument of before.concat(after)) {
|
346
|
+
if (create.includes(argument.id)) {
|
347
|
+
// config.addHierarchy(argument.id, 'unknown')
|
348
|
+
// config.addHierarchy(argument.id, 'what')
|
349
|
+
localHierarchy.push([argument.id, 'unknown'])
|
350
|
+
localHierarchy.push([argument.id, 'what'])
|
351
|
+
}
|
334
352
|
}
|
335
353
|
}
|
336
354
|
|
@@ -354,7 +372,13 @@ class API {
|
|
354
372
|
|
355
373
|
const unflattenArgs = [ ...before.map( (arg) => arg.tag ), ...after.map( (arg) => arg.tag ) ]
|
356
374
|
const focusable = [ ...before.map( (arg) => arg.tag ), ...after.map( (arg) => arg.tag ) ]
|
357
|
-
config.addBridge({
|
375
|
+
config.addBridge({
|
376
|
+
id: operator,
|
377
|
+
level: 0,
|
378
|
+
localHierarchy: [...localHierarchy, ['object', 'unknown']],
|
379
|
+
bridge: `{ ... next(operator) ${doParams} ${beforeArgs} ${afterArgs}, unflatten: ${JSON.stringify(unflattenArgs)}, focusable: ${JSON.stringify(focusable)} }`,
|
380
|
+
allowDups: true
|
381
|
+
})
|
358
382
|
if (words.length > 0) {
|
359
383
|
for (const word of words) {
|
360
384
|
config.addWord(word, { id: operator, initial: `{ value: "${operator}" }` })
|
@@ -384,11 +408,16 @@ class API {
|
|
384
408
|
config.addGenerator({
|
385
409
|
notes: 'ordering generator for paraphrase',
|
386
410
|
match: ({context}) => context.marker == operator && context.paraphrase && !context.query,
|
387
|
-
apply: ({context, gp, g}) => {
|
388
|
-
const beforeGenerator =
|
389
|
-
|
411
|
+
apply: async ({context, gp, g}) => {
|
412
|
+
const beforeGenerator = []
|
413
|
+
for (const arg of before) {
|
414
|
+
beforeGenerator.push(await g(context[arg.tag]))
|
415
|
+
}
|
416
|
+
const afterGenerator = []
|
417
|
+
for (const arg of after) {
|
418
|
+
afterGenerator.push(await gp(context[arg.tag]))
|
419
|
+
}
|
390
420
|
const word = context.word
|
391
|
-
// return beforeGenerator.concat([`${context.word}`]).concat(afterGenerator).join(' ')
|
392
421
|
const sub = []
|
393
422
|
if (context.subphrase) {
|
394
423
|
sub.push(['that'])
|
@@ -400,7 +429,7 @@ class API {
|
|
400
429
|
config.addGenerator({
|
401
430
|
notes: 'ordering generator for response',
|
402
431
|
match: ({context}) => context.marker == operator && context.evalue && context.isResponse,
|
403
|
-
apply: ({context, g, km}) => {
|
432
|
+
apply: async ({context, g, km}) => {
|
404
433
|
const brief = km("dialogues").api.getBrief()
|
405
434
|
|
406
435
|
const { evalue } = context
|
@@ -415,7 +444,7 @@ class API {
|
|
415
444
|
if (evalue.truthValueOnly || brief) {
|
416
445
|
return `${yesno}`
|
417
446
|
} else {
|
418
|
-
return `${yesno} ${g(Object.assign({}, evalue, { paraphrase: true }))}`
|
447
|
+
return `${yesno} ${await g(Object.assign({}, evalue, { paraphrase: true }))}`
|
419
448
|
}
|
420
449
|
}
|
421
450
|
})
|
@@ -501,12 +530,6 @@ class API {
|
|
501
530
|
for (let argument of context.focusable || []) {
|
502
531
|
const value = api.toValue(context[argument])
|
503
532
|
if (value) {
|
504
|
-
/*
|
505
|
-
if (value == 'cleo') {
|
506
|
-
debugger;
|
507
|
-
hierarchy.isA()
|
508
|
-
}
|
509
|
-
*/
|
510
533
|
const minimas = hierarchy.minima(context[argument].types)
|
511
534
|
for (let type of minimas) {
|
512
535
|
if (config.exists(value)) {
|
@@ -635,8 +658,8 @@ class API {
|
|
635
658
|
setValue: ([object, property], value, has) => {
|
636
659
|
return this.setProperty(object, property, value, has, true)
|
637
660
|
},
|
638
|
-
getValue: ([object, property]) => {
|
639
|
-
return this.getPropertyDirectly(object, property)
|
661
|
+
getValue: async ([object, property]) => {
|
662
|
+
return await this.getPropertyDirectly(object, property)
|
640
663
|
},
|
641
664
|
})
|
642
665
|
}
|
@@ -652,16 +675,18 @@ class API {
|
|
652
675
|
error.code = 'ReadOnly'
|
653
676
|
throw error
|
654
677
|
},
|
655
|
-
getValue: ([object, property]) => {
|
656
|
-
return this.getPropertyDirectly(object, property)
|
678
|
+
getValue: async ([object, property]) => {
|
679
|
+
return await this.getPropertyDirectly(object, property)
|
657
680
|
},
|
658
681
|
})
|
659
682
|
this.propertiesFH.setHandler(path, handler)
|
660
683
|
}
|
661
684
|
|
662
|
-
|
685
|
+
/*
|
686
|
+
async getObject(object) {
|
663
687
|
return this.propertiesFH.getValue([object])
|
664
688
|
}
|
689
|
+
*/
|
665
690
|
|
666
691
|
getHandler(object, property) {
|
667
692
|
return this.propertiesFH.getHandler([object, property])
|
@@ -678,34 +703,33 @@ class API {
|
|
678
703
|
// return context.value
|
679
704
|
}
|
680
705
|
|
681
|
-
getProperty(object, property, g) {
|
706
|
+
async getProperty(object, property, g) {
|
682
707
|
object = this.toValue(object)
|
683
708
|
property = this.toValue(property)
|
684
709
|
const handler = this.propertiesFH.getHandler([object, property])
|
685
710
|
if (handler) {
|
686
|
-
return handler.getValue([object, property])
|
711
|
+
return await handler.getValue([object, property])
|
687
712
|
}
|
688
|
-
return this.getPropertyDirectly(object, property, g)
|
713
|
+
return await this.getPropertyDirectly(object, property, g)
|
689
714
|
}
|
690
715
|
|
691
|
-
getPropertyDirectly(object, property, g) {
|
692
|
-
if (property == '
|
693
|
-
const objectProps = this.propertiesFH.getValue([object])
|
716
|
+
async getPropertyDirectly(object, property, g) {
|
717
|
+
if (property == 'property') {
|
718
|
+
const objectProps = await this.propertiesFH.getValue([object])
|
694
719
|
const values = []
|
695
720
|
for (let key of Object.keys(objectProps)) {
|
696
721
|
if (objectProps[key].has) {
|
697
|
-
|
698
|
-
values.push(`${g(key)}: ${g({ ...objectProps[key].value, paraphrase: true })}`)
|
722
|
+
values.push(`${await g(key)}: ${await g({ ...objectProps[key].value, paraphrase: true })}`)
|
699
723
|
}
|
700
724
|
}
|
701
725
|
return { marker: 'list', value: values }
|
702
726
|
} else {
|
703
|
-
return this.propertiesFH.getValue([object, property]).value
|
727
|
+
return (await this.propertiesFH.getValue([object, property])).value
|
704
728
|
}
|
705
729
|
}
|
706
730
|
|
707
|
-
hasProperty(object, property, has) {
|
708
|
-
return this.propertiesFH.getValue([object, property]).has
|
731
|
+
async hasProperty(object, property, has) {
|
732
|
+
return (await this.propertiesFH.getValue([object, property])).has
|
709
733
|
}
|
710
734
|
|
711
735
|
setProperty(object, property, value, has, skipHandler) {
|
@@ -733,8 +757,8 @@ class API {
|
|
733
757
|
}
|
734
758
|
}
|
735
759
|
|
736
|
-
knownObject(object) {
|
737
|
-
if (object == '
|
760
|
+
async knownObject(object) {
|
761
|
+
if (object == 'property') {
|
738
762
|
return object
|
739
763
|
}
|
740
764
|
if ((object || {}).value) {
|
@@ -742,11 +766,11 @@ class API {
|
|
742
766
|
}
|
743
767
|
const path = [object]
|
744
768
|
// return this.knownPropertyNew(path)
|
745
|
-
return this.propertiesFH.knownProperty(path)
|
769
|
+
return await this.propertiesFH.knownProperty(path)
|
746
770
|
}
|
747
771
|
|
748
|
-
hasProperty(object, property) {
|
749
|
-
if (property == '
|
772
|
+
async hasProperty(object, property) {
|
773
|
+
if (property == 'property') {
|
750
774
|
return true;
|
751
775
|
}
|
752
776
|
|
@@ -755,7 +779,7 @@ class API {
|
|
755
779
|
const seen = [object];
|
756
780
|
while (todo.length > 0) {
|
757
781
|
const next = todo.pop();
|
758
|
-
if ((this.propertiesFH.getValue([next, property], false) || {}).has) {
|
782
|
+
if ((await this.propertiesFH.getValue([next, property], false) || {}).has) {
|
759
783
|
return true
|
760
784
|
}
|
761
785
|
const parents = this._objects.parents[next] || [];
|
@@ -770,11 +794,12 @@ class API {
|
|
770
794
|
}
|
771
795
|
|
772
796
|
// NOT DONE
|
773
|
-
knownProperty(object, property) {
|
797
|
+
async knownProperty(object, property) {
|
774
798
|
object = this.toValue(object)
|
775
799
|
property = this.toValue(property)
|
776
|
-
if (property == '
|
777
|
-
|
800
|
+
if (property == 'property') {
|
801
|
+
const objectProps = await this.propertiesFH.getValue([object])
|
802
|
+
return !_.isEmpty(objectProps)
|
778
803
|
}
|
779
804
|
|
780
805
|
// go up the hierarchy
|
@@ -782,7 +807,7 @@ class API {
|
|
782
807
|
const seen = [object];
|
783
808
|
while (todo.length > 0) {
|
784
809
|
const next = todo.pop();
|
785
|
-
if ((this.propertiesFH.getValue([next, property], false) || {}).has) {
|
810
|
+
if ((await this.propertiesFH.getValue([next, property], false) || {}).has) {
|
786
811
|
return true
|
787
812
|
}
|
788
813
|
const parents = this._objects.parents[next] || [];
|
@@ -916,24 +941,7 @@ class API {
|
|
916
941
|
}
|
917
942
|
|
918
943
|
set config(config) {
|
919
|
-
debugger
|
920
944
|
this._config = config
|
921
|
-
/*
|
922
|
-
const toJSON = (h) => {
|
923
|
-
if (h.child && h.parent) {
|
924
|
-
return h
|
925
|
-
} else {
|
926
|
-
return { child: h[0], parent: h[1] }
|
927
|
-
}
|
928
|
-
}
|
929
|
-
for (const tuple of [...config().config.hierarchy]) {
|
930
|
-
const h = toJSON(tuple);
|
931
|
-
// TODO should this notice development flag?
|
932
|
-
if (this.isOperator(h.child) && this.isOperator(h.parent)) {
|
933
|
-
this.rememberIsA(h.child, h.parent)
|
934
|
-
}
|
935
|
-
}
|
936
|
-
*/
|
937
945
|
}
|
938
946
|
|
939
947
|
get config() {
|
package/common/helpers.js
CHANGED
@@ -33,8 +33,8 @@ const getCount = (context) => {
|
|
33
33
|
}
|
34
34
|
}
|
35
35
|
|
36
|
-
const words = (
|
37
|
-
return [{ word: pluralize.singular(
|
36
|
+
const words = (word, additional = {}) => {
|
37
|
+
return [{ word: pluralize.singular(word), number: 'one', ...additional }, { word: pluralize.plural(word), number: 'many', ...additional }]
|
38
38
|
}
|
39
39
|
|
40
40
|
const isMany = (context) => {
|
@@ -63,6 +63,12 @@ const isMany = (context) => {
|
|
63
63
|
return false
|
64
64
|
}
|
65
65
|
|
66
|
+
const requiredArgument = (value, name) => {
|
67
|
+
if (!value) {
|
68
|
+
throw new Error(`${name} is a required argument`)
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
66
72
|
const chooseNumber = (context, one, many) => {
|
67
73
|
if (isMany(context)) {
|
68
74
|
return many;
|
@@ -131,31 +137,35 @@ const toEValue = (context) => {
|
|
131
137
|
return context;
|
132
138
|
}
|
133
139
|
|
134
|
-
const
|
135
|
-
const defaultContextCheck = [
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
140
|
+
const defaultContextCheckProperties = ['marker', 'text', 'verbatim', 'isResponse', { property: 'response', filter: ['marker', 'text', 'verbatim'] }]
|
141
|
+
const defaultContextCheck = (properties = []) => {
|
142
|
+
return [
|
143
|
+
...defaultContextCheckProperties,
|
144
|
+
...properties.map((property) => { return { property, filter: defaultContextCheckProperties } }),
|
145
|
+
(object) => {
|
146
|
+
if (typeof object.value == 'object') {
|
147
|
+
return { property: 'value', filter: defaultContextCheckProperties }
|
148
|
+
} else {
|
149
|
+
return 'value'
|
150
|
+
}
|
151
|
+
},
|
152
|
+
(object) => {
|
153
|
+
if (!Array.isArray(object.modifiers)) {
|
154
|
+
return
|
155
|
+
}
|
156
|
+
if (typeof object.modifiers[0] == 'object') {
|
157
|
+
return { property: 'modifiers', filter: defaultContextCheckProperties }
|
158
|
+
} else {
|
159
|
+
return 'modifiers'
|
160
|
+
}
|
161
|
+
},
|
162
|
+
{ property: 'modifiers', isPropertyList: true, filter: defaultContextCheckProperties }
|
163
|
+
]
|
164
|
+
}
|
156
165
|
|
157
166
|
module.exports = {
|
158
167
|
defaultContextCheck,
|
168
|
+
defaultContextCheckProperties,
|
159
169
|
toEValue,
|
160
170
|
millisecondsUntilHourOfDay,
|
161
171
|
indent,
|
@@ -167,4 +177,5 @@ module.exports = {
|
|
167
177
|
words,
|
168
178
|
propertyToArray,
|
169
179
|
wordNumber,
|
180
|
+
requiredArgument,
|
170
181
|
}
|
package/common/hierarchy.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const {
|
1
|
+
const { knowledgeModule, where } = require('./runtime').theprogrammablemind
|
2
2
|
const { defaultContextCheck } = require('./helpers')
|
3
3
|
const properties = require('./properties')
|
4
4
|
const hierarchy_tests = require('./hierarchy.test.json')
|
@@ -32,7 +32,7 @@ const getTypes = ( km, concept, instance ) => {
|
|
32
32
|
|
33
33
|
// TODO the types of rank are x y z ....
|
34
34
|
// TODO x is a kind of y
|
35
|
-
let
|
35
|
+
let config = {
|
36
36
|
name: 'hierarchy',
|
37
37
|
operators: [
|
38
38
|
// "([hierarchyAble|])",
|
@@ -52,6 +52,7 @@ let configStruct = {
|
|
52
52
|
['have', 'canBeDoQuestion'],
|
53
53
|
],
|
54
54
|
priorities: [
|
55
|
+
{ "context": [['isEd', 0], ['is', 0], ], "choose": [1] },
|
55
56
|
{ "context": [['a', 0], ['questionMark', 0], ['is', 0], ], "choose": [0] },
|
56
57
|
// [['is', 0], ['hierarchyAble', 0]],
|
57
58
|
// [['a', 0], ['is', 0], ['hierarchyAble', 0]],
|
@@ -61,7 +62,7 @@ let configStruct = {
|
|
61
62
|
notes: 'what type is pikachu',
|
62
63
|
where: where(),
|
63
64
|
match: ({context, hierarchy}) => hierarchy.isA(context.marker, 'is') && context.query && !['what'].includes(context.one.marker) && !['what'].includes(context.two.marker) && (context.one.query || context.two.query),
|
64
|
-
apply: ({context, hierarchy, km, log, e
|
65
|
+
apply: async ({context, hierarchy, km, log, e}) => {
|
65
66
|
const one = context.one;
|
66
67
|
const two = context.two;
|
67
68
|
let concept, value;
|
@@ -72,7 +73,7 @@ let configStruct = {
|
|
72
73
|
concept = two;
|
73
74
|
value = one;
|
74
75
|
}
|
75
|
-
let instance = e(value)
|
76
|
+
let instance = await e(value)
|
76
77
|
if (instance.verbatim) {
|
77
78
|
context.evalue = { verbatim: instance.verbatim }
|
78
79
|
context.isResponse = true
|
@@ -80,9 +81,6 @@ let configStruct = {
|
|
80
81
|
}
|
81
82
|
instance = getTypes(km, concept, instance)
|
82
83
|
|
83
|
-
// instance.focusable = ['one', 'two']
|
84
|
-
// concept = JSON.parse(JSON.stringify(value))
|
85
|
-
// greg
|
86
84
|
concept = _.cloneDeep(value)
|
87
85
|
concept.isQuery = undefined
|
88
86
|
|
@@ -106,10 +104,10 @@ let configStruct = {
|
|
106
104
|
notes: 'type of pikachu', // the types of type is the next one
|
107
105
|
where: where(),
|
108
106
|
match: ({context}) => context.marker == 'type' && context.evaluate && context.object && context.objects[context.objects.length-1].number == 'one' && pluralize.isSingular(context.objects[0].word),
|
109
|
-
apply: ({context, objects, e, gs, km, log
|
107
|
+
apply: async ({context, objects, e, gs, km, log}) => {
|
110
108
|
const concept = context.objects[0];
|
111
109
|
const value = context.objects[1];
|
112
|
-
let instance = e(value)
|
110
|
+
let instance = await e(value)
|
113
111
|
if (instance.verbatim) {
|
114
112
|
context.evalue = { verbatim: instance.verbatim }
|
115
113
|
return
|
@@ -135,14 +133,14 @@ let configStruct = {
|
|
135
133
|
}
|
136
134
|
return hierarchy.isA(context.marker, 'is') && context.query && args( { types: ['hierarchyAble', 'hierarchyAble'], properties: ['one', 'two'] } )
|
137
135
|
},
|
138
|
-
apply: ({context, km, objects, g}) => {
|
136
|
+
apply: async ({context, km, objects, g}) => {
|
139
137
|
const api = km('properties').api
|
140
138
|
const one = context.one
|
141
139
|
const two = context.two
|
142
140
|
const oneId = pluralize.singular(one.value);
|
143
141
|
if (!api.conceptExists(oneId)) {
|
144
142
|
context.evalue = {
|
145
|
-
verbatim: `I don't know about ${g({ ...one, paraphrase: true})}`
|
143
|
+
verbatim: `I don't know about ${await g({ ...one, paraphrase: true})}`
|
146
144
|
}
|
147
145
|
context.isResponse = true
|
148
146
|
return
|
@@ -150,7 +148,7 @@ let configStruct = {
|
|
150
148
|
const twoId = pluralize.singular(two.value);
|
151
149
|
if (!api.conceptExists(twoId)) {
|
152
150
|
context.evalue = {
|
153
|
-
verbatim: `I don't know about ${g({ ...two, paraphrase: true})}`
|
151
|
+
verbatim: `I don't know about ${await g({ ...two, paraphrase: true})}`
|
154
152
|
}
|
155
153
|
context.isResponse = true
|
156
154
|
return
|
@@ -201,7 +199,6 @@ let configStruct = {
|
|
201
199
|
},
|
202
200
|
{
|
203
201
|
notes: 'humans are mammels',
|
204
|
-
// match: ({context, listable}) => listable(context, 'unknown') && context.same,
|
205
202
|
where: where(),
|
206
203
|
match: ({context, listable, hierarchy, isA, callId}) => {
|
207
204
|
if (!context.same) {
|
@@ -270,7 +267,7 @@ let configStruct = {
|
|
270
267
|
notes: 'types of type', // what are the types of animals
|
271
268
|
where: where(),
|
272
269
|
match: ({context}) => context.marker == 'type' && context.evaluate && context.object,
|
273
|
-
apply: ({context, objects,
|
270
|
+
apply: ({context, objects, km, isA}) => {
|
274
271
|
const api = km('properties').api
|
275
272
|
const conceptApi = km('concept').api
|
276
273
|
const type = pluralize.singular(context.object.value);
|
@@ -288,23 +285,19 @@ let configStruct = {
|
|
288
285
|
]
|
289
286
|
};
|
290
287
|
|
291
|
-
const
|
292
|
-
const config = new Config(configStruct, module)
|
293
|
-
config.stop_auto_rebuild()
|
294
|
-
config.add(properties())
|
295
|
-
config.initializer( ({apis, hierarchy}) => {
|
288
|
+
const initializer = ({apis, hierarchy}) => {
|
296
289
|
apis('stm').addIsA( (child, parent) => {
|
297
290
|
return hierarchy.isA(child, parent)
|
298
291
|
})
|
299
|
-
}
|
300
|
-
config.restart_auto_rebuild()
|
301
|
-
return config
|
302
|
-
}
|
292
|
+
}
|
303
293
|
|
304
294
|
knowledgeModule( {
|
295
|
+
config,
|
296
|
+
includes: [properties],
|
297
|
+
initializer,
|
298
|
+
|
305
299
|
module,
|
306
300
|
description: 'hierarchy of objects',
|
307
|
-
createConfig,
|
308
301
|
test: {
|
309
302
|
name: './hierarchy.test.json',
|
310
303
|
contents: hierarchy_tests,
|
@@ -312,7 +305,7 @@ knowledgeModule( {
|
|
312
305
|
checks: {
|
313
306
|
objects: ['children', 'concept', 'parents', 'properties'],
|
314
307
|
checks: {
|
315
|
-
context: defaultContextCheck,
|
308
|
+
context: defaultContextCheck(),
|
316
309
|
},
|
317
310
|
|
318
311
|
},
|