skynet-graph 1.2.0
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/CONTRIBUTING.md +22 -0
- package/LICENSE +661 -0
- package/README.md +245 -0
- package/bin/sg +20 -0
- package/concepts/README.md +23 -0
- package/concepts/_substrate/Claim/Confidence/Trusted.json +6 -0
- package/concepts/_substrate/Claim/Confidence.json +10 -0
- package/concepts/_substrate/Claim/Freshness/Stale.json +7 -0
- package/concepts/_substrate/Claim/Freshness.json +5 -0
- package/concepts/_substrate/Claim/Verification/Refuted.json +6 -0
- package/concepts/_substrate/Claim/Verification.json +6 -0
- package/concepts/_substrate/Claim.json +4 -0
- package/concepts/_substrate/Frontier/InBeam.json +6 -0
- package/concepts/_substrate/Frontier/Stuck.json +6 -0
- package/concepts/_substrate/Frontier.json +5 -0
- package/concepts/_substrate/Intake/ToTask.json +22 -0
- package/concepts/_substrate/Intake/Typed.json +10 -0
- package/concepts/_substrate/Intake.json +27 -0
- package/concepts/_substrate/Task/Answer.json +12 -0
- package/concepts/_substrate/Task/Complexity/Atomic.json +5 -0
- package/concepts/_substrate/Task/Complexity/Compound/Expansion.json +7 -0
- package/concepts/_substrate/Task/Complexity/Compound.json +6 -0
- package/concepts/_substrate/Task/Complexity.json +6 -0
- package/concepts/_substrate/Task/EvalComplexity.json +13 -0
- package/concepts/_substrate/Task/ReportUp.json +6 -0
- package/concepts/_substrate/Task/Rollup.json +10 -0
- package/concepts/_substrate/Task.json +5 -0
- package/concepts/clinical/Diagnosis/Medication.json +6 -0
- package/concepts/clinical/Diagnosis.json +15 -0
- package/concepts/clinical/Observation/LabValue/OutOfRange.json +6 -0
- package/concepts/clinical/Observation/LabValue.json +5 -0
- package/concepts/clinical/Observation.json +6 -0
- package/concepts/common/Document/pathBasket.json +6 -0
- package/concepts/common/Document.json +3 -0
- package/concepts/common/Edge/Distance.json +13 -0
- package/concepts/common/Edge/Stay/LongStay.json +8 -0
- package/concepts/common/Edge/Stay.json +8 -0
- package/concepts/common/Edge/Travel/LongTravel.json +16 -0
- package/concepts/common/Edge/Travel/ShortTravel.json +11 -0
- package/concepts/common/Edge/Travel/targetNode.json +7 -0
- package/concepts/common/Edge/Travel.json +7 -0
- package/concepts/common/Edge.json +3 -0
- package/concepts/common/Vertice.json +3 -0
- package/concepts/supply/Fulfillment.json +10 -0
- package/concepts/supply/Inventory/Reorder.json +7 -0
- package/concepts/supply/Inventory.json +5 -0
- package/concepts/supply/Procurement/SupplierConfirm.json +6 -0
- package/concepts/supply/Procurement.json +8 -0
- package/concepts/supply/Transport.json +5 -0
- package/doc/API.md +556 -0
- package/doc/CAPABILITIES.md +373 -0
- package/doc/MODELISATION.md +511 -0
- package/doc/architecture.md +267 -0
- package/doc/concept-as-graph.md +379 -0
- package/doc/concept-learning.md +168 -0
- package/doc/creative-loop-map.md +202 -0
- package/doc/original-2016-doc.md +148 -0
- package/doc/usage.md +501 -0
- package/lib/authoring/abstract.js +401 -0
- package/lib/authoring/abstraction.js +190 -0
- package/lib/authoring/adapt.js +393 -0
- package/lib/authoring/ancestry.js +216 -0
- package/lib/authoring/author.js +147 -0
- package/lib/authoring/bounded-merge.js +57 -0
- package/lib/authoring/canon.js +158 -0
- package/lib/authoring/clock.js +123 -0
- package/lib/authoring/combinator.js +92 -0
- package/lib/authoring/compete.js +76 -0
- package/lib/authoring/compose-hotspot.js +314 -0
- package/lib/authoring/compress.js +279 -0
- package/lib/authoring/concept-net.js +254 -0
- package/lib/authoring/concepts.js +66 -0
- package/lib/authoring/context-project.js +277 -0
- package/lib/authoring/contract.js +476 -0
- package/lib/authoring/corpus-pack.js +125 -0
- package/lib/authoring/cost-probe.js +86 -0
- package/lib/authoring/crystallize.js +555 -0
- package/lib/authoring/dag-decompose.js +256 -0
- package/lib/authoring/dataset-adapter.js +253 -0
- package/lib/authoring/debug-provider.js +92 -0
- package/lib/authoring/decompose.js +343 -0
- package/lib/authoring/emittability.js +236 -0
- package/lib/authoring/equilibrium.js +160 -0
- package/lib/authoring/extract.js +153 -0
- package/lib/authoring/forest.js +55 -0
- package/lib/authoring/forge-fallback.js +116 -0
- package/lib/authoring/givens.js +121 -0
- package/lib/authoring/glossary.js +177 -0
- package/lib/authoring/grammar-graph.js +191 -0
- package/lib/authoring/granularity.js +80 -0
- package/lib/authoring/graph-net.js +108 -0
- package/lib/authoring/ground.js +148 -0
- package/lib/authoring/higher-order.js +85 -0
- package/lib/authoring/hotspot.js +132 -0
- package/lib/authoring/hysteresis.js +85 -0
- package/lib/authoring/index.js +106 -0
- package/lib/authoring/lattice-morphism.js +61 -0
- package/lib/authoring/lattice-pack.js +148 -0
- package/lib/authoring/leaf-io.js +77 -0
- package/lib/authoring/library.js +156 -0
- package/lib/authoring/lifecycle.js +92 -0
- package/lib/authoring/loop.js +193 -0
- package/lib/authoring/master-loop.js +132 -0
- package/lib/authoring/mdl.js +209 -0
- package/lib/authoring/memo-stability.js +122 -0
- package/lib/authoring/method-explorer.js +138 -0
- package/lib/authoring/method-pack.js +181 -0
- package/lib/authoring/method.js +202 -0
- package/lib/authoring/mine.js +510 -0
- package/lib/authoring/mount.js +119 -0
- package/lib/authoring/negotiate.js +100 -0
- package/lib/authoring/parametric.js +139 -0
- package/lib/authoring/reaggregate.js +75 -0
- package/lib/authoring/rebalance.js +157 -0
- package/lib/authoring/recall.js +135 -0
- package/lib/authoring/registry.js +350 -0
- package/lib/authoring/relearn.js +147 -0
- package/lib/authoring/retention.js +89 -0
- package/lib/authoring/segment-proxy.js +114 -0
- package/lib/authoring/serve-leaf.js +64 -0
- package/lib/authoring/slot-aware-serve.js +77 -0
- package/lib/authoring/sound-invoke.js +59 -0
- package/lib/authoring/split-serve.js +74 -0
- package/lib/authoring/ste.js +239 -0
- package/lib/authoring/stock.js +101 -0
- package/lib/authoring/store.js +94 -0
- package/lib/authoring/supervise.js +138 -0
- package/lib/authoring/support.js +131 -0
- package/lib/authoring/task-mirror.js +51 -0
- package/lib/authoring/typed-loop.js +160 -0
- package/lib/authoring/validate.js +569 -0
- package/lib/authoring/widen.js +88 -0
- package/lib/combos/appliance.js +189 -0
- package/lib/combos/critique.js +377 -0
- package/lib/combos/defaults.js +86 -0
- package/lib/combos/durable-runner.js +115 -0
- package/lib/combos/forge.js +209 -0
- package/lib/combos/index.js +86 -0
- package/lib/combos/learning-library.js +253 -0
- package/lib/combos/mixture-serve.js +193 -0
- package/lib/combos/plan-loop.js +192 -0
- package/lib/combos/proxy-cache.js +272 -0
- package/lib/combos/self-mod.js +94 -0
- package/lib/durable/audit.js +102 -0
- package/lib/durable/checkpoint-store.js +550 -0
- package/lib/durable/fold.js +62 -0
- package/lib/durable/interpreter.js +242 -0
- package/lib/durable/xlate.js +185 -0
- package/lib/graph/Graph.js +2486 -0
- package/lib/graph/expr.js +307 -0
- package/lib/graph/index.js +26 -0
- package/lib/graph/log.js +134 -0
- package/lib/graph/objects/Concept.js +382 -0
- package/lib/graph/objects/Entity.js +503 -0
- package/lib/graph/objects/Node.js +57 -0
- package/lib/graph/objects/PathMap.js +557 -0
- package/lib/graph/objects/Segment.js +100 -0
- package/lib/graph/tasks/stabilize.js +59 -0
- package/lib/graph/tasks/taskflow.js +247 -0
- package/lib/index.js +122 -0
- package/lib/load.js +132 -0
- package/lib/providers/backends.js +117 -0
- package/lib/providers/borderline.js +129 -0
- package/lib/providers/cache.js +226 -0
- package/lib/providers/canonicalize.js +198 -0
- package/lib/providers/constat.js +107 -0
- package/lib/providers/geo.js +53 -0
- package/lib/providers/index.js +116 -0
- package/lib/providers/intake.js +263 -0
- package/lib/providers/llm-local.js +88 -0
- package/lib/providers/llm.js +236 -0
- package/lib/providers/local-host.js +197 -0
- package/lib/providers/merge-consistency.js +162 -0
- package/lib/providers/nogood.js +149 -0
- package/lib/providers/reason-loop.js +223 -0
- package/lib/providers/semiring.js +285 -0
- package/lib/providers/solver-fork.js +163 -0
- package/lib/providers/stats.js +228 -0
- package/lib/providers/verify.js +120 -0
- package/lib/runtime/index.js +135 -0
- package/lib/runtime/invoke-pool.js +92 -0
- package/lib/runtime/protocol.js +210 -0
- package/lib/runtime/transport-socket.js +77 -0
- package/lib/runtime/worker-entry.js +31 -0
- package/lib/sg/cli.js +601 -0
- package/lib/sg/log-sinks.js +214 -0
- package/lib/sg/mcp.js +395 -0
- package/lib/sg/proxy-run.js +66 -0
- package/lib/sg/serve-demo.js +185 -0
- package/lib/sg/serve.js +205 -0
- package/lib/sg/trace.js +118 -0
- package/lib/studio/protocol.js +45 -0
- package/lib/studio/public/app.js +310 -0
- package/lib/studio/public/components/ConceptEditor.js +43 -0
- package/lib/studio/public/components/ConceptTree.js +43 -0
- package/lib/studio/public/components/CorpusPanel.js +68 -0
- package/lib/studio/public/components/ForkTree.js +36 -0
- package/lib/studio/public/components/GrammarGraph.js +99 -0
- package/lib/studio/public/components/GraphCanvas.js +156 -0
- package/lib/studio/public/components/Inspector.js +48 -0
- package/lib/studio/public/components/LearningPanel.js +85 -0
- package/lib/studio/public/components/PromptConsole.js +46 -0
- package/lib/studio/public/components/ProviderTrace.js +39 -0
- package/lib/studio/public/components/SessionSplit.js +47 -0
- package/lib/studio/public/components/TilingOverlay.js +40 -0
- package/lib/studio/public/components/Timeline.js +57 -0
- package/lib/studio/public/index.html +26 -0
- package/lib/studio/public/styles.css +185 -0
- package/lib/studio/public/ws.js +58 -0
- package/lib/studio/server.js +130 -0
- package/lib/studio/session.js +397 -0
- package/lib/studio/studio.js +149 -0
- package/package.json +42 -0
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Nathanael Braun
|
|
3
|
+
* @author : Nathanael BRAUN <pp9ping@gmail.com>
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var isArray = require('is').array;
|
|
21
|
+
var isFunction = require('is').fn;
|
|
22
|
+
var isString = require('is').string;
|
|
23
|
+
var { compileExpression } = require('../expr');
|
|
24
|
+
var shortid = require('shortid');
|
|
25
|
+
|
|
26
|
+
// Wrap a query (string | array | fn) into a predicate fn(me, map) that resolves
|
|
27
|
+
// $refs via me.getRef(ref, map) — replaces the old `new Function` query compiler.
|
|
28
|
+
function compilePathQuery ( query ) {
|
|
29
|
+
if ( isFunction(query) ) return query;
|
|
30
|
+
var _q = compileExpression(query, { empty: true });
|
|
31
|
+
return function ( me, map ) {
|
|
32
|
+
return _q(function ( ref ) { return me.getRef(ref, map); });
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// A read-side view over the result of Graph.getPaths: a set of object "maps" plus the
|
|
37
|
+
// paths (sequences of object ids) found between two nodes. It lets a host SELECT a
|
|
38
|
+
// subset of paths (by required/excluded properties or a query) and EXTRACT per-path
|
|
39
|
+
// shape/transport/descriptors. Not part of stabilization — it consumes a stabilized
|
|
40
|
+
// graph. (PathMap is the constructor arg name too; `this._` holds {maps, paths}.)
|
|
41
|
+
function PathMap( PathMap, graph, pathOrigin ) {
|
|
42
|
+
this.init(PathMap, graph, pathOrigin);
|
|
43
|
+
};
|
|
44
|
+
PathMap.fromPath = function ( path ) {
|
|
45
|
+
let tpl = isString(path.tpl) ? JSON.parse(path.tpl) : path.tpl,
|
|
46
|
+
pm = new PathMap(
|
|
47
|
+
{
|
|
48
|
+
maps : [...(path.relatedTpl || []), ...(path.descr || []), ...(tpl || [])],
|
|
49
|
+
paths: tpl.map(m => m._id)
|
|
50
|
+
});
|
|
51
|
+
return pm;
|
|
52
|
+
};
|
|
53
|
+
PathMap.prototype = {
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param PathMap : serialized path list from graph:getPaths
|
|
57
|
+
*/
|
|
58
|
+
init: function ( PathMap ) {
|
|
59
|
+
this._ = PathMap;
|
|
60
|
+
this._._id = this._._id || shortid.generate();
|
|
61
|
+
this._selected = [];
|
|
62
|
+
this._paths = [];
|
|
63
|
+
|
|
64
|
+
this.mount();
|
|
65
|
+
//if ( this._.skycube ) {
|
|
66
|
+
// this.skycube = new Skycube(this._.skycube);
|
|
67
|
+
//}
|
|
68
|
+
},
|
|
69
|
+
/**
|
|
70
|
+
* Get every cbox/cbox socpe with 'p' conceptKey
|
|
71
|
+
* @param p
|
|
72
|
+
* @param map Get the hashMap instead of the cbox
|
|
73
|
+
* @returns {Array}
|
|
74
|
+
*/
|
|
75
|
+
mount: function ( p, map ) {
|
|
76
|
+
|
|
77
|
+
var i = 0, p,
|
|
78
|
+
lib = this._.maps,
|
|
79
|
+
ni,
|
|
80
|
+
map,
|
|
81
|
+
ptest = true,
|
|
82
|
+
cpath;
|
|
83
|
+
|
|
84
|
+
for ( ; i < this._.paths.length; i++ ) {
|
|
85
|
+
p = this._.paths[i];
|
|
86
|
+
cpath = [];
|
|
87
|
+
ptest = false;
|
|
88
|
+
for ( ni = 0; ni < p.length; ni++ ) {
|
|
89
|
+
cpath.push(lib[p[ni]]);
|
|
90
|
+
}
|
|
91
|
+
this._paths[i] = cpath;
|
|
92
|
+
}
|
|
93
|
+
return this;
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Get every cbox/cbox socpe with 'p' conceptKey
|
|
98
|
+
* @param p
|
|
99
|
+
* @param map Get the hashMap instead of the cbox
|
|
100
|
+
* @returns {Array}
|
|
101
|
+
*/
|
|
102
|
+
getAll: function ( p, map ) {
|
|
103
|
+
var s = [];
|
|
104
|
+
for ( var o in this._.maps ) {
|
|
105
|
+
if ( this._.maps.hasOwnProperty(o) && this._.maps[o][p] )
|
|
106
|
+
s.push(map && this._.maps[o] || this._.maps[o][p]);
|
|
107
|
+
}
|
|
108
|
+
return s;
|
|
109
|
+
},
|
|
110
|
+
/**
|
|
111
|
+
* Do select paths with one of '_width' props and not '_without' props
|
|
112
|
+
* @param _with
|
|
113
|
+
* @param _without
|
|
114
|
+
* @returns {PathMap}
|
|
115
|
+
*/
|
|
116
|
+
selectPathsFromReducer: function ( fn, def = true ) {
|
|
117
|
+
var i = 0, p,
|
|
118
|
+
lib = this._.maps,
|
|
119
|
+
ni,
|
|
120
|
+
map,
|
|
121
|
+
ptest = true,
|
|
122
|
+
test = true,
|
|
123
|
+
push = Array.prototype.push,
|
|
124
|
+
selectedMapWith = {},
|
|
125
|
+
selected = [],
|
|
126
|
+
selectedPOI = [],
|
|
127
|
+
cpath;
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
for ( ; i < this._.paths.length; i++ ) {
|
|
131
|
+
cpath = this._.paths[i].map(( mId ) => lib[mId]);
|
|
132
|
+
if ( cpath.reduce(fn, def) )
|
|
133
|
+
selected.push(i);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
this._selected = selected;
|
|
137
|
+
return this;
|
|
138
|
+
},
|
|
139
|
+
/**
|
|
140
|
+
* Do select paths with one of '_width' props and not '_without' props
|
|
141
|
+
* @param _with
|
|
142
|
+
* @param _without
|
|
143
|
+
* @returns {PathMap}
|
|
144
|
+
*/
|
|
145
|
+
selectPaths: function ( _with, _without ) {
|
|
146
|
+
var i = 0, p,
|
|
147
|
+
lib = this._.maps,
|
|
148
|
+
ni,
|
|
149
|
+
map,
|
|
150
|
+
ptest = true,
|
|
151
|
+
test = true,
|
|
152
|
+
push = Array.prototype.push,
|
|
153
|
+
selectedMapWith = {},
|
|
154
|
+
selected = [],
|
|
155
|
+
selectedPOI = [],
|
|
156
|
+
cpath;
|
|
157
|
+
_with = _with || [];
|
|
158
|
+
_without = _without || [];
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
for ( ; i < this._.paths.length; i++ ) {
|
|
162
|
+
p = this._.paths[i];
|
|
163
|
+
cpath = [];
|
|
164
|
+
ptest = false;
|
|
165
|
+
test = true;
|
|
166
|
+
for ( ni = 0; ni < p.length; ni++ ) {
|
|
167
|
+
map = lib[p[ni]];
|
|
168
|
+
|
|
169
|
+
_with.forEach(( k ) => {
|
|
170
|
+
ptest = ptest || map.hasOwnProperty(k)
|
|
171
|
+
selectedMapWith[k] = selectedMapWith[k] || [];
|
|
172
|
+
selectedMapWith[k].push(map)
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
_without.forEach(( k ) => test = test && !map.hasOwnProperty(k));
|
|
176
|
+
cpath.push(map);
|
|
177
|
+
//ptest = ptest&&test;
|
|
178
|
+
if ( !test ) break;
|
|
179
|
+
}
|
|
180
|
+
if ( ptest && test ) {
|
|
181
|
+
selected.push(i);
|
|
182
|
+
push.apply(selectedPOI, cpath);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
this._selected = selected;
|
|
186
|
+
this._selectedMapWith = selectedMapWith;
|
|
187
|
+
this._selectedPOI = selectedPOI;
|
|
188
|
+
return this;
|
|
189
|
+
},
|
|
190
|
+
/**
|
|
191
|
+
* Do select paths with one of it's maps that match query
|
|
192
|
+
* @param query
|
|
193
|
+
* @returns {PathMap}
|
|
194
|
+
*/
|
|
195
|
+
selectPathsFromQuery: function ( query ) {
|
|
196
|
+
var i = 0, p,
|
|
197
|
+
lib = this._.maps,
|
|
198
|
+
ni,
|
|
199
|
+
map,
|
|
200
|
+
ptest = true,
|
|
201
|
+
test = true,
|
|
202
|
+
push = Array.prototype.push,
|
|
203
|
+
selectedMapWith = {},
|
|
204
|
+
selected = [],
|
|
205
|
+
selectedPOI = [],
|
|
206
|
+
cpath,
|
|
207
|
+
fn = compilePathQuery(query);
|
|
208
|
+
|
|
209
|
+
for ( ; i < this._.paths.length; i++ ) {
|
|
210
|
+
p = this._.paths[i];
|
|
211
|
+
cpath = [];
|
|
212
|
+
ptest = true;
|
|
213
|
+
for ( ni = 0; ni < p.length; ni++ ) {
|
|
214
|
+
map = lib[p[ni]];
|
|
215
|
+
if ( !fn(this, map) ) {
|
|
216
|
+
ptest = false;
|
|
217
|
+
// console.log("Path %d have match on ", i, map)
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
;
|
|
221
|
+
}
|
|
222
|
+
if ( ptest ) {
|
|
223
|
+
selected.push(i);
|
|
224
|
+
// push.apply(selectedPOI, cpath);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// this._selectedId = selected;
|
|
228
|
+
this._selected = selected;
|
|
229
|
+
this._selectedMapWith = selectedMapWith;
|
|
230
|
+
// this._selectedPOI = selectedPOI;
|
|
231
|
+
return this;
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Select all node that match the query in a path
|
|
236
|
+
* @param path {Array|int} the path were to search
|
|
237
|
+
* @param query {fn|string} query of function that select the maps
|
|
238
|
+
* @returns {array|*|Array}
|
|
239
|
+
*/
|
|
240
|
+
queryMapsOnPath: function ( path, query ) {
|
|
241
|
+
|
|
242
|
+
var me = this,
|
|
243
|
+
selected = path._isPath ? path.tpl : this._paths[path] || [],
|
|
244
|
+
maps = this._.maps,
|
|
245
|
+
fn = compilePathQuery(query)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
;
|
|
249
|
+
return selected.filter(( v ) => fn(me, v));
|
|
250
|
+
|
|
251
|
+
},
|
|
252
|
+
/**
|
|
253
|
+
* Get all props in a path
|
|
254
|
+
*
|
|
255
|
+
* if _props is a string this will return an array of value if not hashmaps
|
|
256
|
+
*
|
|
257
|
+
*
|
|
258
|
+
* @param i : selected path number or the path itself
|
|
259
|
+
* @param _props {array|string} the wanted props
|
|
260
|
+
* @param mapFn {function} optional function to apply on the results
|
|
261
|
+
* @returns {*}
|
|
262
|
+
*/
|
|
263
|
+
getAllPropsInPath: function ( i, _props, mapFn ) {
|
|
264
|
+
_props = isArray(_props) ? _props : _props && [_props] || [];
|
|
265
|
+
var c,
|
|
266
|
+
// lib = this._.maps,
|
|
267
|
+
pln = _props.length,
|
|
268
|
+
test = true,
|
|
269
|
+
selected = pln && i._isPath ? i.tpl : this._paths[i] || [],
|
|
270
|
+
propsStack = [],
|
|
271
|
+
props, value;
|
|
272
|
+
|
|
273
|
+
(pln > 1) ? selected.forEach(( map ) => {
|
|
274
|
+
props = {};
|
|
275
|
+
c = 0;
|
|
276
|
+
_props.forEach(( k ) => (map[k] && (c++, props[k] = map[k])));
|
|
277
|
+
(pln == c) && propsStack.push(props);
|
|
278
|
+
})
|
|
279
|
+
: selected.forEach(( map ) => {
|
|
280
|
+
props = null;
|
|
281
|
+
c = 0;
|
|
282
|
+
_props.forEach(( k ) => (map[k] && (c++, props = map[k])));
|
|
283
|
+
c && propsStack.push(props);
|
|
284
|
+
});
|
|
285
|
+
if ( mapFn ) {
|
|
286
|
+
propsStack.forEach(( v ) => value = mapFn(value, v));
|
|
287
|
+
return value;
|
|
288
|
+
}
|
|
289
|
+
return propsStack;
|
|
290
|
+
},
|
|
291
|
+
/**
|
|
292
|
+
* Get a serialized specific path by his selected id,
|
|
293
|
+
* Add available descriptors
|
|
294
|
+
* @param i
|
|
295
|
+
* @returns {{_pmap: PathMap, tpl: *, descr: *}}
|
|
296
|
+
*/
|
|
297
|
+
getPath : function ( i ) {
|
|
298
|
+
var path = this._paths[i] || [],
|
|
299
|
+
lib = this._.maps,
|
|
300
|
+
relatedById = {},
|
|
301
|
+
related = [];
|
|
302
|
+
path.forEach(
|
|
303
|
+
( map ) => {
|
|
304
|
+
if ( relatedById[map._origin] ) return;
|
|
305
|
+
while ( map && map._origin ) {
|
|
306
|
+
relatedById[map._origin] = lib[map._origin] || true;// missing silently?
|
|
307
|
+
lib[map._origin] && related.push(lib[map._origin]);
|
|
308
|
+
if ( map == lib[map._origin] ) break;
|
|
309
|
+
map = lib[map._origin]
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
);
|
|
313
|
+
return {
|
|
314
|
+
_id: this._._id + '::' + i,// should be an unique key sync to the query graph params or an unique
|
|
315
|
+
// path hash
|
|
316
|
+
_isPath : true,
|
|
317
|
+
tpl : path,
|
|
318
|
+
relatedTpl: related,//@todo add bagrefs
|
|
319
|
+
|
|
320
|
+
transportTypes: this.extractTransportTypes(path, related),
|
|
321
|
+
shape : this.extractShape(path, related),
|
|
322
|
+
descr : this.getPathDescriptor(i)
|
|
323
|
+
};
|
|
324
|
+
},
|
|
325
|
+
getPaths : function () {
|
|
326
|
+
return this._paths
|
|
327
|
+
&& this._paths.map(( p, i ) => this.getPath(i)) || [];
|
|
328
|
+
},
|
|
329
|
+
getSelectedPaths: function () {
|
|
330
|
+
return this._selected
|
|
331
|
+
&& this._selected.map(this.getPath.bind(this)) || [];
|
|
332
|
+
},
|
|
333
|
+
|
|
334
|
+
extractShape( path, related ) {
|
|
335
|
+
let shapes = [], prec, next;
|
|
336
|
+
path &&
|
|
337
|
+
path.map(
|
|
338
|
+
( map, i ) => {
|
|
339
|
+
let lastShape, dur;
|
|
340
|
+
prec = i && path[i - 1];
|
|
341
|
+
next = path[i + 1];
|
|
342
|
+
if ( map.Segment ) {
|
|
343
|
+
dur = map.DefaultDuration || map.TimePeriod && map.TimePeriod.duration && map.TimePeriod.duration.ms || 60000;
|
|
344
|
+
if ( map.shape ) {
|
|
345
|
+
lastShape = {
|
|
346
|
+
_origin: map._id,
|
|
347
|
+
// etty : map,
|
|
348
|
+
duration : dur,
|
|
349
|
+
transportType: map.transportType || 'pedestrian',
|
|
350
|
+
related : [],
|
|
351
|
+
shape : map.shape
|
|
352
|
+
}
|
|
353
|
+
shapes.push(lastShape);
|
|
354
|
+
}
|
|
355
|
+
else if ( dur ) {
|
|
356
|
+
|
|
357
|
+
lastShape = {
|
|
358
|
+
_origin: map._id,
|
|
359
|
+
// etty : map,
|
|
360
|
+
duration : dur,
|
|
361
|
+
transportType: map.transportType || 'pedestrian',
|
|
362
|
+
related : [],
|
|
363
|
+
shape : []
|
|
364
|
+
}
|
|
365
|
+
shapes.push(lastShape);
|
|
366
|
+
prec && prec.Position &&
|
|
367
|
+
lastShape.shape.push(
|
|
368
|
+
[prec.Position.lat, prec.Position.lng]);
|
|
369
|
+
|
|
370
|
+
next && next.Position &&
|
|
371
|
+
lastShape.shape.push(
|
|
372
|
+
[next.Position.lat, next.Position.lng]);
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
})
|
|
378
|
+
return shapes;
|
|
379
|
+
},
|
|
380
|
+
extractTransportTypes( path, related ) {
|
|
381
|
+
let shapes = [], prec, next;
|
|
382
|
+
path &&
|
|
383
|
+
path.map(
|
|
384
|
+
( map, i ) => {
|
|
385
|
+
let lastShape;
|
|
386
|
+
prec = i && path[i - 1];
|
|
387
|
+
next = path[i + 1];
|
|
388
|
+
if ( map.Segment ) {
|
|
389
|
+
if ( map.shape ) {
|
|
390
|
+
lastShape = {
|
|
391
|
+
_origin: map._id,
|
|
392
|
+
// etty : map,
|
|
393
|
+
transportType: map.transportType,
|
|
394
|
+
related : [],
|
|
395
|
+
shape : map.shape
|
|
396
|
+
}
|
|
397
|
+
shapes.push(lastShape);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
|
|
401
|
+
lastShape = {
|
|
402
|
+
_origin: map._id,
|
|
403
|
+
// etty : map,
|
|
404
|
+
transportType: map.transportType,
|
|
405
|
+
related : [],
|
|
406
|
+
shape : []
|
|
407
|
+
}
|
|
408
|
+
shapes.push(lastShape);
|
|
409
|
+
prec && prec.Position &&
|
|
410
|
+
lastShape.shape.push(
|
|
411
|
+
[prec.Position.lat, prec.Position.lng]);
|
|
412
|
+
|
|
413
|
+
next && next.Position &&
|
|
414
|
+
lastShape.shape.push(
|
|
415
|
+
[next.Position.lat, next.Position.lng]);
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
})
|
|
421
|
+
return shapes;
|
|
422
|
+
},
|
|
423
|
+
// --- kept for reference (R&D): skycube multi-dimensional path selection ---
|
|
424
|
+
// Pareto/skyline selection over path descriptors (loadSkycube/getBest/
|
|
425
|
+
// availableDimension), backed by an external @aetheris/skycube builder. Not shipped
|
|
426
|
+
// in V1 (the dependency isn't vendored); retained as the design sketch for ranking
|
|
427
|
+
// discovered paths by several dimensions at once.
|
|
428
|
+
//loadSkycube: __SERVER__ && function ( callback ) {
|
|
429
|
+
// var skycubeBuilder = new SkycubeBuilder(),
|
|
430
|
+
// me = this;
|
|
431
|
+
//
|
|
432
|
+
// this.skycube = skycubeBuilder.skycube;
|
|
433
|
+
//
|
|
434
|
+
// // If a callback must be called, we bind it to the skycube computation end event
|
|
435
|
+
// if ( callback != undefined ) {
|
|
436
|
+
// skycubeBuilder.eventEmitter.on('file_loaded', callback);
|
|
437
|
+
// }
|
|
438
|
+
//
|
|
439
|
+
// skycubeBuilder.sanitizeDimension(this);
|
|
440
|
+
//
|
|
441
|
+
// // We only apply skycube on path that have a path descriptor (since they are "real" path issued from provider
|
|
442
|
+
// // this may be changed in the future to apply to more generated path (wo path descriptor)
|
|
443
|
+
// this.selectPaths(["pathDescriptor"], []);
|
|
444
|
+
// this._selected.map(( pathId, index ) => {
|
|
445
|
+
// //console.log("Processing " + pathId + " -> " + util.inspect( this.getPath(pathId).tpl , {depth: 3} ) );
|
|
446
|
+
// skycubeBuilder.processObject(pathId, this);
|
|
447
|
+
// });
|
|
448
|
+
//
|
|
449
|
+
// skycubeBuilder.computeSkycube();
|
|
450
|
+
// //skycubeBuilder.skycube.loadStructure();
|
|
451
|
+
//},
|
|
452
|
+
//
|
|
453
|
+
///**
|
|
454
|
+
// * Get a serialized specific path by his selected id,
|
|
455
|
+
// * Add available descriptors
|
|
456
|
+
// * @param i
|
|
457
|
+
// * @returns {{_pmap: PathMap, tpl: *, descr: *}}
|
|
458
|
+
// */
|
|
459
|
+
//getBest: function ( dimensions ) {
|
|
460
|
+
// if ( this.skycube == undefined ) {
|
|
461
|
+
// throw Error("Skycube has not bin yet calculated");
|
|
462
|
+
// }
|
|
463
|
+
// return this.skycube.getIdsFromDim(dimensions);
|
|
464
|
+
//},
|
|
465
|
+
//
|
|
466
|
+
///**
|
|
467
|
+
// * Get a serialized specific path by his selected id,
|
|
468
|
+
// * Add available descriptors
|
|
469
|
+
// * @param i
|
|
470
|
+
// * @returns {{_pmap: PathMap, tpl: *, descr: *}}
|
|
471
|
+
// */
|
|
472
|
+
//availableDimension: function () {
|
|
473
|
+
// if ( this.skycube == undefined ) {
|
|
474
|
+
// throw Error("Skycube has not bin yet calculated");
|
|
475
|
+
// }
|
|
476
|
+
// return this.skycube.getAvailableDimension();
|
|
477
|
+
//},
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
*
|
|
482
|
+
* Will walk in scopes to get some value or be warn if somthing set the value...
|
|
483
|
+
*
|
|
484
|
+
* @param exp
|
|
485
|
+
* @param scope
|
|
486
|
+
* @param follow bool do unstabilize scope's object if the concept asked is not here
|
|
487
|
+
* (so it will warn object that the stuff it ask is now here)
|
|
488
|
+
* @returns {targeted value}
|
|
489
|
+
*/
|
|
490
|
+
getRef: function ( exp, scope, follow, unref ) {
|
|
491
|
+
var cScope = scope;
|
|
492
|
+
exp = exp.split('.');
|
|
493
|
+
|
|
494
|
+
while ( exp.length ) {
|
|
495
|
+
if ( exp[0].indexOf(':') != -1 ) {// follow the ref
|
|
496
|
+
exp[0] = exp[0].split(':');
|
|
497
|
+
cScope = this._.maps[cScope[exp[0][0]]];// switch scope
|
|
498
|
+
|
|
499
|
+
if ( !cScope ) return;
|
|
500
|
+
if ( exp[0][1] )
|
|
501
|
+
exp[0] = exp[0][1];
|
|
502
|
+
else return cScope;
|
|
503
|
+
}
|
|
504
|
+
if ( exp[0][0] == '$' ) {// global ref
|
|
505
|
+
if ( exp.length == 1 ) return this._.maps[exp[0].substr(1)];
|
|
506
|
+
cScope = this._objById[exp[0].substr(1)];
|
|
507
|
+
}
|
|
508
|
+
else if ( exp.length == 1 ) {
|
|
509
|
+
return cScope && cScope[exp[0]];
|
|
510
|
+
}
|
|
511
|
+
if ( !cScope ) return;
|
|
512
|
+
exp.shift();
|
|
513
|
+
}
|
|
514
|
+
return cScope;
|
|
515
|
+
},
|
|
516
|
+
/**
|
|
517
|
+
* Get available descriptors for path i
|
|
518
|
+
* @param i
|
|
519
|
+
* @returns {Array}
|
|
520
|
+
*/
|
|
521
|
+
_getPathDescriptor: function ( i ) {
|
|
522
|
+
var path = i._isPath ? i.tpl : this._paths[i], descr, descrs = [];
|
|
523
|
+
for ( i = 0; i < path.length; i++ ) {
|
|
524
|
+
if ( path[i].pathDescriptor ) {
|
|
525
|
+
descr = this._.maps[path[i].pathDescriptor];
|
|
526
|
+
descrs.push(descr);
|
|
527
|
+
while ( descr.parentPathDescriptor ) {
|
|
528
|
+
descrs.push(this._.maps[descr.parentPathDescriptor]);
|
|
529
|
+
descr = this._.maps[descr.parentPathDescriptor];
|
|
530
|
+
}
|
|
531
|
+
return descrs;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
/**
|
|
536
|
+
* Get available descriptors for path i
|
|
537
|
+
* @param i can be the path object OR the path indice in the pathMap
|
|
538
|
+
* @returns {Array}
|
|
539
|
+
*/
|
|
540
|
+
getPathDescriptor: function ( i, type ) {
|
|
541
|
+
var path = i && i._isPath ? i.tpl : this._paths[i],
|
|
542
|
+
descr,
|
|
543
|
+
descrs = {},
|
|
544
|
+
descrList = [];
|
|
545
|
+
|
|
546
|
+
for ( i = 0; i < path.length; i++ ) {
|
|
547
|
+
if ( path[i].pathDescriptor && (!type || this._.maps[path[i].pathDescriptor].type == type) ) {
|
|
548
|
+
if ( !descrs[path[i].pathDescriptor] ) {
|
|
549
|
+
descrList.push(path[i].pathDescriptor);
|
|
550
|
+
descrs[path[i].pathDescriptor] = this._.maps[path[i].pathDescriptor];
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return descrList.map(( v ) => descrs[v]);
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
module.exports = PathMap;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Nathanael Braun
|
|
3
|
+
* @author : Nathanael BRAUN <pp9ping@gmail.com>
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var Entity = require('./Entity');
|
|
21
|
+
var debug = require('../log').defaultLogger;// fallback; methods log via this._graph._log
|
|
22
|
+
|
|
23
|
+
function Segment( _, graph, parentMutation ) {
|
|
24
|
+
this.init(_, graph, parentMutation);
|
|
25
|
+
};
|
|
26
|
+
Segment.prototype = {
|
|
27
|
+
init : function ( _, graph, parentMutation ) {
|
|
28
|
+
this._id = _._id;
|
|
29
|
+
this._graph = graph;
|
|
30
|
+
this._etty = new Entity(
|
|
31
|
+
{
|
|
32
|
+
_id : _._id,
|
|
33
|
+
Segment: true
|
|
34
|
+
},
|
|
35
|
+
graph
|
|
36
|
+
);
|
|
37
|
+
graph._mapsByConcept["Segment"] = graph._mapsByConcept["Segment"] || [];
|
|
38
|
+
graph._mapsByConcept["Segment"].push(_._id);
|
|
39
|
+
this._etty.follow("targetNode", this._onTargetChange, this);
|
|
40
|
+
this._etty.follow("originNode", this._onOriginChange, this);
|
|
41
|
+
this._etty.follow("_autokill", this._killMe, this);
|
|
42
|
+
this._ppp = _;
|
|
43
|
+
this._etty.update(_, graph);
|
|
44
|
+
|
|
45
|
+
// this._etty.updateApplicableConcepts();
|
|
46
|
+
// this._onTargetChange()
|
|
47
|
+
},
|
|
48
|
+
_killMe : function ( n, o ) {
|
|
49
|
+
this._etty.unRefAll();
|
|
50
|
+
this._graph._log.verbose("segment %s auto-killed (unref)", this._id);
|
|
51
|
+
this._etty.set("targetNode", null);
|
|
52
|
+
this._etty.set("originNode", null);
|
|
53
|
+
// this._graph.removeObj(this._id);
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* update targeted nodes; updating the graph
|
|
57
|
+
* @param o
|
|
58
|
+
* @param n
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
_onTargetChange: function ( n, o ) {
|
|
62
|
+
var node = o && this._graph.getObjById(o), i;
|
|
63
|
+
if ( node ) {
|
|
64
|
+
i = node._incoming.indexOf(this._id);
|
|
65
|
+
if ( i != -1 )
|
|
66
|
+
node._incoming.splice(i, 1);
|
|
67
|
+
}
|
|
68
|
+
node = n && this._graph.getObjById(n);
|
|
69
|
+
node && node._incoming.push(this._id);
|
|
70
|
+
if ( !node && n ) {
|
|
71
|
+
this._graph._log.error("can't relink target from %s to %s (target node missing)", o, n);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* update origin nodes; updating the graph
|
|
76
|
+
* @param o
|
|
77
|
+
* @param n
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
_onOriginChange: function ( n, o ) {
|
|
81
|
+
var node = o && this._graph.getObjById(o), i;
|
|
82
|
+
if ( node ) {
|
|
83
|
+
i = node._outgoing.indexOf(this._id);
|
|
84
|
+
if ( i != -1 )
|
|
85
|
+
node._outgoing.splice(i, 1);
|
|
86
|
+
}
|
|
87
|
+
node = n && this._graph.getObjById(n);
|
|
88
|
+
node && node._outgoing.push(this._id);
|
|
89
|
+
if ( !node && n ) {
|
|
90
|
+
this._graph._log.error("can't relink origin from %s to %s (origin node missing)", o, n);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
relink : function () {
|
|
94
|
+
this._etty.unRefAll();
|
|
95
|
+
},
|
|
96
|
+
specialize : function () {
|
|
97
|
+
return this._etty.specialize();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
module.exports = Segment;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Nathanael Braun
|
|
3
|
+
* @author : Nathanael BRAUN <pp9ping@gmail.com>
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var defaultLogger = require('../log').defaultLogger;// fallback only; we use graph._log below
|
|
21
|
+
/*
|
|
22
|
+
* Launch concepts stabilisation on every unstable nodes
|
|
23
|
+
*/
|
|
24
|
+
module.exports = function ( graph, flow ) {
|
|
25
|
+
var debug = graph._log;
|
|
26
|
+
|
|
27
|
+
graph._stabilizing = true;// a pass is in flight — structural ops (add/patchConcept) issued from a
|
|
28
|
+
// provider now defer to the quiescent _loopTF boundary (#11.a re-entrancy)
|
|
29
|
+
debug.info("launch stabilisation: %s unstable, %s triggers", graph._unstable.length, graph._triggeredCastCount);
|
|
30
|
+
//
|
|
31
|
+
if ( graph._triggeredCastCount ) {
|
|
32
|
+
var updates = Object.keys(graph._triggeredCast);
|
|
33
|
+
flow.pushSubTask(
|
|
34
|
+
updates.map(
|
|
35
|
+
( k ) => {
|
|
36
|
+
debug.log("updates %s !! ", k);
|
|
37
|
+
|
|
38
|
+
graph.toggleGraphObjectState(graph._triggeredCast[k][0], "unstable");
|
|
39
|
+
return graph._conceptLib[graph._triggeredCast[k][1]].applyTo(
|
|
40
|
+
graph._objById[graph._triggeredCast[k][0]]._etty,
|
|
41
|
+
graph
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
graph._triggeredCast = {};
|
|
48
|
+
graph._triggeredCastCount = 0;
|
|
49
|
+
// if ( me._unstable.length )
|
|
50
|
+
// flow.then(me._loopTF);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
flow.pushSubTask(
|
|
54
|
+
graph._unstable.map(
|
|
55
|
+
function ( v ) {
|
|
56
|
+
return v.specialize && v.specialize() || v._etty.specialize();
|
|
57
|
+
}
|
|
58
|
+
));
|
|
59
|
+
};
|