@linked.archi/kernel 0.0.0-stage → 0.1.5
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/LICENSE +202 -0
- package/NOTICE +11 -0
- package/README.md +96 -2
- package/assets/arch-decision/arch-decision-metamodel.ttl +44 -0
- package/assets/arch-decision/arch-decision-onto.ttl +1566 -0
- package/assets/arch-decision/arch-decision-shapes.ttl +582 -0
- package/assets/arch-decision/arch-decision-tax.ttl +129 -0
- package/assets/arch-processes/arch-processes-metamodel.ttl +42 -0
- package/assets/arch-processes/arch-processes-tax.ttl +136 -0
- package/assets/arch-processes/archProcesses-shapes.ttl +189 -0
- package/assets/arch-processes/archProcesses.ttl +953 -0
- package/assets/archimate3/archimate3.2-element-shapes.ttl +379 -0
- package/assets/archimate3/archimate3.2-metamodel.ttl +205 -0
- package/assets/archimate3/archimate3.2-notation.ttl +1503 -0
- package/assets/archimate3/archimate3.2-onto.ttl +1579 -0
- package/assets/archimate3/archimate3.2-presentation-contexts.ttl +90 -0
- package/assets/archimate3/archimate3.2-principle-shapes.ttl +923 -0
- package/assets/archimate3/archimate3.2-questions.ttl +1125 -0
- package/assets/archimate3/archimate3.2-reference-data.ttl +74 -0
- package/assets/archimate3/archimate3.2-relationship-shapes.ttl +30956 -0
- package/assets/archimate3/archimate3.2-relationship-tables.ttl +5992 -0
- package/assets/archimate3/archimate3.2-tax.ttl +724 -0
- package/assets/archimate3/archimate3.2-viewpoint-shapes.ttl +59 -0
- package/assets/archimate3/archimate3.2-viewpoints.ttl +793 -0
- package/assets/archimate3/icons/and-junction.svg +3 -0
- package/assets/archimate3/icons/application-collaboration.svg +22 -0
- package/assets/archimate3/icons/application-component.svg +18 -0
- package/assets/archimate3/icons/application-event.svg +15 -0
- package/assets/archimate3/icons/application-function.svg +14 -0
- package/assets/archimate3/icons/application-interaction.svg +17 -0
- package/assets/archimate3/icons/application-interface.svg +16 -0
- package/assets/archimate3/icons/application-process.svg +14 -0
- package/assets/archimate3/icons/application-service.svg +14 -0
- package/assets/archimate3/icons/artifact.svg +16 -0
- package/assets/archimate3/icons/assessment.svg +17 -0
- package/assets/archimate3/icons/business-actor.svg +22 -0
- package/assets/archimate3/icons/business-collaboration.svg +21 -0
- package/assets/archimate3/icons/business-event.svg +15 -0
- package/assets/archimate3/icons/business-function.svg +14 -0
- package/assets/archimate3/icons/business-interaction.svg +18 -0
- package/assets/archimate3/icons/business-interface.svg +16 -0
- package/assets/archimate3/icons/business-object.svg +14 -0
- package/assets/archimate3/icons/business-process.svg +15 -0
- package/assets/archimate3/icons/business-role.svg +16 -0
- package/assets/archimate3/icons/business-service.svg +14 -0
- package/assets/archimate3/icons/capability.svg +40 -0
- package/assets/archimate3/icons/communication-network.svg +18 -0
- package/assets/archimate3/icons/constraint.svg +18 -0
- package/assets/archimate3/icons/contract.svg +13 -0
- package/assets/archimate3/icons/course-of-action.svg +20 -0
- package/assets/archimate3/icons/data-object.svg +14 -0
- package/assets/archimate3/icons/deliverable.svg +11 -0
- package/assets/archimate3/icons/device.svg +18 -0
- package/assets/archimate3/icons/distribution-network.svg +19 -0
- package/assets/archimate3/icons/driver.svg +24 -0
- package/assets/archimate3/icons/equipment.svg +31 -0
- package/assets/archimate3/icons/facility.svg +16 -0
- package/assets/archimate3/icons/gap.svg +22 -0
- package/assets/archimate3/icons/glyphs/activity.svg +3 -0
- package/assets/archimate3/icons/glyphs/actor.svg +14 -0
- package/assets/archimate3/icons/glyphs/application-component.svg +12 -0
- package/assets/archimate3/icons/glyphs/artifact.svg +9 -0
- package/assets/archimate3/icons/glyphs/assessment.svg +9 -0
- package/assets/archimate3/icons/glyphs/capability.svg +32 -0
- package/assets/archimate3/icons/glyphs/cloud-gear.svg +3 -0
- package/assets/archimate3/icons/glyphs/collaboration.svg +15 -0
- package/assets/archimate3/icons/glyphs/communication-network.svg +12 -0
- package/assets/archimate3/icons/glyphs/constraint.svg +10 -0
- package/assets/archimate3/icons/glyphs/contract.svg +5 -0
- package/assets/archimate3/icons/glyphs/course-of-action.svg +12 -0
- package/assets/archimate3/icons/glyphs/data-object.svg +4 -0
- package/assets/archimate3/icons/glyphs/deliverable.svg +3 -0
- package/assets/archimate3/icons/glyphs/device.svg +10 -0
- package/assets/archimate3/icons/glyphs/distribution-network.svg +11 -0
- package/assets/archimate3/icons/glyphs/driver.svg +16 -0
- package/assets/archimate3/icons/glyphs/equipment.svg +22 -0
- package/assets/archimate3/icons/glyphs/event.svg +6 -0
- package/assets/archimate3/icons/glyphs/facility.svg +7 -0
- package/assets/archimate3/icons/glyphs/function.svg +6 -0
- package/assets/archimate3/icons/glyphs/gap.svg +14 -0
- package/assets/archimate3/icons/glyphs/goal.svg +10 -0
- package/assets/archimate3/icons/glyphs/grouping.svg +4 -0
- package/assets/archimate3/icons/glyphs/interaction.svg +10 -0
- package/assets/archimate3/icons/glyphs/interface.svg +8 -0
- package/assets/archimate3/icons/glyphs/location.svg +6 -0
- package/assets/archimate3/icons/glyphs/material.svg +12 -0
- package/assets/archimate3/icons/glyphs/meaning.svg +3 -0
- package/assets/archimate3/icons/glyphs/node.svg +8 -0
- package/assets/archimate3/icons/glyphs/object.svg +4 -0
- package/assets/archimate3/icons/glyphs/outcome.svg +16 -0
- package/assets/archimate3/icons/glyphs/path.svg +10 -0
- package/assets/archimate3/icons/glyphs/person-silhouette.svg +3 -0
- package/assets/archimate3/icons/glyphs/plateau.svg +8 -0
- package/assets/archimate3/icons/glyphs/principle.svg +12 -0
- package/assets/archimate3/icons/glyphs/process.svg +6 -0
- package/assets/archimate3/icons/glyphs/product.svg +4 -0
- package/assets/archimate3/icons/glyphs/representation.svg +4 -0
- package/assets/archimate3/icons/glyphs/requirement.svg +6 -0
- package/assets/archimate3/icons/glyphs/resource.svg +14 -0
- package/assets/archimate3/icons/glyphs/role.svg +6 -0
- package/assets/archimate3/icons/glyphs/service.svg +6 -0
- package/assets/archimate3/icons/glyphs/stakeholder.svg +6 -0
- package/assets/archimate3/icons/glyphs/system-software.svg +14 -0
- package/assets/archimate3/icons/glyphs/value-stream.svg +3 -0
- package/assets/archimate3/icons/glyphs/value.svg +3 -0
- package/assets/archimate3/icons/glyphs/work-package.svg +4 -0
- package/assets/archimate3/icons/goal.svg +18 -0
- package/assets/archimate3/icons/grouping.svg +12 -0
- package/assets/archimate3/icons/implementation-event.svg +15 -0
- package/assets/archimate3/icons/location.svg +14 -0
- package/assets/archimate3/icons/material.svg +21 -0
- package/assets/archimate3/icons/meaning.svg +11 -0
- package/assets/archimate3/icons/node.svg +14 -0
- package/assets/archimate3/icons/or-junction.svg +3 -0
- package/assets/archimate3/icons/outcome.svg +25 -0
- package/assets/archimate3/icons/path.svg +18 -0
- package/assets/archimate3/icons/plateau.svg +16 -0
- package/assets/archimate3/icons/principle.svg +21 -0
- package/assets/archimate3/icons/product.svg +12 -0
- package/assets/archimate3/icons/representation.svg +12 -0
- package/assets/archimate3/icons/requirement.svg +14 -0
- package/assets/archimate3/icons/resource.svg +23 -0
- package/assets/archimate3/icons/stakeholder.svg +15 -0
- package/assets/archimate3/icons/system-software.svg +22 -0
- package/assets/archimate3/icons/technology-collaboration.svg +22 -0
- package/assets/archimate3/icons/technology-event.svg +15 -0
- package/assets/archimate3/icons/technology-function.svg +14 -0
- package/assets/archimate3/icons/technology-interaction.svg +18 -0
- package/assets/archimate3/icons/technology-interface.svg +16 -0
- package/assets/archimate3/icons/technology-process.svg +14 -0
- package/assets/archimate3/icons/technology-service.svg +14 -0
- package/assets/archimate3/icons/value-stream.svg +11 -0
- package/assets/archimate3/icons/value.svg +11 -0
- package/assets/archimate3/icons/work-package.svg +12 -0
- package/assets/archimate4/archimate4-element-shapes.ttl +404 -0
- package/assets/archimate4/archimate4-metamodel.ttl +179 -0
- package/assets/archimate4/archimate4-notation.ttl +1147 -0
- package/assets/archimate4/archimate4-onto.ttl +1559 -0
- package/assets/archimate4/archimate4-presentation-contexts.ttl +60 -0
- package/assets/archimate4/archimate4-principle-shapes.ttl +893 -0
- package/assets/archimate4/archimate4-questions.ttl +1224 -0
- package/assets/archimate4/archimate4-reference-data.ttl +56 -0
- package/assets/archimate4/archimate4-relationship-shapes.ttl +16920 -0
- package/assets/archimate4/archimate4-relationship-tables.ttl +3200 -0
- package/assets/archimate4/archimate4-tax.ttl +749 -0
- package/assets/archimate4/archimate4-viewpoint-shapes.ttl +55 -0
- package/assets/archimate4/archimate4-viewpoints.ttl +777 -0
- package/assets/archimate4/icons/and-junction.svg +3 -0
- package/assets/archimate4/icons/application-component.svg +18 -0
- package/assets/archimate4/icons/application-interface.svg +16 -0
- package/assets/archimate4/icons/artifact.svg +16 -0
- package/assets/archimate4/icons/assessment.svg +17 -0
- package/assets/archimate4/icons/business-actor.svg +22 -0
- package/assets/archimate4/icons/business-interface.svg +16 -0
- package/assets/archimate4/icons/business-object.svg +14 -0
- package/assets/archimate4/icons/capability.svg +40 -0
- package/assets/archimate4/icons/collaboration.svg +21 -0
- package/assets/archimate4/icons/communication-network.svg +18 -0
- package/assets/archimate4/icons/course-of-action.svg +20 -0
- package/assets/archimate4/icons/data-object.svg +14 -0
- package/assets/archimate4/icons/deliverable.svg +11 -0
- package/assets/archimate4/icons/device.svg +18 -0
- package/assets/archimate4/icons/distribution-network.svg +19 -0
- package/assets/archimate4/icons/driver.svg +24 -0
- package/assets/archimate4/icons/equipment.svg +31 -0
- package/assets/archimate4/icons/event.svg +15 -0
- package/assets/archimate4/icons/facility.svg +16 -0
- package/assets/archimate4/icons/function.svg +13 -0
- package/assets/archimate4/icons/glyphs/activity.svg +3 -0
- package/assets/archimate4/icons/glyphs/actor.svg +14 -0
- package/assets/archimate4/icons/glyphs/application-component.svg +12 -0
- package/assets/archimate4/icons/glyphs/artifact.svg +9 -0
- package/assets/archimate4/icons/glyphs/assessment.svg +9 -0
- package/assets/archimate4/icons/glyphs/capability.svg +32 -0
- package/assets/archimate4/icons/glyphs/cloud-gear.svg +3 -0
- package/assets/archimate4/icons/glyphs/collaboration.svg +15 -0
- package/assets/archimate4/icons/glyphs/communication-network.svg +12 -0
- package/assets/archimate4/icons/glyphs/constraint.svg +10 -0
- package/assets/archimate4/icons/glyphs/contract.svg +5 -0
- package/assets/archimate4/icons/glyphs/course-of-action.svg +12 -0
- package/assets/archimate4/icons/glyphs/data-object.svg +4 -0
- package/assets/archimate4/icons/glyphs/deliverable.svg +3 -0
- package/assets/archimate4/icons/glyphs/device.svg +10 -0
- package/assets/archimate4/icons/glyphs/distribution-network.svg +11 -0
- package/assets/archimate4/icons/glyphs/driver.svg +16 -0
- package/assets/archimate4/icons/glyphs/equipment.svg +22 -0
- package/assets/archimate4/icons/glyphs/event.svg +6 -0
- package/assets/archimate4/icons/glyphs/facility.svg +7 -0
- package/assets/archimate4/icons/glyphs/function.svg +6 -0
- package/assets/archimate4/icons/glyphs/gap.svg +14 -0
- package/assets/archimate4/icons/glyphs/goal.svg +10 -0
- package/assets/archimate4/icons/glyphs/grouping.svg +4 -0
- package/assets/archimate4/icons/glyphs/interaction.svg +10 -0
- package/assets/archimate4/icons/glyphs/interface.svg +8 -0
- package/assets/archimate4/icons/glyphs/location.svg +6 -0
- package/assets/archimate4/icons/glyphs/material.svg +12 -0
- package/assets/archimate4/icons/glyphs/meaning.svg +3 -0
- package/assets/archimate4/icons/glyphs/node.svg +8 -0
- package/assets/archimate4/icons/glyphs/object.svg +4 -0
- package/assets/archimate4/icons/glyphs/outcome.svg +16 -0
- package/assets/archimate4/icons/glyphs/path.svg +10 -0
- package/assets/archimate4/icons/glyphs/person-silhouette.svg +3 -0
- package/assets/archimate4/icons/glyphs/plateau.svg +8 -0
- package/assets/archimate4/icons/glyphs/principle.svg +12 -0
- package/assets/archimate4/icons/glyphs/process.svg +6 -0
- package/assets/archimate4/icons/glyphs/product.svg +4 -0
- package/assets/archimate4/icons/glyphs/representation.svg +4 -0
- package/assets/archimate4/icons/glyphs/requirement.svg +6 -0
- package/assets/archimate4/icons/glyphs/resource.svg +14 -0
- package/assets/archimate4/icons/glyphs/role.svg +6 -0
- package/assets/archimate4/icons/glyphs/service.svg +6 -0
- package/assets/archimate4/icons/glyphs/stakeholder.svg +6 -0
- package/assets/archimate4/icons/glyphs/system-software.svg +14 -0
- package/assets/archimate4/icons/glyphs/value-stream.svg +3 -0
- package/assets/archimate4/icons/glyphs/value.svg +3 -0
- package/assets/archimate4/icons/glyphs/work-package.svg +4 -0
- package/assets/archimate4/icons/goal.svg +18 -0
- package/assets/archimate4/icons/grouping.svg +12 -0
- package/assets/archimate4/icons/location.svg +14 -0
- package/assets/archimate4/icons/material.svg +21 -0
- package/assets/archimate4/icons/meaning.svg +11 -0
- package/assets/archimate4/icons/node.svg +14 -0
- package/assets/archimate4/icons/or-junction.svg +3 -0
- package/assets/archimate4/icons/outcome.svg +25 -0
- package/assets/archimate4/icons/path.svg +18 -0
- package/assets/archimate4/icons/plateau.svg +16 -0
- package/assets/archimate4/icons/principle.svg +21 -0
- package/assets/archimate4/icons/process.svg +15 -0
- package/assets/archimate4/icons/product.svg +12 -0
- package/assets/archimate4/icons/requirement.svg +14 -0
- package/assets/archimate4/icons/resource.svg +23 -0
- package/assets/archimate4/icons/role.svg +16 -0
- package/assets/archimate4/icons/service.svg +13 -0
- package/assets/archimate4/icons/stakeholder.svg +15 -0
- package/assets/archimate4/icons/system-software.svg +22 -0
- package/assets/archimate4/icons/technology-interface.svg +16 -0
- package/assets/archimate4/icons/value-stream.svg +11 -0
- package/assets/archimate4/icons/value.svg +11 -0
- package/assets/archimate4/icons/work-package.svg +12 -0
- package/assets/basic/basic-metamodel.ttl +100 -0
- package/assets/basic/basic-notation-bubble.ttl +175 -0
- package/assets/basic/basic-notation.ttl +172 -0
- package/assets/basic/basic-onto.ttl +171 -0
- package/assets/basic/basic-presentation-contexts.ttl +70 -0
- package/assets/basic/basic-tax.ttl +130 -0
- package/assets/basic/icons/aggregation.svg +7 -0
- package/assets/basic/icons/association.svg +6 -0
- package/assets/basic/icons/element.svg +5 -0
- package/assets/basic/icons/glyphs/aggregation.svg +6 -0
- package/assets/basic/icons/glyphs/association.svg +5 -0
- package/assets/basic/icons/glyphs/element.svg +5 -0
- package/assets/basic/icons/glyphs/relationship.svg +5 -0
- package/assets/basic/icons/relationship.svg +7 -0
- package/assets/basic/notation-bubble/icons/aggregation.svg +7 -0
- package/assets/basic/notation-bubble/icons/association.svg +6 -0
- package/assets/basic/notation-bubble/icons/element.svg +5 -0
- package/assets/basic/notation-bubble/icons/glyphs/aggregation.svg +6 -0
- package/assets/basic/notation-bubble/icons/glyphs/association.svg +5 -0
- package/assets/basic/notation-bubble/icons/glyphs/element.svg +5 -0
- package/assets/basic/notation-bubble/icons/glyphs/relationship.svg +5 -0
- package/assets/basic/notation-bubble/icons/relationship.svg +7 -0
- package/assets/catalog.ttl +7302 -0
- package/assets/core/core-notation.ttl +131 -0
- package/assets/core/core-onto.ttl +2811 -0
- package/assets/core/core-questions.ttl +957 -0
- package/assets/core/core-shapes.ttl +915 -0
- package/assets/core/core-vis-onto.ttl +1408 -0
- package/assets/core/core-vis-shapes.ttl +840 -0
- package/assets/core-vis/markers/circle-dot.svg +3 -0
- package/assets/core-vis/markers/closed-arrowhead.svg +3 -0
- package/assets/core-vis/markers/filled-diamond.svg +3 -0
- package/assets/core-vis/markers/half-arrowhead.svg +3 -0
- package/assets/core-vis/markers/hollow-arrowhead.svg +3 -0
- package/assets/core-vis/markers/hollow-diamond.svg +3 -0
- package/assets/core-vis/markers/open-arrowhead.svg +3 -0
- package/fixtures/interoperability/archimate4-demo.trig +259 -0
- package/fixtures/interoperability/expected-findings.json +26 -0
- package/fixtures/interoperability/shop-seed.ttl +225 -0
- package/package.json +136 -4
- package/scripts/sync-assets.mjs +252 -0
- package/src/conformance.ts +66 -0
- package/src/import-export/model-io.ts +426 -0
- package/src/index.ts +11 -0
- package/src/metamodel-manager/asset-sources.ts +754 -0
- package/src/metamodel-manager/bundled-assets.ts +599 -0
- package/src/metamodel-manager/catalogue.ts +114 -0
- package/src/metamodel-manager/class-hierarchy.ts +155 -0
- package/src/metamodel-manager/index.ts +65 -0
- package/src/metamodel-manager/interfaces.ts +422 -0
- package/src/metamodel-manager/metamodel-completeness.ts +162 -0
- package/src/metamodel-manager/metamodel-loader.ts +864 -0
- package/src/metamodel-manager/notation-resolver.ts +284 -0
- package/src/metamodel-manager/notation.ts +659 -0
- package/src/metamodel-manager/palette-generator.ts +882 -0
- package/src/metamodel-manager/property-shapes.ts +290 -0
- package/src/metamodel-manager/taxonomy.ts +904 -0
- package/src/metamodel-manager/type-guide.ts +241 -0
- package/src/metamodel-manager/viewpoint-manager.ts +147 -0
- package/src/model-manager/appearance.ts +389 -0
- package/src/model-manager/cascade.ts +246 -0
- package/src/model-manager/clipboard.ts +566 -0
- package/src/model-manager/context-names.ts +108 -0
- package/src/model-manager/custom-properties.ts +549 -0
- package/src/model-manager/derivations.ts +166 -0
- package/src/model-manager/direct-permissions.ts +182 -0
- package/src/model-manager/drawing-order.ts +119 -0
- package/src/model-manager/element-manager.ts +69 -0
- package/src/model-manager/element-pictures.ts +118 -0
- package/src/model-manager/field-names.ts +42 -0
- package/src/model-manager/folders.ts +354 -0
- package/src/model-manager/grid.ts +6 -0
- package/src/model-manager/index.ts +43 -0
- package/src/model-manager/interfaces.ts +417 -0
- package/src/model-manager/iri-conformance.ts +183 -0
- package/src/model-manager/label-expression.ts +233 -0
- package/src/model-manager/legacy-migration.ts +200 -0
- package/src/model-manager/missing-references.ts +86 -0
- package/src/model-manager/model-diff-text.ts +150 -0
- package/src/model-manager/model-diff.ts +534 -0
- package/src/model-manager/model-merge.ts +1160 -0
- package/src/model-manager/model-namespace.ts +199 -0
- package/src/model-manager/model-operations.ts +132 -0
- package/src/model-manager/model-queries.ts +616 -0
- package/src/model-manager/model-session.ts +759 -0
- package/src/model-manager/multiplicity.ts +74 -0
- package/src/model-manager/nested-resources.ts +145 -0
- package/src/model-manager/own-metamodel.ts +157 -0
- package/src/model-manager/placement-copy.ts +116 -0
- package/src/model-manager/property-catalog.ts +787 -0
- package/src/model-manager/proposal-order.ts +203 -0
- package/src/model-manager/provenance.ts +396 -0
- package/src/model-manager/questions.ts +470 -0
- package/src/model-manager/rdf-scope.ts +97 -0
- package/src/model-manager/relationship-graph.ts +462 -0
- package/src/model-manager/relationship-manager.ts +962 -0
- package/src/model-manager/relationship-table.ts +189 -0
- package/src/model-manager/relationship-validity.ts +261 -0
- package/src/model-manager/resource-edits.ts +28 -0
- package/src/model-manager/short-hash.ts +104 -0
- package/src/model-manager/snapshot-lines.ts +88 -0
- package/src/model-manager/version-history.ts +205 -0
- package/src/model-manager/view-from-results.ts +81 -0
- package/src/model-manager/view-manager.ts +1410 -0
- package/src/model-manager/vocabulary.ts +279 -0
- package/src/rdf-engine/finding-shape.ts +23 -0
- package/src/rdf-engine/graph-scope.ts +163 -0
- package/src/rdf-engine/index.ts +7 -0
- package/src/rdf-engine/interfaces.ts +144 -0
- package/src/rdf-engine/iri.ts +203 -0
- package/src/rdf-engine/localized-text.ts +13 -0
- package/src/rdf-engine/namespaces.ts +41 -0
- package/src/rdf-engine/observable-store.ts +631 -0
- package/src/rdf-engine/rdf-store.ts +508 -0
- package/src/rdf-engine/shacl-validator.ts +602 -0
- package/src/rdf-engine/shape-reach.ts +140 -0
- package/src/rdf-engine/shape-switches.ts +165 -0
- package/src/rdf-engine/single-valued.ts +219 -0
- package/src/rdf-engine/sparql-constraints.ts +334 -0
- package/src/rdf-engine/term-codec.ts +51 -0
- package/src/rdf-engine/ttl-parser.ts +51 -0
- package/src/rdf-engine/ttl-serializer.ts +79 -0
- package/src/rdf-engine/turtle-writer.ts +284 -0
- package/src/rdf-engine/validation-engine.ts +682 -0
- package/src/rdf-engine/validation-service.ts +184 -0
- package/src/rdf-engine/validation.worker.ts +47 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read-side queries over the model data: what is in the model, and what kind
|
|
3
|
+
* of thing each resource is.
|
|
4
|
+
*
|
|
5
|
+
* ## Where model data lives
|
|
6
|
+
*
|
|
7
|
+
* At runtime the model is the store's *default graph*; every metamodel document
|
|
8
|
+
* sits in a named graph of its own (see `N3MetamodelLoader`). That split is what
|
|
9
|
+
* lets a metamodel be swapped without touching anybody's work, and what the
|
|
10
|
+
* serializer relies on to write only the model. Files are laid out differently
|
|
11
|
+
* — DD-15's `graph/model`, `graph/semantic`, `graph/views`, `graph/provenance` — and `model-io.ts`
|
|
12
|
+
* maps between the two.
|
|
13
|
+
*
|
|
14
|
+
* ## Classifying a resource
|
|
15
|
+
*
|
|
16
|
+
* By the `rdfs:subClassOf*` closure of its types over *all* graphs, so an
|
|
17
|
+
* `am4:ApplicationComponent` is recognised as an element through ArchiMate's
|
|
18
|
+
* own hierarchy up to `arch:Element`. A resource whose type the loaded
|
|
19
|
+
* metamodels do not know is still shown (as "unclassified") when it declares
|
|
20
|
+
* `arch:inModel`: a model opened before its metamodel is loaded must not look
|
|
21
|
+
* empty.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { DataFactory } from 'n3';
|
|
25
|
+
import type { NamedNode, Quad, Term } from '@rdfjs/types';
|
|
26
|
+
import type { RdfStore } from '../rdf-engine/interfaces.js';
|
|
27
|
+
import { selectLocalizedLiteral } from '../rdf-engine/localized-text.js';
|
|
28
|
+
import { NAMESPACES } from '../rdf-engine/namespaces.js';
|
|
29
|
+
import type { ViewInfo } from './interfaces.js';
|
|
30
|
+
import { IRI, T, humanize, localName, nn, relationshipClassAmong } from './vocabulary.js';
|
|
31
|
+
import { certaintyNamed, isCertaintyPredicate, isLedTo, ruleOf, type DerivationCertainty } from './derivations.js';
|
|
32
|
+
|
|
33
|
+
/** What names a concept, in the order {@link labelOf} prefers them. */
|
|
34
|
+
const NAMING_PREDICATES = [T.prefLabel, T.rdfsLabel, nn(IRI.dctermsTitle)];
|
|
35
|
+
|
|
36
|
+
/** The default graph: the model. */
|
|
37
|
+
const MODEL_GRAPH = DataFactory.defaultGraph() as unknown as NamedNode;
|
|
38
|
+
|
|
39
|
+
/** `rdfs:subClassOf*` closure of a type, the type included. */
|
|
40
|
+
export type TypeClosure = (typeIri: string) => string[];
|
|
41
|
+
|
|
42
|
+
/** Kinds of model resource the explorer distinguishes. */
|
|
43
|
+
export type ConceptKind = 'model' | 'view' | 'element' | 'relationship' | 'geometry' | 'unclassified';
|
|
44
|
+
|
|
45
|
+
/** One element or unclassified concept. */
|
|
46
|
+
export interface ConceptSummary {
|
|
47
|
+
iri: string;
|
|
48
|
+
typeIri: string;
|
|
49
|
+
typeLabel: string;
|
|
50
|
+
label: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** One relationship, with its ends. */
|
|
54
|
+
export interface RelationshipSummary extends ConceptSummary {
|
|
55
|
+
sourceIri?: string;
|
|
56
|
+
targetIri?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Set for a derivation the model does not state: a valid one, or a potential
|
|
59
|
+
* one not confirmed (`derivations.ts`) — with the rule's local name.
|
|
60
|
+
*/
|
|
61
|
+
derivation?: { certainty: DerivationCertainty; rule?: string };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* One folder of the model's own organisation (`arch:Folder`): where the tool a
|
|
66
|
+
* model came from kept its concepts — Archi's folders, as the converters carry
|
|
67
|
+
* them over. Navigation only: a folder is not a model concept.
|
|
68
|
+
*/
|
|
69
|
+
export interface FolderSummary {
|
|
70
|
+
iri: string;
|
|
71
|
+
label: string;
|
|
72
|
+
/** The folder it is in; absent for a top-level folder. */
|
|
73
|
+
parentIri?: string;
|
|
74
|
+
/**
|
|
75
|
+
* What it holds besides folders — by the member's `dcterms:isPartOf` or the
|
|
76
|
+
* folder's `schema:itemListElement` — by IRI.
|
|
77
|
+
*/
|
|
78
|
+
members: string[];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Everything the explorer shows. */
|
|
82
|
+
export interface ModelContents {
|
|
83
|
+
model?: { iri: string; label: string };
|
|
84
|
+
views: ViewInfo[];
|
|
85
|
+
elements: ConceptSummary[];
|
|
86
|
+
relationships: RelationshipSummary[];
|
|
87
|
+
unclassified: ConceptSummary[];
|
|
88
|
+
/** The model's folders, when it has any ({@link readFolders}). */
|
|
89
|
+
folders?: FolderSummary[];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Namespaces whose types are never model concepts: geometry and the RDF
|
|
94
|
+
* vocabularies, and the provenance and schema.org metadata a converter records
|
|
95
|
+
* about a conversion — its run, its agent, its source file, its named graphs.
|
|
96
|
+
* A resource typed with nothing else is not a member of the model.
|
|
97
|
+
*/
|
|
98
|
+
const NON_MODEL_NAMESPACES = [
|
|
99
|
+
NAMESPACES['arch-vis'],
|
|
100
|
+
NAMESPACES.rdf,
|
|
101
|
+
NAMESPACES.rdfs,
|
|
102
|
+
NAMESPACES.owl,
|
|
103
|
+
NAMESPACES.sh,
|
|
104
|
+
NAMESPACES.skos,
|
|
105
|
+
NAMESPACES.prov,
|
|
106
|
+
'https://schema.org/',
|
|
107
|
+
'http://schema.org/',
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
/** Every quad in the default graph — the model data. */
|
|
111
|
+
export function modelQuads(store: RdfStore): Quad[] {
|
|
112
|
+
return store.getQuads(null, null, null, DataFactory.defaultGraph() as unknown as NamedNode);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Build a closure function over the store's current class hierarchy. */
|
|
116
|
+
export function typeClosure(store: RdfStore): TypeClosure {
|
|
117
|
+
const parents = new Map<string, string[]>();
|
|
118
|
+
for (const q of store.getQuads(null, T.subClassOf, null)) {
|
|
119
|
+
if (q.subject.termType !== 'NamedNode' || q.object.termType !== 'NamedNode') continue;
|
|
120
|
+
const list = parents.get(q.subject.value);
|
|
121
|
+
if (list) list.push(q.object.value);
|
|
122
|
+
else parents.set(q.subject.value, [q.object.value]);
|
|
123
|
+
}
|
|
124
|
+
const cache = new Map<string, string[]>();
|
|
125
|
+
return (typeIri: string) => {
|
|
126
|
+
const cached = cache.get(typeIri);
|
|
127
|
+
if (cached) return cached;
|
|
128
|
+
const seen = new Set<string>([typeIri]);
|
|
129
|
+
const stack = [...(parents.get(typeIri) ?? [])];
|
|
130
|
+
while (stack.length > 0) {
|
|
131
|
+
const current = stack.pop() as string;
|
|
132
|
+
if (seen.has(current)) continue;
|
|
133
|
+
seen.add(current);
|
|
134
|
+
stack.push(...(parents.get(current) ?? []));
|
|
135
|
+
}
|
|
136
|
+
const closure = [...seen];
|
|
137
|
+
cache.set(typeIri, closure);
|
|
138
|
+
return closure;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Classify a resource from its types. */
|
|
143
|
+
export function classify(types: readonly string[], closure: TypeClosure, hasInModel: boolean): ConceptKind {
|
|
144
|
+
if (types.includes(IRI.Model)) return 'model';
|
|
145
|
+
const all = new Set(types.flatMap((t) => closure(t)));
|
|
146
|
+
if (all.has(IRI.View)) return 'view';
|
|
147
|
+
if (all.has(IRI.QualifiedRelationship)) return 'relationship';
|
|
148
|
+
if (types.some((t) => t.startsWith(NAMESPACES['arch-vis']))) return 'geometry';
|
|
149
|
+
// Folders are presentation (DD-15): navigation structure, not model content.
|
|
150
|
+
if (types.includes(NAMESPACES.arch + 'Folder')) return 'geometry';
|
|
151
|
+
if (all.has(IRI.Element)) return 'element';
|
|
152
|
+
if (types.every((t) => NON_MODEL_NAMESPACES.some((ns) => t.startsWith(ns)))) return 'geometry';
|
|
153
|
+
// A type no loaded metamodel classifies. Shown, not hidden: a model opened
|
|
154
|
+
// before its metamodel is loaded must not look empty. `hasInModel` is kept in
|
|
155
|
+
// the signature for callers that want to tell members from strays.
|
|
156
|
+
void hasInModel;
|
|
157
|
+
return 'unclassified';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Human label for a class or concept: `skos:prefLabel`, then `rdfs:label`, then the local name. */
|
|
161
|
+
export function labelOf(store: RdfStore, iri: string, preferredLanguage = 'en'): string {
|
|
162
|
+
const subject = nn(iri);
|
|
163
|
+
// The model's names first — which the application's store answers from its
|
|
164
|
+
// copy in JavaScript — then every graph's (a class's, in its metamodel).
|
|
165
|
+
for (const graph of [MODEL_GRAPH, null]) {
|
|
166
|
+
for (const predicate of NAMING_PREDICATES) {
|
|
167
|
+
const literals = store.getQuads(subject, predicate, null, graph).map((q) => q.object);
|
|
168
|
+
const label = selectLocalizedLiteral(literals, preferredLanguage);
|
|
169
|
+
if (label) return label.value;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return humanize(localName(iri));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The name the model gives `iri` — `skos:prefLabel`, then `rdfs:label`, then
|
|
177
|
+
* `dcterms:title`, in the preferred language — or `undefined` when it gives
|
|
178
|
+
* none. Read from the model graph alone, which the application's store answers
|
|
179
|
+
* from its copy in JavaScript: a relationship's name, read for every line each
|
|
180
|
+
* time a view is drawn, is never in a metamodel's graph (Task 22).
|
|
181
|
+
*/
|
|
182
|
+
export function modelNameOf(store: RdfStore, iri: string, preferredLanguage = 'en'): string | undefined {
|
|
183
|
+
const subject = nn(iri);
|
|
184
|
+
for (const predicate of NAMING_PREDICATES) {
|
|
185
|
+
const literals = store.getQuads(subject, predicate, null, MODEL_GRAPH).map((q) => q.object);
|
|
186
|
+
const label = selectLocalizedLiteral(literals, preferredLanguage);
|
|
187
|
+
if (label) return label.value;
|
|
188
|
+
}
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Whether `iri` has a name of its own, rather than one {@link labelOf} makes from its IRI. */
|
|
193
|
+
export function hasLabel(store: RdfStore, iri: string): boolean {
|
|
194
|
+
const subject = nn(iri);
|
|
195
|
+
return [MODEL_GRAPH, null].some((graph) => NAMING_PREDICATES.some((predicate) => store.getQuads(subject, predicate, null, graph).length > 0));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* A resource's statements with a predicate: the model's, when it has any —
|
|
200
|
+
* which the application's store answers from its copy in JavaScript — else
|
|
201
|
+
* those of every graph (a class's name, in its metamodel). Task 22.
|
|
202
|
+
*/
|
|
203
|
+
export function statementsOf(store: RdfStore, subject: NamedNode, predicate: NamedNode): Quad[] {
|
|
204
|
+
const own = store.getQuads(subject, predicate, null, MODEL_GRAPH);
|
|
205
|
+
return own.length > 0 ? own : store.getQuads(subject, predicate);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** schema.org, as converters write it, and its older `http:` form. */
|
|
209
|
+
const SCHEMA_NAMESPACES = [NAMESPACES.schema, 'http://schema.org/'];
|
|
210
|
+
const schemaTerms = (local: string): NamedNode[] => SCHEMA_NAMESPACES.map((ns) => nn(ns + local));
|
|
211
|
+
/** A folder's name, its list entries and an entry's item — the `https:` form first, the one la-gram writes. */
|
|
212
|
+
export const SCHEMA_NAME = schemaTerms('name');
|
|
213
|
+
export const SCHEMA_ITEM_LIST_ELEMENT = schemaTerms('itemListElement');
|
|
214
|
+
export const SCHEMA_ITEM = schemaTerms('item');
|
|
215
|
+
|
|
216
|
+
/** The predicates a folder is read from: a change to one of them may change the folders. */
|
|
217
|
+
const FOLDER_PREDICATES = new Set([IRI.dctermsIsPartOf, ...[SCHEMA_NAME, SCHEMA_ITEM_LIST_ELEMENT, SCHEMA_ITEM].flat().map((p) => p.value)]);
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The model's folders (`arch:Folder`), each with the folder it is in and what
|
|
221
|
+
* it holds.
|
|
222
|
+
*
|
|
223
|
+
* A converter states a folder's contents from both ends — the member's
|
|
224
|
+
* `dcterms:isPartOf` and the folder's `schema:itemListElement` — and either is
|
|
225
|
+
* enough here: their union is read. The list's `schema:position` is not: it is
|
|
226
|
+
* the order the source file happened to hold (an Archi model's, say), not an
|
|
227
|
+
* order anybody arranged. A folder with several parent
|
|
228
|
+
* folders is placed under one of them, the same one every time.
|
|
229
|
+
*/
|
|
230
|
+
export function readFolders(store: RdfStore): FolderSummary[] {
|
|
231
|
+
const iris = store
|
|
232
|
+
.getQuads(null, T.rdfType, T.Folder, MODEL_GRAPH)
|
|
233
|
+
.filter((q) => q.subject.termType === 'NamedNode')
|
|
234
|
+
.map((q) => q.subject.value);
|
|
235
|
+
if (iris.length === 0) return [];
|
|
236
|
+
const isFolder = new Set(iris);
|
|
237
|
+
const folders: FolderSummary[] = [...isFolder].sort().map((iri) => ({ iri, label: folderLabel(store, iri), members: [] }));
|
|
238
|
+
const parents = new Map<string, string>();
|
|
239
|
+
for (const folder of folders) {
|
|
240
|
+
const held = new Set<string>();
|
|
241
|
+
for (const q of store.getQuads(null, T.dctermsIsPartOf, nn(folder.iri), MODEL_GRAPH)) {
|
|
242
|
+
if (q.subject.termType === 'NamedNode') held.add(q.subject.value);
|
|
243
|
+
}
|
|
244
|
+
for (const listed of SCHEMA_ITEM_LIST_ELEMENT.flatMap((p) => store.getQuads(nn(folder.iri), p, null, MODEL_GRAPH))) {
|
|
245
|
+
// The list entry is named (`folderEntryIri`), or a blank node in a file written before DD-41: the store takes
|
|
246
|
+
// either back as a subject.
|
|
247
|
+
const entry = listed.object as NamedNode;
|
|
248
|
+
const item = SCHEMA_ITEM.flatMap((p) => store.getQuads(entry, p, null, MODEL_GRAPH))[0]?.object;
|
|
249
|
+
if (item?.termType === 'NamedNode') held.add(item.value);
|
|
250
|
+
}
|
|
251
|
+
held.delete(folder.iri);
|
|
252
|
+
for (const member of held) {
|
|
253
|
+
if (!isFolder.has(member)) folder.members.push(member);
|
|
254
|
+
// Folders are visited in IRI order: a folder's parent is the first that holds it.
|
|
255
|
+
else if (!parents.has(member)) parents.set(member, folder.iri);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
for (const folder of folders) {
|
|
259
|
+
const parentIri = parents.get(folder.iri);
|
|
260
|
+
if (parentIri) folder.parentIri = parentIri;
|
|
261
|
+
}
|
|
262
|
+
return folders;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** A folder's name: `schema:name`, then the names a concept has, then its IRI's local name. */
|
|
266
|
+
function folderLabel(store: RdfStore, iri: string): string {
|
|
267
|
+
const names = SCHEMA_NAME.flatMap((p) => store.getQuads(nn(iri), p, null, MODEL_GRAPH))
|
|
268
|
+
.map((q) => q.object)
|
|
269
|
+
.filter((o) => o.termType === 'Literal');
|
|
270
|
+
return selectLocalizedLiteral(names)?.value ?? labelOf(store, iri);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** The model's `arch:Model` resource, if the data declares one. */
|
|
274
|
+
export function findModelIri(store: RdfStore): string | undefined {
|
|
275
|
+
const models = modelQuads(store)
|
|
276
|
+
.filter((q) => q.predicate.value === IRI.rdfType && q.object.value === IRI.Model)
|
|
277
|
+
.map((q) => q.subject.value)
|
|
278
|
+
.sort();
|
|
279
|
+
return models[0];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** What the tree shows of a concept is read from: its types, membership, names and ends. */
|
|
283
|
+
interface ConceptFacts {
|
|
284
|
+
types: string[];
|
|
285
|
+
inModel: boolean;
|
|
286
|
+
/** Its names by naming predicate (literals only). */
|
|
287
|
+
names: Map<string, Term[]>;
|
|
288
|
+
/** Its first end by end predicate. */
|
|
289
|
+
ends: Map<string, string>;
|
|
290
|
+
/** Its derivation certainty, when it is a derivation. */
|
|
291
|
+
certainty?: DerivationCertainty;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const NAMING = new Set(NAMING_PREDICATES.map((p) => p.value));
|
|
295
|
+
const ENDS = new Set([IRI.source, IRI.legacyRelSource, IRI.target, IRI.legacyRelTarget]);
|
|
296
|
+
|
|
297
|
+
/** The facts of each named subject of these quads, in one pass. */
|
|
298
|
+
function collectFacts(quads: Iterable<Quad>): Map<string, ConceptFacts> {
|
|
299
|
+
const facts = new Map<string, ConceptFacts>();
|
|
300
|
+
const of = (iri: string) => {
|
|
301
|
+
let f = facts.get(iri);
|
|
302
|
+
if (!f) facts.set(iri, (f = { types: [], inModel: false, names: new Map(), ends: new Map() }));
|
|
303
|
+
return f;
|
|
304
|
+
};
|
|
305
|
+
for (const q of quads) {
|
|
306
|
+
if (q.subject.termType !== 'NamedNode') continue;
|
|
307
|
+
const p = q.predicate.value;
|
|
308
|
+
if (p === IRI.rdfType) of(q.subject.value).types.push(q.object.value);
|
|
309
|
+
else if (p === IRI.inModel || p === IRI.legacyPartOfModel) of(q.subject.value).inModel = true;
|
|
310
|
+
else if (NAMING.has(p) && q.object.termType === 'Literal') {
|
|
311
|
+
const names = of(q.subject.value).names;
|
|
312
|
+
const list = names.get(p);
|
|
313
|
+
if (list) list.push(q.object);
|
|
314
|
+
else names.set(p, [q.object]);
|
|
315
|
+
} else if (ENDS.has(p)) {
|
|
316
|
+
const ends = of(q.subject.value).ends;
|
|
317
|
+
if (!ends.has(p)) ends.set(p, q.object.value);
|
|
318
|
+
} else if (isCertaintyPredicate(p) && q.object.termType === 'NamedNode') {
|
|
319
|
+
const certainty = certaintyNamed(q.object.value);
|
|
320
|
+
if (certainty) of(q.subject.value).certainty = certainty;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return facts;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** A concept as the tree lists it, or `undefined` when it is not one (geometry, a view). */
|
|
327
|
+
export type Summarised =
|
|
328
|
+
| { kind: 'model'; summary: { iri: string; label: string } }
|
|
329
|
+
| { kind: 'element' | 'unclassified'; summary: ConceptSummary }
|
|
330
|
+
| { kind: 'relationship'; summary: RelationshipSummary };
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* How a derivation is listed, from the store: `undefined` when the model states
|
|
334
|
+
* it — a potential derivation a modeller confirmed.
|
|
335
|
+
*/
|
|
336
|
+
function derivationOf(store: RdfStore, iri: string, certainty: DerivationCertainty): RelationshipSummary['derivation'] {
|
|
337
|
+
if (certainty === 'potential' && isLedTo(store, iri)) return undefined;
|
|
338
|
+
const rule = ruleOf(store, iri);
|
|
339
|
+
return { certainty, ...(rule ? { rule: localName(rule) } : {}) };
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** What the tree lists of a concept, from its facts. */
|
|
343
|
+
function summarize(
|
|
344
|
+
iri: string,
|
|
345
|
+
facts: ConceptFacts,
|
|
346
|
+
closure: TypeClosure,
|
|
347
|
+
nameOf: (iri: string) => string,
|
|
348
|
+
typeLabel: (typeIri: string) => string,
|
|
349
|
+
store?: RdfStore,
|
|
350
|
+
): Summarised | undefined {
|
|
351
|
+
const { types } = facts;
|
|
352
|
+
if (types.length === 0) return undefined;
|
|
353
|
+
const kind = classify(types, closure, facts.inModel);
|
|
354
|
+
// The most specific type is the one whose closure is largest.
|
|
355
|
+
const typeIri = [...types].sort((a, b) => closure(b).length - closure(a).length)[0] ?? IRI.ModelConcept;
|
|
356
|
+
switch (kind) {
|
|
357
|
+
case 'model':
|
|
358
|
+
return { kind, summary: { iri, label: nameOf(iri) } };
|
|
359
|
+
case 'element':
|
|
360
|
+
case 'unclassified':
|
|
361
|
+
return { kind, summary: { iri, typeIri, typeLabel: typeLabel(typeIri), label: nameOf(iri) } };
|
|
362
|
+
case 'relationship': {
|
|
363
|
+
const relType = relationshipClassAmong(types, closure) ?? typeIri;
|
|
364
|
+
const sourceIri = facts.ends.get(IRI.source) ?? facts.ends.get(IRI.legacyRelSource);
|
|
365
|
+
const targetIri = facts.ends.get(IRI.target) ?? facts.ends.get(IRI.legacyRelTarget);
|
|
366
|
+
const explicit = facts.names.get(T.prefLabel.value)?.[0]?.value;
|
|
367
|
+
const label = explicit ?? `${sourceIri ? nameOf(sourceIri) : '?'} → ${targetIri ? nameOf(targetIri) : '?'}`;
|
|
368
|
+
const derivation = facts.certainty && store ? derivationOf(store, iri, facts.certainty) : undefined;
|
|
369
|
+
return {
|
|
370
|
+
kind,
|
|
371
|
+
summary: {
|
|
372
|
+
iri,
|
|
373
|
+
typeIri: relType,
|
|
374
|
+
typeLabel: typeLabel(relType),
|
|
375
|
+
label,
|
|
376
|
+
...(sourceIri ? { sourceIri } : {}),
|
|
377
|
+
...(targetIri ? { targetIri } : {}),
|
|
378
|
+
...(derivation ? { derivation } : {}),
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
default:
|
|
383
|
+
return undefined;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** The order of the tree's lists: by type, name, IRI — a concept's place unique. */
|
|
388
|
+
function byLabel(a: ConceptSummary, b: ConceptSummary): number {
|
|
389
|
+
return a.typeLabel.localeCompare(b.typeLabel) || a.label.localeCompare(b.label) || a.iri.localeCompare(b.iri);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** A cache of type labels, from the store. */
|
|
393
|
+
function typeLabels(store: RdfStore, preferredLanguage = 'en'): (typeIri: string) => string {
|
|
394
|
+
const labels = new Map<string, string>();
|
|
395
|
+
return (typeIri) => {
|
|
396
|
+
let label = labels.get(typeIri);
|
|
397
|
+
if (label === undefined) labels.set(typeIri, (label = labelOf(store, typeIri, preferredLanguage)));
|
|
398
|
+
return label;
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Everything in the model, classified.
|
|
404
|
+
*
|
|
405
|
+
* @param views The view list, from the view manager, so this module does not
|
|
406
|
+
* duplicate view reading.
|
|
407
|
+
*/
|
|
408
|
+
export function readModelContents(
|
|
409
|
+
store: RdfStore, views: ViewInfo[], closure: TypeClosure = typeClosure(store), preferredLanguage = 'en',
|
|
410
|
+
): ModelContents {
|
|
411
|
+
// One pass over the model for what the tree shows of each concept — its
|
|
412
|
+
// types, names and ends — rather than a query a concept (Task 22).
|
|
413
|
+
const facts = collectFacts(modelQuads(store));
|
|
414
|
+
/** A concept's name from the model; one the model does not name is looked up as before. */
|
|
415
|
+
const nameOf = (iri: string): string => {
|
|
416
|
+
const names = facts.get(iri)?.names;
|
|
417
|
+
for (const predicate of NAMING_PREDICATES) {
|
|
418
|
+
const literals = names?.get(predicate.value);
|
|
419
|
+
const label = selectLocalizedLiteral(literals ?? [], preferredLanguage);
|
|
420
|
+
if (label) return label.value;
|
|
421
|
+
}
|
|
422
|
+
return labelOf(store, iri, preferredLanguage);
|
|
423
|
+
};
|
|
424
|
+
const typeLabel = typeLabels(store, preferredLanguage);
|
|
425
|
+
const contents: ModelContents = { views, elements: [], relationships: [], unclassified: [] };
|
|
426
|
+
for (const [iri, f] of facts) {
|
|
427
|
+
const concept = summarize(iri, f, closure, nameOf, typeLabel, store);
|
|
428
|
+
if (!concept) continue;
|
|
429
|
+
if (concept.kind === 'model') contents.model = concept.summary;
|
|
430
|
+
else if (concept.kind === 'relationship') contents.relationships.push(concept.summary);
|
|
431
|
+
else contents[concept.kind === 'element' ? 'elements' : 'unclassified'].push(concept.summary);
|
|
432
|
+
}
|
|
433
|
+
contents.elements.sort(byLabel);
|
|
434
|
+
contents.relationships.sort(byLabel);
|
|
435
|
+
contents.unclassified.sort(byLabel);
|
|
436
|
+
contents.folders = readFolders(store);
|
|
437
|
+
return contents;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* The model's contents, kept up to date by its changes (Task 22): the tree,
|
|
442
|
+
* refreshed after every edit, read the whole model each time. Told each change
|
|
443
|
+
* ({@link note}), it reads again, when next asked, only the concepts a change
|
|
444
|
+
* touched — and the relationships whose label is made of their ends' names —
|
|
445
|
+
* each from its own triples, and moves it in its sorted list. It reads the
|
|
446
|
+
* whole model at first, when the metamodels change ({@link invalidate}), when
|
|
447
|
+
* the class hierarchy changes, and when a change touches too many concepts.
|
|
448
|
+
* The folders are read again, all of them, after a change that touches one.
|
|
449
|
+
*/
|
|
450
|
+
export class ModelContentsIndex {
|
|
451
|
+
private concepts = new Map<string, Summarised>();
|
|
452
|
+
private lists: Pick<ModelContents, 'model' | 'elements' | 'relationships' | 'unclassified'> = { elements: [], relationships: [], unclassified: [] };
|
|
453
|
+
private changed = new Set<string>();
|
|
454
|
+
private whole = true;
|
|
455
|
+
private typeLabel: (typeIri: string) => string;
|
|
456
|
+
private folders: FolderSummary[] = [];
|
|
457
|
+
private folderIris = new Set<string>();
|
|
458
|
+
private foldersStale = true;
|
|
459
|
+
|
|
460
|
+
/** More concepts touched than this: the whole model is read again. */
|
|
461
|
+
static readonly WHOLE_AFTER = 2000;
|
|
462
|
+
|
|
463
|
+
constructor(
|
|
464
|
+
private readonly store: RdfStore,
|
|
465
|
+
private readonly closure: () => TypeClosure,
|
|
466
|
+
) {
|
|
467
|
+
this.typeLabel = typeLabels(store);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** A change to the model: the concepts it touches are read again when next asked. */
|
|
471
|
+
note(change: { added: readonly Quad[]; removed: readonly Quad[] }): void {
|
|
472
|
+
if (this.whole) return;
|
|
473
|
+
for (const list of [change.added, change.removed]) {
|
|
474
|
+
for (const q of list) {
|
|
475
|
+
if (q.predicate.value === NAMESPACES.rdfs + 'subClassOf') {
|
|
476
|
+
this.whole = true;
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (q.subject.termType === 'NamedNode') this.changed.add(q.subject.value);
|
|
480
|
+
// A qualified predicate leading to a relationship decides whether a potential derivation is confirmed.
|
|
481
|
+
if (q.object.termType === 'NamedNode' && isQualifiedPointer(q.predicate.value)) this.changed.add(q.object.value);
|
|
482
|
+
if (!this.foldersStale && this.touchesFolders(q)) this.foldersStale = true;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (this.changed.size > ModelContentsIndex.WHOLE_AFTER) this.whole = true;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/** Whether a statement may change the folders: what they hold, where they sit, their names. */
|
|
489
|
+
private touchesFolders(q: Quad): boolean {
|
|
490
|
+
if (FOLDER_PREDICATES.has(q.predicate.value)) return true;
|
|
491
|
+
if (q.predicate.value === IRI.rdfType && q.object.value === IRI.Folder) return true;
|
|
492
|
+
return this.folderIris.has(q.subject.value);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** The metamodels changed — classes, their labels: everything is read again. */
|
|
496
|
+
invalidate(): void {
|
|
497
|
+
this.whole = true;
|
|
498
|
+
this.typeLabel = typeLabels(this.store);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/** The model's contents now. The lists are the caller's to keep or change. */
|
|
502
|
+
contents(views: ViewInfo[]): ModelContents {
|
|
503
|
+
this.catchUp();
|
|
504
|
+
if (this.foldersStale) this.keepFolders(readFolders(this.store));
|
|
505
|
+
return {
|
|
506
|
+
...(this.lists.model ? { model: this.lists.model } : {}),
|
|
507
|
+
views,
|
|
508
|
+
elements: this.lists.elements.slice(),
|
|
509
|
+
relationships: this.lists.relationships.slice(),
|
|
510
|
+
unclassified: this.lists.unclassified.slice(),
|
|
511
|
+
folders: this.folders.slice(),
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
private keepFolders(folders: FolderSummary[]): void {
|
|
516
|
+
this.folders = folders;
|
|
517
|
+
this.folderIris = new Set(folders.map((f) => f.iri));
|
|
518
|
+
this.foldersStale = false;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** One concept as the tree lists it — its kind, name and type — or `undefined` when it is none (a view, a diagram node). */
|
|
522
|
+
concept(iri: string): Summarised | undefined {
|
|
523
|
+
this.catchUp();
|
|
524
|
+
return this.concepts.get(iri);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
private catchUp(): void {
|
|
528
|
+
if (this.whole) this.readWhole();
|
|
529
|
+
else if (this.changed.size > 0) this.readChanged();
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
private readWhole(): void {
|
|
533
|
+
const all = readModelContents(this.store, [], this.closure());
|
|
534
|
+
this.lists = { ...(all.model ? { model: all.model } : {}), elements: all.elements, relationships: all.relationships, unclassified: all.unclassified };
|
|
535
|
+
this.keepFolders(all.folders ?? []);
|
|
536
|
+
this.concepts = new Map();
|
|
537
|
+
if (all.model) this.concepts.set(all.model.iri, { kind: 'model', summary: all.model });
|
|
538
|
+
for (const summary of all.elements) this.concepts.set(summary.iri, { kind: 'element', summary });
|
|
539
|
+
for (const summary of all.unclassified) this.concepts.set(summary.iri, { kind: 'unclassified', summary });
|
|
540
|
+
for (const summary of all.relationships) this.concepts.set(summary.iri, { kind: 'relationship', summary });
|
|
541
|
+
this.changed.clear();
|
|
542
|
+
this.whole = false;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
private readChanged(): void {
|
|
546
|
+
const affected = new Set(this.changed);
|
|
547
|
+
this.changed.clear();
|
|
548
|
+
// A relationship without a name of its own is labelled with its ends' names.
|
|
549
|
+
for (const iri of [...affected]) {
|
|
550
|
+
for (const predicate of ENDS) {
|
|
551
|
+
for (const q of this.store.getQuads(null, nn(predicate), nn(iri), MODEL_GRAPH)) {
|
|
552
|
+
if (q.subject.termType === 'NamedNode') affected.add(q.subject.value);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const closure = this.closure();
|
|
557
|
+
const nameOf = (iri: string) => labelOf(this.store, iri);
|
|
558
|
+
for (const iri of affected) {
|
|
559
|
+
const facts = collectFacts(this.store.getQuads(nn(iri), null, null, MODEL_GRAPH)).get(iri);
|
|
560
|
+
this.place(iri, facts ? summarize(iri, facts, closure, nameOf, this.typeLabel, this.store) : undefined);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** Put a concept's new summary in place of its old one. */
|
|
565
|
+
private place(iri: string, next: Summarised | undefined): void {
|
|
566
|
+
const previous = this.concepts.get(iri);
|
|
567
|
+
if (previous) {
|
|
568
|
+
if (previous.kind === 'model') delete this.lists.model;
|
|
569
|
+
else remove(this.listOf(previous.kind), previous.summary);
|
|
570
|
+
}
|
|
571
|
+
if (!next) {
|
|
572
|
+
this.concepts.delete(iri);
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
this.concepts.set(iri, next);
|
|
576
|
+
if (next.kind === 'model') this.lists.model = next.summary;
|
|
577
|
+
else insert(this.listOf(next.kind), next.summary);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
private listOf(kind: 'element' | 'unclassified' | 'relationship'): ConceptSummary[] {
|
|
581
|
+
return kind === 'element' ? this.lists.elements : kind === 'unclassified' ? this.lists.unclassified : this.lists.relationships;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Whether a predicate leads to a relationship's resource: a notation's
|
|
587
|
+
* `qualified…` property (named after the class it leads to), or core's fallback.
|
|
588
|
+
*/
|
|
589
|
+
function isQualifiedPointer(predicateIri: string): boolean {
|
|
590
|
+
return predicateIri === IRI.hasQualifiedRelationship || localName(predicateIri).startsWith('qualified');
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/** Where a summary goes in a sorted list: the index of the first not before it. */
|
|
594
|
+
function position(list: readonly ConceptSummary[], summary: ConceptSummary): number {
|
|
595
|
+
let low = 0;
|
|
596
|
+
let high = list.length;
|
|
597
|
+
while (low < high) {
|
|
598
|
+
const mid = (low + high) >>> 1;
|
|
599
|
+
if (byLabel(list[mid], summary) < 0) low = mid + 1;
|
|
600
|
+
else high = mid;
|
|
601
|
+
}
|
|
602
|
+
return low;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function insert(list: ConceptSummary[], summary: ConceptSummary): void {
|
|
606
|
+
list.splice(position(list, summary), 0, summary);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function remove(list: ConceptSummary[], summary: ConceptSummary): void {
|
|
610
|
+
const at = position(list, summary);
|
|
611
|
+
if (list[at] === summary) list.splice(at, 1);
|
|
612
|
+
else {
|
|
613
|
+
const found = list.indexOf(summary);
|
|
614
|
+
if (found >= 0) list.splice(found, 1);
|
|
615
|
+
}
|
|
616
|
+
}
|