theprogrammablemind 8.9.0-beta.1 → 8.9.0-beta.10

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/package.json CHANGED
@@ -65,6 +65,6 @@
65
65
  "sort-json": "^2.0.0",
66
66
  "uuid": "^8.3.2"
67
67
  },
68
- "version": "8.9.0-beta.1",
68
+ "version": "8.9.0-beta.10",
69
69
  "license": "UNLICENSED"
70
70
  }
@@ -40,12 +40,20 @@ const asList = (context) => {
40
40
  }
41
41
  }
42
42
 
43
- const isA = (hierarchy) => (child, parent, { extended=false } = {}) => {
43
+ const isA = (hierarchy) => (child, parent, { strict=false } = {}) => {
44
44
  if (!child || !parent) {
45
45
  return false
46
46
  }
47
47
 
48
- if (extended) {
48
+ if (strict) {
49
+ if (child.marker) {
50
+ child = child.marker
51
+ }
52
+ if (parent.marker) {
53
+ parent = parent.marker
54
+ }
55
+ return hierarchy.isA(child, parent)
56
+ } else {
49
57
  if (hierarchy.isA(child.marker || child, parent.marker || parent)) {
50
58
  return true
51
59
  }
@@ -57,14 +65,6 @@ const isA = (hierarchy) => (child, parent, { extended=false } = {}) => {
57
65
  }
58
66
  }
59
67
  return false
60
- } else {
61
- if (child.marker) {
62
- child = child.marker
63
- }
64
- if (parent.marker) {
65
- parent = parent.marker
66
- }
67
- return hierarchy.isA(child, parent)
68
68
  }
69
69
  }
70
70
 
@@ -468,4 +468,5 @@ module.exports = {
468
468
  gs,
469
469
  processContextsB,
470
470
  loadInstance,
471
+ isA,
471
472
  }
package/src/digraph.js CHANGED
@@ -118,8 +118,12 @@ class Digraph {
118
118
  return this.acdcs(s, 1, 0)
119
119
  }
120
120
 
121
- ancestors (s) {
122
- return this.acdcs(s, 0, 1)
121
+ ancestors (s, { includeSelf } = {}) {
122
+ const ancestors = this.acdcs(s, 0, 1)
123
+ if (includeSelf) {
124
+ ancestors.add(s)
125
+ }
126
+ return ancestors
123
127
  }
124
128
 
125
129
  minima (nodes) {
@@ -147,6 +151,24 @@ class Digraph {
147
151
  return minima
148
152
  }
149
153
 
154
+ lub (nodes) {
155
+ if (nodes.length === 0) {
156
+ return new Set([])
157
+ }
158
+ debugger
159
+ nodes = Array.from(nodes);
160
+ let common = this.ancestors(nodes[0], { includeSelf: true })
161
+
162
+ for (let i = 1; i < nodes.length; i++) {
163
+ const ancestors = this.ancestors(nodes[i], { includeSelf: true })
164
+ common = new Set([...common].filter(x => ancestors.has(x)))
165
+ if (common.size === 0) {
166
+ break;
167
+ }
168
+ }
169
+ return this.minima(common);
170
+ }
171
+
150
172
  /*
151
173
  maxima (nodes) {
152
174
  const maxima = new Set(nodes)