theprogrammablemind 9.6.3-beta.3 → 9.6.3-beta.31
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/client.js +5 -0
- package/package.json +1 -1
- package/src/config.js +9 -1
- package/src/configHelpers.js +26 -0
- package/src/flatten.js +4 -4
- package/src/fragments.js +1 -13
- package/src/helpers.js +17 -0
- package/src/project.js +6 -0
- package/src/project2.js +30 -6
- package/src/semantics.js +13 -2
package/client.js
CHANGED
|
@@ -1339,6 +1339,7 @@ const knowledgeModuleImpl = async ({
|
|
|
1339
1339
|
parser.add_argument('-q', '--query', { help: 'Run the specified query' })
|
|
1340
1340
|
parser.add_argument('-f', '--filter', { help: 'for -pd only the data for the knowledge modules that start with this string will be shown' })
|
|
1341
1341
|
parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
|
|
1342
|
+
parser.add_argument('--trace', { action: 'store_true', help: 'Trace the semantics and generator calls.' })
|
|
1342
1343
|
parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
|
|
1343
1344
|
parser.add_argument('-dt', '--deleteTest', { help: 'Delete the specified query from the tests file.' })
|
|
1344
1345
|
parser.add_argument('--parenthesized', { action: 'store_true', help: 'Show the generated phrases with parenthesis.' })
|
|
@@ -1402,6 +1403,10 @@ const knowledgeModuleImpl = async ({
|
|
|
1402
1403
|
|
|
1403
1404
|
// setup();
|
|
1404
1405
|
|
|
1406
|
+
if (args.trace) {
|
|
1407
|
+
process.env.TPMKMS_TRACE = true
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1405
1410
|
if (args.parenthesized) {
|
|
1406
1411
|
config.parenthesized = true
|
|
1407
1412
|
}
|
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -115,6 +115,10 @@ const debugOperator = (operator) => {
|
|
|
115
115
|
// debug operator hit
|
|
116
116
|
debugger // eslint-disable-line no-debugger
|
|
117
117
|
}
|
|
118
|
+
if ((`${operator.pattern || operator}`).includes(global.entodictonDebugOperator)) {
|
|
119
|
+
// debug operator hit
|
|
120
|
+
debugger // eslint-disable-line no-debugger
|
|
121
|
+
}
|
|
118
122
|
}
|
|
119
123
|
}
|
|
120
124
|
|
|
@@ -987,7 +991,7 @@ class Config {
|
|
|
987
991
|
getInfo () {
|
|
988
992
|
const name = this.name
|
|
989
993
|
const includes = this.configs.slice(1).map((km) => km.config.name)
|
|
990
|
-
includes.sort()
|
|
994
|
+
// includes.sort()
|
|
991
995
|
const visibleExamples = []
|
|
992
996
|
for (const test of this.tests) {
|
|
993
997
|
if (!test.developerTest) {
|
|
@@ -2874,6 +2878,9 @@ class Config {
|
|
|
2874
2878
|
}
|
|
2875
2879
|
|
|
2876
2880
|
getContextChecks() {
|
|
2881
|
+
if (this.getContextChecksCache) {
|
|
2882
|
+
return this.getContextChecksCache
|
|
2883
|
+
}
|
|
2877
2884
|
const allChecks = []
|
|
2878
2885
|
let defaults = () => []
|
|
2879
2886
|
if (this.loadOrdering) {
|
|
@@ -2910,6 +2917,7 @@ class Config {
|
|
|
2910
2917
|
match: () => true,
|
|
2911
2918
|
apply: defaults
|
|
2912
2919
|
})
|
|
2920
|
+
this.getContextChecksCache = allChecks
|
|
2913
2921
|
return allChecks
|
|
2914
2922
|
}
|
|
2915
2923
|
|
package/src/configHelpers.js
CHANGED
|
@@ -86,6 +86,30 @@ const cleanAssign = (dest, ...srcs) => {
|
|
|
86
86
|
Object.assign(dest, ...srcs)
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
// handler is a semantic or a generator
|
|
90
|
+
class HandlerStack {
|
|
91
|
+
constructor(handlers = []) {
|
|
92
|
+
this.handlers = [...handlers]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
push(handler) {
|
|
96
|
+
this.handlers.push(handler)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
pop() {
|
|
100
|
+
this.handlers.pop()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
toString() {
|
|
104
|
+
let str = ''
|
|
105
|
+
for (let i = this.handlers.length - 1; i >= 0; --i) {
|
|
106
|
+
str += this.handlers[i].toLabel() + '\n'
|
|
107
|
+
str += this.handlers[i].toString() + '\n\n'
|
|
108
|
+
}
|
|
109
|
+
return str
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
89
113
|
class ContextHierarchy {
|
|
90
114
|
constructor(contexts = []) {
|
|
91
115
|
this.contexts = [...contexts]
|
|
@@ -139,6 +163,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
|
139
163
|
}
|
|
140
164
|
}
|
|
141
165
|
args.contextHierarchy = new ContextHierarchy()
|
|
166
|
+
args.handlerStack = new HandlerStack()
|
|
142
167
|
args.cleanAssign = cleanAssign
|
|
143
168
|
args.km = (name) => config.getConfig(name)
|
|
144
169
|
args.api = (name) => config.getConfig(name).api
|
|
@@ -591,4 +616,5 @@ module.exports = {
|
|
|
591
616
|
loadInstance,
|
|
592
617
|
isA,
|
|
593
618
|
ContextHierarchy,
|
|
619
|
+
HandlerStack,
|
|
594
620
|
}
|
package/src/flatten.js
CHANGED
|
@@ -109,7 +109,7 @@ const flatten = (markers, value) => {
|
|
|
109
109
|
const keys = []
|
|
110
110
|
const valuess = []
|
|
111
111
|
const unchanged = {}
|
|
112
|
-
DEBUG('properties', JSON.stringify(properties, null, 2))
|
|
112
|
+
DEBUG('properties', () => JSON.stringify(properties, null, 2))
|
|
113
113
|
for (const key in properties) {
|
|
114
114
|
let wf = false
|
|
115
115
|
let values
|
|
@@ -133,11 +133,11 @@ const flatten = (markers, value) => {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
const propertiess = []
|
|
136
|
-
DEBUG('-----------> valuess', JSON.stringify(valuess))
|
|
137
|
-
DEBUG('-----------> cartesian(valuess)', JSON.stringify(cartesian(valuess)))
|
|
136
|
+
DEBUG('-----------> valuess', () => JSON.stringify(valuess))
|
|
137
|
+
DEBUG('-----------> cartesian(valuess)', () => JSON.stringify(cartesian(valuess)))
|
|
138
138
|
// for (let values of itertools.product(*valuess)) {
|
|
139
139
|
const cp = cartesian(...valuess)
|
|
140
|
-
DEBUG('-----------> cp', JSON.stringify(cp))
|
|
140
|
+
DEBUG('-----------> cp', () => JSON.stringify(cp))
|
|
141
141
|
for (const values of cartesian(...valuess)) {
|
|
142
142
|
// properties = copy.deepcopy(unchanged)
|
|
143
143
|
properties = _.cloneDeep(unchanged)
|
package/src/fragments.js
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
const _ = require('lodash')
|
|
2
2
|
const helpers = require('./helpers')
|
|
3
3
|
|
|
4
|
-
function pathEquals (p1, p2) {
|
|
5
|
-
if (p1.length !== p2.length) {
|
|
6
|
-
return false
|
|
7
|
-
}
|
|
8
|
-
for (let i = 0; i < p1.length; ++i) {
|
|
9
|
-
if (p1[i] !== p2[i]) {
|
|
10
|
-
return false
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return true
|
|
14
|
-
}
|
|
15
|
-
|
|
16
4
|
function fragmentInstantiator (args, contexts) {
|
|
17
5
|
return new Object({
|
|
18
6
|
contexts: () => {
|
|
@@ -22,7 +10,7 @@ function fragmentInstantiator (args, contexts) {
|
|
|
22
10
|
const instantiated = _.cloneDeep(contexts)
|
|
23
11
|
const todo = [{ context: instantiated, path: [] }]
|
|
24
12
|
args = { ...args }
|
|
25
|
-
args.pathEquals = pathEquals
|
|
13
|
+
args.pathEquals = helpers.pathEquals
|
|
26
14
|
while (todo.length > 0) {
|
|
27
15
|
const { context, path } = todo.pop()
|
|
28
16
|
args.context = context
|
package/src/helpers.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
const deepEqual = require('deep-equal')
|
|
2
2
|
const stringify = require('json-stable-stringify')
|
|
3
3
|
|
|
4
|
+
function pathEquals (p1, p2) {
|
|
5
|
+
if (p1.length !== p2.length) {
|
|
6
|
+
return false
|
|
7
|
+
}
|
|
8
|
+
for (let i = 0; i < p1.length; ++i) {
|
|
9
|
+
if (typeof p2[i] == 'function') {
|
|
10
|
+
if (!p2[i](p1[i])) {
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
} else if (p1[i] !== p2[i]) {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return true
|
|
18
|
+
}
|
|
19
|
+
|
|
4
20
|
function watchProperty(obj, propName) {
|
|
5
21
|
let value = obj[propName];
|
|
6
22
|
|
|
@@ -594,4 +610,5 @@ module.exports = {
|
|
|
594
610
|
setByPath,
|
|
595
611
|
assignAssumed,
|
|
596
612
|
watchProperty,
|
|
613
|
+
pathEquals,
|
|
597
614
|
}
|
package/src/project.js
CHANGED
|
@@ -23,6 +23,12 @@ const project = (object, filter) => {
|
|
|
23
23
|
return object
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
if (object.checks) {
|
|
27
|
+
for (const check in object.checks) {
|
|
28
|
+
filter.push(check)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
const projection = {}
|
|
27
33
|
const set = (property, value) => {
|
|
28
34
|
if (value === null || value === undefined) {
|
package/src/project2.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const debug = require('./debug')
|
|
2
|
+
const helpers = require('./helpers')
|
|
2
3
|
|
|
3
4
|
function areFirstNEqual(arr1, arr2, n) {
|
|
4
5
|
if (n <= 0) return true;
|
|
@@ -16,6 +17,7 @@ function project(source, filters, path=[]) {
|
|
|
16
17
|
if (['boolean', 'string', 'number'].includes(typeof source)) {
|
|
17
18
|
return source
|
|
18
19
|
}
|
|
20
|
+
|
|
19
21
|
if (Array.isArray(source)) {
|
|
20
22
|
const result = []
|
|
21
23
|
for (const value of source) {
|
|
@@ -35,8 +37,8 @@ function project(source, filters, path=[]) {
|
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
// Find the applicable filter for the current context
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
+
const selectedFilters = filters.filter(f => f.match({ context: source, path, pathEquals: helpers.pathEquals }));
|
|
41
|
+
if (filters.length == 0) {
|
|
40
42
|
if (Array.isArray(source)) {
|
|
41
43
|
return source.map((element) => project(element, filters, [...path, '*']))
|
|
42
44
|
}
|
|
@@ -44,7 +46,17 @@ function project(source, filters, path=[]) {
|
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
// Get the properties to include from the apply function
|
|
47
|
-
let properties =
|
|
49
|
+
let properties = []
|
|
50
|
+
for (const filter of selectedFilters) {
|
|
51
|
+
for (const property of filter.apply(source)) {
|
|
52
|
+
properties.push(property)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (source?.checks) {
|
|
56
|
+
for (const check of source.checks) {
|
|
57
|
+
properties.push(check)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
48
60
|
|
|
49
61
|
// update
|
|
50
62
|
const updatedProperties = []
|
|
@@ -69,7 +81,7 @@ function project(source, filters, path=[]) {
|
|
|
69
81
|
result[endProp] = source[endProp]
|
|
70
82
|
} else if (Array.isArray(source[endProp])) {
|
|
71
83
|
result[endProp] = []
|
|
72
|
-
for (const key
|
|
84
|
+
for (const key of source[endProp].keys()) {
|
|
73
85
|
result[endProp].push(project(source[endProp][key], filters, [...path, endProp, key]))
|
|
74
86
|
}
|
|
75
87
|
} else {
|
|
@@ -90,7 +102,19 @@ function project(source, filters, path=[]) {
|
|
|
90
102
|
// If the property is an object and not null, recursively project it
|
|
91
103
|
if (typeof source[prop.property] === 'object' && source[prop.property] !== null) {
|
|
92
104
|
result[prop.property] = {}
|
|
93
|
-
|
|
105
|
+
const instantiatedCheck = []
|
|
106
|
+
for (const check of prop.check) {
|
|
107
|
+
if (typeof check.property == 'function') {
|
|
108
|
+
for (const sourceKey of source[prop.property].keys()) {
|
|
109
|
+
if (check.property(sourceKey)) {
|
|
110
|
+
instantiatedCheck.push({ property: sourceKey, check: check.check })
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
instantiatedCheck.push(check)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const key of instantiatedCheck) {
|
|
94
118
|
if (typeof key == 'string') {
|
|
95
119
|
result[prop.property][key] = project(source[prop.property][key], filters, [...path, prop.property, key]);
|
|
96
120
|
} else {
|
|
@@ -98,7 +122,7 @@ function project(source, filters, path=[]) {
|
|
|
98
122
|
match: () => true,
|
|
99
123
|
apply: () => key.check
|
|
100
124
|
}
|
|
101
|
-
result[prop.property][key.property] = project(source[prop.property][key.property], [f], [...path, prop.property, key.property]);
|
|
125
|
+
result[prop.property][key.property] = project(source[prop.property][key.property], [...filters, f], [...path, prop.property, key.property]);
|
|
102
126
|
}
|
|
103
127
|
}
|
|
104
128
|
} else {
|
package/src/semantics.js
CHANGED
|
@@ -103,7 +103,14 @@ class Semantic {
|
|
|
103
103
|
if (args.breakOnSemantics) {
|
|
104
104
|
debugger // eslint-disable-line no-debugger
|
|
105
105
|
}
|
|
106
|
-
|
|
106
|
+
try {
|
|
107
|
+
args.handlerStack.push(this)
|
|
108
|
+
await this._apply(args)
|
|
109
|
+
args.handlerStack.pop()
|
|
110
|
+
} catch( e ) {
|
|
111
|
+
args.handlerStack.pop()
|
|
112
|
+
throw e
|
|
113
|
+
}
|
|
107
114
|
return contextPrime
|
|
108
115
|
}
|
|
109
116
|
}
|
|
@@ -172,7 +179,6 @@ class Semantics {
|
|
|
172
179
|
args = { ...args }
|
|
173
180
|
|
|
174
181
|
const config = args.config
|
|
175
|
-
const debug = config.getDebug()
|
|
176
182
|
let contextPrime = Object.assign({}, context)
|
|
177
183
|
const s = (context, options) => this.apply(args, context, options)
|
|
178
184
|
let applied = false
|
|
@@ -205,6 +211,11 @@ class Semantics {
|
|
|
205
211
|
continueWasCalled = true
|
|
206
212
|
}
|
|
207
213
|
args._continue = _continue
|
|
214
|
+
if (process.env.TPMKMS_TRACE) {
|
|
215
|
+
console.error("TPMKMS_TRACE", debug.counter("TPMKMS_TRACE"))
|
|
216
|
+
console.error(semantic.toLabel())
|
|
217
|
+
console.error(semantic.toString())
|
|
218
|
+
}
|
|
208
219
|
contextPrime = await semantic.apply(args, context, s, options)
|
|
209
220
|
if (continueWasCalled) {
|
|
210
221
|
continue
|