theprogrammablemind_4wp 7.5.8-beta.57 → 7.5.8-beta.58
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +86 -161
- package/package.json +1 -1
package/client.js
CHANGED
@@ -126,6 +126,7 @@ const setupArgs = (args, config, logs, hierarchy) => {
|
|
126
126
|
args.listable = listable(hierarchy)
|
127
127
|
args.asList = asList
|
128
128
|
args.retry = () => { throw new RetryError() }
|
129
|
+
args.fragments = (query) => config.fragment(query)
|
129
130
|
const scopedAsk = getAsk(config)
|
130
131
|
|
131
132
|
const getAPI = (uuid) => {
|
@@ -608,7 +609,6 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
608
609
|
if (writeTests) {
|
609
610
|
config.rebuild()
|
610
611
|
const objects = getObjects(config.config.objects)(config.uuid)
|
611
|
-
config.beforeQuery({ query, isModule: false, objects })
|
612
612
|
}
|
613
613
|
} catch(error) {
|
614
614
|
throw error
|
@@ -744,7 +744,7 @@ const getConfigForTest = (config, testConfig) => {
|
|
744
744
|
return configForTest
|
745
745
|
}
|
746
746
|
|
747
|
-
const runTest = async (config, expected, { args, verbose,
|
747
|
+
const runTest = async (config, expected, { args, verbose, testConfig, debug }) => {
|
748
748
|
const test = expected.query
|
749
749
|
// initialize in between test so state is not preserved since the test was adding without state
|
750
750
|
config.rebuild()
|
@@ -769,7 +769,6 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
|
|
769
769
|
objects = getObjects(config.config.objects)(config.getConfigs()[testConfig.testModuleName].uuid)
|
770
770
|
testConfigName = testConfig.testModuleName
|
771
771
|
}
|
772
|
-
config.beforeQuery({ query: test, isModule: false, objects })
|
773
772
|
try {
|
774
773
|
const result = await _process(config, test, { errorHandler, isTest: true })
|
775
774
|
result.query = test
|
@@ -844,37 +843,6 @@ const runTest = async (config, expected, { args, verbose, afterTest, testConfig,
|
|
844
843
|
const expected_config = sortJson(convertToStable(expected.config), { depth: 25 })
|
845
844
|
const failed_config = !matching(actual_config, expected_config)
|
846
845
|
let failed = failed_paraphrases || failed_paraphrasesParenthesized || failed_generatedParenthesized || failed_responses || failed_contexts || failed_objects || failed_config || failed_checked
|
847
|
-
if (!failed) {
|
848
|
-
if (config.afterTest) {
|
849
|
-
failed = config.afterTest({ query: test, expected, actual: result, config })
|
850
|
-
if (failed) {
|
851
|
-
return {
|
852
|
-
utterance: test,
|
853
|
-
errorFromAfterTest: failed,
|
854
|
-
expected: {
|
855
|
-
responses: expected.responses,
|
856
|
-
paraphrases: expected.paraphrases,
|
857
|
-
paraphrasesParenthesized: expected.paraphrasesParenthesized,
|
858
|
-
generatedParenthesized: expected.generatedParenthesized,
|
859
|
-
results: expected.contexts,
|
860
|
-
checked: expected_checked,
|
861
|
-
objects: expected_objects,
|
862
|
-
config: expected.config
|
863
|
-
},
|
864
|
-
actual: {
|
865
|
-
responses: result.responses,
|
866
|
-
paraphrases: result.paraphrases,
|
867
|
-
paraphrasesParenthesized: result.paraphrasesParenthesized,
|
868
|
-
generatedParenthesized: result.generatedParenthesized,
|
869
|
-
results: result.contexts,
|
870
|
-
checked: actual_checked,
|
871
|
-
objects: actual_objects,
|
872
|
-
config: actual_config
|
873
|
-
}
|
874
|
-
}
|
875
|
-
}
|
876
|
-
}
|
877
|
-
}
|
878
846
|
|
879
847
|
if (expected.metadata && result.metadata && failed) {
|
880
848
|
const priorities = analyzeMetaData(expected.metadata, result.metadata)
|
@@ -942,19 +910,16 @@ const runTestsHelper = async (config, tests, failed, juicyBits) => {
|
|
942
910
|
|
943
911
|
const runTests = async (config, testFile, juicyBits) => {
|
944
912
|
const tests = JSON.parse(runtime.fs.readFileSync(testFile))
|
945
|
-
config.beforeTests()
|
946
913
|
if (juicyBits.verbose) {
|
947
914
|
console.log('\n', testFile, '-----------------------------------------------', '\n')
|
948
915
|
}
|
949
916
|
const v = await runTestsHelper(config, [...tests], [], juicyBits)
|
950
|
-
config.afterTests()
|
951
917
|
return v
|
952
918
|
}
|
953
919
|
|
954
920
|
const saveTest = async (testFile, config, test, expected, testConfig, saveDeveloper) => {
|
955
921
|
config.rebuild()
|
956
922
|
const objects = getObjects(config.config.objects)(config.uuid)
|
957
|
-
config.beforeQuery({ query: test, isModule: false, objects })
|
958
923
|
console.log(test)
|
959
924
|
const result = await _process(config, test, { isTest: true })
|
960
925
|
// const actualObjects = config.config.objects
|
@@ -1232,31 +1197,6 @@ const defaultProcess = ({ config, errorHandler }) => async (promise) => {
|
|
1232
1197
|
}
|
1233
1198
|
}
|
1234
1199
|
|
1235
|
-
/*
|
1236
|
-
const kmFileTemplate = (kmBaseName, kmName) =>
|
1237
|
-
`const entodicton = require('entodicton')
|
1238
|
-
const base = require('./${kmBaseName}').copy()
|
1239
|
-
const ${kmName}_tests = require('./${kmName}.test.json')
|
1240
|
-
const ${kmName}_instance = require('./${kmBaseName}.${kmName}.instance.json')
|
1241
|
-
|
1242
|
-
const config = new entodicton.Config({ name: '${kmName}' })
|
1243
|
-
config.add(base)
|
1244
|
-
kirk_instance.base = '${kmBaseName}'
|
1245
|
-
config.load(${kmName}_instance)
|
1246
|
-
|
1247
|
-
entodicton.knowledgeModule( {
|
1248
|
-
module,
|
1249
|
-
description: '${kmName} related concepts',
|
1250
|
-
section,
|
1251
|
-
config,
|
1252
|
-
test: {
|
1253
|
-
name: './${kmName}.test.json',
|
1254
|
-
contents: ${kmName}_tests
|
1255
|
-
},
|
1256
|
-
})
|
1257
|
-
`
|
1258
|
-
*/
|
1259
|
-
|
1260
1200
|
// loadTemplate BuiltTemplate
|
1261
1201
|
const rebuildTemplate = async ({ config, target, template, errorHandler = defaultErrorHandler }) => {
|
1262
1202
|
const accumulators = {
|
@@ -1393,18 +1333,15 @@ const knowledgeModule = async ({
|
|
1393
1333
|
module: moduleFromJSFile,
|
1394
1334
|
description,
|
1395
1335
|
section,
|
1396
|
-
config,
|
1336
|
+
// config, createConfig,
|
1337
|
+
createConfig,
|
1338
|
+
newWay,
|
1397
1339
|
demo,
|
1398
1340
|
test,
|
1399
1341
|
template,
|
1400
1342
|
errorHandler = defaultErrorHandler,
|
1401
1343
|
process: processResults = defaultProcess,
|
1402
1344
|
stopAtFirstFailure = true,
|
1403
|
-
beforeQuery = () => {},
|
1404
|
-
beforeTests = () => {},
|
1405
|
-
afterTests = () => {},
|
1406
|
-
beforeTest = () => {},
|
1407
|
-
afterTest = () => {},
|
1408
1345
|
...rest
|
1409
1346
|
} = {}) => {
|
1410
1347
|
|
@@ -1413,22 +1350,14 @@ const knowledgeModule = async ({
|
|
1413
1350
|
throw new Error(`Unknown arguments to knowledgeModule: ${unknownArgs.join()}`)
|
1414
1351
|
}
|
1415
1352
|
|
1416
|
-
config.beforeQuery = beforeQuery
|
1417
|
-
config.beforeTests = beforeTests
|
1418
|
-
config.afterTests = afterTests
|
1419
|
-
config.beforeTest = beforeTest
|
1420
|
-
config.afterTest = afterTest
|
1421
|
-
|
1422
1353
|
const testConfig = test
|
1423
1354
|
|
1424
1355
|
if (!moduleFromJSFile) {
|
1425
1356
|
throw new Error("'module' is a required parameter. The value should be either 'module' or a lambda that will be called when the file is acting as a module.")
|
1426
1357
|
}
|
1427
|
-
if (!config) {
|
1428
|
-
|
1429
|
-
|
1430
|
-
if (!config.name) {
|
1431
|
-
throw new Error("config must have 'name' set to the knowledge module name.")
|
1358
|
+
// if (!config && !createConfig) {
|
1359
|
+
if (!createConfig) {
|
1360
|
+
throw new Error("'config' or 'createConfig' is a required parameter. The value should the config that defines the knowledge module.")
|
1432
1361
|
}
|
1433
1362
|
if (!description) {
|
1434
1363
|
throw new Error("'description' is a required parameter. The value should the description of the knowledge module.")
|
@@ -1438,82 +1367,44 @@ const knowledgeModule = async ({
|
|
1438
1367
|
}
|
1439
1368
|
|
1440
1369
|
const isProcess = require.main === moduleFromJSFile
|
1441
|
-
|
1442
|
-
|
1443
|
-
if (
|
1444
|
-
|
1370
|
+
|
1371
|
+
const setupConfig = (config) => {
|
1372
|
+
if (!config.name) {
|
1373
|
+
throw new Error("config must have 'name' set to the knowledge module name.")
|
1445
1374
|
}
|
1446
|
-
}
|
1447
1375
|
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
} else {
|
1454
|
-
return true
|
1455
|
-
}
|
1456
|
-
})
|
1457
|
-
config.config.bridges = config.config.bridges.filter( (bridge) => {
|
1458
|
-
if (bridge.development) {
|
1459
|
-
return false
|
1460
|
-
} else {
|
1461
|
-
return true
|
1376
|
+
config.description = description
|
1377
|
+
if (typeof test === 'object') {
|
1378
|
+
if (test.contents) {
|
1379
|
+
config.tests = test.contents
|
1380
|
+
test = test.name
|
1462
1381
|
}
|
1463
|
-
})
|
1464
|
-
}
|
1465
|
-
|
1466
|
-
let module
|
1467
|
-
if (_.isFunction(moduleFromJSFile)) {
|
1468
|
-
module = moduleFromJSFile
|
1469
|
-
} else {
|
1470
|
-
module = () => {
|
1471
|
-
config.rebuild({ isModule: true })
|
1472
|
-
moduleFromJSFile.exports = config
|
1473
|
-
}
|
1474
|
-
}
|
1475
|
-
processResults = processResults({ config, errorHandler })
|
1476
|
-
config.description = description
|
1477
|
-
config.demo = demo
|
1478
|
-
if (typeof test === 'object') {
|
1479
|
-
if (test.contents) {
|
1480
|
-
config.tests = test.contents
|
1481
|
-
test = test.name
|
1482
|
-
}
|
1483
|
-
} else {
|
1484
|
-
if (runtime.fs && runtime.fs.existsSync(test)) {
|
1485
|
-
config.tests = JSON.parse(runtime.fs.readFileSync(test))
|
1486
1382
|
} else {
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
if (!isProcess) {
|
1493
|
-
if (template) {
|
1494
|
-
if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess })) {
|
1495
|
-
const error = `This module "${config.name}" cannot be used because the instance file needs rebuilding. Run on the command line with no arguments or the -rt argument to rebuild.`
|
1496
|
-
throw new Error(error)
|
1497
|
-
}
|
1498
|
-
try {
|
1499
|
-
config.load(template.template, template.instance)
|
1500
|
-
} catch( e ) {
|
1501
|
-
errorHandler(e)
|
1383
|
+
if (runtime.fs && runtime.fs.existsSync(test)) {
|
1384
|
+
config.tests = JSON.parse(runtime.fs.readFileSync(test))
|
1385
|
+
} else {
|
1386
|
+
config.tests = {}
|
1502
1387
|
}
|
1503
1388
|
}
|
1389
|
+
config.setTestConfig(testConfig)
|
1504
1390
|
}
|
1391
|
+
|
1392
|
+
|
1505
1393
|
if (isProcess) {
|
1394
|
+
const config = createConfig()
|
1395
|
+
setupConfig(config)
|
1396
|
+
processResults = processResults({ config, errorHandler })
|
1506
1397
|
// setup();
|
1507
1398
|
const parser = new runtime.ArgumentParser({
|
1508
1399
|
description: 'Entodicton knowledge module'
|
1509
1400
|
})
|
1510
1401
|
|
1511
|
-
const helpDebugAssociation = 'In order to get a debug break when a specific association is created set the DEBUG_ASSOCIATION environment variable to the JSON of the association to break on. For example DEBUG_ASSOCIATION=\'[["the", 0], ["mammal", 1]]\'
|
1512
|
-
const helpDebugHierarchy = 'In order to get a debug break when a specific hierarchy is created set the DEBUG_HIERARCHY environment variable to the JSON of the child-parent pair to break on. For example DEBUG_HIERARCHY=\'[["cat", 1], ["mammel", 1]]\'
|
1513
|
-
const helpDebugPriority = 'In order to get a debug break when a specific set of priorities is created set set DEBUG_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_PRIORITY=\'[["verb", 0], ["article", 0]]\'
|
1514
|
-
const helpDebugContextualPriority = 'In order to get a debug break when a specific set of contextual priorities is created set set DEBUG_CONTEXTUAL_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_CONTEXTUAL_PRIORITY=\'{ context: [["verb", 0], ["article", 0], select: 1}\'
|
1515
|
-
const helpDebugBridge = 'In order to get a debug break when a specific bridge is created set the DEBUG_BRIDGE environment variable to id/level to break on. For example DEBUG_BRIDGE=\'id#level\'
|
1516
|
-
const helpDebugOperator = 'In order to get a debug break when a specific hierarcy is created set the DEBUG_OPERATOR environment variable to debug any config loaded. For example DEBUG_OPERATOR=\'([operator] ([arg]))\'
|
1402
|
+
const helpDebugAssociation = 'In order to get a debug break when a specific association is created set the DEBUG_ASSOCIATION environment variable to the JSON of the association to break on. For example DEBUG_ASSOCIATION=\'[["the", 0], ["mammal", 1]]\''
|
1403
|
+
const helpDebugHierarchy = 'In order to get a debug break when a specific hierarchy is created set the DEBUG_HIERARCHY environment variable to the JSON of the child-parent pair to break on. For example DEBUG_HIERARCHY=\'[["cat", 1], ["mammel", 1]]\''
|
1404
|
+
const helpDebugPriority = 'In order to get a debug break when a specific set of priorities is created set set DEBUG_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_PRIORITY=\'[["verb", 0], ["article", 0]]\''
|
1405
|
+
const helpDebugContextualPriority = 'In order to get a debug break when a specific set of contextual priorities is created set set DEBUG_CONTEXTUAL_PRIORITY environment variable to the JSON of the priorities that you want to break on. For example DEBUG_CONTEXTUAL_PRIORITY=\'{ context: [["verb", 0], ["article", 0], select: 1}\''
|
1406
|
+
const helpDebugBridge = 'In order to get a debug break when a specific bridge is created set the DEBUG_BRIDGE environment variable to id/level to break on. For example DEBUG_BRIDGE=\'id#level\''
|
1407
|
+
const helpDebugOperator = 'In order to get a debug break when a specific hierarcy is created set the DEBUG_OPERATOR environment variable to debug any config loaded. For example DEBUG_OPERATOR=\'([operator] ([arg]))\''
|
1517
1408
|
|
1518
1409
|
|
1519
1410
|
parser.add_argument('-tmn', '--testModuleName', { help: 'When running tests instead of using the current modules tests use the specified modules tests' })
|
@@ -1624,6 +1515,10 @@ const knowledgeModule = async ({
|
|
1624
1515
|
|
1625
1516
|
}
|
1626
1517
|
config.load(template.template, template.instance, { rebuild: needsRebuild })
|
1518
|
+
if (config.name == 'ui') {
|
1519
|
+
console.log('config.COUNTER', config.COUNTER)
|
1520
|
+
debugger
|
1521
|
+
}
|
1627
1522
|
if (needsRebuild) {
|
1628
1523
|
return
|
1629
1524
|
}
|
@@ -1631,20 +1526,8 @@ const knowledgeModule = async ({
|
|
1631
1526
|
|
1632
1527
|
if (!args.save && !args.rebuildTemplate && !args.dontAddAssociations) {
|
1633
1528
|
config.addAssociationsFromTests(config.tests);
|
1634
|
-
//for (let query in config.tests) {
|
1635
|
-
// config.addAssociations(config.tests[query].associations || []);
|
1636
|
-
//}
|
1637
1529
|
}
|
1638
1530
|
|
1639
|
-
/*
|
1640
|
-
if (args.buildTemplate) {
|
1641
|
-
if (template) {
|
1642
|
-
config.rebuild()
|
1643
|
-
config.load(template.template, template.instance, { rebuild: true })
|
1644
|
-
}
|
1645
|
-
}
|
1646
|
-
*/
|
1647
|
-
|
1648
1531
|
let configPrinted = false
|
1649
1532
|
const printConfig = () => {
|
1650
1533
|
if (configPrinted) {
|
@@ -1892,7 +1775,6 @@ const knowledgeModule = async ({
|
|
1892
1775
|
if (query.length === 0) {
|
1893
1776
|
return readline.close()
|
1894
1777
|
}
|
1895
|
-
// const promise = processResults(_process(config, query, { testsFN: test }))
|
1896
1778
|
const promise = _process(config, query, { testsFN: test }).then((results) => {
|
1897
1779
|
console.log(results.responses.join(' '))
|
1898
1780
|
})
|
@@ -1920,7 +1802,6 @@ const knowledgeModule = async ({
|
|
1920
1802
|
if (args.objectDiff) {
|
1921
1803
|
global.beforeObjects = _.cloneDeep(objects)
|
1922
1804
|
}
|
1923
|
-
config.beforeQuery({ query: args.query, isModule: false, objects })
|
1924
1805
|
try {
|
1925
1806
|
await processResults(_process(config, args.query, { commandLineArgs: args, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
1926
1807
|
} catch( error ) {
|
@@ -1929,11 +1810,55 @@ const knowledgeModule = async ({
|
|
1929
1810
|
}
|
1930
1811
|
printConfig()
|
1931
1812
|
} else {
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1813
|
+
const initConfig = (config) => {
|
1814
|
+
setupConfig(config)
|
1815
|
+
|
1816
|
+
let loadForTesting = false
|
1817
|
+
if (global.theprogrammablemind) {
|
1818
|
+
if (global.theprogrammablemind.loadForTesting[config.name]) {
|
1819
|
+
loadForTesting = true
|
1820
|
+
}
|
1821
|
+
}
|
1822
|
+
// remove test only stuff
|
1823
|
+
if (!isProcess && !loadForTesting) {
|
1824
|
+
config.config.operators = config.config.operators.filter( (operator) => {
|
1825
|
+
if (operator.development) {
|
1826
|
+
return false
|
1827
|
+
} else {
|
1828
|
+
return true
|
1829
|
+
}
|
1830
|
+
})
|
1831
|
+
config.config.bridges = config.config.bridges.filter( (bridge) => {
|
1832
|
+
if (bridge.development) {
|
1833
|
+
return false
|
1834
|
+
} else {
|
1835
|
+
return true
|
1836
|
+
}
|
1837
|
+
})
|
1838
|
+
}
|
1839
|
+
|
1840
|
+
if (template) {
|
1841
|
+
if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess })) {
|
1842
|
+
const error = `This module "${config.name}" cannot be used because the instance file needs rebuilding. Run on the command line with no arguments or the -rt argument to rebuild.`
|
1843
|
+
throw new Error(error)
|
1844
|
+
}
|
1845
|
+
try {
|
1846
|
+
config.load(template.template, template.instance)
|
1847
|
+
} catch( e ) {
|
1848
|
+
errorHandler(e)
|
1849
|
+
}
|
1850
|
+
}
|
1851
|
+
|
1852
|
+
config.addAssociationsFromTests(config.tests);
|
1853
|
+
}
|
1854
|
+
|
1855
|
+
createConfigExport = () => {
|
1856
|
+
const config = createConfig()
|
1857
|
+
initConfig(config)
|
1858
|
+
config.rebuild({ isModule: true })
|
1859
|
+
return config
|
1860
|
+
}
|
1861
|
+
moduleFromJSFile.exports = createConfigExport
|
1937
1862
|
}
|
1938
1863
|
|
1939
1864
|
}
|