theprogrammablemind 8.9.1-beta.2 → 8.9.1-beta.20
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 +24 -26
- package/package.json +4 -2
- package/src/config.js +26 -27
- package/src/configHelpers.js +9 -3
- package/src/digraph.js +6 -6
- package/src/digraph_internal.js +7 -8
- package/src/helpers.js +1 -1
- package/src/semantics.js +1 -1
package/client.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
const { Semantics, Semantic } = require('./src/semantics')
|
2
2
|
const { Generators, Generator } = require('./src/generators')
|
3
3
|
const { Config } = require('./src/config')
|
4
|
-
const { loadInstance, ErrorReason, listable, setupArgs, gs, processContext, getObjects, setupProcessB, processContextsB
|
4
|
+
const { loadInstance, ErrorReason, listable, setupArgs, gs, processContext, getObjects, setupProcessB, processContextsB } = require('./src/configHelpers')
|
5
5
|
const DigraphInternal = require('./src/digraph_internal')
|
6
6
|
const Digraph = require('./src/digraph')
|
7
7
|
const { project } = require('./src/project')
|
@@ -23,7 +23,7 @@ const getConfig_getObjectsCheck = (config, testConfig) => {
|
|
23
23
|
}
|
24
24
|
const checks = (testConfig.checks && testConfig.checks.objects) || []
|
25
25
|
if (Array.isArray(checks)) {
|
26
|
-
const kmToChecks = { [testConfigName]: checks.filter(
|
26
|
+
const kmToChecks = { [testConfigName]: checks.filter((check) => !check.km) }
|
27
27
|
for (const check of checks) {
|
28
28
|
if (check.km) {
|
29
29
|
kmToChecks[check.km] = config.km(check.km).testConfig.checks.objects
|
@@ -53,7 +53,7 @@ const pickObjects = (config, testConfig, getObjects) => {
|
|
53
53
|
*/
|
54
54
|
const checks = getConfig_getObjectsCheck(config, testConfig)
|
55
55
|
const projection = {}
|
56
|
-
for (
|
56
|
+
for (const km in checks) {
|
57
57
|
const objects = getObjects(km)
|
58
58
|
if (!objects) {
|
59
59
|
throw new Error(`In the checks for ${config.name} the KM ${km} does not exist`)
|
@@ -72,9 +72,9 @@ const sameJSON = (json1, json2) => {
|
|
72
72
|
const vimdiff = (actualJSON, expectedJSON, title) => {
|
73
73
|
const path = '.'
|
74
74
|
const actual = sortJson(actualJSON, { depth: 25 })
|
75
|
-
runtime.fs.writeFileSync(`${path}/actual.json`, JSON.stringify({ title, actual}, 0, 2))
|
75
|
+
runtime.fs.writeFileSync(`${path}/actual.json`, JSON.stringify({ title, actual }, 0, 2))
|
76
76
|
const expected = sortJson(expectedJSON, { depth: 25 })
|
77
|
-
runtime.fs.writeFileSync(`${path}/expected.json`, JSON.stringify({ title, expected}, 0, 2))
|
77
|
+
runtime.fs.writeFileSync(`${path}/expected.json`, JSON.stringify({ title, expected }, 0, 2))
|
78
78
|
// console.log(`vimdiff ${path}/actual.json ${path}/expected.json`)
|
79
79
|
{
|
80
80
|
const editor = runtime.process.env.EDITOR || 'vimdiff'
|
@@ -326,7 +326,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
326
326
|
}
|
327
327
|
}
|
328
328
|
json.contexts = json.results
|
329
|
-
startCounter= json.end_counter + 1
|
329
|
+
startCounter = json.end_counter + 1
|
330
330
|
delete json.results
|
331
331
|
if (json.status !== 200) {
|
332
332
|
throw json
|
@@ -364,7 +364,6 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
364
364
|
response.generatedParenthesized = response.generatedParenthesized.concat(generatedParenthesizedPrime)
|
365
365
|
response.responses = response.responses.concat(responsesPrime)
|
366
366
|
queries = queries.slice(1)
|
367
|
-
|
368
367
|
}
|
369
368
|
}
|
370
369
|
|
@@ -397,7 +396,7 @@ const getConfigForTest = (config, testConfig) => {
|
|
397
396
|
configForTest.words = {
|
398
397
|
literals: {},
|
399
398
|
patterns: [],
|
400
|
-
hierarchy: []
|
399
|
+
hierarchy: []
|
401
400
|
}
|
402
401
|
|
403
402
|
const literals = config.config.words.literals
|
@@ -427,7 +426,7 @@ const getConfigForTest = (config, testConfig) => {
|
|
427
426
|
if (Array.isArray(includes.operators)) {
|
428
427
|
include = (operator) => includes.operators.includes(operator.pattern)
|
429
428
|
}
|
430
|
-
configForTest.operators = config.config.operators.filter(
|
429
|
+
configForTest.operators = config.config.operators.filter(include).map((operator) => Object.assign({}, operator, { uuid: undefined }))
|
431
430
|
} else if (key === 'bridges') {
|
432
431
|
let include = (operator) => true
|
433
432
|
if (Array.isArray(includes.bridges)) {
|
@@ -441,7 +440,7 @@ const getConfigForTest = (config, testConfig) => {
|
|
441
440
|
return configForTest
|
442
441
|
}
|
443
442
|
|
444
|
-
const runTest = async (config, expected, { args, verbose, testConfig, debug, timings={ server: 0, client: 0 } }) => {
|
443
|
+
const runTest = async (config, expected, { args, verbose, testConfig, debug, timings = { server: 0, client: 0 } }) => {
|
445
444
|
const test = expected.query
|
446
445
|
if (args.query && args.query != test) {
|
447
446
|
// no run this
|
@@ -460,7 +459,7 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug, tim
|
|
460
459
|
defaultErrorHandler(error)
|
461
460
|
}
|
462
461
|
|
463
|
-
|
462
|
+
const objects = getObjects(config.config.objects)(config.uuid)
|
464
463
|
try {
|
465
464
|
const result = await _process(config, test, { errorHandler, isTest: true })
|
466
465
|
result.query = test
|
@@ -768,13 +767,13 @@ const printContextualPrioritiesAmbiguities = (cpa) => {
|
|
768
767
|
console.log(` Counter ${counter}`)
|
769
768
|
for (const choices of cpa[counter]) {
|
770
769
|
console.log(' [')
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
}
|
776
|
-
console.log(' ],')
|
770
|
+
for (const choice of choices) {
|
771
|
+
console.log(' [')
|
772
|
+
for (const element of choice) {
|
773
|
+
console.log(` ${JSON.stringify(element)},`)
|
777
774
|
}
|
775
|
+
console.log(' ],')
|
776
|
+
}
|
778
777
|
console.log(' ],')
|
779
778
|
}
|
780
779
|
}
|
@@ -873,7 +872,7 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
873
872
|
console.log('')
|
874
873
|
const screen_width = process.stdout.columns
|
875
874
|
// || 0 for when running without a console
|
876
|
-
const widths = [70, 10, Math.max(80, screen_width-71 || 0)]
|
875
|
+
const widths = [70, 10, Math.max(80, screen_width - 71 || 0)]
|
877
876
|
const lines = new Lines(widths)
|
878
877
|
lines.setElement(0, 0, '--- The paraphrases are ----------')
|
879
878
|
lines.setElement(0, 2, '--- The response strings are ----------')
|
@@ -922,7 +921,7 @@ const rebuildTemplate = async ({ config, target, previousResultss, startOfChange
|
|
922
921
|
// queries are strings or { query: "blah", development: true/false }
|
923
922
|
if (typeof queryOrExtraConfig === 'string' || queryOrExtraConfig.query || queryOrExtraConfig.isFragment) {
|
924
923
|
let query = queryOrExtraConfig
|
925
|
-
|
924
|
+
const isFragment = queryOrExtraConfig.isFragment
|
926
925
|
if (typeof queryOrExtraConfig === 'string') {
|
927
926
|
query = { query }
|
928
927
|
}
|
@@ -1096,14 +1095,14 @@ const checkTest = (testConfig) => {
|
|
1096
1095
|
if (!testConfig.contents) {
|
1097
1096
|
throw new Error("The 'test' property is missing the 'contents' property that contains contents of the '<km>.test.json' file")
|
1098
1097
|
}
|
1099
|
-
if (testConfig.checks?.context && typeof testConfig.checks.context
|
1098
|
+
if (testConfig.checks?.context && typeof testConfig.checks.context === 'function') {
|
1100
1099
|
throw new Error(`The 'test.check.context' property should not be a function for ${testConfig.name}. If you are using defaultContextCheck then do this defaultContextCheck().`)
|
1101
1100
|
}
|
1102
1101
|
}
|
1103
1102
|
|
1104
1103
|
const knowledgeModuleImpl = async ({
|
1105
1104
|
includes,
|
1106
|
-
config
|
1105
|
+
config: configStruct,
|
1107
1106
|
api,
|
1108
1107
|
initializer,
|
1109
1108
|
terminator,
|
@@ -1248,7 +1247,7 @@ const knowledgeModuleImpl = async ({
|
|
1248
1247
|
}
|
1249
1248
|
|
1250
1249
|
config = await createConfig()
|
1251
|
-
|
1250
|
+
|
1252
1251
|
// dont debug the load of the KM's if rebuild template is on since we want to debug the template rebuild not the load
|
1253
1252
|
if (args.rebuildTemplate) {
|
1254
1253
|
global.pauseDebugging = true
|
@@ -1398,7 +1397,7 @@ const knowledgeModuleImpl = async ({
|
|
1398
1397
|
// { literals: Object, patterns: Array(2), hierarchy: Array(97) }
|
1399
1398
|
console.log('literals')
|
1400
1399
|
for (const word in config.config.words.literals) {
|
1401
|
-
console.log(' ' + word.concat(...config.config.words.literals[word].map((def, i) => ((i > 0) ? ' '.repeat(4+word.length) : ' ') + JSON.stringify(def) + '\n')))
|
1400
|
+
console.log(' ' + word.concat(...config.config.words.literals[word].map((def, i) => ((i > 0) ? ' '.repeat(4 + word.length) : ' ') + JSON.stringify(def) + '\n')))
|
1402
1401
|
}
|
1403
1402
|
console.log('patterns')
|
1404
1403
|
for (const pattern of config.config.words.patterns) {
|
@@ -1567,7 +1566,6 @@ const knowledgeModuleImpl = async ({
|
|
1567
1566
|
}
|
1568
1567
|
}
|
1569
1568
|
|
1570
|
-
|
1571
1569
|
console.log(`Total Server Time: ${timings.server.toFixed(2)}. Total Client Time: ${timings.client.toFixed(2)}`)
|
1572
1570
|
if (hasError) {
|
1573
1571
|
console.log('**************************** ERRORS ************************')
|
@@ -1723,7 +1721,7 @@ const knowledgeModuleImpl = async ({
|
|
1723
1721
|
})
|
1724
1722
|
f()
|
1725
1723
|
} else if (args.query) {
|
1726
|
-
|
1724
|
+
const useTestConfig = testConfig
|
1727
1725
|
if (args.testModuleName) {
|
1728
1726
|
config.testConfig.testModuleName = args.testModuleName
|
1729
1727
|
config.testConfig.checks = config.getConfigs()[args.testModuleName].getTestConfig().checks
|
@@ -1855,5 +1853,5 @@ module.exports = {
|
|
1855
1853
|
gs,
|
1856
1854
|
flattens,
|
1857
1855
|
writeTest,
|
1858
|
-
getConfigForTest
|
1856
|
+
getConfigForTest
|
1859
1857
|
}
|
package/package.json
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"devDependencies": {
|
3
|
+
"@eslint/js": "^9.21.0",
|
3
4
|
"@typescript-eslint/eslint-plugin": "^4.28.4",
|
4
5
|
"@typescript-eslint/parser": "^4.28.4",
|
5
|
-
"eslint": "^7.
|
6
|
+
"eslint": "^7.32.0",
|
6
7
|
"eslint-config-standard": "^16.0.3",
|
7
8
|
"eslint-plugin-import": "^2.23.4",
|
8
9
|
"eslint-plugin-node": "^11.1.0",
|
9
10
|
"eslint-plugin-promise": "^5.1.0",
|
11
|
+
"globals": "^16.0.0",
|
10
12
|
"jest": "^29.7.0"
|
11
13
|
},
|
12
14
|
"scripts": {
|
@@ -65,6 +67,6 @@
|
|
65
67
|
"sort-json": "^2.0.0",
|
66
68
|
"uuid": "^8.3.2"
|
67
69
|
},
|
68
|
-
"version": "8.9.1-beta.
|
70
|
+
"version": "8.9.1-beta.20",
|
69
71
|
"license": "UNLICENSED"
|
70
72
|
}
|
package/src/config.js
CHANGED
@@ -132,8 +132,7 @@ const debugConfigProps = (config) => {
|
|
132
132
|
check(value)
|
133
133
|
}
|
134
134
|
}
|
135
|
-
}
|
136
|
-
else if (config[property]) {
|
135
|
+
} else if (config[property]) {
|
137
136
|
for (const value of config[property]) {
|
138
137
|
check(value)
|
139
138
|
}
|
@@ -400,7 +399,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
400
399
|
match: (args) => bridge.id == args.context.marker && !!args.context.evaluate == evaluate && match(args),
|
401
400
|
apply: (args) => apply(args),
|
402
401
|
applyWrapped: semantic,
|
403
|
-
property: evaluate ? 'evaluator':'semantic'
|
402
|
+
property: evaluate ? 'evaluator' : 'semantic'
|
404
403
|
}
|
405
404
|
if (addFirst) {
|
406
405
|
config.config.semantics.unshift(addUUID(semanticDef))
|
@@ -531,7 +530,7 @@ const addWord = (config, uuid) => ({ word, id, initial }) => {
|
|
531
530
|
config.words = {
|
532
531
|
literals: {},
|
533
532
|
patterns: [],
|
534
|
-
hierarchy: []
|
533
|
+
hierarchy: []
|
535
534
|
}
|
536
535
|
}
|
537
536
|
const literals = config.words.literals
|
@@ -610,7 +609,7 @@ function setWordsUUIDs (words, uuid) {
|
|
610
609
|
}
|
611
610
|
const hierarchy = words.hierarchy
|
612
611
|
for (const pair of hierarchy) {
|
613
|
-
pair.uuid = uuid
|
612
|
+
pair.uuid = uuid
|
614
613
|
}
|
615
614
|
}
|
616
615
|
|
@@ -938,7 +937,7 @@ class Config {
|
|
938
937
|
words: {
|
939
938
|
literals: {},
|
940
939
|
patterns: [],
|
941
|
-
hierarchy: []
|
940
|
+
hierarchy: []
|
942
941
|
}, // Done
|
943
942
|
floaters: [],
|
944
943
|
implicits: [],
|
@@ -998,7 +997,7 @@ class Config {
|
|
998
997
|
}
|
999
998
|
}
|
1000
999
|
|
1001
|
-
get semantics() {
|
1000
|
+
get semantics () {
|
1002
1001
|
return [...this.config.semantics]
|
1003
1002
|
}
|
1004
1003
|
|
@@ -1044,7 +1043,7 @@ class Config {
|
|
1044
1043
|
// const todo = [...instantiated]
|
1045
1044
|
// const todo = [...instantiated]
|
1046
1045
|
const todo = _.clone(instantiated)
|
1047
|
-
args = {...args}
|
1046
|
+
args = { ...args }
|
1048
1047
|
while (todo.length > 0) {
|
1049
1048
|
const context = todo.pop()
|
1050
1049
|
args.context = context
|
@@ -1125,18 +1124,18 @@ class Config {
|
|
1125
1124
|
delete config.where
|
1126
1125
|
|
1127
1126
|
if (config.words && config.words.hierarchy) {
|
1128
|
-
config.words.hierarchy = config.words.hierarchy.map(
|
1129
|
-
value = {...value}
|
1127
|
+
config.words.hierarchy = config.words.hierarchy.map((value) => {
|
1128
|
+
value = { ...value }
|
1130
1129
|
delete value.uuid
|
1131
1130
|
return value
|
1132
1131
|
})
|
1133
1132
|
}
|
1134
1133
|
|
1135
1134
|
if (config.words && config.words.patterns) {
|
1136
|
-
config.words.patterns = config.words.patterns.map(
|
1137
|
-
value = {...value}
|
1138
|
-
value.defs = value.defs.map(
|
1139
|
-
value = {...value}
|
1135
|
+
config.words.patterns = config.words.patterns.map((value) => {
|
1136
|
+
value = { ...value }
|
1137
|
+
value.defs = value.defs.map((value) => {
|
1138
|
+
value = { ...value }
|
1140
1139
|
delete value.uuid
|
1141
1140
|
return value
|
1142
1141
|
})
|
@@ -1174,7 +1173,7 @@ class Config {
|
|
1174
1173
|
delete bridge.semantic
|
1175
1174
|
delete bridge.semantics
|
1176
1175
|
if (!bridge.bridge) {
|
1177
|
-
bridge.bridge =
|
1176
|
+
bridge.bridge = '{ ...next(operator) }'
|
1178
1177
|
}
|
1179
1178
|
return bridge
|
1180
1179
|
})
|
@@ -1237,7 +1236,7 @@ class Config {
|
|
1237
1236
|
let hasQueryOrFragment = false
|
1238
1237
|
for (let rest = iq; rest < templateQueries.length; ++rest) {
|
1239
1238
|
const value = templateQueries[rest]
|
1240
|
-
if (typeof value
|
1239
|
+
if (typeof value === 'string' || (value.query && value.isFragment)) {
|
1241
1240
|
hasQueryOrFragment = true
|
1242
1241
|
break
|
1243
1242
|
}
|
@@ -1247,7 +1246,7 @@ class Config {
|
|
1247
1246
|
startOfChanges = iq
|
1248
1247
|
}
|
1249
1248
|
}
|
1250
|
-
break
|
1249
|
+
break
|
1251
1250
|
}
|
1252
1251
|
}
|
1253
1252
|
|
@@ -1396,7 +1395,7 @@ class Config {
|
|
1396
1395
|
|
1397
1396
|
addHierarchyInternal (edge) {
|
1398
1397
|
debugHierarchy([edge[0], edge[1]])
|
1399
|
-
// because this is called from the semantics and internally. in the semantics the config can be a pseudo config
|
1398
|
+
// because this is called from the semantics and internally. in the semantics the config can be a pseudo config
|
1400
1399
|
// where hierarchy and config.hierarchy do not match
|
1401
1400
|
if (this.hierarchy) {
|
1402
1401
|
this.hierarchy.addEdge(edge)
|
@@ -1588,7 +1587,7 @@ class Config {
|
|
1588
1587
|
this.config.words = {
|
1589
1588
|
literals: {},
|
1590
1589
|
patterns: [],
|
1591
|
-
hierarchy: []
|
1590
|
+
hierarchy: []
|
1592
1591
|
}
|
1593
1592
|
}
|
1594
1593
|
debugWord(word)
|
@@ -1611,7 +1610,7 @@ class Config {
|
|
1611
1610
|
this.config.words = {
|
1612
1611
|
literals: {},
|
1613
1612
|
patterns: [],
|
1614
|
-
hierarchy: []
|
1613
|
+
hierarchy: []
|
1615
1614
|
}
|
1616
1615
|
}
|
1617
1616
|
|
@@ -1834,7 +1833,7 @@ class Config {
|
|
1834
1833
|
let defs = pattern.defs || []
|
1835
1834
|
defs = defs.filter((def) => !def.development)
|
1836
1835
|
if (defs.length !== 0) {
|
1837
|
-
patternsPrime.push({...pattern, defs})
|
1836
|
+
patternsPrime.push({ ...pattern, defs })
|
1838
1837
|
}
|
1839
1838
|
}
|
1840
1839
|
config.words.patterns = patternsPrime
|
@@ -1849,7 +1848,7 @@ class Config {
|
|
1849
1848
|
config.words.hierarchy = hierarchyPrime
|
1850
1849
|
}
|
1851
1850
|
|
1852
|
-
terminate() {
|
1851
|
+
terminate () {
|
1853
1852
|
this.configs.forEach((km) => {
|
1854
1853
|
const config = km.config
|
1855
1854
|
if (!config.terminatorFn) {
|
@@ -1860,7 +1859,7 @@ class Config {
|
|
1860
1859
|
})
|
1861
1860
|
}
|
1862
1861
|
|
1863
|
-
setTerminator(terminatorFn) {
|
1862
|
+
setTerminator (terminatorFn) {
|
1864
1863
|
if (terminatorFn) {
|
1865
1864
|
this.terminatorFn = terminatorFn
|
1866
1865
|
}
|
@@ -1968,11 +1967,11 @@ class Config {
|
|
1968
1967
|
this.addedArgss.push(moreArgs)
|
1969
1968
|
}
|
1970
1969
|
|
1971
|
-
stop_auto_rebuild() {
|
1970
|
+
stop_auto_rebuild () {
|
1972
1971
|
this._stop_auto_rebuild = true
|
1973
1972
|
}
|
1974
1973
|
|
1975
|
-
async restart_auto_rebuild() {
|
1974
|
+
async restart_auto_rebuild () {
|
1976
1975
|
this._stop_auto_rebuild = false
|
1977
1976
|
await this.rebuild()
|
1978
1977
|
}
|
@@ -2975,7 +2974,7 @@ class Config {
|
|
2975
2974
|
async add (...createConfigs) {
|
2976
2975
|
createConfigs.forEach((createConfig, index) => {
|
2977
2976
|
if (typeof createConfig !== 'function') {
|
2978
|
-
throw new Error(`Expected add argument number ${index+1} to be a function that constructs the config.`)
|
2977
|
+
throw new Error(`Expected add argument number ${index + 1} to be a function that constructs the config.`)
|
2979
2978
|
}
|
2980
2979
|
})
|
2981
2980
|
|
@@ -3330,5 +3329,5 @@ module.exports = {
|
|
3330
3329
|
Config,
|
3331
3330
|
config_toServer,
|
3332
3331
|
operatorKey_valid,
|
3333
|
-
handleBridgeProps
|
3332
|
+
handleBridgeProps
|
3334
3333
|
}
|
package/src/configHelpers.js
CHANGED
@@ -29,7 +29,7 @@ const gs = (g) => async (contexts, separator, lastSeparator) => {
|
|
29
29
|
return s
|
30
30
|
}
|
31
31
|
|
32
|
-
const isA = (hierarchy) => (child, parent, { strict=false } = {}) => {
|
32
|
+
const isA = (hierarchy) => (child, parent, { strict = false } = {}) => {
|
33
33
|
if (!child || !parent) {
|
34
34
|
return false
|
35
35
|
}
|
@@ -81,7 +81,6 @@ const cleanAssign = (dest, ...srcs) => {
|
|
81
81
|
}
|
82
82
|
|
83
83
|
const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
84
|
-
|
85
84
|
// callId
|
86
85
|
args.calls = new InitCalls(args.isInstance ? `${args.isInstance}#${config.name}` : config.name)
|
87
86
|
if (global.theprogrammablemind && global.theprogrammablemind.loadForTesting) {
|
@@ -251,6 +250,13 @@ const setupContexts = (rawContexts) => {
|
|
251
250
|
contexts.push(context)
|
252
251
|
}
|
253
252
|
contexts.push({ marker: 'controlEnd', controlRemove: true })
|
253
|
+
|
254
|
+
let _index = 0
|
255
|
+
const id = (context) => {
|
256
|
+
context.context_index = _index
|
257
|
+
++_index
|
258
|
+
}
|
259
|
+
contexts.forEach( id )
|
254
260
|
return contexts
|
255
261
|
}
|
256
262
|
|
@@ -440,5 +446,5 @@ module.exports = {
|
|
440
446
|
gs,
|
441
447
|
processContextsB,
|
442
448
|
loadInstance,
|
443
|
-
isA
|
449
|
+
isA
|
444
450
|
}
|
package/src/digraph.js
CHANGED
@@ -132,7 +132,7 @@ class Digraph {
|
|
132
132
|
for (const node of nodes) {
|
133
133
|
nodeToDescendants[node] = this.descendants(node)
|
134
134
|
}
|
135
|
-
|
135
|
+
const minima = new Set()
|
136
136
|
for (const node of nodes) {
|
137
137
|
let okay = true
|
138
138
|
for (const key of nodeToDescendants[node]) {
|
@@ -156,17 +156,17 @@ class Digraph {
|
|
156
156
|
return new Set([])
|
157
157
|
}
|
158
158
|
debugger
|
159
|
-
nodes = Array.from(nodes)
|
159
|
+
nodes = Array.from(nodes)
|
160
160
|
let common = this.ancestors(nodes[0], { includeSelf: true })
|
161
161
|
|
162
162
|
for (let i = 1; i < nodes.length; i++) {
|
163
163
|
const ancestors = this.ancestors(nodes[i], { includeSelf: true })
|
164
164
|
common = new Set([...common].filter(x => ancestors.has(x)))
|
165
165
|
if (common.size === 0) {
|
166
|
-
break
|
166
|
+
break
|
167
167
|
}
|
168
168
|
}
|
169
|
-
return this.minima(common)
|
169
|
+
return this.minima(common)
|
170
170
|
}
|
171
171
|
|
172
172
|
/*
|
@@ -185,13 +185,13 @@ class Digraph {
|
|
185
185
|
this._edges.push([child, parent])
|
186
186
|
}
|
187
187
|
|
188
|
-
exists(child, parent) {
|
188
|
+
exists (child, parent) {
|
189
189
|
return this._edges.find((edge) => edge[0] == child && edge[1] == parent)
|
190
190
|
}
|
191
191
|
|
192
192
|
addList (l) {
|
193
193
|
for (let i = 1; i < l.length; ++i) {
|
194
|
-
if (!this.exists(l[i-1], l[i])) {
|
194
|
+
if (!this.exists(l[i - 1], l[i])) {
|
195
195
|
this._edges.push([l[i - 1], l[i]])
|
196
196
|
}
|
197
197
|
}
|
package/src/digraph_internal.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const _ = require('lodash')
|
1
|
+
const _ = require('lodash')
|
2
2
|
|
3
3
|
const toA = (edge) => {
|
4
4
|
if (Array.isArray(edge)) {
|
@@ -92,7 +92,6 @@ class DigraphInternal {
|
|
92
92
|
ancestors.add(s)
|
93
93
|
}
|
94
94
|
return ancestors
|
95
|
-
|
96
95
|
}
|
97
96
|
|
98
97
|
minima (nodes) {
|
@@ -101,7 +100,7 @@ class DigraphInternal {
|
|
101
100
|
for (const node of nodes) {
|
102
101
|
nodeToDescendants[node] = this.descendants(node)
|
103
102
|
}
|
104
|
-
|
103
|
+
const minima = new Set()
|
105
104
|
for (const node of nodes) {
|
106
105
|
let okay = true
|
107
106
|
for (const key of nodeToDescendants[node]) {
|
@@ -124,17 +123,17 @@ class DigraphInternal {
|
|
124
123
|
if (nodes.length === 0) {
|
125
124
|
return new Set([])
|
126
125
|
}
|
127
|
-
nodes = Array.from(nodes)
|
126
|
+
nodes = Array.from(nodes)
|
128
127
|
let common = this.ancestors(nodes[0], { includeSelf: true })
|
129
128
|
|
130
129
|
for (let i = 1; i < nodes.length; i++) {
|
131
130
|
const ancestors = this.ancestors(nodes[i], { includeSelf: true })
|
132
131
|
common = new Set([...common].filter(x => ancestors.has(x)))
|
133
132
|
if (common.size === 0) {
|
134
|
-
break
|
133
|
+
break
|
135
134
|
}
|
136
135
|
}
|
137
|
-
return this.minima(common)
|
136
|
+
return this.minima(common)
|
138
137
|
}
|
139
138
|
|
140
139
|
/*
|
@@ -153,13 +152,13 @@ class DigraphInternal {
|
|
153
152
|
this._edges.push([child, parent])
|
154
153
|
}
|
155
154
|
|
156
|
-
exists(child, parent) {
|
155
|
+
exists (child, parent) {
|
157
156
|
return this._edges.findIndex((edge) => edge[0] == child && edge[1] == parent) != -1
|
158
157
|
}
|
159
158
|
|
160
159
|
addList (l) {
|
161
160
|
for (let i = 1; i < l.length; ++i) {
|
162
|
-
if (!this.exists(l[i-1], l[i])) {
|
161
|
+
if (!this.exists(l[i - 1], l[i])) {
|
163
162
|
this._edges.push([l[i - 1], l[i]])
|
164
163
|
}
|
165
164
|
}
|
package/src/helpers.js
CHANGED
package/src/semantics.js
CHANGED
@@ -182,7 +182,7 @@ class Semantics {
|
|
182
182
|
let deferWasCalled = false
|
183
183
|
const defer = (listener) => {
|
184
184
|
deferred.push({ semantic, listener })
|
185
|
-
deferWasCalled = true
|
185
|
+
deferWasCalled = true
|
186
186
|
}
|
187
187
|
args.defer = defer
|
188
188
|
contextPrime = await semantic.apply(args, context, s, options)
|