@linked.archi/kernel 0.1.5 → 0.1.7
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/README.md +8 -0
- package/assets/archimate3/archimate3.2-metamodel.ttl +18 -1
- package/assets/archimate3/archimate3.2-principle-shapes.ttl +16 -22
- package/assets/archimate3/archimate3.2-questions.ttl +38 -38
- package/assets/archimate3/archimate3.2-viewpoint-shapes.ttl +1 -1
- package/assets/archimate4/archimate4-metamodel.ttl +18 -1
- package/assets/archimate4/archimate4-principle-shapes.ttl +38 -36
- package/assets/archimate4/archimate4-questions.ttl +38 -38
- package/assets/archimate4/archimate4-viewpoint-shapes.ttl +1 -1
- package/assets/catalog.ttl +776 -464
- package/assets/core/core-onto.ttl +12 -9
- package/assets/core/core-shapes.ttl +1 -1
- package/assets/core/core-vis-onto.ttl +99 -5
- package/assets/core/core-vis-shapes.ttl +275 -11
- package/package.json +5 -2
- package/src/model-manager/appearance.ts +131 -7
- package/src/model-manager/cascade.ts +5 -3
- package/src/model-manager/clipboard.ts +10 -2
- package/src/model-manager/concept-styles.ts +230 -0
- package/src/model-manager/interfaces.ts +19 -1
- package/src/model-manager/iri-conformance.ts +9 -2
- package/src/model-manager/placement-copy.ts +35 -8
- package/src/model-manager/questions.ts +6 -1
- package/src/model-manager/style-sets.ts +399 -0
- package/src/model-manager/style-values.ts +349 -0
- package/src/model-manager/view-manager.ts +74 -22
- package/src/model-manager/vocabulary.ts +10 -0
- package/src/rdf-engine/iri.ts +6 -3
- package/src/rdf-engine/native-load.ts +37 -0
- package/src/rdf-engine/observable-store.ts +98 -120
- package/src/rdf-engine/rdf-store.ts +14 -2
- package/src/rdf-engine/sparql-constraints.ts +15 -0
- package/src/rdf-engine/turtle-writer.ts +1 -0
- package/src/rdf-engine/validation-engine.ts +97 -32
- package/src/rdf-engine/validation-service.ts +3 -1
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A style's values in the model, written and read as a diagram element's own are (`ViewManager.setAppearance`):
|
|
3
|
+
* for the styles no diagram element hangs — a style set's named styles and a model concept's own looks
|
|
4
|
+
* (core-vis 0.11, `style-sets.ts` and `concept-styles.ts`) — and for a diagram element's, by `setAppearance`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { DataFactory } from 'n3';
|
|
8
|
+
import type { NamedNode, Quad, Term } from '@rdfjs/types';
|
|
9
|
+
import { partIri } from '../rdf-engine/iri.js';
|
|
10
|
+
import type { RdfStore } from '../rdf-engine/interfaces.js';
|
|
11
|
+
import { NAMESPACES } from '../rdf-engine/namespaces.js';
|
|
12
|
+
import {
|
|
13
|
+
APPEARANCE_KEYS,
|
|
14
|
+
APPEARANCE_PREDICATES,
|
|
15
|
+
STYLE_KEYS,
|
|
16
|
+
appearanceObject,
|
|
17
|
+
appearanceValue,
|
|
18
|
+
detachedLooks,
|
|
19
|
+
type Appearance,
|
|
20
|
+
type AppearanceChanges,
|
|
21
|
+
type AppearanceKey,
|
|
22
|
+
type LookSources,
|
|
23
|
+
} from './appearance.js';
|
|
24
|
+
import { shortHash } from './short-hash.js';
|
|
25
|
+
import { IRI, T, netChange, nn, quadKey, triple } from './vocabulary.js';
|
|
26
|
+
|
|
27
|
+
/** The default graph: the model. */
|
|
28
|
+
const MODEL_GRAPH = DataFactory.defaultGraph() as unknown as NamedNode;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The term a value is written as: an enumeration's member or an IRI (a shape type, the style based on), an
|
|
32
|
+
* `xsd:integer`, an `xsd:anyURI` (a picture), an `xsd:boolean` or a string — `undefined` for a value that is
|
|
33
|
+
* not one of the key's.
|
|
34
|
+
*/
|
|
35
|
+
export function appearanceTerm<K extends AppearanceKey>(key: K, value: NonNullable<Appearance[K]>): Term | undefined {
|
|
36
|
+
const object = appearanceObject(key, value);
|
|
37
|
+
if (!object) return undefined;
|
|
38
|
+
if ('iri' in object) return nn(object.iri);
|
|
39
|
+
if ('integer' in object) return DataFactory.literal(String(object.integer), nn(NAMESPACES.xsd + 'integer')) as unknown as Term;
|
|
40
|
+
if ('uri' in object) return DataFactory.literal(object.uri, nn(NAMESPACES.xsd + 'anyURI')) as unknown as Term;
|
|
41
|
+
if ('boolean' in object) return DataFactory.literal(String(object.boolean), nn(NAMESPACES.xsd + 'boolean')) as unknown as Term;
|
|
42
|
+
return DataFactory.literal(object.string) as unknown as Term;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** What a style says in the model: its look's values, and the style it is based on. */
|
|
46
|
+
export function styleAppearance(store: RdfStore, style: Term): Appearance {
|
|
47
|
+
const appearance: Record<string, unknown> = {};
|
|
48
|
+
for (const key of STYLE_KEYS) {
|
|
49
|
+
const term = store.getQuads(style as NamedNode, nn(APPEARANCE_PREDICATES[key]), null, MODEL_GRAPH)[0]?.object;
|
|
50
|
+
const value = term ? appearanceValue(key, term) : undefined;
|
|
51
|
+
if (value !== undefined) appearance[key] = value;
|
|
52
|
+
}
|
|
53
|
+
return appearance as Appearance;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* What writes `changes` on `style`: a value replaces what the style says of its key, `null` takes it away, and a
|
|
58
|
+
* value that is not one of the key's — a picture's address that is none — changes nothing. Only what differs.
|
|
59
|
+
*/
|
|
60
|
+
export function styleValuesChange(store: RdfStore, style: NamedNode, changes: AppearanceChanges): { remove: Quad[]; add: Quad[] } {
|
|
61
|
+
const remove: Quad[] = [];
|
|
62
|
+
const add: Quad[] = [];
|
|
63
|
+
for (const key of STYLE_KEYS) {
|
|
64
|
+
const value = changes[key];
|
|
65
|
+
if (value === undefined) continue;
|
|
66
|
+
const term = value === null ? undefined : appearanceTerm(key, value as NonNullable<Appearance[typeof key]>);
|
|
67
|
+
if (value !== null && !term) continue;
|
|
68
|
+
const predicate = nn(APPEARANCE_PREDICATES[key]);
|
|
69
|
+
remove.push(...store.getQuads(style, predicate, null, MODEL_GRAPH));
|
|
70
|
+
if (term) add.push(triple(style, predicate, term));
|
|
71
|
+
}
|
|
72
|
+
return netChange({ remove, add });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ── Based on another style (core-vis 0.11) ──────────────────────────────
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The styles in the model based on `base` (`arch-vis:basedOn`): diagram elements' own, in IRI order — not a named
|
|
79
|
+
* style's looks for each context, which are based on it as part of it (`baseContextLooks`).
|
|
80
|
+
*/
|
|
81
|
+
export function stylesBasedOn(store: RdfStore, base: Term): Term[] {
|
|
82
|
+
return store
|
|
83
|
+
.getQuads(null, T.basedOn, base as NamedNode, MODEL_GRAPH)
|
|
84
|
+
.map((q) => q.subject)
|
|
85
|
+
.filter((style) => store.getQuads(style as NamedNode, T.inStyleSet, null, MODEL_GRAPH).length === 0)
|
|
86
|
+
.sort((a, b) => a.value.localeCompare(b.value));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The looks for each presentation context of `base`, a style a diagram element's may be based on, by context
|
|
91
|
+
* (core-vis 0.11): a named style's — the styles of its set based on it, each for a context — or, for a concept's
|
|
92
|
+
* look for every context, the concept's looks for each. `undefined` when it has none that says something.
|
|
93
|
+
*/
|
|
94
|
+
export function baseContextLooks(store: RdfStore, base: Term): Record<string, Appearance> | undefined {
|
|
95
|
+
const looks: Record<string, Appearance> = {};
|
|
96
|
+
const add = (style: Term) => {
|
|
97
|
+
const context = store.getQuads(style as NamedNode, T.inPresentationContext, null, MODEL_GRAPH)[0]?.object.value;
|
|
98
|
+
if (!context || looks[context]) return;
|
|
99
|
+
const look = lookOfStyle(store, style);
|
|
100
|
+
if (APPEARANCE_KEYS.some((key) => look[key] !== undefined)) looks[context] = look;
|
|
101
|
+
};
|
|
102
|
+
const set = store.getQuads(base as NamedNode, T.inStyleSet, null, MODEL_GRAPH)[0]?.object;
|
|
103
|
+
if (set) {
|
|
104
|
+
for (const q of store.getQuads(null, T.basedOn, base as NamedNode, MODEL_GRAPH)) {
|
|
105
|
+
if (store.getQuads(q.subject as NamedNode, T.inStyleSet, set as NamedNode, MODEL_GRAPH).length > 0) add(q.subject);
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
for (const holder of store.getQuads(null, T.conceptStyle, base as NamedNode, MODEL_GRAPH)) {
|
|
109
|
+
for (const q of store.getQuads(holder.subject as NamedNode, T.conceptStyle, null, MODEL_GRAPH)) {
|
|
110
|
+
if (q.object.termType !== 'Literal' && !q.object.equals(base)) add(q.object);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return Object.keys(looks).length > 0 ? looks : undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The quads of `base`'s looks for each presentation context (`baseContextLooks`): what a copy holds with the style it
|
|
119
|
+
* is based on, so that a paste that may not stay based on it writes them in — a named style's looks, and a concept's
|
|
120
|
+
* own looks for each context with what names them its looks.
|
|
121
|
+
*/
|
|
122
|
+
export function baseContextLookQuads(store: RdfStore, base: Term): Quad[] {
|
|
123
|
+
const quads: Quad[] = [];
|
|
124
|
+
const set = store.getQuads(base as NamedNode, T.inStyleSet, null, MODEL_GRAPH)[0]?.object;
|
|
125
|
+
const forContext = (style: Term) => store.getQuads(style as NamedNode, T.inPresentationContext, null, MODEL_GRAPH).length > 0;
|
|
126
|
+
if (set) {
|
|
127
|
+
for (const q of store.getQuads(null, T.basedOn, base as NamedNode, MODEL_GRAPH)) {
|
|
128
|
+
if (forContext(q.subject) && store.getQuads(q.subject as NamedNode, T.inStyleSet, set as NamedNode, MODEL_GRAPH).length > 0) {
|
|
129
|
+
quads.push(...store.getQuads(q.subject as NamedNode, null, null, MODEL_GRAPH));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return quads;
|
|
133
|
+
}
|
|
134
|
+
for (const holder of store.getQuads(null, T.conceptStyle, base as NamedNode, MODEL_GRAPH)) {
|
|
135
|
+
for (const q of store.getQuads(holder.subject as NamedNode, T.conceptStyle, null, MODEL_GRAPH)) {
|
|
136
|
+
if (q.object.termType === 'Literal' || q.object.equals(base) || !forContext(q.object)) continue;
|
|
137
|
+
quads.push(q, ...store.getQuads(q.object as NamedNode, null, null, MODEL_GRAPH));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return quads;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* What detaches `style` from the style it is based on (meta's DD-47), so that what hangs it is drawn as it was in
|
|
145
|
+
* every presentation context: unless `keepValues` is false, what the base gave it is written on it — for a style
|
|
146
|
+
* for one context, the base's look for that context first — and it is based on nothing. A style for every context
|
|
147
|
+
* also gives the base's looks for each context to its diagram element's style for that context, made where it has
|
|
148
|
+
* none, wherever nothing drawn before them there sets the value (`appearance.ts`' `detachedLooks`). A style left
|
|
149
|
+
* saying nothing — but what it is and the context it is for — goes, with what hangs it (`arch-vis:style`), as a
|
|
150
|
+
* diagram element's style emptied by `setAppearance` does.
|
|
151
|
+
*/
|
|
152
|
+
export function detachChange(store: RdfStore, style: Term, keepValues = true): { remove: Quad[]; add: Quad[] } {
|
|
153
|
+
const base = store.getQuads(style as NamedNode, T.basedOn, null, MODEL_GRAPH)[0]?.object.value;
|
|
154
|
+
if (!base) return { remove: [], add: [] };
|
|
155
|
+
const context = store.getQuads(style as NamedNode, T.inPresentationContext, null, MODEL_GRAPH)[0]?.object.value;
|
|
156
|
+
const holders = store.getQuads(null, T.visStyle, style as NamedNode, MODEL_GRAPH).map((q) => q.subject);
|
|
157
|
+
if (holders.length === 0) return looseDetachChange(store, style, keepValues);
|
|
158
|
+
return joined(holders.map((holder) => detachHolderChange(store, holder, (b, c) => b === base && c === context, keepValues)));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* What detaches every style based on one of `bases` from it, as when they go (`detachChange`): diagram element by
|
|
163
|
+
* diagram element, so that one with styles based on several of them is rewritten once.
|
|
164
|
+
*/
|
|
165
|
+
export function detachAllChange(store: RdfStore, bases: Term | readonly Term[], keepValues = true): { remove: Quad[]; add: Quad[] } {
|
|
166
|
+
const going = new Set((Array.isArray(bases) ? bases : [bases]).map((base: Term) => base.value));
|
|
167
|
+
const holders = new Map<string, Term>();
|
|
168
|
+
const loose: Term[] = [];
|
|
169
|
+
for (const base of going) {
|
|
170
|
+
for (const style of stylesBasedOn(store, nn(base))) {
|
|
171
|
+
const hangers = store.getQuads(null, T.visStyle, style as NamedNode, MODEL_GRAPH).map((q) => q.subject);
|
|
172
|
+
if (hangers.length === 0) loose.push(style);
|
|
173
|
+
for (const holder of hangers) holders.set(holder.value, holder);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return joined([
|
|
177
|
+
...[...holders.values()].map((holder) => detachHolderChange(store, holder, (base) => going.has(base), keepValues)),
|
|
178
|
+
...loose.map((style) => looseDetachChange(store, style, keepValues)),
|
|
179
|
+
]);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** A style's look's values: what a style based on it takes from it. */
|
|
183
|
+
export function lookOfStyle(store: RdfStore, style: Term): Appearance {
|
|
184
|
+
const look = styleAppearance(store, style);
|
|
185
|
+
delete look.basedOn;
|
|
186
|
+
return look;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* What a node or a link is drawn from, read from the store as its info gives it (`LookSources`): its style for every
|
|
191
|
+
* context and for each — with the style each is based on — and what those based-on styles give.
|
|
192
|
+
*/
|
|
193
|
+
export function holderLooks(store: RdfStore, holder: Term): { every?: Term; contexts: Map<string, Term>; sources: LookSources } {
|
|
194
|
+
let every: Term | undefined;
|
|
195
|
+
const contexts = new Map<string, Term>();
|
|
196
|
+
for (const q of store.getQuads(holder as NamedNode, T.visStyle, null, MODEL_GRAPH)) {
|
|
197
|
+
if (q.object.termType === 'Literal') continue;
|
|
198
|
+
const context = store.getQuads(q.object as NamedNode, T.inPresentationContext, null, MODEL_GRAPH)[0]?.object.value;
|
|
199
|
+
if (context) {
|
|
200
|
+
if (!contexts.has(context)) contexts.set(context, q.object);
|
|
201
|
+
} else every ??= q.object;
|
|
202
|
+
}
|
|
203
|
+
const basedOnLooks: Record<string, Appearance> = {};
|
|
204
|
+
const basedOnContextLooks: Record<string, Record<string, Appearance>> = {};
|
|
205
|
+
const read = (style: Term): Appearance => {
|
|
206
|
+
const look = styleAppearance(store, style);
|
|
207
|
+
if (look.basedOn && !basedOnLooks[look.basedOn]) {
|
|
208
|
+
basedOnLooks[look.basedOn] = lookOfStyle(store, nn(look.basedOn));
|
|
209
|
+
const forContexts = baseContextLooks(store, nn(look.basedOn));
|
|
210
|
+
if (forContexts) basedOnContextLooks[look.basedOn] = forContexts;
|
|
211
|
+
}
|
|
212
|
+
return look;
|
|
213
|
+
};
|
|
214
|
+
const sources: LookSources = {};
|
|
215
|
+
if (every) sources.appearance = read(every);
|
|
216
|
+
if (contexts.size > 0) sources.contextAppearances = Object.fromEntries([...contexts].map(([context, style]) => [context, read(style)]));
|
|
217
|
+
if (Object.keys(basedOnLooks).length > 0) sources.basedOnLooks = basedOnLooks;
|
|
218
|
+
if (Object.keys(basedOnContextLooks).length > 0) sources.basedOnContextLooks = basedOnContextLooks;
|
|
219
|
+
return { ...(every ? { every } : {}), contexts, sources };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* What detaches a node's or a link's styles from the bases `detach` names — given the base and the context the style
|
|
224
|
+
* is for, none for every context: rewritten as `detachedLooks` gives them, or, without `keepValues`, only based on
|
|
225
|
+
* nothing. A style is made for a context where it is given one, and one left saying nothing goes.
|
|
226
|
+
*/
|
|
227
|
+
function detachHolderChange(
|
|
228
|
+
store: RdfStore,
|
|
229
|
+
holder: Term,
|
|
230
|
+
detach: (base: string, context: string | undefined) => boolean,
|
|
231
|
+
keepValues: boolean,
|
|
232
|
+
): { remove: Quad[]; add: Quad[] } {
|
|
233
|
+
const { every, contexts, sources } = holderLooks(store, holder);
|
|
234
|
+
const cut = (look: Appearance | undefined, context: string | undefined): Appearance | undefined =>
|
|
235
|
+
look?.basedOn && detach(look.basedOn, context) ? withoutBase(look) : look;
|
|
236
|
+
const after = keepValues
|
|
237
|
+
? detachedLooks(sources, detach)
|
|
238
|
+
: {
|
|
239
|
+
appearance: cut(sources.appearance, undefined),
|
|
240
|
+
contextAppearances: Object.fromEntries(Object.entries(sources.contextAppearances ?? {}).map(([c, look]) => [c, cut(look, c) ?? {}])),
|
|
241
|
+
};
|
|
242
|
+
const changes = [rewriteStyleChange(store, holder, every, undefined, after.appearance ?? {})];
|
|
243
|
+
const contextIris = new Set([...contexts.keys(), ...Object.keys(after.contextAppearances ?? {})]);
|
|
244
|
+
for (const context of contextIris) changes.push(rewriteStyleChange(store, holder, contexts.get(context), context, after.contextAppearances?.[context] ?? {}));
|
|
245
|
+
return joined(changes);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* What makes `style` — `holder`'s style for `context`, every context when absent — say `look`'s values and the style
|
|
250
|
+
* it is based on, and no others: made where `holder` has none and `look` says something; left saying nothing, gone
|
|
251
|
+
* with what hangs it. What else it says — a label expression — stays.
|
|
252
|
+
*/
|
|
253
|
+
function rewriteStyleChange(store: RdfStore, holder: Term, style: Term | undefined, context: string | undefined, look: Appearance): { remove: Quad[]; add: Quad[] } {
|
|
254
|
+
if (!style) {
|
|
255
|
+
if (!STYLE_KEYS.some((key) => look[key] !== undefined)) return { remove: [], add: [] };
|
|
256
|
+
const made = nn(context ? partIri(partIri(holder.value, 'style'), shortHash(context)) : partIri(holder.value, 'style'));
|
|
257
|
+
return {
|
|
258
|
+
remove: [],
|
|
259
|
+
add: [
|
|
260
|
+
triple(holder as NamedNode, T.visStyle, made),
|
|
261
|
+
triple(made, T.rdfType, T.Style),
|
|
262
|
+
...(context ? [triple(made, T.inPresentationContext, nn(context))] : []),
|
|
263
|
+
...styleQuads(made, look),
|
|
264
|
+
],
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
const subject = style as NamedNode;
|
|
268
|
+
const current = styleAppearance(store, subject);
|
|
269
|
+
const remove: Quad[] = [];
|
|
270
|
+
const add: Quad[] = [];
|
|
271
|
+
for (const key of STYLE_KEYS) {
|
|
272
|
+
if (current[key] === look[key]) continue;
|
|
273
|
+
const predicate = nn(APPEARANCE_PREDICATES[key]);
|
|
274
|
+
remove.push(...store.getQuads(subject, predicate, null, MODEL_GRAPH));
|
|
275
|
+
const value = look[key];
|
|
276
|
+
const term = value === undefined ? undefined : appearanceTerm(key, value as NonNullable<Appearance[typeof key]>);
|
|
277
|
+
if (term) add.push(triple(subject, predicate, term));
|
|
278
|
+
}
|
|
279
|
+
if (remove.length === 0 && add.length === 0) return { remove, add };
|
|
280
|
+
return withEmptyStyleGone(store, subject, netChange({ remove, add }));
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** A style no diagram element hangs, detached: based on nothing, and — unless `keepValues` is false — its base's values written in. */
|
|
284
|
+
function looseDetachChange(store: RdfStore, style: Term, keepValues: boolean): { remove: Quad[]; add: Quad[] } {
|
|
285
|
+
const subject = style as NamedNode;
|
|
286
|
+
const pointers = store.getQuads(subject, T.basedOn, null, MODEL_GRAPH);
|
|
287
|
+
if (pointers.length === 0) return { remove: [], add: [] };
|
|
288
|
+
const own = styleAppearance(store, subject);
|
|
289
|
+
const base = keepValues ? lookOfStyle(store, pointers[0]!.object) : ({} as Appearance);
|
|
290
|
+
const add = APPEARANCE_KEYS.filter((key) => own[key] === undefined).flatMap((key) => {
|
|
291
|
+
const value = base[key];
|
|
292
|
+
const term = value === undefined ? undefined : appearanceTerm(key, value as NonNullable<Appearance[typeof key]>);
|
|
293
|
+
return term ? [triple(subject, nn(APPEARANCE_PREDICATES[key]), term)] : [];
|
|
294
|
+
});
|
|
295
|
+
return netChange({ remove: pointers, add });
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** `look`'s values and the style it is based on, on `style`, as quads. */
|
|
299
|
+
function styleQuads(style: NamedNode, look: Appearance): Quad[] {
|
|
300
|
+
return STYLE_KEYS.flatMap((key) => {
|
|
301
|
+
const value = look[key];
|
|
302
|
+
const term = value === undefined ? undefined : appearanceTerm(key, value as NonNullable<Appearance[typeof key]>);
|
|
303
|
+
return term ? [triple(style, nn(APPEARANCE_PREDICATES[key]), term)] : [];
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** A look without the style it is based on. */
|
|
308
|
+
function withoutBase(look: Appearance): Appearance {
|
|
309
|
+
const values = { ...look };
|
|
310
|
+
delete values.basedOn;
|
|
311
|
+
return values;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Several changes as one. */
|
|
315
|
+
function joined(changes: ReadonlyArray<{ remove: Quad[]; add: Quad[] }>): { remove: Quad[]; add: Quad[] } {
|
|
316
|
+
return {
|
|
317
|
+
remove: dedupeQuads(changes.flatMap((change) => change.remove)),
|
|
318
|
+
add: dedupeQuads(changes.flatMap((change) => change.add)),
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** Quads, each once. */
|
|
323
|
+
function dedupeQuads(quads: Quad[]): Quad[] {
|
|
324
|
+
const seen = new Set<string>();
|
|
325
|
+
return quads.filter((q) => {
|
|
326
|
+
const key = quadKey(q);
|
|
327
|
+
if (seen.has(key)) return false;
|
|
328
|
+
seen.add(key);
|
|
329
|
+
return true;
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* `change` with, when it leaves `style` saying nothing but what it is and the context it is for, the style's
|
|
336
|
+
* remaining quads and what hangs it (`arch-vis:style`) removed too.
|
|
337
|
+
*/
|
|
338
|
+
function withEmptyStyleGone(store: RdfStore, style: NamedNode, change: { remove: Quad[]; add: Quad[] }): { remove: Quad[]; add: Quad[] } {
|
|
339
|
+
const removed = new Set(change.remove.map(quadKey));
|
|
340
|
+
const kept = store.getQuads(style, null, null, MODEL_GRAPH).filter((q) => !removed.has(quadKey(q)));
|
|
341
|
+
const added = change.add.filter((q) => q.subject.value === style.value);
|
|
342
|
+
// A label expression it gives is something it says, as anything but its type and its context is.
|
|
343
|
+
const says = [...kept, ...added].some((q) => q.predicate.value !== IRI.rdfType && q.predicate.value !== IRI.inPresentationContext);
|
|
344
|
+
if (says) return change;
|
|
345
|
+
return {
|
|
346
|
+
remove: [...change.remove, ...kept, ...store.getQuads(null, T.visStyle, style, MODEL_GRAPH)],
|
|
347
|
+
add: change.add.filter((q) => q.subject.value !== style.value),
|
|
348
|
+
};
|
|
349
|
+
}
|
|
@@ -82,12 +82,15 @@ import { collectRelationshipQuads, relationshipsTouching } from './cascade.js';
|
|
|
82
82
|
import {
|
|
83
83
|
APPEARANCE_KEYS,
|
|
84
84
|
APPEARANCE_PREDICATES,
|
|
85
|
-
|
|
85
|
+
STYLE_KEYS,
|
|
86
86
|
appearanceOrNone,
|
|
87
87
|
appearanceValue,
|
|
88
|
+
lookValues,
|
|
88
89
|
type Appearance,
|
|
89
90
|
type AppearanceChanges,
|
|
90
91
|
} from './appearance.js';
|
|
92
|
+
import { conceptStyleQuads } from './concept-styles.js';
|
|
93
|
+
import { appearanceTerm, baseContextLooks } from './style-values.js';
|
|
91
94
|
import type {
|
|
92
95
|
Bounds,
|
|
93
96
|
FigureColours,
|
|
@@ -286,7 +289,8 @@ export class OxigraphViewManager implements ViewManager {
|
|
|
286
289
|
|
|
287
290
|
collectViewQuads(viewIri: string): Quad[] {
|
|
288
291
|
const view = nn(viewIri);
|
|
289
|
-
|
|
292
|
+
// Its own triples, and its own looks (core-vis 0.11), which its references were drawn with.
|
|
293
|
+
const quads: Quad[] = [...this.read(view, null, null), ...conceptStyleQuads(this.store, viewIri)];
|
|
290
294
|
// Everything drawn in it, with its routes…
|
|
291
295
|
for (const node of this.read(null, T.visView, view)) {
|
|
292
296
|
quads.push(...this.subjectQuads(node.subject));
|
|
@@ -378,8 +382,8 @@ export class OxigraphViewManager implements ViewManager {
|
|
|
378
382
|
const [parentNode] = figure.parentIri ? this.nodeIrisFor(viewIri, figure.parentIri) : [];
|
|
379
383
|
if (parentNode && parentNode !== nodeIri) quads.push(triple(node, T.inNode, nn(parentNode)));
|
|
380
384
|
this.store.addQuads(quads);
|
|
381
|
-
// How it looks, as a copied view's figure does.
|
|
382
|
-
const appearance = appearanceOrNone(Object.fromEntries(
|
|
385
|
+
// How it looks, as a copied view's figure does — and the style it is based on (core-vis 0.11).
|
|
386
|
+
const appearance = appearanceOrNone(Object.fromEntries(STYLE_KEYS.map((key) => [key, figure[key]])) as Appearance);
|
|
383
387
|
if (appearance) this.setAppearance(viewIri, nodeIri, appearance);
|
|
384
388
|
return nodeIri;
|
|
385
389
|
}
|
|
@@ -786,6 +790,8 @@ export class OxigraphViewManager implements ViewManager {
|
|
|
786
790
|
return {
|
|
787
791
|
nodeIri: node.value,
|
|
788
792
|
elementIri,
|
|
793
|
+
// What it is drawn from besides its own styles: what they are based on.
|
|
794
|
+
...this.inheritedLooks(node),
|
|
789
795
|
...(zOrder ? { zOrder } : {}),
|
|
790
796
|
...(labelExpressions.length > 0 ? { labelExpressions } : {}),
|
|
791
797
|
...(contextAppearances ? { contextAppearances } : {}),
|
|
@@ -821,6 +827,7 @@ export class OxigraphViewManager implements ViewManager {
|
|
|
821
827
|
return {
|
|
822
828
|
...(appearance ? { appearance } : {}),
|
|
823
829
|
...(contextAppearances ? { contextAppearances } : {}),
|
|
830
|
+
...this.inheritedLooks(link),
|
|
824
831
|
...(text ? { text } : {}),
|
|
825
832
|
linkIri: link.value,
|
|
826
833
|
relationshipIri,
|
|
@@ -967,7 +974,8 @@ export class OxigraphViewManager implements ViewManager {
|
|
|
967
974
|
// A node or a link of this view, named by its own IRI.
|
|
968
975
|
if (!this.objects(subject, T.visView).includes(viewIri)) return;
|
|
969
976
|
if (!this.readNode(subject) && !this.objects(subject, T.rdfType).includes(IRI.Link)) return;
|
|
970
|
-
|
|
977
|
+
// Its look's values, and the style it is based on (core-vis 0.11): a set's named style, its concept's own look.
|
|
978
|
+
const keys = STYLE_KEYS.filter((key) => changes[key] !== undefined);
|
|
971
979
|
if (keys.length === 0) return;
|
|
972
980
|
// A line's text put somewhere else along it: no longer where it was moved by hand.
|
|
973
981
|
const current = context ? this.contextAppearancesOf(subject)?.[context] : this.appearanceOf(subject);
|
|
@@ -979,22 +987,11 @@ export class OxigraphViewManager implements ViewManager {
|
|
|
979
987
|
for (const key of keys) {
|
|
980
988
|
const predicate = nn(APPEARANCE_PREDICATES[key]);
|
|
981
989
|
const value = changes[key];
|
|
982
|
-
const
|
|
990
|
+
const term = value === null || value === undefined ? undefined : appearanceTerm(key, value);
|
|
983
991
|
// A value that is not one of the key's — a picture's address that is none — changes nothing.
|
|
984
|
-
if (value !== null && !
|
|
992
|
+
if (value !== null && !term) continue;
|
|
985
993
|
this.remove(this.read(style, predicate));
|
|
986
|
-
if (
|
|
987
|
-
const term =
|
|
988
|
-
'iri' in object
|
|
989
|
-
? nn(object.iri)
|
|
990
|
-
: 'integer' in object
|
|
991
|
-
? DataFactory.literal(String(object.integer), nn(NAMESPACES.xsd + 'integer'))
|
|
992
|
-
: 'uri' in object
|
|
993
|
-
? DataFactory.literal(object.uri, nn(NAMESPACES.xsd + 'anyURI'))
|
|
994
|
-
: 'boolean' in object
|
|
995
|
-
? DataFactory.literal(String(object.boolean), nn(NAMESPACES.xsd + 'boolean'))
|
|
996
|
-
: DataFactory.literal(object.string);
|
|
997
|
-
this.store.addQuads([triple(style, predicate, term)]);
|
|
994
|
+
if (term) this.store.addQuads([triple(style, predicate, term)]);
|
|
998
995
|
}
|
|
999
996
|
// Nothing left to say — but what it is, and the context it is for: no such style at all.
|
|
1000
997
|
if (this.read(style).every((q) => q.predicate.value === IRI.rdfType || q.predicate.value === IRI.inPresentationContext)) {
|
|
@@ -1037,6 +1034,33 @@ export class OxigraphViewManager implements ViewManager {
|
|
|
1037
1034
|
return Object.keys(looks).length > 0 ? looks : undefined;
|
|
1038
1035
|
}
|
|
1039
1036
|
|
|
1037
|
+
/**
|
|
1038
|
+
* What a node or a link is drawn from besides its own styles (core-vis 0.11, `drawnLook`): the looks its styles
|
|
1039
|
+
* are based on, for every presentation context and for each, by the based-on style's IRI — a style set's named
|
|
1040
|
+
* style and its looks for each context, its concept's saved look and its looks for each. A based-on style's own
|
|
1041
|
+
* base is not followed: a style is based on one that is based on none (core-vis-shapes 0.7.0), so there is no
|
|
1042
|
+
* chain to read, nor a loop.
|
|
1043
|
+
*/
|
|
1044
|
+
private inheritedLooks(subject: Term): Pick<NodeInfo, 'basedOnLooks' | 'basedOnContextLooks'> {
|
|
1045
|
+
const basedOnLooks: Record<string, Appearance> = {};
|
|
1046
|
+
const basedOnContextLooks: Record<string, Record<string, Appearance>> = {};
|
|
1047
|
+
const seen = new Set<string>();
|
|
1048
|
+
for (const q of this.read(subject as NamedNode, T.visStyle)) {
|
|
1049
|
+
for (const base of this.read(q.object as NamedNode, T.basedOn)) {
|
|
1050
|
+
if (base.object.termType !== 'NamedNode' || seen.has(base.object.value)) continue;
|
|
1051
|
+
seen.add(base.object.value);
|
|
1052
|
+
const look = appearanceOrNone(lookValues(this.appearanceOfStyle(base.object)));
|
|
1053
|
+
if (look) basedOnLooks[base.object.value] = look;
|
|
1054
|
+
const forContexts = baseContextLooks(this.store, base.object);
|
|
1055
|
+
if (forContexts) basedOnContextLooks[base.object.value] = forContexts;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return {
|
|
1059
|
+
...(Object.keys(basedOnLooks).length > 0 ? { basedOnLooks } : {}),
|
|
1060
|
+
...(Object.keys(basedOnContextLooks).length > 0 ? { basedOnContextLooks } : {}),
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1040
1064
|
usedImages(): string[] {
|
|
1041
1065
|
// A picture in a node, and a placement's own icon — a style a diagram element hangs, not a notation's glyph.
|
|
1042
1066
|
const own = this.read(null, nn(APPEARANCE_PREDICATES.iconSymbol)).filter(
|
|
@@ -1148,10 +1172,10 @@ export class OxigraphViewManager implements ViewManager {
|
|
|
1148
1172
|
return style ? appearanceOrNone(this.appearanceOfStyle(style)) : undefined;
|
|
1149
1173
|
}
|
|
1150
1174
|
|
|
1151
|
-
/** What a style says of how its node or link looks. */
|
|
1175
|
+
/** What a style says of how its node or link looks — and the style it is based on (core-vis 0.11). */
|
|
1152
1176
|
private appearanceOfStyle(style: Term): Appearance {
|
|
1153
1177
|
const appearance: Record<string, unknown> = {};
|
|
1154
|
-
for (const key of
|
|
1178
|
+
for (const key of STYLE_KEYS) {
|
|
1155
1179
|
const term = this.read(style as NamedNode, nn(APPEARANCE_PREDICATES[key]))[0]?.object;
|
|
1156
1180
|
const value = term ? appearanceValue(key, term) : undefined;
|
|
1157
1181
|
if (value !== undefined) appearance[key] = value;
|
|
@@ -1177,9 +1201,22 @@ export class OxigraphViewManager implements ViewManager {
|
|
|
1177
1201
|
if (current.length === 1 && this.isOwnStyle(subject.value, current[0]!.object)) return current[0]!.object as NamedNode;
|
|
1178
1202
|
const own = nn(this.styleIriOf(subject.value));
|
|
1179
1203
|
const quads: Quad[] = [triple(subject, T.visStyle, own), triple(own, T.rdfType, T.Style)];
|
|
1204
|
+
// One base at most: a style is based on one style (core-vis 0.11).
|
|
1205
|
+
let based = false;
|
|
1180
1206
|
for (const q of current) {
|
|
1207
|
+
// A style set's named style, or its concept's saved look, is not copied but based on: so it keeps following it.
|
|
1208
|
+
if (this.isBase(subject, q.object)) {
|
|
1209
|
+
if (!based) quads.push(triple(own, T.basedOn, q.object));
|
|
1210
|
+
based = true;
|
|
1211
|
+
continue;
|
|
1212
|
+
}
|
|
1181
1213
|
for (const said of this.read(q.object)) {
|
|
1182
|
-
if (said.predicate.value
|
|
1214
|
+
if (said.predicate.value === IRI.rdfType) continue;
|
|
1215
|
+
if (said.predicate.value === IRI.basedOn) {
|
|
1216
|
+
if (based) continue;
|
|
1217
|
+
based = true;
|
|
1218
|
+
}
|
|
1219
|
+
quads.push(triple(own, said.predicate as NamedNode, said.object));
|
|
1183
1220
|
}
|
|
1184
1221
|
}
|
|
1185
1222
|
// What it replaces goes: a blank style only it used, and one named as its own — not a style others share.
|
|
@@ -1191,6 +1228,21 @@ export class OxigraphViewManager implements ViewManager {
|
|
|
1191
1228
|
return own;
|
|
1192
1229
|
}
|
|
1193
1230
|
|
|
1231
|
+
/**
|
|
1232
|
+
* Whether `style` is one a diagram element's style is based on rather than a copy of (core-vis 0.11): a style
|
|
1233
|
+
* set's named style, or the saved look — for every presentation context — of the concept `subject` draws.
|
|
1234
|
+
*/
|
|
1235
|
+
private isBase(subject: Term, style: Term): boolean {
|
|
1236
|
+
if (style.termType !== 'NamedNode') return false;
|
|
1237
|
+
if (this.read(style as NamedNode, T.inStyleSet).length > 0) return true;
|
|
1238
|
+
const concept = this.objects(subject, T.archElement)[0] ?? this.objects(subject, T.archRelationship)[0] ?? this.viewOf(subject);
|
|
1239
|
+
return (
|
|
1240
|
+
concept !== undefined &&
|
|
1241
|
+
this.read(nn(concept), T.conceptStyle, style as NamedNode).length > 0 &&
|
|
1242
|
+
this.read(style as NamedNode, T.inPresentationContext).length === 0
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1194
1246
|
/** A blank-node style only `style` names — a converter's — whose quads go with what it styles. */
|
|
1195
1247
|
private ownedBlankStyle(style: Term): Quad[] {
|
|
1196
1248
|
if (style.termType !== 'BlankNode' || this.read(null, T.visStyle, style).length !== 1) return [];
|
|
@@ -132,6 +132,16 @@ export const IRI = {
|
|
|
132
132
|
ViewReferenceNode: VIS + 'ViewReferenceNode',
|
|
133
133
|
visStyle: VIS + 'style',
|
|
134
134
|
Style: VIS + 'Style',
|
|
135
|
+
/**
|
|
136
|
+
* Looks to share, and a concept's own (core-vis 0.11): a named set of styles, the set a named style is in, the
|
|
137
|
+
* sets a model's diagrams take styles from, the style a style takes its values from where it sets none, and a
|
|
138
|
+
* model concept's own look — one for every presentation context, and one for each.
|
|
139
|
+
*/
|
|
140
|
+
StyleSet: VIS + 'StyleSet',
|
|
141
|
+
inStyleSet: VIS + 'inStyleSet',
|
|
142
|
+
usesStyleSet: VIS + 'usesStyleSet',
|
|
143
|
+
basedOn: VIS + 'basedOn',
|
|
144
|
+
conceptStyle: VIS + 'conceptStyle',
|
|
135
145
|
/** What a label says (core-vis 0.7): an `arch-vis:LabelExpression`, its text, the notation set it is for. */
|
|
136
146
|
labelExpression: VIS + 'labelExpression',
|
|
137
147
|
LabelExpression: VIS + 'LabelExpression',
|
package/src/rdf-engine/iri.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
* ```
|
|
18
18
|
* {ns}model the arch:Model
|
|
19
|
-
* {ns}{kind}/{uuid} an element, relationship, view or
|
|
19
|
+
* {ns}{kind}/{uuid} an element, relationship, view, folder or style set
|
|
20
20
|
* {view}#node-{uuid} {view}#link-{uuid} a shape drawn in a view, named in the view's IRI
|
|
21
21
|
* {owner}/{part}[/{key}] a part: {concept}/name/{context}, {folder}/item/{digest}, …
|
|
22
22
|
* {shape}-{part}[-{key}] a shape's part: {node}-style, {link}-points-{i}, {link}-point-{i}, …
|
|
@@ -68,8 +68,11 @@ export function uuid(): string {
|
|
|
68
68
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
/**
|
|
72
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Kinds of resource minted in a model's namespace, `{ns}{kind}/{uuid}` — a style set's too (core-vis 0.11's
|
|
73
|
+
* `arch-vis:StyleSet`, kept in the model). A shape is minted in its view: {@link mintShapeIri}.
|
|
74
|
+
*/
|
|
75
|
+
export type MintKind = 'element' | 'relationship' | 'view' | 'folder' | 'styleset';
|
|
73
76
|
|
|
74
77
|
/** Kinds of shape drawn in a view. */
|
|
75
78
|
export type ShapeKind = 'node' | 'link';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quads given to Oxigraph in one native load of N-Triples rather than quad by quad: on a model of 365 000 triples,
|
|
3
|
+
* 2.1 s against 55 s and 402 against 570 MiB of WebAssembly memory, measured in Node (KD-28, KD-29). For the quads
|
|
4
|
+
* N-Triples carries as they are; the rest go one by one.
|
|
5
|
+
*/
|
|
6
|
+
import { DataFactory, Writer } from 'n3';
|
|
7
|
+
import type { Quad, Term } from '@rdfjs/types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Whether a term goes into a native load as it is: not a blank node, whose label a bulk load reassigns, nor a
|
|
11
|
+
* directional literal; a triple term of such terms.
|
|
12
|
+
*/
|
|
13
|
+
export function canLoadAsTriples(term: Term): boolean {
|
|
14
|
+
if (term.termType === 'BlankNode') return false;
|
|
15
|
+
if (term.termType === 'Literal') return !(term as { direction?: string }).direction;
|
|
16
|
+
if (term.termType === 'Quad') {
|
|
17
|
+
const triple = term as unknown as Quad;
|
|
18
|
+
return triple.graph.termType === 'DefaultGraph' && canLoadAsTriples(triple.subject) && canLoadAsTriples(triple.object);
|
|
19
|
+
}
|
|
20
|
+
return term.termType === 'NamedNode';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The quads a native load takes as they are, and the rest, for one by one. */
|
|
24
|
+
export function splitForNativeLoad(quads: Iterable<Quad>): { native: Quad[]; oneByOne: Quad[] } {
|
|
25
|
+
const native: Quad[] = [];
|
|
26
|
+
const oneByOne: Quad[] = [];
|
|
27
|
+
for (const q of quads) (canLoadAsTriples(q.subject) && canLoadAsTriples(q.object) ? native : oneByOne).push(q);
|
|
28
|
+
return { native, oneByOne };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The quads as N-Triples, each in the default graph: a load names the graph they go into. */
|
|
32
|
+
export function nTriples(quads: readonly Quad[]): string {
|
|
33
|
+
const triples = quads.map((q) =>
|
|
34
|
+
q.graph.termType === 'DefaultGraph' ? q : (DataFactory.quad(q.subject as never, q.predicate as never, q.object as never) as unknown as Quad),
|
|
35
|
+
);
|
|
36
|
+
return new Writer({ format: 'N-Triples' }).quadsToString(triples as never);
|
|
37
|
+
}
|