theprogrammablemind 7.3.5 → 7.3.6
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 +32 -51
- package/package.json +32 -31
- package/readme +7 -0
- package/runtime.js +18 -0
- package/src/config.js +6 -8
- package/src/semantics.js +3 -0
- package/src/unflatten.js +1 -1
package/client.js
CHANGED
@@ -9,29 +9,8 @@ const stringify = require('json-stable-stringify')
|
|
9
9
|
const Lines = require('./lines')
|
10
10
|
const flattens = require('./src/flatten')
|
11
11
|
const { appendNoDups, InitCalls } = require('./src/helpers')
|
12
|
-
const
|
13
|
-
const
|
14
|
-
const { diffString } = require('json-diff')
|
15
|
-
|
16
|
-
const isJest = () => {
|
17
|
-
return process.env.JEST_WORKER_ID !== undefined;
|
18
|
-
}
|
19
|
-
|
20
|
-
let fs
|
21
|
-
let ArgumentParser
|
22
|
-
|
23
|
-
const setupLibs = () => {
|
24
|
-
if (!fs) {
|
25
|
-
fs = require('fs')
|
26
|
-
}
|
27
|
-
if (!ArgumentParser) {
|
28
|
-
ArgumentParser = require('argparse').ArgumentParser
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
if (isJest()) {
|
33
|
-
setupLibs()
|
34
|
-
}
|
12
|
+
const runtime = require('./runtime')
|
13
|
+
const sortJson = runtime.sortJson
|
35
14
|
|
36
15
|
const ask = (config) => (asks) => {
|
37
16
|
for (let ask of asks) {
|
@@ -70,13 +49,13 @@ const ask = (config) => (asks) => {
|
|
70
49
|
const vimdiff = (actualJSON, expectedJSON) => {
|
71
50
|
const path = '.'
|
72
51
|
const actual = sortJson(actualJSON, { depth: 25 })
|
73
|
-
fs.writeFileSync(`${path}/actual.json`, JSON.stringify(actual, 0, 2))
|
52
|
+
runtime.fs.writeFileSync(`${path}/actual.json`, JSON.stringify(actual, 0, 2))
|
74
53
|
const expected = sortJson(expectedJSON, { depth: 25 })
|
75
|
-
fs.writeFileSync(`${path}/expected.json`, JSON.stringify(expected, 0, 2))
|
54
|
+
runtime.fs.writeFileSync(`${path}/expected.json`, JSON.stringify(expected, 0, 2))
|
76
55
|
// console.log(`vimdiff ${path}/actual.json ${path}/expected.json`)
|
77
56
|
{
|
78
|
-
const editor = process.env.EDITOR || 'vimdiff'
|
79
|
-
const child = child_process.spawn(editor, [`${path}/expected.json`, `${path}/actual.json`], { stdio: 'inherit' })
|
57
|
+
const editor = runtime.process.env.EDITOR || 'vimdiff'
|
58
|
+
const child = runtime.child_process.spawn(editor, [`${path}/expected.json`, `${path}/actual.json`], { stdio: 'inherit' })
|
80
59
|
child.on('exit', function (e, code) {
|
81
60
|
console.log('finished')
|
82
61
|
})
|
@@ -251,13 +230,13 @@ const writeTestFile = (fn, tests) => {
|
|
251
230
|
}
|
252
231
|
}
|
253
232
|
stabilize(tests)
|
254
|
-
fs.writeFileSync(fn, stringify(tests, { space: 2 }), { encoding: 'utf8', flag: 'w+' })
|
233
|
+
runtime.fs.writeFileSync(fn, stringify(tests, { space: 2 }), { encoding: 'utf8', flag: 'w+' })
|
255
234
|
}
|
256
235
|
|
257
236
|
const writeTest = (fn, query, objects, generated, paraphrases, responses, contexts, associations, metadata, config, saveDeveloper) => {
|
258
237
|
let tests = []
|
259
|
-
if (fs.existsSync(fn)) {
|
260
|
-
tests = JSON.parse(fs.readFileSync(fn))
|
238
|
+
if (runtime.fs.existsSync(fn)) {
|
239
|
+
tests = JSON.parse(runtime.fs.readFileSync(fn))
|
261
240
|
}
|
262
241
|
for (let association of associations) {
|
263
242
|
association.sort()
|
@@ -723,7 +702,7 @@ const runTestsHelper = async (config, tests, failed, juicyBits) => {
|
|
723
702
|
}
|
724
703
|
|
725
704
|
const runTests = async (config, testFile, juicyBits) => {
|
726
|
-
const tests = JSON.parse(fs.readFileSync(testFile))
|
705
|
+
const tests = JSON.parse(runtime.fs.readFileSync(testFile))
|
727
706
|
const { beforeTests, afterTests } = juicyBits
|
728
707
|
beforeTests()
|
729
708
|
if (juicyBits.verbose) {
|
@@ -760,7 +739,7 @@ const saveTestsHelper = async (testFile, config, tests, todo, beforeQuery, testC
|
|
760
739
|
}
|
761
740
|
|
762
741
|
const saveTests = (config, testFile, beforeQuery, testConfig) => {
|
763
|
-
const tests = JSON.parse(fs.readFileSync(testFile))
|
742
|
+
const tests = JSON.parse(runtime.fs.readFileSync(testFile))
|
764
743
|
console.log(testFile)
|
765
744
|
return saveTestsHelper(testFile, config, tests, tests.map( (test) => test.query ), beforeQuery, testConfig)
|
766
745
|
}
|
@@ -862,7 +841,7 @@ const defaultErrorHandler = async (error) => {
|
|
862
841
|
}
|
863
842
|
|
864
843
|
if (error.config) {
|
865
|
-
console.log('objects', util.inspect(error.config.get('objects'), { depth: Infinity, sorted: true }))
|
844
|
+
console.log('objects', runtime.util.inspect(error.config.get('objects'), { depth: Infinity, sorted: true }))
|
866
845
|
}
|
867
846
|
|
868
847
|
if (error.stack) {
|
@@ -914,9 +893,9 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
914
893
|
console.log(responses.trace)
|
915
894
|
|
916
895
|
if (global.beforeObjects) {
|
917
|
-
console.log('objects', diffString(global.beforeObjects, config.get('objects')))
|
896
|
+
console.log('objects', runtime.jsonDiff.diffString(global.beforeObjects, config.get('objects')))
|
918
897
|
} else {
|
919
|
-
console.log('objects', util.inspect(config.get('objects'), { depth: Infinity, sorted: true }))
|
898
|
+
console.log('objects', runtime.util.inspect(config.get('objects'), { depth: Infinity, sorted: true }))
|
920
899
|
}
|
921
900
|
console.log('--- The contexts are ----------')
|
922
901
|
console.log(JSON.stringify(sortJson(responses.contexts, { depth: 25 }), null, 2))
|
@@ -1077,13 +1056,13 @@ const build = async ({ config, target, beforeQuery, template, errorHandler = def
|
|
1077
1056
|
return template
|
1078
1057
|
};
|
1079
1058
|
stabilizeOutput(accumulators)
|
1080
|
-
fs.writeFileSync(instanceName, JSON.stringify(Object.assign({ queries: template.queries }, accumulators), 0, 2))
|
1059
|
+
runtime.fs.writeFileSync(instanceName, JSON.stringify(Object.assign({ queries: template.queries }, accumulators), 0, 2))
|
1081
1060
|
|
1082
1061
|
// km tests file
|
1083
1062
|
const testsName = `./${target}.test.json`
|
1084
|
-
if (!fs.existsSync(testsName)) {
|
1063
|
+
if (!runtime.fs.existsSync(testsName)) {
|
1085
1064
|
console.log(`Writing km file tests file "${testsName}" since it does not exist`)
|
1086
|
-
fs.writeFileSync(testsName, JSON.stringify({}, 0, 2))
|
1065
|
+
runtime.fs.writeFileSync(testsName, JSON.stringify({}, 0, 2))
|
1087
1066
|
}
|
1088
1067
|
}
|
1089
1068
|
|
@@ -1171,8 +1150,8 @@ const knowledgeModule = async ({
|
|
1171
1150
|
config.tests = test.contents
|
1172
1151
|
test = test.name
|
1173
1152
|
} else {
|
1174
|
-
if (fs && fs.existsSync(test)) {
|
1175
|
-
config.tests = JSON.parse(fs.readFileSync(test))
|
1153
|
+
if (runtime.fs && runtime.fs.existsSync(test)) {
|
1154
|
+
config.tests = JSON.parse(runtime.fs.readFileSync(test))
|
1176
1155
|
} else {
|
1177
1156
|
config.tests = {}
|
1178
1157
|
}
|
@@ -1189,8 +1168,7 @@ const knowledgeModule = async ({
|
|
1189
1168
|
|
1190
1169
|
if (isProcess) {
|
1191
1170
|
// setup();
|
1192
|
-
|
1193
|
-
const parser = new ArgumentParser({
|
1171
|
+
const parser = new runtime.ArgumentParser({
|
1194
1172
|
description: 'Entodicton knowledge module'
|
1195
1173
|
})
|
1196
1174
|
|
@@ -1237,7 +1215,7 @@ const knowledgeModule = async ({
|
|
1237
1215
|
}
|
1238
1216
|
|
1239
1217
|
if (args.clean) {
|
1240
|
-
const tests = JSON.parse(fs.readFileSync(testConfig.name))
|
1218
|
+
const tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
|
1241
1219
|
for (let test of tests) {
|
1242
1220
|
delete test.associations
|
1243
1221
|
}
|
@@ -1247,7 +1225,7 @@ const knowledgeModule = async ({
|
|
1247
1225
|
}
|
1248
1226
|
|
1249
1227
|
if (args.queryDelete) {
|
1250
|
-
let tests = JSON.parse(fs.readFileSync(testConfig.name))
|
1228
|
+
let tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
|
1251
1229
|
tests = tests.filter( (test) => test.query !== args.queryDelete );
|
1252
1230
|
writeTestFile(testConfig.name, tests)
|
1253
1231
|
console.log(`Remove the test for "${args.queryDelete}"`)
|
@@ -1399,7 +1377,7 @@ const knowledgeModule = async ({
|
|
1399
1377
|
const l = (n, hasError) => {
|
1400
1378
|
if (n === 0) {
|
1401
1379
|
if (hasError) {
|
1402
|
-
process.exit(-1)
|
1380
|
+
runtime.process.exit(-1)
|
1403
1381
|
}
|
1404
1382
|
return
|
1405
1383
|
}
|
@@ -1445,7 +1423,7 @@ const knowledgeModule = async ({
|
|
1445
1423
|
l(n - 1, hasError || newError)
|
1446
1424
|
}).catch((error) => {
|
1447
1425
|
console.error(error)
|
1448
|
-
process.exit(-1)
|
1426
|
+
runtime.process.exit(-1)
|
1449
1427
|
errorHandler(error)
|
1450
1428
|
})
|
1451
1429
|
}
|
@@ -1454,7 +1432,7 @@ const knowledgeModule = async ({
|
|
1454
1432
|
test()
|
1455
1433
|
}
|
1456
1434
|
} else if (args.loop) {
|
1457
|
-
const readline =
|
1435
|
+
const readline = runtime.readline.createInterface({ input: runtime.process.stdin, output: runtime.process.stdout })
|
1458
1436
|
const f = () => readline.question('Enter query? (newline to quit) ', query => {
|
1459
1437
|
query = query.trim()
|
1460
1438
|
if (query.length === 0) {
|
@@ -1502,13 +1480,12 @@ const test = (name) => {
|
|
1502
1480
|
*/
|
1503
1481
|
|
1504
1482
|
const ensureTestFile = (module, name, type) => {
|
1505
|
-
setupLibs()
|
1506
1483
|
const isProcess = require.main === module
|
1507
1484
|
if (isProcess) {
|
1508
1485
|
const fn = `./${name}.${type}.json`
|
1509
|
-
if (!fs.existsSync(fn)) {
|
1486
|
+
if (!runtime.fs.existsSync(fn)) {
|
1510
1487
|
console.log('writing')
|
1511
|
-
fs.writeFileSync(fn, '[]')
|
1488
|
+
runtime.fs.writeFileSync(fn, '[]')
|
1512
1489
|
}
|
1513
1490
|
}
|
1514
1491
|
}
|
@@ -1519,7 +1496,11 @@ function where(goUp = 2) {
|
|
1519
1496
|
const regexForm2 = /at (.*):(\d+):(\d+)$/
|
1520
1497
|
const line = e.stack.split("\n")[goUp];
|
1521
1498
|
const match = regexForm1.exec(line) || regexForm2.exec(line);
|
1522
|
-
|
1499
|
+
if (match) {
|
1500
|
+
return `${match[1]}:${match[2]}`
|
1501
|
+
} else {
|
1502
|
+
return 'running in browser'
|
1503
|
+
}
|
1523
1504
|
}
|
1524
1505
|
|
1525
1506
|
function w(func) {
|
package/package.json
CHANGED
@@ -1,6 +1,24 @@
|
|
1
1
|
{
|
2
|
-
"
|
3
|
-
|
2
|
+
"devDependencies": {
|
3
|
+
"eslint-plugin-import": "^2.23.4",
|
4
|
+
"jest": "^26.6.3",
|
5
|
+
"@typescript-eslint/parser": "^4.28.4",
|
6
|
+
"@typescript-eslint/eslint-plugin": "^4.28.4",
|
7
|
+
"eslint-plugin-node": "^11.1.0",
|
8
|
+
"eslint-config-standard": "^16.0.3",
|
9
|
+
"eslint-plugin-promise": "^5.1.0",
|
10
|
+
"eslint": "^7.31.0"
|
11
|
+
},
|
12
|
+
"scripts": {
|
13
|
+
"to:debug": "node inspect node_modules/.bin/jest --runInBand -t ONE23",
|
14
|
+
"test:debug": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
|
15
|
+
"tod": "node inspect node_modules/.bin/jest --runInBand -t ONE23",
|
16
|
+
"lint:fix": "eslint \"**/*.js\" --fix",
|
17
|
+
"lint": "eslint \"**/*.js\"",
|
18
|
+
"to": "node node_modules/.bin/jest --runInBand -t NEO",
|
19
|
+
"test": "jest --config ./jest.config.json",
|
20
|
+
"test:watch": "npm run test -- --watch"
|
21
|
+
},
|
4
22
|
"keywords": [
|
5
23
|
"NLP",
|
6
24
|
"NLU",
|
@@ -10,14 +28,15 @@
|
|
10
28
|
"natural language understanding",
|
11
29
|
"chatbot"
|
12
30
|
],
|
13
|
-
"version": "7.3.5",
|
14
31
|
"main": "index.js",
|
32
|
+
"name": "theprogrammablemind",
|
15
33
|
"files": [
|
16
34
|
"client.js",
|
17
35
|
"index.js",
|
18
36
|
"lines.js",
|
19
37
|
"demo.js",
|
20
38
|
"demo.test.json",
|
39
|
+
"runtime.js",
|
21
40
|
"src/helpers.js",
|
22
41
|
"src/flatten.js",
|
23
42
|
"src/unflatten.js",
|
@@ -27,39 +46,21 @@
|
|
27
46
|
"src/generators.js",
|
28
47
|
"src/semantics.js"
|
29
48
|
],
|
30
|
-
"
|
31
|
-
"tod": "node inspect node_modules/.bin/jest --runInBand -t NEO",
|
32
|
-
"lint": "eslint \"**/*.js\"",
|
33
|
-
"to:debug": "node inspect node_modules/.bin/jest --runInBand -t NEO",
|
34
|
-
"lint:fix": "eslint \"**/*.js\" --fix",
|
35
|
-
"test:watch": "npm run test -- --watch",
|
36
|
-
"test:debug": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
|
37
|
-
"test": "jest --config ./jest.config.json",
|
38
|
-
"to": "node node_modules/.bin/jest --runInBand -t NEO"
|
39
|
-
},
|
40
|
-
"name": "theprogrammablemind",
|
49
|
+
"author": "dev@thinktelligence.com",
|
41
50
|
"dependencies": {
|
42
51
|
"deep-equal": "^2.0.4",
|
43
|
-
"fs": "0.0.1-security",
|
44
|
-
"lodash": "^4.17.20",
|
45
|
-
"underscore": "^1.13.1",
|
46
52
|
"uuid": "^8.3.2",
|
47
|
-
"base-64": "^1.0.0",
|
48
53
|
"json-diff": "^1.0.3",
|
54
|
+
"lodash": "^4.17.20",
|
55
|
+
"fs": "0.0.1-security",
|
56
|
+
"base-64": "^1.0.0",
|
49
57
|
"sort-json": "^2.0.0",
|
50
|
-
"json-stable-stringify": "^1.0.1",
|
51
|
-
"node-fetch": "^2.6.1",
|
52
58
|
"readline": "^1.3.0",
|
53
|
-
"scriptjs": "^2.5.9"
|
59
|
+
"scriptjs": "^2.5.9",
|
60
|
+
"underscore": "^1.13.1",
|
61
|
+
"json-stable-stringify": "^1.0.1",
|
62
|
+
"node-fetch": "^2.6.1"
|
54
63
|
},
|
55
|
-
"
|
56
|
-
|
57
|
-
"eslint-plugin-promise": "^5.1.0",
|
58
|
-
"eslint-plugin-node": "^11.1.0",
|
59
|
-
"@typescript-eslint/eslint-plugin": "^4.28.4",
|
60
|
-
"eslint-plugin-import": "^2.23.4",
|
61
|
-
"eslint-config-standard": "^16.0.3",
|
62
|
-
"@typescript-eslint/parser": "^4.28.4",
|
63
|
-
"eslint": "^7.31.0"
|
64
|
-
}
|
64
|
+
"version": "7.3.6",
|
65
|
+
"license": "ISC"
|
65
66
|
}
|
package/readme
CHANGED
@@ -144,3 +144,10 @@ Videos with more details can be found at <a href=http://thinktelligence.com/kms>
|
|
144
144
|
|
145
145
|
This is a list of statement that will be processed using the given definitions
|
146
146
|
|
147
|
+
# Problems?
|
148
|
+
|
149
|
+
## With WebPack?
|
150
|
+
|
151
|
+
Recent Webpack has an optimization that causes the code not to run like normal javascript. It manifest with errors about fs, or process or util not being defined so you need a polyfill. You can do that if you want or you can used the 4WP (for webpack) versions of this module, <a href='https://www.npmjs.com/package/theprogrammablemind_4wp'>TheProgrammableMind 4WP</a>
|
152
|
+
|
153
|
+
|
package/runtime.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
const ArgumentParser = require('argparse').ArgumentParser
|
2
|
+
const fs = require('fs')
|
3
|
+
|
4
|
+
module.exports = {
|
5
|
+
process: {
|
6
|
+
env: process.env,
|
7
|
+
exit: process.exit,
|
8
|
+
stdin: process.stdin,
|
9
|
+
stdout: process.stdout,
|
10
|
+
},
|
11
|
+
child_process: 'wtf',
|
12
|
+
fs,
|
13
|
+
ArgumentParser,
|
14
|
+
readline: require('readline'),
|
15
|
+
jsonDiff: require('json-diff'),
|
16
|
+
sortJson: require('sort-json'),
|
17
|
+
util: require('util'),
|
18
|
+
}
|
package/src/config.js
CHANGED
@@ -6,6 +6,7 @@ const client = require('../client')
|
|
6
6
|
const Digraph = require('./digraph')
|
7
7
|
const helpers = require('./helpers')
|
8
8
|
const deepEqual = require('deep-equal')
|
9
|
+
const runtime = require('../runtime')
|
9
10
|
const _ = require('lodash')
|
10
11
|
|
11
12
|
const debugBreak = () => {
|
@@ -21,13 +22,13 @@ const indent = (string, indent) => {
|
|
21
22
|
return string.replace(/^/gm, ' '.repeat(indent));
|
22
23
|
}
|
23
24
|
|
24
|
-
if (process.env.DEBUG_HIERARCHY) {
|
25
|
-
global.entodictonDebugHierarchy = JSON.parse(process.env.DEBUG_HIERARCHY)
|
25
|
+
if (runtime.process.env.DEBUG_HIERARCHY) {
|
26
|
+
global.entodictonDebugHierarchy = JSON.parse(runtime.process.env.DEBUG_HIERARCHY)
|
26
27
|
}
|
27
28
|
|
28
|
-
if (process.env.DEBUG_BRIDGE) {
|
29
|
+
if (runtime.process.env.DEBUG_BRIDGE) {
|
29
30
|
// id/level
|
30
|
-
global.entodictonDebugBridge = process.env.DEBUG_BRIDGE.split('/')
|
31
|
+
global.entodictonDebugBridge = runtime.process.env.DEBUG_BRIDGE.split('/')
|
31
32
|
if (global.entodictonDebugBridge.length !== 2) {
|
32
33
|
console.log('Expected DEBUG_BRIDGE to be of the form "id/level"');
|
33
34
|
}
|
@@ -1230,12 +1231,9 @@ class Config {
|
|
1230
1231
|
return true
|
1231
1232
|
}
|
1232
1233
|
|
1233
|
-
/*
|
1234
1234
|
dump(fn) {
|
1235
|
-
|
1236
|
-
fs.writeFileSync(fn, JSON.stringify(this.config, 0, 2))
|
1235
|
+
runtime.fs.writeFileSync(fn, JSON.stringify(this.config, 0, 2))
|
1237
1236
|
}
|
1238
|
-
*/
|
1239
1237
|
|
1240
1238
|
copy (options = {}) {
|
1241
1239
|
this.valid()
|
package/src/semantics.js
CHANGED
@@ -169,6 +169,9 @@ class Semantics {
|
|
169
169
|
let counter = 0;
|
170
170
|
for (const isemantic in this.semantics) {
|
171
171
|
const semantic = this.semantics[isemantic]
|
172
|
+
if (!semantic) {
|
173
|
+
debugger;
|
174
|
+
}
|
172
175
|
if (semantic.matches(args, context, options)) {
|
173
176
|
if (!this.calls[counter]) {
|
174
177
|
this.calls[counter] = 0;
|
package/src/unflatten.js
CHANGED
@@ -77,7 +77,7 @@ class JSONSet {
|
|
77
77
|
// x wants and likes y C
|
78
78
|
|
79
79
|
const canonicalDefault = (value) => {
|
80
|
-
if (!value
|
80
|
+
if (!value || !value.marker) {
|
81
81
|
return value;
|
82
82
|
}
|
83
83
|
return { marker: value.marker, value: value.value, word: value.wordi, types: value.types }
|