theprogrammablemind 7.3.1 → 7.3.2-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/client.js +77 -15
- package/package.json +34 -34
- package/src/config.js +3 -0
package/client.js
CHANGED
@@ -19,11 +19,16 @@ const isJest = () => {
|
|
19
19
|
|
20
20
|
let fs
|
21
21
|
let ArgumentParser
|
22
|
-
|
22
|
+
|
23
|
+
const setupLibs = () => {
|
23
24
|
fs = require('fs')
|
24
25
|
ArgumentParser = require('argparse').ArgumentParser
|
25
26
|
}
|
26
27
|
|
28
|
+
if (isJest()) {
|
29
|
+
setupLibs()
|
30
|
+
}
|
31
|
+
|
27
32
|
const ask = (config) => (asks) => {
|
28
33
|
for (let ask of asks) {
|
29
34
|
config.addMotivation({
|
@@ -270,16 +275,37 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
270
275
|
writeTestFile(fn, tests)
|
271
276
|
}
|
272
277
|
|
273
|
-
const
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
278
|
+
const combineRange = (r1, r2) => {
|
279
|
+
let start = r2.start;
|
280
|
+
if (r1.start < r2.start) {
|
281
|
+
start = r1.start
|
282
|
+
}
|
283
|
+
let end = r2.end
|
284
|
+
if (r1.end > r2.end) {
|
285
|
+
end = r2.end
|
286
|
+
}
|
287
|
+
return { start, end }
|
288
|
+
}
|
289
|
+
|
290
|
+
const overlaps = (r1, context) => {
|
291
|
+
if (!context.range) {
|
292
|
+
return true;
|
293
|
+
}
|
294
|
+
const r2 = context.range
|
295
|
+
if (r1.start <= r2.end && r1.start >= r2.start) {
|
296
|
+
return true;
|
297
|
+
}
|
298
|
+
if (r1.end <= r2.end && r1.end >= r2.start) {
|
299
|
+
return true;
|
300
|
+
}
|
301
|
+
return false
|
302
|
+
}
|
303
|
+
|
304
|
+
const setupContexts = (rawContexts) => {
|
280
305
|
let first = true
|
306
|
+
const contexts = []
|
281
307
|
contexts.push({ marker: 'controlStart', controlRemove: true })
|
282
|
-
for (const context of
|
308
|
+
for (const context of rawContexts) {
|
283
309
|
if (first) {
|
284
310
|
first = false
|
285
311
|
} else {
|
@@ -288,14 +314,49 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
288
314
|
contexts.push(context)
|
289
315
|
}
|
290
316
|
contexts.push({ marker: 'controlEnd', controlRemove: true })
|
317
|
+
return contexts
|
318
|
+
}
|
319
|
+
|
320
|
+
const processContextsB = ({ config, hierarchy, semantics, generators, json, isTest, query, data, retries, url }) => {
|
321
|
+
// TODO fix this name to contextsPrime
|
322
|
+
const contextsPrime = []
|
323
|
+
const generatedPrime = []
|
324
|
+
const paraphrasesPrime = []
|
325
|
+
const responsesPrime = []
|
326
|
+
const contexts = setupContexts(json.contexts)
|
327
|
+
|
291
328
|
const objects = config.get('objects')
|
292
329
|
const args = { objects, isResponse: true, response: json, isTest, getObjects: getObjects(objects) }
|
293
330
|
setupArgs(args, config, json.logs, hierarchy)
|
294
331
|
const toDo = [...contexts]
|
295
332
|
args.insert = (context) => toDo.unshift(context)
|
333
|
+
let overlap, lastRange;
|
296
334
|
while (toDo.length > 0) {
|
297
|
-
args.calls.next()
|
298
335
|
const context = toDo.shift()
|
336
|
+
/*
|
337
|
+
if (false && query) {
|
338
|
+
if (config.wasChanged()) {
|
339
|
+
// process contexts that overlap
|
340
|
+
overlap = lastRange
|
341
|
+
} else {
|
342
|
+
config.watch()
|
343
|
+
}
|
344
|
+
if (overlap) {
|
345
|
+
if (overlaps(overlap, context)) {
|
346
|
+
// okay
|
347
|
+
query = query.slice(overlap.end+1)
|
348
|
+
data.utterance = query
|
349
|
+
debugger;
|
350
|
+
const json = await doWithRetries(retries, url, data)
|
351
|
+
toDo = setupContexts(json.contexts).slice(1) // take off the start context
|
352
|
+
}
|
353
|
+
overlap = undefined
|
354
|
+
}
|
355
|
+
lastRange = context.range
|
356
|
+
}
|
357
|
+
*/
|
358
|
+
|
359
|
+
args.calls.next()
|
299
360
|
let contextPrime = context
|
300
361
|
context.topLevel = true
|
301
362
|
try {
|
@@ -924,7 +985,7 @@ const build = async ({ config, target, beforeQuery, template, errorHandler = def
|
|
924
985
|
semantics: [],
|
925
986
|
associations: [],
|
926
987
|
}
|
927
|
-
const looper = (queries) => {
|
988
|
+
const looper = async (queries) => {
|
928
989
|
if (queries.length === 0) {
|
929
990
|
finish()
|
930
991
|
return
|
@@ -955,7 +1016,7 @@ const build = async ({ config, target, beforeQuery, template, errorHandler = def
|
|
955
1016
|
}
|
956
1017
|
|
957
1018
|
try {
|
958
|
-
const results = _process(config, query.query, { beforeQuery })
|
1019
|
+
const results = await _process(config, query.query, { beforeQuery })
|
959
1020
|
if (config.config.debug) {
|
960
1021
|
// TODO pass in the error handler like the other ones
|
961
1022
|
defaultInnerProcess(config, defaultErrorHandler, results)
|
@@ -967,7 +1028,7 @@ const build = async ({ config, target, beforeQuery, template, errorHandler = def
|
|
967
1028
|
results.key = { query: query.query, hierarchy }
|
968
1029
|
accumulators[property].push(results)
|
969
1030
|
accumulators.associations = accumulators.associations.concat(results.associations)
|
970
|
-
looper(queries)
|
1031
|
+
await looper(queries)
|
971
1032
|
} catch(e) {
|
972
1033
|
const error = { errors: [e], query: query.query };
|
973
1034
|
config.config.skipSemantics = null
|
@@ -979,7 +1040,7 @@ const build = async ({ config, target, beforeQuery, template, errorHandler = def
|
|
979
1040
|
const extraConfig = queryOrExtraConfig
|
980
1041
|
console.log('config', extraConfig)
|
981
1042
|
accumulators[property].push({ extraConfig: true, ...extraConfig })
|
982
|
-
looper(queries)
|
1043
|
+
await looper(queries)
|
983
1044
|
}
|
984
1045
|
}
|
985
1046
|
|
@@ -1031,7 +1092,7 @@ const build = async ({ config, target, beforeQuery, template, errorHandler = def
|
|
1031
1092
|
let todo = (template.queries || []).map((query) => { return { property: 'resultss', query, skipSemantics: false } })
|
1032
1093
|
todo = todo.concat((template.fragments || []).map((query) => { return Object.assign({}, toProperties(query), { property: 'fragments', skipSemantics: false }) }))
|
1033
1094
|
todo = todo.concat((template.semantics || []).map((definition) => { return { property: 'semantics', query: `${definition.from}\n${definition.to}`, skipSemantics: true } }))
|
1034
|
-
looper(Object.assign([], todo))
|
1095
|
+
await looper(Object.assign([], todo))
|
1035
1096
|
}
|
1036
1097
|
|
1037
1098
|
const knowledgeModule = async ({
|
@@ -1123,6 +1184,7 @@ const knowledgeModule = async ({
|
|
1123
1184
|
|
1124
1185
|
if (isProcess) {
|
1125
1186
|
// setup();
|
1187
|
+
setupLibs()
|
1126
1188
|
const parser = new ArgumentParser({
|
1127
1189
|
description: 'Entodicton knowledge module'
|
1128
1190
|
})
|
package/package.json
CHANGED
@@ -1,4 +1,31 @@
|
|
1
1
|
{
|
2
|
+
"name": "theprogrammablemind",
|
3
|
+
"author": "dev@thinktelligence.com",
|
4
|
+
"main": "index.js",
|
5
|
+
"dependencies": {
|
6
|
+
"readline": "^1.3.0",
|
7
|
+
"deep-equal": "^2.0.4",
|
8
|
+
"scriptjs": "^2.5.9",
|
9
|
+
"underscore": "^1.13.1",
|
10
|
+
"sort-json": "^2.0.0",
|
11
|
+
"json-stable-stringify": "^1.0.1",
|
12
|
+
"node-fetch": "^2.6.1",
|
13
|
+
"base-64": "^1.0.0",
|
14
|
+
"fs": "0.0.1-security",
|
15
|
+
"lodash": "^4.17.20",
|
16
|
+
"json-diff": "^1.0.3",
|
17
|
+
"uuid": "^8.3.2"
|
18
|
+
},
|
19
|
+
"devDependencies": {
|
20
|
+
"eslint-config-standard": "^16.0.3",
|
21
|
+
"eslint-plugin-promise": "^5.1.0",
|
22
|
+
"eslint": "^7.31.0",
|
23
|
+
"@typescript-eslint/eslint-plugin": "^4.28.4",
|
24
|
+
"@typescript-eslint/parser": "^4.28.4",
|
25
|
+
"eslint-plugin-node": "^11.1.0",
|
26
|
+
"jest": "^26.6.3",
|
27
|
+
"eslint-plugin-import": "^2.23.4"
|
28
|
+
},
|
2
29
|
"keywords": [
|
3
30
|
"NLP",
|
4
31
|
"NLU",
|
@@ -8,21 +35,6 @@
|
|
8
35
|
"natural language understanding",
|
9
36
|
"chatbot"
|
10
37
|
],
|
11
|
-
"author": "dev@thinktelligence.com",
|
12
|
-
"dependencies": {
|
13
|
-
"sort-json": "^2.0.0",
|
14
|
-
"scriptjs": "^2.5.9",
|
15
|
-
"deep-equal": "^2.0.4",
|
16
|
-
"readline": "^1.3.0",
|
17
|
-
"json-diff": "^1.0.3",
|
18
|
-
"uuid": "^8.3.2",
|
19
|
-
"node-fetch": "^2.6.1",
|
20
|
-
"json-stable-stringify": "^1.0.1",
|
21
|
-
"fs": "0.0.1-security",
|
22
|
-
"base-64": "^1.0.0",
|
23
|
-
"lodash": "^4.17.20",
|
24
|
-
"underscore": "^1.13.1"
|
25
|
-
},
|
26
38
|
"files": [
|
27
39
|
"client.js",
|
28
40
|
"index.js",
|
@@ -38,28 +50,16 @@
|
|
38
50
|
"src/generators.js",
|
39
51
|
"src/semantics.js"
|
40
52
|
],
|
41
|
-
"name": "theprogrammablemind",
|
42
53
|
"scripts": {
|
43
|
-
"test:watch": "npm run test -- --watch",
|
44
|
-
"tod": "node inspect node_modules/.bin/jest --runInBand -t NEO",
|
45
|
-
"to": "node node_modules/.bin/jest --runInBand -t NEO",
|
46
|
-
"lint:fix": "eslint \"**/*.js\" --fix",
|
47
|
-
"test": "jest --config ./jest.config.json",
|
48
54
|
"test:debug": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
|
49
55
|
"lint": "eslint \"**/*.js\"",
|
50
|
-
"to
|
51
|
-
|
52
|
-
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"
|
56
|
-
"@typescript-eslint/parser": "^4.28.4",
|
57
|
-
"jest": "^26.6.3",
|
58
|
-
"eslint": "^7.31.0",
|
59
|
-
"eslint-plugin-node": "^11.1.0",
|
60
|
-
"eslint-plugin-import": "^2.23.4"
|
56
|
+
"to": "node node_modules/.bin/jest --runInBand -t NEO",
|
57
|
+
"to:debug": "node inspect node_modules/.bin/jest --runInBand -t NEO",
|
58
|
+
"tod": "node inspect node_modules/.bin/jest --runInBand -t NEO",
|
59
|
+
"lint:fix": "eslint \"**/*.js\" --fix",
|
60
|
+
"test:watch": "npm run test -- --watch",
|
61
|
+
"test": "jest --config ./jest.config.json"
|
61
62
|
},
|
62
63
|
"license": "ISC",
|
63
|
-
"
|
64
|
-
"version": "7.3.1"
|
64
|
+
"version": "7.3.2-beta.1"
|
65
65
|
}
|