@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,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How far from its focus node a shapes graph reads (Task 22): which nodes an
|
|
3
|
+
* edit can change the findings of, so that only those are validated again.
|
|
4
|
+
*
|
|
5
|
+
* Validating a focus node against a shape reads the focus node's own triples,
|
|
6
|
+
* those along each `sh:path` — a path of length L reaches value nodes L hops
|
|
7
|
+
* away, whose types `sh:class` reads — and, for a shape nested on the values
|
|
8
|
+
* (`sh:node`, `sh:property`, `sh:qualifiedValueShape`, `sh:not`, the members of
|
|
9
|
+
* `sh:and`, `sh:or`, `sh:xone`), what that shape reads from there. The reach is
|
|
10
|
+
* the most hops from a focus node to the subject of a triple it reads; a triple
|
|
11
|
+
* whose subject changed matters to the nodes that many hops before it.
|
|
12
|
+
*/
|
|
13
|
+
import type { Quad, Term } from '@rdfjs/types';
|
|
14
|
+
import { NAMESPACES } from './namespaces.js';
|
|
15
|
+
|
|
16
|
+
const SH = NAMESPACES.sh;
|
|
17
|
+
const RDF = NAMESPACES.rdf;
|
|
18
|
+
|
|
19
|
+
/** Shapes nested on the value nodes (or, on a node shape, on the focus node). */
|
|
20
|
+
const NESTED = [SH + 'node', SH + 'property', SH + 'qualifiedValueShape', SH + 'not'];
|
|
21
|
+
/** Lists of shapes, likewise. */
|
|
22
|
+
const NESTED_LISTS = [SH + 'and', SH + 'or', SH + 'xone'];
|
|
23
|
+
|
|
24
|
+
export interface ShapesReach {
|
|
25
|
+
/**
|
|
26
|
+
* The most hops from a focus node to the subject of a triple its validation
|
|
27
|
+
* reads; `Infinity` when unbounded — a `sh:zeroOrMorePath` or
|
|
28
|
+
* `sh:oneOrMorePath`, or a shape nested in itself.
|
|
29
|
+
*/
|
|
30
|
+
hops: number;
|
|
31
|
+
/** Whether a path goes backwards (`sh:inversePath`): a triple then matters on both its sides. */
|
|
32
|
+
inverse: boolean;
|
|
33
|
+
/** Whether a shape is nested in itself — the only case where checking a node against a shape can recurse. */
|
|
34
|
+
recursive: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether a property shape has a `sh:property` of its own: rdf-validate-shacl
|
|
37
|
+
* then reports what that finds with the value node as the focus node, so a
|
|
38
|
+
* node's validation reports findings of another.
|
|
39
|
+
*/
|
|
40
|
+
valuesAsFocus: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The reach of a shapes graph: the most of any shape in it. */
|
|
44
|
+
export function shapesReach(shapes: readonly Quad[]): ShapesReach {
|
|
45
|
+
const bySubject = new Map<string, Quad[]>();
|
|
46
|
+
for (const q of shapes) {
|
|
47
|
+
const key = id(q.subject);
|
|
48
|
+
const list = bySubject.get(key);
|
|
49
|
+
if (list) list.push(q);
|
|
50
|
+
else bySubject.set(key, [q]);
|
|
51
|
+
}
|
|
52
|
+
const objects = (node: Term, predicate: string) => (bySubject.get(id(node)) ?? []).filter((q) => q.predicate.value === predicate).map((q) => q.object);
|
|
53
|
+
const list = (head: Term): Term[] => {
|
|
54
|
+
const items: Term[] = [];
|
|
55
|
+
const seen = new Set<string>();
|
|
56
|
+
let cell: Term | undefined = head;
|
|
57
|
+
while (cell && cell.value !== RDF + 'nil' && !seen.has(id(cell))) {
|
|
58
|
+
seen.add(id(cell));
|
|
59
|
+
items.push(...objects(cell, RDF + 'first'));
|
|
60
|
+
cell = objects(cell, RDF + 'rest')[0];
|
|
61
|
+
}
|
|
62
|
+
return items;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
let inverse = false;
|
|
66
|
+
let recursive = false;
|
|
67
|
+
let valuesAsFocus = false;
|
|
68
|
+
/** How many hops a path goes. */
|
|
69
|
+
const pathLength = (path: Term): number => {
|
|
70
|
+
if (path.termType === 'NamedNode') return 1;
|
|
71
|
+
const inner = (predicate: string) => objects(path, predicate)[0];
|
|
72
|
+
const inv = inner(SH + 'inversePath');
|
|
73
|
+
if (inv) {
|
|
74
|
+
inverse = true;
|
|
75
|
+
return pathLength(inv);
|
|
76
|
+
}
|
|
77
|
+
const alternatives = inner(SH + 'alternativePath');
|
|
78
|
+
if (alternatives) return Math.max(0, ...list(alternatives).map(pathLength));
|
|
79
|
+
if (inner(SH + 'zeroOrMorePath') || inner(SH + 'oneOrMorePath')) return Infinity;
|
|
80
|
+
const optional = inner(SH + 'zeroOrOnePath');
|
|
81
|
+
if (optional) return pathLength(optional);
|
|
82
|
+
// A sequence: an RDF list of paths.
|
|
83
|
+
return list(path).reduce((sum, step) => sum + pathLength(step), 0);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const memo = new Map<string, number>();
|
|
87
|
+
const reach = (shape: Term, visiting: Set<string>): number => {
|
|
88
|
+
const key = id(shape);
|
|
89
|
+
const known = memo.get(key);
|
|
90
|
+
if (known !== undefined) return known;
|
|
91
|
+
if (visiting.has(key)) {
|
|
92
|
+
recursive = true;
|
|
93
|
+
return Infinity;
|
|
94
|
+
}
|
|
95
|
+
visiting.add(key);
|
|
96
|
+
const path = objects(shape, SH + 'path')[0];
|
|
97
|
+
const length = path ? pathLength(path) : 0;
|
|
98
|
+
if (path && objects(shape, SH + 'property').length > 0) valuesAsFocus = true;
|
|
99
|
+
let nested = 0;
|
|
100
|
+
for (const predicate of NESTED) for (const inner of objects(shape, predicate)) nested = Math.max(nested, reach(inner, visiting));
|
|
101
|
+
for (const predicate of NESTED_LISTS) {
|
|
102
|
+
for (const head of objects(shape, predicate)) for (const inner of list(head)) nested = Math.max(nested, reach(inner, visiting));
|
|
103
|
+
}
|
|
104
|
+
visiting.delete(key);
|
|
105
|
+
const result = length + nested;
|
|
106
|
+
memo.set(key, result);
|
|
107
|
+
return result;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
let hops = 0;
|
|
111
|
+
for (const quads of bySubject.values()) {
|
|
112
|
+
const isShape = quads.some(
|
|
113
|
+
(q) =>
|
|
114
|
+
q.predicate.value === SH + 'path' ||
|
|
115
|
+
q.predicate.value === SH + 'property' ||
|
|
116
|
+
(q.predicate.value === RDF + 'type' && (q.object.value === SH + 'NodeShape' || q.object.value === SH + 'PropertyShape')),
|
|
117
|
+
);
|
|
118
|
+
if (isShape) hops = Math.max(hops, reach(quads[0].subject, new Set()));
|
|
119
|
+
}
|
|
120
|
+
return { hops, inverse, recursive, valuesAsFocus };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The predicates whose triples a shapes graph can make SHACL read — every IRI it has as a value: a path's, each step
|
|
125
|
+
* of a path expression's, a target's (`sh:targetSubjectsOf`), a comparison's (`sh:equals`, `sh:lessThan`), among the
|
|
126
|
+
* classes and the rest it names — or `every` when a shape is closed (`sh:closed`), which reads whatever predicates its
|
|
127
|
+
* focus nodes have. A triple by any other predicate is read by no shape (the kernel's KD-21).
|
|
128
|
+
*/
|
|
129
|
+
export function predicatesRead(shapes: readonly Quad[]): ReadonlySet<string> | 'every' {
|
|
130
|
+
const named = new Set<string>();
|
|
131
|
+
for (const q of shapes) {
|
|
132
|
+
if (q.predicate.value === SH + 'closed' && q.object.value !== 'false' && q.object.value !== '0') return 'every';
|
|
133
|
+
if (q.object.termType === 'NamedNode') named.add(q.object.value);
|
|
134
|
+
}
|
|
135
|
+
return named;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function id(term: Term): string {
|
|
139
|
+
return term.termType === 'BlankNode' ? `_:${term.value}` : term.value;
|
|
140
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which shapes a user may switch off, and switching them off (KReq 6.4, KD-20).
|
|
3
|
+
*
|
|
4
|
+
* A shapes document gives rules and advice. Advice is what a shape reports as `sh:Warning` or `sh:Info`: a
|
|
5
|
+
* principle, a viewpoint's completeness. A rule is what it reports as `sh:Violation`, which a shape with no
|
|
6
|
+
* `sh:severity` does: a relationship the tables forbid, a malformed multiplicity. Only advice may be switched off,
|
|
7
|
+
* so that a model a consumer shows as conforming still is.
|
|
8
|
+
*
|
|
9
|
+
* A shape is switchable when it has a target — it runs on its own, not only from another shape — and it reports
|
|
10
|
+
* advice, and so does every property shape under it (`sh:property`, at any depth): SHACL does not hand a node
|
|
11
|
+
* shape's severity down, so a Warning node shape whose property shape names no severity reports Violations from
|
|
12
|
+
* it, and switching it off would hide them. A shape nested otherwise (`sh:node`, `sh:and`, `sh:or`, `sh:xone`,
|
|
13
|
+
* `sh:not`, `sh:qualifiedValueShape`) reports nothing of its own: the constraint that names it does, with its
|
|
14
|
+
* shape's severity.
|
|
15
|
+
*
|
|
16
|
+
* Switching off adds `sh:deactivated true` to the shapes handed to the validator — never to the store — which
|
|
17
|
+
* the SHACL library and the SPARQL-based constraints (`sparql-constraints.ts`) both honour.
|
|
18
|
+
*/
|
|
19
|
+
import { DataFactory } from 'n3';
|
|
20
|
+
import type { Quad, Term } from '@rdfjs/types';
|
|
21
|
+
import { NAMESPACES } from './namespaces.js';
|
|
22
|
+
|
|
23
|
+
const SH = NAMESPACES.sh;
|
|
24
|
+
const TARGETS = new Set([SH + 'targetClass', SH + 'targetNode', SH + 'targetSubjectsOf', SH + 'targetObjectsOf', SH + 'target']);
|
|
25
|
+
const ADVICE = new Map([
|
|
26
|
+
[SH + 'Warning', 'Warning'],
|
|
27
|
+
[SH + 'Info', 'Info'],
|
|
28
|
+
] as const);
|
|
29
|
+
const LABELS = [NAMESPACES.skos + 'prefLabel', NAMESPACES.rdfs + 'label', SH + 'name'];
|
|
30
|
+
const DEFINITIONS = [NAMESPACES.skos + 'definition', SH + 'description', NAMESPACES.rdfs + 'comment'];
|
|
31
|
+
|
|
32
|
+
/** A shape that gives advice, and may be switched off. */
|
|
33
|
+
export interface SwitchableShape {
|
|
34
|
+
iri: string;
|
|
35
|
+
/** Its `skos:prefLabel`, `rdfs:label` or `sh:name` (English first), else its IRI's local name in words. */
|
|
36
|
+
label: string;
|
|
37
|
+
severity: 'Warning' | 'Info';
|
|
38
|
+
/** Its `skos:definition`, `sh:description` or `rdfs:comment`, when it has one. */
|
|
39
|
+
definition?: string;
|
|
40
|
+
/**
|
|
41
|
+
* The messages its findings carry, as written (`sh:message`, English first, `{$this}` and `{?var}` unfilled): its
|
|
42
|
+
* own, its SPARQL-based constraints' and its property shapes', at any depth, each once. A finding is told by them.
|
|
43
|
+
*/
|
|
44
|
+
messages: string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A term's key: an IRI or a blank node, the two a shape may be. */
|
|
48
|
+
const key = (term: Term): string => `${term.termType === 'BlankNode' ? '_:' : ''}${term.value}`;
|
|
49
|
+
|
|
50
|
+
/** The shapes' statements by subject. */
|
|
51
|
+
function bySubject(quads: readonly Quad[]): Map<string, Quad[]> {
|
|
52
|
+
const index = new Map<string, Quad[]>();
|
|
53
|
+
for (const q of quads) {
|
|
54
|
+
if (q.subject.termType !== 'NamedNode' && q.subject.termType !== 'BlankNode') continue;
|
|
55
|
+
const k = key(q.subject);
|
|
56
|
+
const list = index.get(k);
|
|
57
|
+
if (list) list.push(q);
|
|
58
|
+
else index.set(k, [q]);
|
|
59
|
+
}
|
|
60
|
+
return index;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The text of the first of `predicates` that has one, English or untagged first. */
|
|
64
|
+
function text(statements: readonly Quad[], predicates: readonly string[]): string | undefined {
|
|
65
|
+
for (const predicate of predicates) {
|
|
66
|
+
const literals = statements.filter((q) => q.predicate.value === predicate && q.object.termType === 'Literal');
|
|
67
|
+
const preferred =
|
|
68
|
+
literals.find((q) => (q.object as { language?: string }).language === 'en') ??
|
|
69
|
+
literals.find((q) => !(q.object as { language?: string }).language) ??
|
|
70
|
+
literals[0];
|
|
71
|
+
if (preferred) return preferred.object.value.replace(/\s+/g, ' ').trim();
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The severity a shape reports with: `Warning` or `Info` when advice, else `undefined` (a Violation). */
|
|
77
|
+
function advice(statements: readonly Quad[]): 'Warning' | 'Info' | undefined {
|
|
78
|
+
const severity = statements.find((q) => q.predicate.value === SH + 'severity');
|
|
79
|
+
return severity ? ADVICE.get(severity.object.value as never) : undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Whether a shape and every property shape under it report advice. */
|
|
83
|
+
function onlyAdvice(index: Map<string, Quad[]>, shape: string, seen: Set<string>): boolean {
|
|
84
|
+
if (seen.has(shape)) return true;
|
|
85
|
+
seen.add(shape);
|
|
86
|
+
const statements = index.get(shape) ?? [];
|
|
87
|
+
if (!advice(statements)) return false;
|
|
88
|
+
return statements
|
|
89
|
+
.filter((q) => q.predicate.value === SH + 'property')
|
|
90
|
+
.every((q) => onlyAdvice(index, key(q.object), seen));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A name for a shape with no label, from its IRI's local name — after its last `#` or `/` — in words, without the
|
|
95
|
+
* `Shape` most end in: `ViewDeclaresViewpointShape` is "View Declares Viewpoint".
|
|
96
|
+
*/
|
|
97
|
+
function nameFromIri(iri: string): string {
|
|
98
|
+
const local = iri.slice(Math.max(iri.lastIndexOf('#'), iri.lastIndexOf('/')) + 1) || iri;
|
|
99
|
+
const words = local
|
|
100
|
+
.replace(/Shape$/, '')
|
|
101
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
102
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
|
|
103
|
+
.replace(/[_-]+/g, ' ')
|
|
104
|
+
.trim();
|
|
105
|
+
return words || local;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The messages of a shape, of its `sh:sparql` constraints and of its property shapes, at any depth. */
|
|
109
|
+
function messagesOf(index: Map<string, Quad[]>, shape: string, seen: Set<string>, out: string[]): string[] {
|
|
110
|
+
if (seen.has(shape)) return out;
|
|
111
|
+
seen.add(shape);
|
|
112
|
+
const statements = index.get(shape) ?? [];
|
|
113
|
+
const message = text(statements, [SH + 'message']);
|
|
114
|
+
if (message && !out.includes(message)) out.push(message);
|
|
115
|
+
for (const q of statements) {
|
|
116
|
+
if (q.predicate.value === SH + 'sparql' || q.predicate.value === SH + 'property') messagesOf(index, key(q.object), seen, out);
|
|
117
|
+
}
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The switchable shapes among `quads` — a shapes document's, or several — by label. */
|
|
122
|
+
export function switchableShapes(quads: readonly Quad[]): SwitchableShape[] {
|
|
123
|
+
const index = bySubject(quads);
|
|
124
|
+
const found: SwitchableShape[] = [];
|
|
125
|
+
for (const [subject, statements] of index) {
|
|
126
|
+
if (subject.startsWith('_:')) continue;
|
|
127
|
+
if (!statements.some((q) => TARGETS.has(q.predicate.value))) continue;
|
|
128
|
+
if (!onlyAdvice(index, subject, new Set())) continue;
|
|
129
|
+
const definition = text(statements, DEFINITIONS);
|
|
130
|
+
found.push({
|
|
131
|
+
iri: subject,
|
|
132
|
+
label: text(statements, LABELS) ?? nameFromIri(subject),
|
|
133
|
+
severity: advice(statements)!,
|
|
134
|
+
...(definition ? { definition } : {}),
|
|
135
|
+
messages: messagesOf(index, subject, new Set(), []),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return found.sort((a, b) => a.label.localeCompare(b.label) || a.iri.localeCompare(b.iri));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The shapes with those named in `off` switched off: `sh:deactivated true` added beside each, in its graph. A name
|
|
143
|
+
* that is no switchable shape among `shapes` — a rule, or a shape not loaded — is passed over. Returns `shapes`
|
|
144
|
+
* itself when nothing is switched off.
|
|
145
|
+
*/
|
|
146
|
+
export function switchShapesOff(shapes: readonly Quad[], off: Iterable<string>): Quad[] {
|
|
147
|
+
const wanted = new Set(off);
|
|
148
|
+
if (wanted.size === 0) return shapes as Quad[];
|
|
149
|
+
const switchable = new Set(switchableShapes(shapes).map((s) => s.iri));
|
|
150
|
+
const graphOf = new Map<string, Quad['graph']>();
|
|
151
|
+
for (const q of shapes) if (q.subject.termType === 'NamedNode' && !graphOf.has(q.subject.value)) graphOf.set(q.subject.value, q.graph);
|
|
152
|
+
const added: Quad[] = [];
|
|
153
|
+
for (const iri of wanted) {
|
|
154
|
+
if (!switchable.has(iri)) continue;
|
|
155
|
+
added.push(
|
|
156
|
+
DataFactory.quad(
|
|
157
|
+
DataFactory.namedNode(iri),
|
|
158
|
+
DataFactory.namedNode(SH + 'deactivated'),
|
|
159
|
+
DataFactory.literal('true', DataFactory.namedNode(NAMESPACES.xsd + 'boolean')),
|
|
160
|
+
graphOf.get(iri) as never,
|
|
161
|
+
) as unknown as Quad,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
return added.length > 0 ? [...shapes, ...added] : (shapes as Quad[]);
|
|
165
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which properties take one value per subject — or one per language — defined
|
|
3
|
+
* once for the two places that settle such values: the room
|
|
4
|
+
* (`collab/rdf-yjs-binding.ts`), which keeps one value when collaborators set two
|
|
5
|
+
* at once, and the three-way merge (`model-manager/model-merge.ts`), which
|
|
6
|
+
* reports a conflict when two versions set different ones.
|
|
7
|
+
*
|
|
8
|
+
* ## Where the rules come from
|
|
9
|
+
*
|
|
10
|
+
* - **Built in**: what a diagram and a relationship cannot have two of — bounds,
|
|
11
|
+
* point coordinates, a node's element, a link's relationship and ends, a
|
|
12
|
+
* diagram element's view, the cells of an `rdf:List` — and `skos:prefLabel`,
|
|
13
|
+
* one per language (SKOS's own rule). They hold whatever metamodel is loaded.
|
|
14
|
+
* - **`owl:FunctionalProperty`** in a loaded ontology: one value, for every
|
|
15
|
+
* subject — that is what the declaration means.
|
|
16
|
+
* - **`sh:maxCount 1`** on a property shape that a node shape with a target
|
|
17
|
+
* holds (`sh:property`), or that has a target itself: one value, for instances
|
|
18
|
+
* of the target classes and their subclasses only. Read as a rule for every
|
|
19
|
+
* subject, a shape for one class would make the room drop a second value that
|
|
20
|
+
* another class is allowed. Shapes nested in `sh:or`, `sh:xone`, `sh:and`,
|
|
21
|
+
* `sh:not` or `sh:node` are not read — their limit holds only when the branch
|
|
22
|
+
* is the one taken (core's model questions put `sh:maxCount 0` on
|
|
23
|
+
* `sh:construct` in an `sh:xone` branch) — nor is `sh:maxCount 0`, which says
|
|
24
|
+
* "none", not "one".
|
|
25
|
+
* - **`sh:uniqueLang true`**, read the same way: one value per language.
|
|
26
|
+
*
|
|
27
|
+
* A target is a `sh:targetClass`, or the shape itself when it is also a class (an
|
|
28
|
+
* implicit class target). A `sh:targetSubjectsOf` the property itself makes the
|
|
29
|
+
* rule hold for every subject — whatever has a value of it is a target — as
|
|
30
|
+
* core's `arch:inModel` shape does. Other `sh:targetSubjectsOf`, and
|
|
31
|
+
* `sh:targetNode` and `sh:targetObjectsOf`, are not read.
|
|
32
|
+
*
|
|
33
|
+
* Where several rules name a property, the stricter wins: one value overall
|
|
34
|
+
* over one per language.
|
|
35
|
+
*
|
|
36
|
+
* Three properties are settled rather than chosen: `dcterms:modified`, which
|
|
37
|
+
* la-gram stamps on a concept at every edit, and `prov:generatedAtTime` and
|
|
38
|
+
* `prov:endedAtTime`, the provenance of edits (Req 9.16). Two stamps made apart
|
|
39
|
+
* are no disagreement, so each takes the later of them (`latest`) — in the room
|
|
40
|
+
* as in the merge, which reports no conflict for them.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
import { DataFactory } from 'n3';
|
|
44
|
+
import type { NamedNode, Quad, Term } from '@rdfjs/types';
|
|
45
|
+
import { NAMESPACES } from './namespaces.js';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* How many values a property takes per subject: one; one per language; or one,
|
|
49
|
+
* the latest (`xsd:dateTime` values in one form, so the greatest is the latest).
|
|
50
|
+
*/
|
|
51
|
+
export type ValueLimit = 'one' | 'one-per-language' | 'latest';
|
|
52
|
+
|
|
53
|
+
/** Where the metamodel rules are read from: the metamodel graphs, not the model's. */
|
|
54
|
+
export interface QuadSource {
|
|
55
|
+
getQuads(subject?: NamedNode | null, predicate?: NamedNode | null, object?: NamedNode | null, graph?: NamedNode | null): Quad[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const VIS = NAMESPACES['arch-vis'];
|
|
59
|
+
const SH = NAMESPACES.sh;
|
|
60
|
+
const RDF_TYPE = NAMESPACES.rdf + 'type';
|
|
61
|
+
const SUBCLASS_OF = NAMESPACES.rdfs + 'subClassOf';
|
|
62
|
+
const CLASSES = new Set([NAMESPACES.rdfs + 'Class', NAMESPACES.owl + 'Class']);
|
|
63
|
+
|
|
64
|
+
/** The rules that hold whatever metamodel is loaded. */
|
|
65
|
+
export const BUILT_IN_LIMITS: ReadonlyMap<string, ValueLimit> = new Map<string, ValueLimit>([
|
|
66
|
+
...[
|
|
67
|
+
'bounds-x',
|
|
68
|
+
'bounds-y',
|
|
69
|
+
'bounds-w',
|
|
70
|
+
'bounds-h',
|
|
71
|
+
// A node's drawing order (core-vis 0.10): one, as its bounds are.
|
|
72
|
+
'zOrder',
|
|
73
|
+
'point-x',
|
|
74
|
+
'point-y',
|
|
75
|
+
'archElement',
|
|
76
|
+
'archRelationship',
|
|
77
|
+
'view',
|
|
78
|
+
'source',
|
|
79
|
+
'target',
|
|
80
|
+
'points',
|
|
81
|
+
].map((local): [string, ValueLimit] => [VIS + local, 'one']),
|
|
82
|
+
[NAMESPACES.rdf + 'first', 'one'],
|
|
83
|
+
[NAMESPACES.rdf + 'rest', 'one'],
|
|
84
|
+
[NAMESPACES.arch + 'source', 'one'],
|
|
85
|
+
[NAMESPACES.arch + 'target', 'one'],
|
|
86
|
+
[NAMESPACES.skos + 'prefLabel', 'one-per-language'],
|
|
87
|
+
[NAMESPACES.dcterms + 'modified', 'latest'],
|
|
88
|
+
// The provenance of edits (Req 9.16): when a concept was last changed, and when an editing activity ended.
|
|
89
|
+
[NAMESPACES.prov + 'generatedAtTime', 'latest'],
|
|
90
|
+
[NAMESPACES.prov + 'endedAtTime', 'latest'],
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
const nn = (iri: string) => DataFactory.namedNode(iri) as unknown as NamedNode;
|
|
94
|
+
|
|
95
|
+
/** The stricter of two limits; `latest` is one value too, and says how to settle it. */
|
|
96
|
+
function stricter(a: ValueLimit | undefined, b: ValueLimit | undefined): ValueLimit | undefined {
|
|
97
|
+
if (a === 'latest' || b === 'latest') return 'latest';
|
|
98
|
+
return a === 'one' || b === 'one' ? 'one' : (a ?? b);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** A literal's language, `''` for none and for anything that is not a literal. */
|
|
102
|
+
export function languageOf(term: Term): string {
|
|
103
|
+
return term.termType === 'Literal' ? ((term as { language?: string }).language ?? '').toLowerCase() : '';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Which properties take one value per subject, or one per language. */
|
|
107
|
+
export class SingleValued {
|
|
108
|
+
private static builtInRules?: SingleValued;
|
|
109
|
+
|
|
110
|
+
private constructor(
|
|
111
|
+
/** Limits for every subject. */
|
|
112
|
+
private readonly everywhere: ReadonlyMap<string, ValueLimit>,
|
|
113
|
+
/** Limits for instances of a class: property → class → limit. */
|
|
114
|
+
private readonly byClass: ReadonlyMap<string, ReadonlyMap<string, ValueLimit>>,
|
|
115
|
+
/** Direct superclasses of a class. */
|
|
116
|
+
private readonly parents: ReadonlyMap<string, readonly string[]>,
|
|
117
|
+
) {}
|
|
118
|
+
|
|
119
|
+
/** Only the built-in rules. */
|
|
120
|
+
static builtIn(): SingleValued {
|
|
121
|
+
SingleValued.builtInRules ??= new SingleValued(BUILT_IN_LIMITS, new Map(), new Map());
|
|
122
|
+
return SingleValued.builtInRules;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The built-in rules and those of the metamodels `source` holds. Give it the
|
|
127
|
+
* metamodel graphs only: the model's own quads are not rules.
|
|
128
|
+
*/
|
|
129
|
+
static from(source: QuadSource): SingleValued {
|
|
130
|
+
const everywhere = new Map(BUILT_IN_LIMITS);
|
|
131
|
+
for (const q of source.getQuads(null, nn(RDF_TYPE), nn(NAMESPACES.owl + 'FunctionalProperty'))) {
|
|
132
|
+
if (q.subject.termType === 'NamedNode') everywhere.set(q.subject.value, stricter(everywhere.get(q.subject.value), 'one') as ValueLimit);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Property shapes with a limit, by the term that names them (a blank node, mostly).
|
|
136
|
+
const limited = new Map<string, { shape: Term; limit: ValueLimit }>();
|
|
137
|
+
const note = (shape: Term, limit: ValueLimit) => {
|
|
138
|
+
const key = `${shape.termType}:${shape.value}`;
|
|
139
|
+
limited.set(key, { shape, limit: stricter(limited.get(key)?.limit, limit) as ValueLimit });
|
|
140
|
+
};
|
|
141
|
+
for (const q of source.getQuads(null, nn(SH + 'maxCount'), null)) {
|
|
142
|
+
if (q.object.termType === 'Literal' && Number(q.object.value) === 1) note(q.subject, 'one');
|
|
143
|
+
}
|
|
144
|
+
for (const q of source.getQuads(null, nn(SH + 'uniqueLang'), null)) {
|
|
145
|
+
if (q.object.termType === 'Literal' && q.object.value === 'true') note(q.subject, 'one-per-language');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const objects = (subject: Term, predicate: string) => source.getQuads(subject as NamedNode, nn(predicate)).map((q) => q.object);
|
|
149
|
+
const targetsOf = (shape: Term): string[] => {
|
|
150
|
+
const classes = objects(shape, SH + 'targetClass')
|
|
151
|
+
.filter((o) => o.termType === 'NamedNode')
|
|
152
|
+
.map((o) => o.value);
|
|
153
|
+
if (shape.termType === 'NamedNode' && objects(shape, RDF_TYPE).some((o) => CLASSES.has(o.value))) classes.push(shape.value);
|
|
154
|
+
return classes;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const byClass = new Map<string, Map<string, ValueLimit>>();
|
|
158
|
+
for (const { shape, limit } of limited.values()) {
|
|
159
|
+
const path = objects(shape, SH + 'path')[0];
|
|
160
|
+
if (path?.termType !== 'NamedNode') continue;
|
|
161
|
+
const holders = [shape, ...source.getQuads(null, nn(SH + 'property'), shape as NamedNode).map((q) => q.subject)];
|
|
162
|
+
if (holders.some((h) => objects(h, SH + 'targetSubjectsOf').some((o) => o.value === path.value))) {
|
|
163
|
+
everywhere.set(path.value, stricter(everywhere.get(path.value), limit) as ValueLimit);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const classes = holders.flatMap(targetsOf);
|
|
167
|
+
if (classes.length === 0) continue;
|
|
168
|
+
const forPath = byClass.get(path.value) ?? new Map<string, ValueLimit>();
|
|
169
|
+
for (const cls of classes) forPath.set(cls, stricter(forPath.get(cls), limit) as ValueLimit);
|
|
170
|
+
byClass.set(path.value, forPath);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const parents = new Map<string, string[]>();
|
|
174
|
+
if (byClass.size > 0) {
|
|
175
|
+
for (const q of source.getQuads(null, nn(SUBCLASS_OF), null)) {
|
|
176
|
+
if (q.subject.termType !== 'NamedNode' || q.object.termType !== 'NamedNode') continue;
|
|
177
|
+
const list = parents.get(q.subject.value);
|
|
178
|
+
if (list) list.push(q.object.value);
|
|
179
|
+
else parents.set(q.subject.value, [q.object.value]);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return new SingleValued(everywhere, byClass, parents);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Whether some rule names the property: cheap, before a subject's types are looked up. */
|
|
186
|
+
mayLimit(predicate: string): boolean {
|
|
187
|
+
return this.everywhere.has(predicate) || this.byClass.has(predicate);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* How many values `predicate` takes on a subject of `types` (its asserted
|
|
192
|
+
* types; their superclasses are followed here), or `undefined` for any number.
|
|
193
|
+
* `types` is called only when a class-scoped rule names the property.
|
|
194
|
+
*/
|
|
195
|
+
limitOf(predicate: string, types: () => Iterable<string>): ValueLimit | undefined {
|
|
196
|
+
let limit = this.everywhere.get(predicate);
|
|
197
|
+
if (limit === 'one' || limit === 'latest') return limit;
|
|
198
|
+
const scoped = this.byClass.get(predicate);
|
|
199
|
+
if (!scoped) return limit;
|
|
200
|
+
for (const cls of this.closure(types())) {
|
|
201
|
+
limit = stricter(limit, scoped.get(cls));
|
|
202
|
+
if (limit === 'one' || limit === 'latest') return limit;
|
|
203
|
+
}
|
|
204
|
+
return limit;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The classes and every superclass of them. */
|
|
208
|
+
private closure(types: Iterable<string>): Set<string> {
|
|
209
|
+
const seen = new Set<string>();
|
|
210
|
+
const stack = [...types];
|
|
211
|
+
while (stack.length > 0) {
|
|
212
|
+
const cls = stack.pop() as string;
|
|
213
|
+
if (seen.has(cls)) continue;
|
|
214
|
+
seen.add(cls);
|
|
215
|
+
stack.push(...(this.parents.get(cls) ?? []));
|
|
216
|
+
}
|
|
217
|
+
return seen;
|
|
218
|
+
}
|
|
219
|
+
}
|