@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,962 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Relationship Manager — CRUD operations for architecture relationships.
|
|
3
|
+
*
|
|
4
|
+
* Creates, queries, and deletes relationships in the RDF store,
|
|
5
|
+
* supporting both direct triples and `arch:QualifiedRelationship` resources.
|
|
6
|
+
*
|
|
7
|
+
* ## How relationship validity is decided
|
|
8
|
+
*
|
|
9
|
+
* **The relationship shapes first.** Where the metamodel publishes them —
|
|
10
|
+
* ArchiMate 4.0 and 3.2 encode the specification's relationship matrix as SHACL
|
|
11
|
+
* — they decide what {@link OxigraphRelationshipManager.getValidRelationships}
|
|
12
|
+
* answers, exactly as validation would (`relationship-table.ts`, read once per
|
|
13
|
+
* set of loaded graphs; a shape on a relationship superclass applies to its
|
|
14
|
+
* subclasses). The hints below decide only for relationship types no shape
|
|
15
|
+
* covers — metamodels without relationship shapes.
|
|
16
|
+
*
|
|
17
|
+
* **Never an abstract type.** A relationship class marked `arch:isAbstractClass
|
|
18
|
+
* true` classifies its subclasses and is never offered, as an abstract element
|
|
19
|
+
* type is no palette type: EDGY's Enterprise Relationship, of its Link, Flow and
|
|
20
|
+
* Tree.
|
|
21
|
+
*
|
|
22
|
+
* **A language's types for its own elements.** Between elements of different
|
|
23
|
+
* languages the core's types are offered (DD-40). A type no shape covers whose
|
|
24
|
+
* hints name only core classes, or nothing, says nothing about any language's
|
|
25
|
+
* elements and relates only its own metamodel's (`own-metamodel.ts`). One that
|
|
26
|
+
* names a class of its own at one end and `arch:ModelConcept` at the other — the
|
|
27
|
+
* decision extension's Modifies, from an option to any concept — relates any
|
|
28
|
+
* concept at that end.
|
|
29
|
+
*
|
|
30
|
+
* **What is proposed first.** In three groups (core's `arch:relationshipProposalOrder`):
|
|
31
|
+
* what the relationship tables let a modeller draw directly, or say nothing
|
|
32
|
+
* about; then what they permit only as the conclusion of a derivation (`direct:
|
|
33
|
+
* false`); then the fallbacks — Association and a generic relationship (one
|
|
34
|
+
* whose hints name only core classes, for any two elements of its metamodel),
|
|
35
|
+
* which say least — unless an order scoped to the pair lists one, as
|
|
36
|
+
* ArchiMate's does association to a meaning or a value. Within a group, a
|
|
37
|
+
* candidate takes the place the most specific order of proposal that lists it
|
|
38
|
+
* gives it (`proposal-order.ts`): between two behaviour elements triggering and
|
|
39
|
+
* flow first, from a service serving, the strongest first elsewhere. What no
|
|
40
|
+
* order lists — every candidate, in a language that publishes none — comes
|
|
41
|
+
* after what an order lists: one whose `arch:domainIncludes` /
|
|
42
|
+
* `arch:rangeIncludes` hints describe the pair before one they do not, then the
|
|
43
|
+
* score's small nudges, then the label. Whether the
|
|
44
|
+
* language's metamodel figures draw a relationship does not move it; it is
|
|
45
|
+
* said (`drawn`).
|
|
46
|
+
*
|
|
47
|
+
* `arch:domainIncludes` / `arch:rangeIncludes` are `owl:AnnotationProperty`
|
|
48
|
+
* *hints*, not `rdfs:domain` / `rdfs:range` axioms. The core ontology is
|
|
49
|
+
* explicit: they are "used for guiding modelling but not restricting
|
|
50
|
+
* relationships … not to be used for validation". Two consequences drive the
|
|
51
|
+
* matching logic here:
|
|
52
|
+
*
|
|
53
|
+
* 1. **Constraints are declared broadly.** ArchiMate's `serves` declares
|
|
54
|
+
* `arch:domainIncludes am4:ActiveStructureElement`, not each of the ~60
|
|
55
|
+
* concrete leaf classes. Matching therefore runs against the transitive
|
|
56
|
+
* `rdfs:subClassOf*` closure of the source and target types, not their exact
|
|
57
|
+
* IRIs.
|
|
58
|
+
* 2. **Absent means unconstrained.** A relationship type that declares no
|
|
59
|
+
* domain (or no range) is permitted to anything at that end, rather than
|
|
60
|
+
* forbidden everywhere — among its own metamodel's elements when none of its
|
|
61
|
+
* hints names a class of a language (above).
|
|
62
|
+
*
|
|
63
|
+
* ## Where the constraints live
|
|
64
|
+
*
|
|
65
|
+
* Metamodels split a relationship type across two resources — an
|
|
66
|
+
* `owl:ObjectProperty` for the direct predicate and an `owl:Class` subclassing
|
|
67
|
+
* `arch:QualifiedRelationship` for the palette concept, linked by
|
|
68
|
+
* `arch:unqualifiedForm` — and the hints belong on the first:
|
|
69
|
+
*
|
|
70
|
+
* - ArchiMate 4.0 declares `am4:Serving a owl:Class ; rdfs:subClassOf
|
|
71
|
+
* arch:QualifiedRelationship ; arch:unqualifiedForm am4:serves` with no
|
|
72
|
+
* constraints on the class at all, hanging `arch:domainIncludes` /
|
|
73
|
+
* `arch:rangeIncludes` off the *property* `am4:serves`, as every published
|
|
74
|
+
* metamodel does.
|
|
75
|
+
* - An older or hand-written metamodel may put them on the class instead.
|
|
76
|
+
*
|
|
77
|
+
* Constraints are consequently gathered from the class and from whatever
|
|
78
|
+
* `arch:unqualifiedForm` points at, de-duplicated, so no metamodel-specific
|
|
79
|
+
* fallback table is needed.
|
|
80
|
+
*
|
|
81
|
+
* ## Which graphs the metamodel queries read
|
|
82
|
+
*
|
|
83
|
+
* `N3MetamodelLoader` puts each metamodel document in its own named graph, so
|
|
84
|
+
* an unscoped pattern — which in SPARQL means the default graph alone — finds
|
|
85
|
+
* none of it. Every read below therefore goes through {@link GraphScope}, which
|
|
86
|
+
* spans the default graph *and* every named graph; see `graph-scope.ts` for why
|
|
87
|
+
* that is expressed as two runs of the same query rather than a `GRAPH ?g`
|
|
88
|
+
* union. The relationship *writes* stay in the default graph, alongside the
|
|
89
|
+
* rest of the model data.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
import { DataFactory } from 'n3';
|
|
93
|
+
import type { NamedNode, Quad } from '@rdfjs/types';
|
|
94
|
+
import type { RdfStore } from '../rdf-engine/interfaces.js';
|
|
95
|
+
import type { RelationshipTypeInfo } from '../metamodel-manager/interfaces.js';
|
|
96
|
+
import { matchesClass } from '../metamodel-manager/taxonomy.js';
|
|
97
|
+
import { isGenericRelationshipType } from '../metamodel-manager/class-hierarchy.js';
|
|
98
|
+
import type {
|
|
99
|
+
CreateRelationshipRequest,
|
|
100
|
+
RelationshipInfo,
|
|
101
|
+
RelationshipManager,
|
|
102
|
+
} from './interfaces.js';
|
|
103
|
+
import { NAMESPACES } from '../rdf-engine/namespaces.js';
|
|
104
|
+
import { graphScope, isSafeIri, type GraphScope } from '../rdf-engine/graph-scope.js';
|
|
105
|
+
import { mintIri } from '../rdf-engine/iri.js';
|
|
106
|
+
import { conceptNamespace, modelNamespace } from './model-namespace.js';
|
|
107
|
+
import { readRelationshipTable, type RelationshipTable } from './relationship-table.js';
|
|
108
|
+
import { OwnMetamodels, namesNoLanguageClass } from './own-metamodel.js';
|
|
109
|
+
import { readDirectPermissions, readDrawnPermissions, type TablePermissions } from './direct-permissions.js';
|
|
110
|
+
import { compareProposals, isProposed, readProposalOrders, type ProposalOrders, type Proposal } from './proposal-order.js';
|
|
111
|
+
import {
|
|
112
|
+
collectRelationshipQuads,
|
|
113
|
+
qualifiedFormOf,
|
|
114
|
+
qualifiedPointerQuads,
|
|
115
|
+
relationshipClassOf,
|
|
116
|
+
relationshipsTouching,
|
|
117
|
+
unqualifiedFormOf,
|
|
118
|
+
} from './cascade.js';
|
|
119
|
+
import { IRI, T, langLiteral, nn, triple, tripleTerm } from './vocabulary.js';
|
|
120
|
+
|
|
121
|
+
const { namedNode, quad } = DataFactory;
|
|
122
|
+
|
|
123
|
+
const RDF_TYPE = namedNode(NAMESPACES.rdf + 'type');
|
|
124
|
+
const ARCH_QUALIFIED_RELATIONSHIP = namedNode(NAMESPACES.arch + 'QualifiedRelationship');
|
|
125
|
+
const ARCH_SOURCE = namedNode(NAMESPACES.arch + 'source');
|
|
126
|
+
const ARCH_TARGET = namedNode(NAMESPACES.arch + 'target');
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* `arch:Element` — the universal element superclass. Treated as a wildcard by
|
|
130
|
+
* {@link matchesClass}: a constraint naming it says "any element, of any
|
|
131
|
+
* language" — except that a type naming no class of its own at either end
|
|
132
|
+
* relates its own metamodel's elements only (DD-40).
|
|
133
|
+
*/
|
|
134
|
+
const ARCH_ELEMENT = NAMESPACES.arch + 'Element';
|
|
135
|
+
/** `arch:ModelConcept` — superclass of both elements and relationships; also a wildcard. */
|
|
136
|
+
const ARCH_MODEL_CONCEPT = NAMESPACES.arch + 'ModelConcept';
|
|
137
|
+
/** `arch:isAbstractClass` — on a relationship class, one that is never offered. */
|
|
138
|
+
const ARCH_IS_ABSTRACT_CLASS = nn(NAMESPACES.arch + 'isAbstractClass');
|
|
139
|
+
|
|
140
|
+
// ── Ranking weights ────────────────────────────────────────────────────
|
|
141
|
+
|
|
142
|
+
/** Every candidate that passes domain/range matching starts here. */
|
|
143
|
+
const BASE_SCORE = 10;
|
|
144
|
+
/** Added when the source type is named directly in `arch:domainIncludes`. */
|
|
145
|
+
const EXACT_SOURCE_BONUS = 5;
|
|
146
|
+
/** Added when the target type is named directly in `arch:rangeIncludes`. */
|
|
147
|
+
const EXACT_TARGET_BONUS = 5;
|
|
148
|
+
/** Association carries almost no semantics, so it sinks below everything else. */
|
|
149
|
+
const ASSOCIATION_PENALTY = 4;
|
|
150
|
+
/** Composition and aggregation are valid nearly everywhere; nudge them down. */
|
|
151
|
+
const CONTAINMENT_PENALTY = 1;
|
|
152
|
+
/** Specialization is valid between any two elements of one type; nudge it down too. */
|
|
153
|
+
const SPECIALIZATION_PENALTY = 1;
|
|
154
|
+
/** A generic relationship (relates any elements) says less than any language's: below Association. */
|
|
155
|
+
const GENERIC_PENALTY = 5;
|
|
156
|
+
|
|
157
|
+
/** Counter for generating unique QualifiedRelationship IRIs. */
|
|
158
|
+
let qrCounter = 0;
|
|
159
|
+
|
|
160
|
+
/** Reset the counter (useful for testing). */
|
|
161
|
+
export function resetQrCounter(): void {
|
|
162
|
+
qrCounter = 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ── IRI helpers ────────────────────────────────────────────────────────
|
|
166
|
+
//
|
|
167
|
+
// `isSafeIri` — the guard that keeps an IRI from breaking the query or
|
|
168
|
+
// injecting syntax when interpolated into a `<...>` term — comes from
|
|
169
|
+
// `graph-scope.ts`, which needs the same check for graph names.
|
|
170
|
+
|
|
171
|
+
/** Local name of an IRI (after the last `#` or `/`). */
|
|
172
|
+
function iriFragment(iri: string): string {
|
|
173
|
+
const hash = iri.lastIndexOf('#');
|
|
174
|
+
if (hash !== -1) return iri.slice(hash + 1);
|
|
175
|
+
const slash = iri.lastIndexOf('/');
|
|
176
|
+
return slash !== -1 ? iri.slice(slash + 1) : iri;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Turn a CamelCase / kebab / snake local name into a spaced label. */
|
|
180
|
+
function fragmentToLabel(fragment: string): string {
|
|
181
|
+
return fragment
|
|
182
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
183
|
+
.replace(/[-_]/g, ' ')
|
|
184
|
+
.replace(/\s+/g, ' ')
|
|
185
|
+
.trim();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Short, human-friendly name for an IRI, used when building reason strings. */
|
|
189
|
+
function shortLabel(iri: string): string {
|
|
190
|
+
if (iri === ARCH_ELEMENT) return 'Element';
|
|
191
|
+
if (iri === ARCH_MODEL_CONCEPT) return 'ModelConcept';
|
|
192
|
+
return fragmentToLabel(iriFragment(iri));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Render a constraint list for a reason string. */
|
|
196
|
+
function shortList(items: string[]): string {
|
|
197
|
+
if (items.length === 0) return 'unconstrained concept';
|
|
198
|
+
return items.map(shortLabel).join(' / ');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** A relationship type as read out of the metamodel, before pair matching. */
|
|
202
|
+
interface RelationshipTypeRecord {
|
|
203
|
+
iri: string;
|
|
204
|
+
label?: string;
|
|
205
|
+
iconUrl?: string;
|
|
206
|
+
unqualifiedPredicateIri?: string;
|
|
207
|
+
domainTypes: string[];
|
|
208
|
+
rangeTypes: string[];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Concrete implementation of the `RelationshipManager` interface.
|
|
213
|
+
*
|
|
214
|
+
* Queries the RDF store for relationship type metadata (domain/range)
|
|
215
|
+
* and creates/deletes relationship triples or QualifiedRelationship resources.
|
|
216
|
+
*/
|
|
217
|
+
export class OxigraphRelationshipManager implements RelationshipManager {
|
|
218
|
+
constructor(private readonly store: RdfStore) {
|
|
219
|
+
const observed = store as RdfStore & { onEveryWrite?(listener: () => void): unknown };
|
|
220
|
+
if (typeof observed.onEveryWrite === 'function') {
|
|
221
|
+
this.memoOn = true;
|
|
222
|
+
observed.onEveryWrite(() => {
|
|
223
|
+
this.memo = null;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* What one task reads of the metamodels for {@link getValidRelationships} —
|
|
230
|
+
* the scope, the relationship types, class closures — kept until the task
|
|
231
|
+
* ends or the store is written to: a context pad asks for forty pairs at once,
|
|
232
|
+
* each reading them again by SPARQL (Task 22). Only over a store that tells
|
|
233
|
+
* of every write.
|
|
234
|
+
*/
|
|
235
|
+
private memo: { scope: GraphScope; candidates?: RelationshipTypeRecord[]; closures: Map<string, string[]> } | null = null;
|
|
236
|
+
private memoOn = false;
|
|
237
|
+
|
|
238
|
+
private taskMemo(): { scope: GraphScope; candidates?: RelationshipTypeRecord[]; closures: Map<string, string[]> } | null {
|
|
239
|
+
if (!this.memoOn) return null;
|
|
240
|
+
if (!this.memo) {
|
|
241
|
+
const memo = { scope: graphScope(this.store), closures: new Map<string, string[]>() };
|
|
242
|
+
this.memo = memo;
|
|
243
|
+
queueMicrotask(() => {
|
|
244
|
+
if (this.memo === memo) this.memo = null;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
return this.memo;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Return the relationship types that may connect `sourceTypeIri` to
|
|
252
|
+
* `targetTypeIri`, best fit first.
|
|
253
|
+
*
|
|
254
|
+
* A type qualifies when its relationship shapes admit the pair or, where none
|
|
255
|
+
* covers it, when its `arch:domainIncludes` matches somewhere in the source
|
|
256
|
+
* type's superclass closure (or declares nothing at all) and its
|
|
257
|
+
* `arch:rangeIncludes` does the same for the target — both being of its own
|
|
258
|
+
* metamodel when its hints name no class of a language. An abstract type never
|
|
259
|
+
* qualifies. Each result carries a `score` and a `reason` explaining the decision.
|
|
260
|
+
*/
|
|
261
|
+
getValidRelationships(sourceTypeIri: string, targetTypeIri: string): RelationshipTypeInfo[] {
|
|
262
|
+
// One scope for all three reads below: enumerating the named graphs costs a
|
|
263
|
+
// scan, and nothing here mutates the store.
|
|
264
|
+
const memo = this.taskMemo();
|
|
265
|
+
const scope = memo?.scope ?? graphScope(this.store);
|
|
266
|
+
|
|
267
|
+
const candidates = memo ? (memo.candidates ??= this.readRelationshipTypes(scope)) : this.readRelationshipTypes(scope);
|
|
268
|
+
if (candidates.length === 0) return [];
|
|
269
|
+
|
|
270
|
+
const closureOf = (typeIri: string) => {
|
|
271
|
+
if (!memo) return this.classClosure(typeIri, scope);
|
|
272
|
+
let closure = memo.closures.get(typeIri);
|
|
273
|
+
if (!closure) memo.closures.set(typeIri, (closure = this.classClosure(typeIri, scope)));
|
|
274
|
+
return closure;
|
|
275
|
+
};
|
|
276
|
+
const sourceClosure = closureOf(sourceTypeIri);
|
|
277
|
+
const targetClosure = closureOf(targetTypeIri);
|
|
278
|
+
const table = this.relationshipTable(scope);
|
|
279
|
+
const ownMetamodels = this.ownMetamodels(scope);
|
|
280
|
+
const directPermissions = this.directPermissions(scope);
|
|
281
|
+
const drawnPermissions = this.drawnPermissions(scope);
|
|
282
|
+
const proposalOrders = this.proposalOrders(scope);
|
|
283
|
+
|
|
284
|
+
const matches: RelationshipTypeInfo[] = [];
|
|
285
|
+
/** Each candidate's place in the proposal orders, and whether its hints describe the pair. */
|
|
286
|
+
const ranking = new Map<RelationshipTypeInfo, { proposal: Proposal; hintFit: boolean }>();
|
|
287
|
+
|
|
288
|
+
for (const candidate of candidates) {
|
|
289
|
+
const { domainTypes, rangeTypes } = candidate;
|
|
290
|
+
const relationshipClosure = this.relationshipClosure(candidate.iri, scope);
|
|
291
|
+
const shaped = table.covers(relationshipClosure);
|
|
292
|
+
// A language's type whose hints name no class of a language relates its own metamodel's elements only.
|
|
293
|
+
const ownOnly =
|
|
294
|
+
!shaped && !candidate.iri.startsWith(NAMESPACES.arch) && namesNoLanguageClass(domainTypes, rangeTypes);
|
|
295
|
+
|
|
296
|
+
if (shaped) {
|
|
297
|
+
// The relationship shapes are normative (the language's relationship
|
|
298
|
+
// table); the domain/range hints are not consulted where they exist.
|
|
299
|
+
if (!table.allows(relationshipClosure, sourceClosure, targetClosure)) continue;
|
|
300
|
+
} else {
|
|
301
|
+
// Empty constraints are permissive: arch:domainIncludes is a hint, so an
|
|
302
|
+
// absent hint restricts nothing.
|
|
303
|
+
const sourceOk =
|
|
304
|
+
domainTypes.length === 0 || domainTypes.some((iri) => matchesClass(sourceClosure, iri));
|
|
305
|
+
const targetOk =
|
|
306
|
+
rangeTypes.length === 0 || rangeTypes.some((iri) => matchesClass(targetClosure, iri));
|
|
307
|
+
if (!sourceOk || !targetOk) continue;
|
|
308
|
+
// Hints that name only core classes, or none, say nothing about another language's elements: such a type
|
|
309
|
+
// relates its own metamodel's, and between two languages the core's types are offered (DD-40).
|
|
310
|
+
const ofItsMetamodel = (closure: readonly string[]) => ownMetamodels.includes(candidate.iri, closure);
|
|
311
|
+
if (ownOnly && !(ofItsMetamodel(sourceClosure) && ofItsMetamodel(targetClosure))) continue;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const label = candidate.label ?? fragmentToLabel(iriFragment(candidate.iri));
|
|
315
|
+
|
|
316
|
+
let score = BASE_SCORE;
|
|
317
|
+
if (domainTypes.includes(sourceTypeIri)) score += EXACT_SOURCE_BONUS;
|
|
318
|
+
if (rangeTypes.includes(targetTypeIri)) score += EXACT_TARGET_BONUS;
|
|
319
|
+
// Association, and a kind of it (a directed association), is the fallback.
|
|
320
|
+
const association = label === 'Association' || relationshipClosure.some((c) => iriFragment(c) === 'Association');
|
|
321
|
+
// Generic: it relates any two elements of its metamodel, and no relationship table restricts it
|
|
322
|
+
// (a table governs a type whatever its hints name).
|
|
323
|
+
const generic = !shaped && isGenericRelationshipType(domainTypes, rangeTypes);
|
|
324
|
+
if (association) score -= ASSOCIATION_PENALTY;
|
|
325
|
+
if (generic) score -= GENERIC_PENALTY;
|
|
326
|
+
if (label === 'Composition' || label === 'Aggregation') score -= CONTAINMENT_PENALTY;
|
|
327
|
+
if (label === 'Specialization') score -= SPECIALIZATION_PENALTY;
|
|
328
|
+
|
|
329
|
+
const predicate = candidate.unqualifiedPredicateIri;
|
|
330
|
+
const direct = predicate ? directPermissions.holds(predicate, sourceClosure, targetClosure) : undefined;
|
|
331
|
+
const drawn = predicate ? drawnPermissions.holds(predicate, sourceClosure, targetClosure) === true : false;
|
|
332
|
+
const proposal = proposalOrders.proposal(candidate.iri, relationshipClosure, sourceClosure, targetClosure);
|
|
333
|
+
const fallback = association || generic;
|
|
334
|
+
const hintFit =
|
|
335
|
+
(domainTypes.length === 0 || domainTypes.some((iri) => matchesClass(sourceClosure, iri))) &&
|
|
336
|
+
(rangeTypes.length === 0 || rangeTypes.some((iri) => matchesClass(targetClosure, iri)));
|
|
337
|
+
|
|
338
|
+
const constrained = domainTypes.length > 0 || rangeTypes.length > 0;
|
|
339
|
+
const allowed = shaped
|
|
340
|
+
? `Allowed by the metamodel's relationship shapes: a ${shortLabel(sourceTypeIri)} may have ` +
|
|
341
|
+
`${label} to a ${shortLabel(targetTypeIri)}.`
|
|
342
|
+
: constrained && ownOnly
|
|
343
|
+
? `Allowed because ${shortLabel(sourceTypeIri)} matches ${shortList(domainTypes)} ` +
|
|
344
|
+
`and ${shortLabel(targetTypeIri)} matches ${shortList(rangeTypes)}, both of the metamodel that defines ` +
|
|
345
|
+
`${label}: hints naming only core classes relate its own elements.`
|
|
346
|
+
: constrained
|
|
347
|
+
? `Allowed because ${shortLabel(sourceTypeIri)} matches ${shortList(domainTypes)} ` +
|
|
348
|
+
`and ${shortLabel(targetTypeIri)} matches ${shortList(rangeTypes)}.`
|
|
349
|
+
: ownOnly
|
|
350
|
+
? 'Allowed because the metamodel declares no arch:domainIncludes or arch:rangeIncludes for this type, ' +
|
|
351
|
+
`and ${shortLabel(sourceTypeIri)} and ${shortLabel(targetTypeIri)} are both of the metamodel that defines ` +
|
|
352
|
+
'it: it relates any two of its elements.'
|
|
353
|
+
: 'Allowed because the metamodel declares no arch:domainIncludes or ' +
|
|
354
|
+
'arch:rangeIncludes for this type, and an absent constraint hint is permissive.';
|
|
355
|
+
const why = drawn ? ' The language\'s metamodel figures draw it between these element types.' : '';
|
|
356
|
+
const reason =
|
|
357
|
+
direct === false
|
|
358
|
+
? `${allowed}${why} Only by derivation: the relationship tables permit it as the conclusion of a ` +
|
|
359
|
+
'derivation, not drawn directly.'
|
|
360
|
+
: `${allowed}${why}`;
|
|
361
|
+
|
|
362
|
+
const match: RelationshipTypeInfo = {
|
|
363
|
+
iri: candidate.iri,
|
|
364
|
+
label,
|
|
365
|
+
iconUrl: candidate.iconUrl,
|
|
366
|
+
domainTypes,
|
|
367
|
+
rangeTypes,
|
|
368
|
+
unqualifiedPredicateIri: candidate.unqualifiedPredicateIri,
|
|
369
|
+
score,
|
|
370
|
+
reason,
|
|
371
|
+
...(direct === undefined ? {} : { direct }),
|
|
372
|
+
...(generic ? { generic } : {}),
|
|
373
|
+
...(drawn ? { drawn } : {}),
|
|
374
|
+
...(fallback ? { fallback } : {}),
|
|
375
|
+
};
|
|
376
|
+
matches.push(match);
|
|
377
|
+
ranking.set(match, { proposal, hintFit });
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Core's own relationship types (Association, Depends On, Has Part, Refines) are for two elements no loaded
|
|
381
|
+
// language relates — an element of one metamodel and one of another, or two of a metamodel with no relationship
|
|
382
|
+
// types: where a language permits anything, they are not offered (Req 4.21).
|
|
383
|
+
const ofLanguage = matches.filter((m) => !m.iri.startsWith(NAMESPACES.arch));
|
|
384
|
+
if (ofLanguage.length > 0 && ofLanguage.length < matches.length) {
|
|
385
|
+
matches.length = 0;
|
|
386
|
+
matches.push(...ofLanguage);
|
|
387
|
+
} else if (ofLanguage.length === 0) {
|
|
388
|
+
// The least said first: Association, then Depends On, the one with a direction and nothing more, then Has
|
|
389
|
+
// Part and Refines.
|
|
390
|
+
const CORE_ORDER = ['Association', 'DependsOn', 'HasPart', 'Refines'];
|
|
391
|
+
for (const match of matches) {
|
|
392
|
+
const place = CORE_ORDER.indexOf(match.iri.slice(NAMESPACES.arch.length));
|
|
393
|
+
match.fallback = true;
|
|
394
|
+
match.score = CORE_ORDER.length - (place === -1 ? CORE_ORDER.length : place);
|
|
395
|
+
match.reason = 'Allowed because the loaded metamodels permit no relationship between these two element types: one of the core\'s own.';
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Three groups, in core's rule: what a modeller may draw directly, what only a derivation gives, and the
|
|
400
|
+
// fallbacks — Association, a generic relationship — unless an order scoped to the pair lists one.
|
|
401
|
+
const group = (match: RelationshipTypeInfo, proposal: Proposal) =>
|
|
402
|
+
match.fallback && !(isProposed(proposal) && proposal.ends > 0) ? 2 : match.direct === false ? 1 : 0;
|
|
403
|
+
return matches.sort((a, b) => {
|
|
404
|
+
const ra = ranking.get(a)!;
|
|
405
|
+
const rb = ranking.get(b)!;
|
|
406
|
+
const byGroup = group(a, ra.proposal) - group(b, rb.proposal);
|
|
407
|
+
if (byGroup !== 0) return byGroup;
|
|
408
|
+
const listedA = isProposed(ra.proposal);
|
|
409
|
+
const listedB = isProposed(rb.proposal);
|
|
410
|
+
if (listedA !== listedB) return listedA ? -1 : 1;
|
|
411
|
+
return (
|
|
412
|
+
// The place the most specific order that lists each gives it.
|
|
413
|
+
(listedA ? compareProposals(ra.proposal, rb.proposal) : 0) ||
|
|
414
|
+
// Where no order decides — a language that publishes none — the hints' fit, the score, the label.
|
|
415
|
+
Number(rb.hintFit) - Number(ra.hintFit) ||
|
|
416
|
+
(b.score ?? 0) - (a.score ?? 0) ||
|
|
417
|
+
a.label.localeCompare(b.label)
|
|
418
|
+
);
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** The relationships the loaded metamodel figures draw (`drawnBy`), read once per set of loaded graphs. */
|
|
423
|
+
private drawnCache: { key: string; permissions: TablePermissions } | undefined;
|
|
424
|
+
/** The loaded proposal orders, read likewise. */
|
|
425
|
+
private proposalCache: { key: string; orders: ProposalOrders } | undefined;
|
|
426
|
+
|
|
427
|
+
/** Which relationships the language's metamodel figures draw, per pair (`direct-permissions.ts`). */
|
|
428
|
+
drawnPermissions(scope: GraphScope = graphScope(this.store)): TablePermissions {
|
|
429
|
+
const key = scope.namedGraphs.join('\n');
|
|
430
|
+
if (this.drawnCache?.key !== key) {
|
|
431
|
+
this.drawnCache = { key, permissions: readDrawnPermissions(this.store) };
|
|
432
|
+
}
|
|
433
|
+
return this.drawnCache.permissions;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** The loaded languages' orders of proposal (`proposal-order.ts`). */
|
|
437
|
+
proposalOrders(scope: GraphScope = graphScope(this.store)): ProposalOrders {
|
|
438
|
+
const key = scope.namedGraphs.join('\n');
|
|
439
|
+
if (this.proposalCache?.key !== key) {
|
|
440
|
+
this.proposalCache = { key, orders: readProposalOrders(this.store) };
|
|
441
|
+
}
|
|
442
|
+
return this.proposalCache.orders;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** The relationship table of the loaded shapes, read once per set of loaded graphs. */
|
|
446
|
+
private tableCache: { key: string; table: RelationshipTable } | undefined;
|
|
447
|
+
/** The direct permissions of the loaded relationship tables, read likewise. */
|
|
448
|
+
private directCache: { key: string; permissions: TablePermissions } | undefined;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Which relationships the loaded relationship tables let a modeller draw
|
|
452
|
+
* directly (`direct-permissions.ts`), read once per set of loaded graphs.
|
|
453
|
+
*/
|
|
454
|
+
directPermissions(scope: GraphScope = graphScope(this.store)): TablePermissions {
|
|
455
|
+
const key = scope.namedGraphs.join('\n');
|
|
456
|
+
if (this.directCache?.key !== key) {
|
|
457
|
+
this.directCache = { key, permissions: readDirectPermissions(this.store) };
|
|
458
|
+
}
|
|
459
|
+
return this.directCache.permissions;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* The relationship table the loaded relationship shapes encode
|
|
464
|
+
* (`relationship-table.ts`). Loading or unloading a metamodel changes the
|
|
465
|
+
* store's named graphs, which is what the cache is keyed on.
|
|
466
|
+
*/
|
|
467
|
+
relationshipTable(scope: GraphScope = graphScope(this.store)): RelationshipTable {
|
|
468
|
+
const key = scope.namedGraphs.join('\n');
|
|
469
|
+
if (this.tableCache?.key !== key) {
|
|
470
|
+
this.tableCache = { key, table: readRelationshipTable(this.store) };
|
|
471
|
+
this.relationshipClosures.clear();
|
|
472
|
+
}
|
|
473
|
+
return this.tableCache.table;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** The loaded metamodels' documents, read likewise. */
|
|
477
|
+
private ownCache: { key: string; metamodels: OwnMetamodels } | undefined;
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Which metamodel each relationship type is of, for the types whose hints name no class of a language
|
|
481
|
+
* (`own-metamodel.ts`), read once per set of loaded graphs.
|
|
482
|
+
*/
|
|
483
|
+
private ownMetamodels(scope: GraphScope): OwnMetamodels {
|
|
484
|
+
const key = scope.namedGraphs.join('\n');
|
|
485
|
+
if (this.ownCache?.key !== key) {
|
|
486
|
+
this.ownCache = { key, metamodels: new OwnMetamodels(this.store, scope.namedGraphs) };
|
|
487
|
+
}
|
|
488
|
+
return this.ownCache.metamodels;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** `rdfs:subClassOf*` closures of relationship classes; they change only with the metamodels. */
|
|
492
|
+
private readonly relationshipClosures = new Map<string, string[]>();
|
|
493
|
+
|
|
494
|
+
private relationshipClosure(relationshipClassIri: string, scope: GraphScope): string[] {
|
|
495
|
+
let closure = this.relationshipClosures.get(relationshipClassIri);
|
|
496
|
+
if (!closure) {
|
|
497
|
+
closure = this.classClosure(relationshipClassIri, scope);
|
|
498
|
+
this.relationshipClosures.set(relationshipClassIri, closure);
|
|
499
|
+
}
|
|
500
|
+
return closure;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* The transitive `rdfs:subClassOf*` closure of a type, including the type
|
|
505
|
+
* itself.
|
|
506
|
+
*
|
|
507
|
+
* Computed by SPARQL property path so the store does the graph walk. Falls
|
|
508
|
+
* back to the bare type when the IRI cannot be safely interpolated or the
|
|
509
|
+
* store has no hierarchy for it.
|
|
510
|
+
*
|
|
511
|
+
* The walk has to cross document boundaries — ArchiMate declares
|
|
512
|
+
* `am4:StructureElement rdfs:subClassOf arch:Element` in its own document but
|
|
513
|
+
* `arch:Element rdfs:subClassOf arch:ModelConcept` in the core one — which is
|
|
514
|
+
* why the scope merges the named graphs rather than visiting them one at a
|
|
515
|
+
* time.
|
|
516
|
+
*/
|
|
517
|
+
private classClosure(typeIri: string, scope: GraphScope): string[] {
|
|
518
|
+
if (!isSafeIri(typeIri)) return [typeIri];
|
|
519
|
+
|
|
520
|
+
const rows = scope.select(
|
|
521
|
+
(from) => `
|
|
522
|
+
PREFIX rdfs: <${NAMESPACES.rdfs}>
|
|
523
|
+
|
|
524
|
+
SELECT DISTINCT ?super
|
|
525
|
+
${from}
|
|
526
|
+
WHERE {
|
|
527
|
+
<${typeIri}> rdfs:subClassOf* ?super .
|
|
528
|
+
FILTER(isIRI(?super))
|
|
529
|
+
}
|
|
530
|
+
`,
|
|
531
|
+
);
|
|
532
|
+
|
|
533
|
+
const closure = new Set<string>([typeIri]);
|
|
534
|
+
for (const row of rows) {
|
|
535
|
+
const value = row['super']?.value;
|
|
536
|
+
if (value) closure.add(value);
|
|
537
|
+
}
|
|
538
|
+
return Array.from(closure);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Read every relationship type in the store together with its constraints.
|
|
543
|
+
*
|
|
544
|
+
* A relationship type is any resource whose `rdfs:subClassOf+` closure
|
|
545
|
+
* reaches `arch:QualifiedRelationship` — `+` rather than `*` because
|
|
546
|
+
* intermediate steps are real (ArchiMate's `Composition` subclasses
|
|
547
|
+
* `Aggregation`, which subclasses `arch:QualifiedRelationship`) and because
|
|
548
|
+
* `arch:QualifiedRelationship` itself is not a relationship type. A generic
|
|
549
|
+
* relationship — one that relates any two elements of its metamodel — is a
|
|
550
|
+
* language's own type whose domain and range name only core classes.
|
|
551
|
+
*
|
|
552
|
+
* A class marked `arch:isAbstractClass true` is left out: it classifies its
|
|
553
|
+
* subclasses and is never offered (EDGY's Enterprise Relationship). The mark is
|
|
554
|
+
* looked for in every graph, as the palette looks for it, not inside the query,
|
|
555
|
+
* whose two passes each see only part of the store.
|
|
556
|
+
*
|
|
557
|
+
* A legacy `?rel a arch:Relationship` typing is also accepted. That class was
|
|
558
|
+
* removed from the core ontology, but recognising it costs one UNION branch
|
|
559
|
+
* and keeps older or hand-written metamodels working.
|
|
560
|
+
*/
|
|
561
|
+
private readRelationshipTypes(scope: GraphScope): RelationshipTypeRecord[] {
|
|
562
|
+
const rows = scope.select(
|
|
563
|
+
(from) => `
|
|
564
|
+
PREFIX rdf: <${NAMESPACES.rdf}>
|
|
565
|
+
PREFIX rdfs: <${NAMESPACES.rdfs}>
|
|
566
|
+
PREFIX arch: <${NAMESPACES.arch}>
|
|
567
|
+
PREFIX skos: <${NAMESPACES.skos}>
|
|
568
|
+
|
|
569
|
+
SELECT DISTINCT ?rel ?label ?icon ?pred ?domain ?range
|
|
570
|
+
${from}
|
|
571
|
+
WHERE {
|
|
572
|
+
{
|
|
573
|
+
?rel rdfs:subClassOf+ arch:QualifiedRelationship .
|
|
574
|
+
} UNION {
|
|
575
|
+
?rel rdf:type arch:Relationship .
|
|
576
|
+
}
|
|
577
|
+
OPTIONAL { ?rel skos:prefLabel ?label }
|
|
578
|
+
OPTIONAL { ?rel arch:prefVisNotation ?icon }
|
|
579
|
+
OPTIONAL { ?rel arch:unqualifiedForm ?pred }
|
|
580
|
+
OPTIONAL {
|
|
581
|
+
{ ?rel arch:domainIncludes ?domain }
|
|
582
|
+
UNION
|
|
583
|
+
{ ?rel arch:unqualifiedForm ?domainSource . ?domainSource arch:domainIncludes ?domain }
|
|
584
|
+
}
|
|
585
|
+
OPTIONAL {
|
|
586
|
+
{ ?rel arch:rangeIncludes ?range }
|
|
587
|
+
UNION
|
|
588
|
+
{ ?rel arch:unqualifiedForm ?rangeSource . ?rangeSource arch:rangeIncludes ?range }
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
`,
|
|
592
|
+
);
|
|
593
|
+
|
|
594
|
+
// One relationship type spans several rows — the domain × range cross
|
|
595
|
+
// product, doubled again when the same triples sit in both the default graph
|
|
596
|
+
// and a named graph. Keying by IRI collapses all of it into one record.
|
|
597
|
+
const byIri = new Map<string, RelationshipTypeRecord>();
|
|
598
|
+
|
|
599
|
+
for (const row of rows) {
|
|
600
|
+
const iri = row['rel']?.value;
|
|
601
|
+
if (!iri) continue;
|
|
602
|
+
|
|
603
|
+
let record = byIri.get(iri);
|
|
604
|
+
if (!record) {
|
|
605
|
+
record = {
|
|
606
|
+
iri,
|
|
607
|
+
label: row['label']?.value,
|
|
608
|
+
iconUrl: row['icon']?.value,
|
|
609
|
+
unqualifiedPredicateIri: row['pred']?.value,
|
|
610
|
+
domainTypes: [],
|
|
611
|
+
rangeTypes: [],
|
|
612
|
+
};
|
|
613
|
+
byIri.set(iri, record);
|
|
614
|
+
} else {
|
|
615
|
+
// A later row may carry an OPTIONAL the first one lacked — the two
|
|
616
|
+
// passes are independent, so neither is guaranteed to be the richer.
|
|
617
|
+
record.label ??= row['label']?.value;
|
|
618
|
+
record.iconUrl ??= row['icon']?.value;
|
|
619
|
+
record.unqualifiedPredicateIri ??= row['pred']?.value;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const domain = row['domain']?.value;
|
|
623
|
+
if (domain && !record.domainTypes.includes(domain)) record.domainTypes.push(domain);
|
|
624
|
+
|
|
625
|
+
const range = row['range']?.value;
|
|
626
|
+
if (range && !record.rangeTypes.includes(range)) record.rangeTypes.push(range);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
return Array.from(byIri.values()).filter((record) => !this.isAbstractClass(record.iri));
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/** Whether a class carries `arch:isAbstractClass true`, in any graph. */
|
|
633
|
+
private isAbstractClass(iri: string): boolean {
|
|
634
|
+
return this.store.getQuads(nn(iri), ARCH_IS_ABSTRACT_CLASS).some((q) => q.object.value === 'true');
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Create a relationship between source and target.
|
|
639
|
+
*
|
|
640
|
+
* - If `qualified` is false/undefined: creates a direct triple
|
|
641
|
+
* `<sourceIri> <typeIri> <targetIri>` and returns `null`.
|
|
642
|
+
* - If `qualified` is true: creates an `arch:QualifiedRelationship`
|
|
643
|
+
* resource with `arch:source` / `arch:target` and returns the QR resource
|
|
644
|
+
* NamedNode. When the metamodel maps `typeIri` back to a relationship class
|
|
645
|
+
* via `arch:unqualifiedForm`, the resource is also typed with that class —
|
|
646
|
+
* that class type is what identifies the relationship kind on a qualified
|
|
647
|
+
* resource.
|
|
648
|
+
*
|
|
649
|
+
* The core ontology declares exactly two properties on a
|
|
650
|
+
* `arch:QualifiedRelationship`: `arch:source` and `arch:target`, both with
|
|
651
|
+
* `rdfs:domain arch:QualifiedRelationship`. The older
|
|
652
|
+
* `arch:relSource` / `arch:relTarget` / `arch:relPredicate` triple — sub-properties
|
|
653
|
+
* of `rdf:subject` / `rdf:object` / `rdf:predicate` under the `rdf:Statement`
|
|
654
|
+
* reification pattern — was removed from the core ontology (see the
|
|
655
|
+
* `skos:historyNote` on `arch:QualifiedRelationship`), so nothing here emits it.
|
|
656
|
+
* There is consequently no predicate property on the resource: the relationship
|
|
657
|
+
* kind is carried by the `rdf:type` of the relationship class.
|
|
658
|
+
*/
|
|
659
|
+
createRelationship(
|
|
660
|
+
typeIri: string,
|
|
661
|
+
sourceIri: string,
|
|
662
|
+
targetIri: string,
|
|
663
|
+
qualified?: boolean,
|
|
664
|
+
): NamedNode | null {
|
|
665
|
+
const source = namedNode(sourceIri) as unknown as NamedNode;
|
|
666
|
+
const target = namedNode(targetIri) as unknown as NamedNode;
|
|
667
|
+
const predicate = namedNode(typeIri) as unknown as NamedNode;
|
|
668
|
+
|
|
669
|
+
if (!qualified) {
|
|
670
|
+
// Direct triple: source --predicate--> target
|
|
671
|
+
const directQuad = quad(
|
|
672
|
+
source as any,
|
|
673
|
+
predicate as any,
|
|
674
|
+
target as any,
|
|
675
|
+
) as unknown as Quad;
|
|
676
|
+
this.store.addQuads([directQuad]);
|
|
677
|
+
return null;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// Qualified relationship resource. Random, not counted: a counter restarts
|
|
681
|
+
// with the process and would reuse an IRI already in a loaded model.
|
|
682
|
+
qrCounter += 1;
|
|
683
|
+
// In the source's model's namespace: `{ns}relationship/{uuid}`, never beside the source's own IRI.
|
|
684
|
+
const qrIri = mintIri(conceptNamespace(this.store, sourceIri), 'relationship');
|
|
685
|
+
const qrNode = namedNode(qrIri) as unknown as NamedNode;
|
|
686
|
+
|
|
687
|
+
const quads: Quad[] = [
|
|
688
|
+
quad(qrNode as any, RDF_TYPE as any, ARCH_QUALIFIED_RELATIONSHIP as any) as unknown as Quad,
|
|
689
|
+
quad(qrNode as any, ARCH_SOURCE as any, source as any) as unknown as Quad,
|
|
690
|
+
quad(qrNode as any, ARCH_TARGET as any, target as any) as unknown as Quad,
|
|
691
|
+
];
|
|
692
|
+
|
|
693
|
+
const relationshipClassIri = this.findRelationshipClass(typeIri);
|
|
694
|
+
if (relationshipClassIri) {
|
|
695
|
+
quads.push(
|
|
696
|
+
quad(
|
|
697
|
+
qrNode as any,
|
|
698
|
+
RDF_TYPE as any,
|
|
699
|
+
namedNode(relationshipClassIri) as any,
|
|
700
|
+
) as unknown as Quad,
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
this.store.addQuads(quads);
|
|
705
|
+
return qrNode;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Resolve the relationship class whose `arch:unqualifiedForm` is `predicateIri`.
|
|
710
|
+
* Subclasses share their class's predicate — `am4:ReadAccess` is an
|
|
711
|
+
* `am4:Access` and also `am4:accesses` — so the most general one is meant: a
|
|
712
|
+
* bare triple says no more than that.
|
|
713
|
+
*
|
|
714
|
+
* Returns `null` when the metamodel is not loaded or declares no such
|
|
715
|
+
* mapping.
|
|
716
|
+
*/
|
|
717
|
+
private findRelationshipClass(predicateIri: string): string | null {
|
|
718
|
+
if (!isSafeIri(predicateIri)) return null;
|
|
719
|
+
|
|
720
|
+
// `LIMIT 1` applies per pass, so this yields at most one row from the
|
|
721
|
+
// default graph and one from the named-graph merge; the first wins.
|
|
722
|
+
const rows = graphScope(this.store).select(
|
|
723
|
+
(from) => `
|
|
724
|
+
PREFIX rdfs: <${NAMESPACES.rdfs}>
|
|
725
|
+
PREFIX arch: <${NAMESPACES.arch}>
|
|
726
|
+
|
|
727
|
+
SELECT ?cls
|
|
728
|
+
${from}
|
|
729
|
+
WHERE {
|
|
730
|
+
?cls arch:unqualifiedForm <${predicateIri}> .
|
|
731
|
+
?cls rdfs:subClassOf+ arch:QualifiedRelationship .
|
|
732
|
+
FILTER NOT EXISTS {
|
|
733
|
+
?cls rdfs:subClassOf+ ?general .
|
|
734
|
+
?general arch:unqualifiedForm <${predicateIri}> .
|
|
735
|
+
FILTER(?general != ?cls)
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
LIMIT 1
|
|
739
|
+
`,
|
|
740
|
+
);
|
|
741
|
+
|
|
742
|
+
for (const row of rows) {
|
|
743
|
+
const cls = row['cls']?.value;
|
|
744
|
+
if (cls) return cls;
|
|
745
|
+
}
|
|
746
|
+
return null;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* Create a relationship the Linked.Archi way: a qualified resource typed
|
|
751
|
+
* with its relationship class, carrying `arch:source` / `arch:target` and
|
|
752
|
+
* `arch:inModel`, *plus* the unqualified triple the class maps to through
|
|
753
|
+
* `arch:unqualifiedForm` (DD-10), which the resource `rdf:reifies` (RDF 1.2,
|
|
754
|
+
* `<<( s p o )>>`), and the qualified predicate leading from the source to the
|
|
755
|
+
* resource (`am4:qualifiedServing`; core's `arch:hasQualifiedRelationship` for
|
|
756
|
+
* a class the metamodel gives none). The resource is what views draw, what
|
|
757
|
+
* properties hang off, and what has a stable IRI; the triple is what makes
|
|
758
|
+
* `?a am4:serves ?b` work in SPARQL; `rdf:reifies` says which triple the
|
|
759
|
+
* resource is about; the qualified predicate is the way in from the source.
|
|
760
|
+
*
|
|
761
|
+
* `typeIri` may name either the class (`am4:Serving`, what the palette
|
|
762
|
+
* offers) or the predicate (`am4:serves`); the other is resolved from the
|
|
763
|
+
* metamodel. When the metamodel names neither mapping the resource is typed
|
|
764
|
+
* with `typeIri` alone and no unqualified triple is written.
|
|
765
|
+
*/
|
|
766
|
+
createQualifiedRelationship(request: CreateRelationshipRequest): RelationshipInfo {
|
|
767
|
+
const { sourceIri, targetIri } = request;
|
|
768
|
+
let classIri = request.typeIri;
|
|
769
|
+
let predicateIri = request.predicateIri;
|
|
770
|
+
|
|
771
|
+
if (this.isRelationshipClass(request.typeIri)) {
|
|
772
|
+
predicateIri ??= unqualifiedFormOf(this.store, request.typeIri);
|
|
773
|
+
} else {
|
|
774
|
+
// Given a predicate: find the class that maps to it.
|
|
775
|
+
predicateIri ??= request.typeIri;
|
|
776
|
+
classIri = this.findRelationshipClass(request.typeIri) ?? request.typeIri;
|
|
777
|
+
}
|
|
778
|
+
if (predicateIri === classIri && !this.isProperty(predicateIri)) predicateIri = undefined;
|
|
779
|
+
|
|
780
|
+
const iri =
|
|
781
|
+
request.iri ??
|
|
782
|
+
mintIri(request.modelIri ? modelNamespace(this.store, request.modelIri) : conceptNamespace(this.store, sourceIri), 'relationship');
|
|
783
|
+
const rel = nn(iri);
|
|
784
|
+
const quads: Quad[] = [
|
|
785
|
+
triple(rel, T.rdfType, nn(classIri)),
|
|
786
|
+
triple(rel, T.source, nn(sourceIri)),
|
|
787
|
+
triple(rel, T.target, nn(targetIri)),
|
|
788
|
+
triple(nn(sourceIri), nn(qualifiedFormOf(this.store, classIri)), rel),
|
|
789
|
+
];
|
|
790
|
+
if (request.modelIri) quads.push(triple(rel, T.inModel, nn(request.modelIri)));
|
|
791
|
+
if (request.label?.trim()) quads.push(triple(rel, T.prefLabel, langLiteral(request.label.trim())));
|
|
792
|
+
if (predicateIri) {
|
|
793
|
+
quads.push(
|
|
794
|
+
triple(nn(sourceIri), nn(predicateIri), nn(targetIri)),
|
|
795
|
+
triple(rel, T.reifies, tripleTerm(nn(sourceIri), nn(predicateIri), nn(targetIri))),
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
this.store.addQuads(quads);
|
|
799
|
+
|
|
800
|
+
return {
|
|
801
|
+
iri,
|
|
802
|
+
classIri,
|
|
803
|
+
...(predicateIri ? { predicateIri } : {}),
|
|
804
|
+
sourceIri,
|
|
805
|
+
targetIri,
|
|
806
|
+
...(request.label?.trim() ? { label: request.label.trim() } : {}),
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Change a relationship's kind in place. The IRI, the endpoints, the label
|
|
812
|
+
* and every other property stay; the class type, the qualified predicate
|
|
813
|
+
* from the source and the unqualified triple are swapped (the old triple only
|
|
814
|
+
* when no sibling still justifies it).
|
|
815
|
+
*/
|
|
816
|
+
retypeRelationship(relationshipIri: string, typeIri: string): RelationshipInfo | undefined {
|
|
817
|
+
const current = this.getRelationship(relationshipIri);
|
|
818
|
+
if (!current) return undefined;
|
|
819
|
+
const rel = nn(relationshipIri);
|
|
820
|
+
const newClass = this.isRelationshipClass(typeIri) ? typeIri : (this.findRelationshipClass(typeIri) ?? typeIri);
|
|
821
|
+
if (newClass === current.classIri) return current;
|
|
822
|
+
const newPredicate = unqualifiedFormOf(this.store, newClass) ?? (newClass === typeIri ? undefined : typeIri);
|
|
823
|
+
|
|
824
|
+
const remove: Quad[] = [
|
|
825
|
+
...this.store.getQuads(rel, T.rdfType, nn(current.classIri)),
|
|
826
|
+
...this.store.getQuads(rel, T.reifies),
|
|
827
|
+
...qualifiedPointerQuads(this.store, relationshipIri, current.sourceIri),
|
|
828
|
+
];
|
|
829
|
+
if (current.predicateIri) {
|
|
830
|
+
const siblings = this.getRelationshipsOf(current.sourceIri).filter(
|
|
831
|
+
(r) => r.iri !== relationshipIri && r.targetIri === current.targetIri && r.classIri === current.classIri,
|
|
832
|
+
);
|
|
833
|
+
if (siblings.length === 0) {
|
|
834
|
+
remove.push(...this.store.getQuads(nn(current.sourceIri), nn(current.predicateIri), nn(current.targetIri)));
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
if (remove.length > 0) this.store.removeQuads(remove);
|
|
838
|
+
const add: Quad[] = [
|
|
839
|
+
triple(rel, T.rdfType, nn(newClass)),
|
|
840
|
+
triple(nn(current.sourceIri), nn(qualifiedFormOf(this.store, newClass)), rel),
|
|
841
|
+
];
|
|
842
|
+
if (newPredicate) {
|
|
843
|
+
add.push(
|
|
844
|
+
triple(nn(current.sourceIri), nn(newPredicate), nn(current.targetIri)),
|
|
845
|
+
triple(rel, T.reifies, tripleTerm(nn(current.sourceIri), nn(newPredicate), nn(current.targetIri))),
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
this.store.addQuads(add);
|
|
849
|
+
return this.getRelationship(relationshipIri);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* Reattach a relationship to other elements. Its IRI, type and properties
|
|
854
|
+
* stay; the ends, the qualified predicate from the source and the
|
|
855
|
+
* unqualified triple move.
|
|
856
|
+
*/
|
|
857
|
+
reconnectRelationship(relationshipIri: string, sourceIri: string, targetIri: string): RelationshipInfo | undefined {
|
|
858
|
+
const current = this.getRelationship(relationshipIri);
|
|
859
|
+
if (!current) return undefined;
|
|
860
|
+
if (current.sourceIri === sourceIri && current.targetIri === targetIri) return current;
|
|
861
|
+
const rel = nn(relationshipIri);
|
|
862
|
+
// The way in from the source moves with it, by whichever predicate the data uses.
|
|
863
|
+
const pointers = qualifiedPointerQuads(this.store, relationshipIri, current.sourceIri);
|
|
864
|
+
const pointerPredicates = pointers.length > 0 ? [...new Set(pointers.map((q) => q.predicate.value))] : [qualifiedFormOf(this.store, current.classIri)];
|
|
865
|
+
const remove: Quad[] = [
|
|
866
|
+
...this.store.getQuads(rel, T.source),
|
|
867
|
+
...this.store.getQuads(rel, T.target),
|
|
868
|
+
...this.store.getQuads(rel, T.reifies),
|
|
869
|
+
...pointers,
|
|
870
|
+
];
|
|
871
|
+
if (current.predicateIri) {
|
|
872
|
+
const siblings = this.getRelationshipsOf(current.sourceIri).filter(
|
|
873
|
+
(r) => r.iri !== relationshipIri && r.targetIri === current.targetIri && r.classIri === current.classIri,
|
|
874
|
+
);
|
|
875
|
+
if (siblings.length === 0) {
|
|
876
|
+
remove.push(...this.store.getQuads(nn(current.sourceIri), nn(current.predicateIri), nn(current.targetIri)));
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
this.store.removeQuads(remove);
|
|
880
|
+
const add: Quad[] = [
|
|
881
|
+
triple(rel, T.source, nn(sourceIri)),
|
|
882
|
+
triple(rel, T.target, nn(targetIri)),
|
|
883
|
+
...pointerPredicates.map((p) => triple(nn(sourceIri), nn(p), rel)),
|
|
884
|
+
];
|
|
885
|
+
if (current.predicateIri) {
|
|
886
|
+
add.push(
|
|
887
|
+
triple(nn(sourceIri), nn(current.predicateIri), nn(targetIri)),
|
|
888
|
+
triple(rel, T.reifies, tripleTerm(nn(sourceIri), nn(current.predicateIri), nn(targetIri))),
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
this.store.addQuads(add);
|
|
892
|
+
return this.getRelationship(relationshipIri);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/** Read one qualified relationship, current or legacy vocabulary. */
|
|
896
|
+
getRelationship(relationshipIri: string): RelationshipInfo | undefined {
|
|
897
|
+
const rel = nn(relationshipIri);
|
|
898
|
+
const first = (predicate: string) => this.store.getQuads(rel, nn(predicate))[0]?.object.value;
|
|
899
|
+
const sourceIri = first(IRI.source) ?? first(IRI.legacyRelSource);
|
|
900
|
+
const targetIri = first(IRI.target) ?? first(IRI.legacyRelTarget);
|
|
901
|
+
if (!sourceIri || !targetIri) return undefined;
|
|
902
|
+
const classIri = relationshipClassOf(this.store, relationshipIri) ?? IRI.QualifiedRelationship;
|
|
903
|
+
const predicateIri = unqualifiedFormOf(this.store, classIri) ?? first(IRI.legacyRelPredicate);
|
|
904
|
+
const label = first(IRI.prefLabel);
|
|
905
|
+
return {
|
|
906
|
+
iri: relationshipIri,
|
|
907
|
+
classIri,
|
|
908
|
+
...(predicateIri ? { predicateIri } : {}),
|
|
909
|
+
sourceIri,
|
|
910
|
+
targetIri,
|
|
911
|
+
...(label ? { label } : {}),
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/** Every qualified relationship with the element at either end. */
|
|
916
|
+
getRelationshipsOf(elementIri: string): RelationshipInfo[] {
|
|
917
|
+
return relationshipsTouching(this.store, elementIri)
|
|
918
|
+
.map((iri) => this.getRelationship(iri))
|
|
919
|
+
.filter((info): info is RelationshipInfo => info !== undefined);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
/** The quads {@link deleteRelationship} removes. */
|
|
923
|
+
collectRelationshipQuads(relationshipIri: string): Quad[] {
|
|
924
|
+
return collectRelationshipQuads(this.store, relationshipIri);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/** Whether an IRI is a relationship class (reaches `arch:QualifiedRelationship`). */
|
|
928
|
+
private isRelationshipClass(iri: string): boolean {
|
|
929
|
+
if (!isSafeIri(iri)) return false;
|
|
930
|
+
const rows = graphScope(this.store).select(
|
|
931
|
+
(from) => `
|
|
932
|
+
PREFIX rdfs: <${NAMESPACES.rdfs}>
|
|
933
|
+
PREFIX arch: <${NAMESPACES.arch}>
|
|
934
|
+
SELECT ?x ${from} WHERE { <${iri}> rdfs:subClassOf+ arch:QualifiedRelationship . BIND(1 AS ?x) } LIMIT 1
|
|
935
|
+
`,
|
|
936
|
+
);
|
|
937
|
+
return rows.length > 0;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/** Whether an IRI is declared as a property anywhere in the store. */
|
|
941
|
+
private isProperty(iri: string): boolean {
|
|
942
|
+
const types = this.store.getQuads(nn(iri), T.rdfType).map((q) => q.object.value);
|
|
943
|
+
return types.some((t) => t.endsWith('ObjectProperty') || t.endsWith('#Property'));
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* Delete a QualifiedRelationship from the model by its IRI.
|
|
948
|
+
*
|
|
949
|
+
* Removes the resource, its unqualified triple when no sibling occurrence
|
|
950
|
+
* keeps that triple true, and every diagram link drawing it. Source and
|
|
951
|
+
* target elements remain intact.
|
|
952
|
+
*
|
|
953
|
+
* A relationship that exists *only* as a direct triple has no IRI; the
|
|
954
|
+
* caller retracts that triple directly via the RDF store.
|
|
955
|
+
*/
|
|
956
|
+
deleteRelationship(relationshipIri: string): void {
|
|
957
|
+
// The resource, its unqualified triple (unless a sibling keeps it true),
|
|
958
|
+
// and every link drawing it — see `cascade.ts`.
|
|
959
|
+
const quads = this.collectRelationshipQuads(relationshipIri);
|
|
960
|
+
if (quads.length > 0) this.store.removeQuads(quads);
|
|
961
|
+
}
|
|
962
|
+
}
|