@linked.archi/kernel 0.0.0-stage → 0.1.6
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 +102 -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 +917 -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 +895 -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 +7406 -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 +851 -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 +475 -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/native-load.ts +37 -0
- package/src/rdf-engine/observable-store.ts +609 -0
- package/src/rdf-engine/rdf-store.ts +520 -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 +349 -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 +747 -0
- package/src/rdf-engine/validation-service.ts +186 -0
- package/src/rdf-engine/validation.worker.ts +47 -0
|
@@ -0,0 +1,787 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which properties to offer when adding one to a concept, and how to read
|
|
3
|
+
* what the modeller types instead.
|
|
4
|
+
*
|
|
5
|
+
* Offering every property the loaded vocabularies declare is too much, and
|
|
6
|
+
* mostly wrong: the core-vis ontology alone brings the diagram geometry
|
|
7
|
+
* (`bounds-x`, `point-y`) and the notation styling (`fillColor`), the core
|
|
8
|
+
* ontology brings the metamodel-authoring annotations (`unqualifiedForm`) and
|
|
9
|
+
* the deliverable-template machinery. The vocabularies say where each property
|
|
10
|
+
* applies (`rdfs:domain`), so the catalog uses that:
|
|
11
|
+
*
|
|
12
|
+
* | group | what |
|
|
13
|
+
* |-----------------|-------------------------------------------------------------|
|
|
14
|
+
* | `type` | properties whose domain — or a SHACL shape — covers the concept's type |
|
|
15
|
+
* | | (a link by `rdfs:domain` or `arch:domainIncludes` more particular than `arch:Element`) |
|
|
16
|
+
* | `model` | properties the model already uses (custom ones included) |
|
|
17
|
+
* | `documentation` | SKOS / Dublin Core / PROV documentation properties |
|
|
18
|
+
* | `more` | the rest that may apply: no declared domain |
|
|
19
|
+
*
|
|
20
|
+
* A link — an object property — that a loaded relationship class draws is not
|
|
21
|
+
* offered: its `arch:unqualifiedForm`, the inverse a vocabulary declares of one
|
|
22
|
+
* (`ap:taskOfActivity`, of the drawn `ap:hasTask`), and a qualified predicate,
|
|
23
|
+
* which leads to a relationship resource. Those are made on the canvas, where a
|
|
24
|
+
* link is a line with a resource behind it, not a value typed here. Nor is a link
|
|
25
|
+
* whose domain is any element (`arch:Element`, `arch:ModelConcept`, `owl:Thing`):
|
|
26
|
+
* core's are metamodel authoring and notation (`arch:templateResource`,
|
|
27
|
+
* `arch:prefVisNotation`), and the rest can be typed.
|
|
28
|
+
*
|
|
29
|
+
* An attribute — a datatype or annotation property — applies by `rdfs:domain`
|
|
30
|
+
* or by the classes its vocabulary says it is for (`arch:domainIncludes`):
|
|
31
|
+
* ArchiMate 4.0's `am4:sourceMultiplicity`, for its relationships. Of a property
|
|
32
|
+
* and a subproperty of it that both apply to the type, the subproperty alone is
|
|
33
|
+
* offered for it — the language's narrower term, not the core's
|
|
34
|
+
* `arch:sourceMultiplicity` — the broader one still under *Used in this model*
|
|
35
|
+
* when the model uses it (KD-19).
|
|
36
|
+
*
|
|
37
|
+
* A property whose domain is some other class is not offered — it does not
|
|
38
|
+
* apply — nor is one its vocabulary deprecates (`owl:deprecated true`, as
|
|
39
|
+
* ArchiMate's `accessType`, replaced by the kinds of access); both can still be
|
|
40
|
+
* typed. Anything can be typed: a CURIE with a known prefix is expanded, a full
|
|
41
|
+
* IRI is taken as it is, and anything else is the name of a custom property, as
|
|
42
|
+
* typed ({@link resolve}).
|
|
43
|
+
*
|
|
44
|
+
* A custom property is a name and a value no vocabulary declares, a
|
|
45
|
+
* `schema:PropertyValue` pair as the converters write one (`custom-properties.ts`,
|
|
46
|
+
* KD-12). The model's are offered by name under *Used in this model*: `iri` is
|
|
47
|
+
* `schema:additionalProperty` and `customName` the name, counted and with values
|
|
48
|
+
* as any other. The pairs' own `schema:name` and `schema:value` are not offered.
|
|
49
|
+
*
|
|
50
|
+
* Each suggestion also says how the model and the metamodel stand on it (KD-9):
|
|
51
|
+
* `usage`, how many of the model's concepts of the concept's type have it (the
|
|
52
|
+
* concept itself among them); `values`, what they have, the most used first, so
|
|
53
|
+
* that what a team fills in on every Application Component can be picked on the
|
|
54
|
+
* next one; and `required`, a SHACL shape for the type asks for at least one
|
|
55
|
+
* value (`sh:minCount`). Within a group, suggestions are sorted by the prefixed name
|
|
56
|
+
* they are shown with, then by name ({@link compareProperties}, KD-10).
|
|
57
|
+
*
|
|
58
|
+
* A value typed for a property no shape constrains takes the datatype its
|
|
59
|
+
* vocabulary declares as its range ({@link PropertyCatalog.datatypeOf}): core's
|
|
60
|
+
* `isAbstract` is an `xsd:boolean`.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
import { DataFactory, type Store as N3Store } from 'n3';
|
|
64
|
+
import type { NamedNode, Quad, Term } from '@rdfjs/types';
|
|
65
|
+
import type { PrefixMap, RdfStore } from '../rdf-engine/interfaces.js';
|
|
66
|
+
import { NAMESPACES } from '../rdf-engine/namespaces.js';
|
|
67
|
+
import type { TypeClosure } from './model-queries.js';
|
|
68
|
+
import { modelQuads } from './model-queries.js';
|
|
69
|
+
import { CUSTOM_PROPERTY, PAIR_NAME, PAIR_VALUE } from './custom-properties.js';
|
|
70
|
+
import { IRI, T, humanize, localName, nn, sentenceCase } from './vocabulary.js';
|
|
71
|
+
|
|
72
|
+
/** Where a suggestion is listed. */
|
|
73
|
+
export type PropertyGroup = 'type' | 'model' | 'documentation' | 'more';
|
|
74
|
+
|
|
75
|
+
/** A property offered for adding. */
|
|
76
|
+
export interface PropertySuggestion {
|
|
77
|
+
iri: string;
|
|
78
|
+
/** What the modeller reads: the vocabulary's label, or the local name in words. */
|
|
79
|
+
label: string;
|
|
80
|
+
/** The IRI as a prefixed name when a prefix covers it, else the IRI. */
|
|
81
|
+
curie: string;
|
|
82
|
+
group: PropertyGroup;
|
|
83
|
+
/** The group's heading (`For Business Actor`, `Used in this model`, …). */
|
|
84
|
+
groupLabel: string;
|
|
85
|
+
/** The vocabulary's definition, when it has one. */
|
|
86
|
+
description?: string;
|
|
87
|
+
/**
|
|
88
|
+
* How many of the model's concepts of this concept's type have the property:
|
|
89
|
+
* `count` of the `of` concepts of the type, this one included. Absent when none has.
|
|
90
|
+
*/
|
|
91
|
+
usage?: PropertyUsage;
|
|
92
|
+
/**
|
|
93
|
+
* The values the model's concepts of this concept's type have, the most used first, then by value; at most
|
|
94
|
+
* {@link MAX_PROPOSED_VALUES}. Given with `usage`, and absent as it is — but for a property from outside that no
|
|
95
|
+
* concept of the type has ({@link outside}), whose values are the model's concepts', counted over the model
|
|
96
|
+
* ({@link valuesInModel}).
|
|
97
|
+
*/
|
|
98
|
+
values?: ProposedValue[];
|
|
99
|
+
/** `values` are counted over the model's concepts, not the type's (KD-13): no concept of the type has the property. */
|
|
100
|
+
valuesInModel?: true;
|
|
101
|
+
/** A SHACL shape for the concept's type asks for at least one value (`sh:minCount` 1 or more). */
|
|
102
|
+
required?: true;
|
|
103
|
+
/** A custom property (KD-12): its name, as written. `iri` is then `schema:additionalProperty`. */
|
|
104
|
+
customName?: string;
|
|
105
|
+
/**
|
|
106
|
+
* Offered because the model uses it, from a vocabulary that is not loaded (KD-13): no loaded vocabulary declares it,
|
|
107
|
+
* it is not in the model's namespace, and it is no documentation property. Without a declared domain it may apply to
|
|
108
|
+
* any concept, so a consumer may suggest it for every type, not only where others of the type have it.
|
|
109
|
+
*/
|
|
110
|
+
outside?: true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** How many concepts of a type have a property (see {@link PropertySuggestion.usage}). */
|
|
114
|
+
export interface PropertyUsage {
|
|
115
|
+
count: number;
|
|
116
|
+
of: number;
|
|
117
|
+
/**
|
|
118
|
+
* The type counted over, by name, when it is not the concept's own (KD-14): a Microservice — a kind of Application
|
|
119
|
+
* Component — is counted among the Application Components.
|
|
120
|
+
*/
|
|
121
|
+
over?: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** A value the model's concepts of a type have for a property (see {@link PropertySuggestion.values}). */
|
|
125
|
+
export interface ProposedValue {
|
|
126
|
+
/** A literal's text, or an IRI. */
|
|
127
|
+
value: string;
|
|
128
|
+
/** The value is an IRI — a link — not text. */
|
|
129
|
+
isIri?: true;
|
|
130
|
+
/** A literal's datatype, when it is not a plain string (`xsd:string`) or text in a language. */
|
|
131
|
+
datatype?: string;
|
|
132
|
+
/** A literal's language. */
|
|
133
|
+
language?: string;
|
|
134
|
+
/** How many of the type's concepts have it. */
|
|
135
|
+
count: number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The most values a suggestion proposes: a property whose values are all different proposes few that help. */
|
|
139
|
+
export const MAX_PROPOSED_VALUES = 50;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* From how many concepts on, values no two of them share are not proposed (KD-16): each says what one concept is — a
|
|
143
|
+
* cost, an identifier, an address — and helps no one pick the next. Below it, a few values are proposed whatever they
|
|
144
|
+
* are.
|
|
145
|
+
*/
|
|
146
|
+
export const IDENTIFYING_VALUES = 5;
|
|
147
|
+
|
|
148
|
+
/** What {@link PropertyCatalog.resolve} makes of typed text. */
|
|
149
|
+
export interface ResolvedProperty {
|
|
150
|
+
iri: string;
|
|
151
|
+
curie: string;
|
|
152
|
+
label: string;
|
|
153
|
+
/** A custom property's name, as typed (KD-12); `iri` is then `schema:additionalProperty`. */
|
|
154
|
+
customName?: string;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Documentation properties, offered for anything. Not `skos:definition` — the
|
|
159
|
+
* panel always lists it under the name — nor `dcterms:description`, which says
|
|
160
|
+
* the same again.
|
|
161
|
+
*/
|
|
162
|
+
export const DOCUMENTATION_PROPERTIES = [
|
|
163
|
+
NAMESPACES.skos + 'altLabel',
|
|
164
|
+
NAMESPACES.skos + 'note',
|
|
165
|
+
NAMESPACES.skos + 'scopeNote',
|
|
166
|
+
NAMESPACES.skos + 'example',
|
|
167
|
+
NAMESPACES.dcterms + 'source',
|
|
168
|
+
NAMESPACES.dcterms + 'creator',
|
|
169
|
+
NAMESPACES.dcterms + 'created',
|
|
170
|
+
NAMESPACES.rdfs + 'comment',
|
|
171
|
+
NAMESPACES.rdfs + 'seeAlso',
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Never offered: what the tool writes itself (type, membership, the ends of a
|
|
176
|
+
* relationship, conformance, the model's namespace), the name and the
|
|
177
|
+
* definition (always listed in the panel), and the annotations that describe
|
|
178
|
+
* classes, not model concepts.
|
|
179
|
+
*/
|
|
180
|
+
const NOT_OFFERED = new Set([
|
|
181
|
+
IRI.rdfType,
|
|
182
|
+
IRI.prefLabel,
|
|
183
|
+
IRI.definition,
|
|
184
|
+
IRI.inModel,
|
|
185
|
+
IRI.inView,
|
|
186
|
+
IRI.source,
|
|
187
|
+
IRI.target,
|
|
188
|
+
IRI.modelConformsToMetamodel,
|
|
189
|
+
IRI.viewConformsToViewpoint,
|
|
190
|
+
IRI.dctermsModified,
|
|
191
|
+
IRI.unqualifiedForm,
|
|
192
|
+
NAMESPACES.arch + 'domainIncludes',
|
|
193
|
+
NAMESPACES.arch + 'rangeIncludes',
|
|
194
|
+
NAMESPACES.arch + 'isAbstractClass',
|
|
195
|
+
NAMESPACES.vann + 'preferredNamespacePrefix',
|
|
196
|
+
NAMESPACES.vann + 'preferredNamespaceUri',
|
|
197
|
+
]);
|
|
198
|
+
|
|
199
|
+
/** Documentation properties whose values are things — another concept, a page — rather than text. */
|
|
200
|
+
const LINKING_PROPERTIES = new Set([
|
|
201
|
+
NAMESPACES.rdfs + 'seeAlso',
|
|
202
|
+
NAMESPACES.prov + 'wasDerivedFrom',
|
|
203
|
+
NAMESPACES.dcterms + 'source',
|
|
204
|
+
NAMESPACES.dcterms + 'relation',
|
|
205
|
+
NAMESPACES.dcterms + 'references',
|
|
206
|
+
]);
|
|
207
|
+
|
|
208
|
+
/** Ranges that are text, not things. */
|
|
209
|
+
const LITERAL_RANGES = new Set([
|
|
210
|
+
NAMESPACES.rdfs + 'Literal',
|
|
211
|
+
NAMESPACES.rdf + 'langString',
|
|
212
|
+
NAMESPACES.rdf + 'HTML',
|
|
213
|
+
NAMESPACES.rdf + 'PlainLiteral',
|
|
214
|
+
]);
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Namespaces whose properties are never offered: diagram geometry and notation; and provenance, which la-gram
|
|
218
|
+
* and the converters record and the panel shows read-only (Req 9.16).
|
|
219
|
+
*/
|
|
220
|
+
const NOT_OFFERED_NAMESPACES = [NAMESPACES['arch-vis'], NAMESPACES.sh, NAMESPACES.owl, NAMESPACES.prov];
|
|
221
|
+
|
|
222
|
+
const GROUP_ORDER: PropertyGroup[] = ['type', 'model', 'documentation', 'more'];
|
|
223
|
+
|
|
224
|
+
/** What the catalog reads from its surroundings, current at each call. */
|
|
225
|
+
export interface PropertyCatalogContext {
|
|
226
|
+
/** Superclasses (and the class itself) of a class. */
|
|
227
|
+
closure: () => TypeClosure;
|
|
228
|
+
/** Prefixes for CURIEs, the model's own included. */
|
|
229
|
+
prefixes: () => PrefixMap;
|
|
230
|
+
/** Where a typed plain name is minted: the model's namespace. */
|
|
231
|
+
modelNamespace: () => string;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* What {@link PropertyCatalog.suggest} reads of the model whole (KD-22): which resources are the model, provenance
|
|
236
|
+
* records and custom property pairs, the pairs' owners and names, and how the model uses each property that may be
|
|
237
|
+
* offered. Read again after a change to the model, else kept.
|
|
238
|
+
*/
|
|
239
|
+
interface ModelFacts {
|
|
240
|
+
/** The model resources (`arch:Model`): what they say is the tool's metadata, no property to offer. */
|
|
241
|
+
models: Set<string>;
|
|
242
|
+
/** Provenance records — the edits, the tool and the user (`prov:Activity`, `prov:SoftwareAgent`, `prov:Person`). */
|
|
243
|
+
records: Set<string>;
|
|
244
|
+
/** Custom property pairs (KD-12), each linked to by `schema:additionalProperty`. */
|
|
245
|
+
pairs: Set<string>;
|
|
246
|
+
/** Each pair's concepts, the model resources left out. */
|
|
247
|
+
pairOwners: Map<string, string[]>;
|
|
248
|
+
/** Each pair's name, the first one it has, for the pairs a concept has. */
|
|
249
|
+
pairNames: Map<string, string>;
|
|
250
|
+
/** The types the model's resources have. */
|
|
251
|
+
types: string[];
|
|
252
|
+
/**
|
|
253
|
+
* How the model's concepts — not the model resources, the pairs or the records — use each property that may be
|
|
254
|
+
* offered: with text, with an IRI, with anything.
|
|
255
|
+
*/
|
|
256
|
+
uses: Map<string, { literal: boolean; iri: boolean; any: boolean }>;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** The model's triples by pattern, and what is in it. */
|
|
260
|
+
interface ModelReader {
|
|
261
|
+
quads(subject: Term | null, predicate: Term | null, object: Term | null): Iterable<Quad>;
|
|
262
|
+
predicates(): string[];
|
|
263
|
+
types(): string[];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** The catalog of properties for the add-property picker. */
|
|
267
|
+
export class PropertyCatalog {
|
|
268
|
+
/** What was read of the model whole, while it is current ({@link ModelFacts}). */
|
|
269
|
+
private facts: ModelFacts | null = null;
|
|
270
|
+
/** Whether the store tells of every write, so that what was read can be kept until one (KD-22). */
|
|
271
|
+
private readonly keepsFacts: boolean;
|
|
272
|
+
|
|
273
|
+
constructor(
|
|
274
|
+
private readonly store: RdfStore,
|
|
275
|
+
private readonly context: PropertyCatalogContext,
|
|
276
|
+
) {
|
|
277
|
+
const observed = store as RdfStore & { onEveryWrite?(listener: () => void): unknown };
|
|
278
|
+
this.keepsFacts = typeof observed.onEveryWrite === 'function';
|
|
279
|
+
if (this.keepsFacts) {
|
|
280
|
+
observed.onEveryWrite!(() => {
|
|
281
|
+
this.facts = null;
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** The properties to offer for a concept, grouped and sorted (see the module doc). */
|
|
287
|
+
suggest(subjectIri: string): PropertySuggestion[] {
|
|
288
|
+
const store = this.store;
|
|
289
|
+
const prefixes = this.context.prefixes();
|
|
290
|
+
const types = store
|
|
291
|
+
.getQuads(nn(subjectIri), T.rdfType)
|
|
292
|
+
.filter((q) => q.graph.termType === 'DefaultGraph')
|
|
293
|
+
.map((q) => q.object.value);
|
|
294
|
+
const closure = this.context.closure();
|
|
295
|
+
const applicable = new Set(types.flatMap((t) => closure(t)));
|
|
296
|
+
const typeLabel = types[0] ? this.labelOf(types[0]) : 'this concept';
|
|
297
|
+
|
|
298
|
+
const groupOf = new Map<string, PropertyGroup>();
|
|
299
|
+
const deprecated = (iri: string) =>
|
|
300
|
+
store.getQuads(nn(iri), nn(NAMESPACES.owl + 'deprecated')).some((q) => q.object.value === 'true');
|
|
301
|
+
const offer = (iri: string, group: PropertyGroup) => {
|
|
302
|
+
if (!offerable(iri) || deprecated(iri)) return;
|
|
303
|
+
const current = groupOf.get(iri);
|
|
304
|
+
if (!current || GROUP_ORDER.indexOf(group) < GROUP_ORDER.indexOf(current)) groupOf.set(iri, group);
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// Declared in a vocabulary: by domain.
|
|
308
|
+
const objectProperties = new Set(
|
|
309
|
+
store.getQuads(null, T.rdfType, nn(NAMESPACES.owl + 'ObjectProperty')).map((q) => q.subject.value),
|
|
310
|
+
);
|
|
311
|
+
// Links: by domain too, except what a relationship class draws (see the module doc).
|
|
312
|
+
const drawn = new Set<string>();
|
|
313
|
+
for (const q of store.getQuads(null, T.unqualifiedForm, null)) {
|
|
314
|
+
drawn.add(q.object.value);
|
|
315
|
+
// The qualified predicate names the form too: it leads to the resource.
|
|
316
|
+
if (objectProperties.has(q.subject.value)) drawn.add(q.subject.value);
|
|
317
|
+
}
|
|
318
|
+
for (const q of store.getQuads(null, nn(NAMESPACES.owl + 'inverseOf'), null)) {
|
|
319
|
+
if (drawn.has(q.object.value)) drawn.add(q.subject.value);
|
|
320
|
+
else if (drawn.has(q.subject.value)) drawn.add(q.object.value);
|
|
321
|
+
}
|
|
322
|
+
const anyElement = new Set([IRI.Element, IRI.ModelConcept, NAMESPACES.owl + 'Thing']);
|
|
323
|
+
for (const iri of objectProperties) {
|
|
324
|
+
if (drawn.has(iri)) continue;
|
|
325
|
+
const domains = [
|
|
326
|
+
...store.getQuads(nn(iri), nn(NAMESPACES.rdfs + 'domain')),
|
|
327
|
+
...store.getQuads(nn(iri), nn(NAMESPACES.arch + 'domainIncludes')),
|
|
328
|
+
].map((d) => d.object.value);
|
|
329
|
+
if (domains.some((d) => applicable.has(d) && !anyElement.has(d))) offer(iri, 'type');
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Attributes: by domain, or by the classes a vocabulary says they are for (`arch:domainIncludes`, KD-19) — a
|
|
333
|
+
// language's own attributes say where they apply so, as ArchiMate 4.0's `am4:sourceMultiplicity` does.
|
|
334
|
+
for (const kind of ['DatatypeProperty', 'AnnotationProperty']) {
|
|
335
|
+
for (const q of store.getQuads(null, T.rdfType, nn(NAMESPACES.owl + kind))) {
|
|
336
|
+
if (q.subject.termType !== 'NamedNode' || q.graph.termType === 'DefaultGraph') continue;
|
|
337
|
+
const domains = [
|
|
338
|
+
...store.getQuads(q.subject as NamedNode, nn(NAMESPACES.rdfs + 'domain')),
|
|
339
|
+
...store.getQuads(q.subject as NamedNode, nn(NAMESPACES.arch + 'domainIncludes')),
|
|
340
|
+
].map((d) => d.object.value);
|
|
341
|
+
if (domains.length === 0) offer(q.subject.value, 'more');
|
|
342
|
+
else if (domains.some((d) => applicable.has(d))) offer(q.subject.value, 'type');
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Constrained by a shape for the type: the shape says it belongs here.
|
|
347
|
+
const required = new Set<string>();
|
|
348
|
+
for (const q of store.getQuads(null, nn(NAMESPACES.sh + 'targetClass'))) {
|
|
349
|
+
if (!applicable.has(q.object.value)) continue;
|
|
350
|
+
for (const link of store.getQuads(q.subject as NamedNode, nn(NAMESPACES.sh + 'property'))) {
|
|
351
|
+
// A shape that lists the values (`sh:in`) makes even a link an attribute —
|
|
352
|
+
// Backstage's bs:lifecycleState takes one of three named states.
|
|
353
|
+
const listed = store.getQuads(link.object as NamedNode, nn(NAMESPACES.sh + 'in')).length > 0;
|
|
354
|
+
const atLeastOne = store
|
|
355
|
+
.getQuads(link.object as NamedNode, nn(NAMESPACES.sh + 'minCount'))
|
|
356
|
+
.some((m) => Number(m.object.value) >= 1);
|
|
357
|
+
for (const path of store.getQuads(link.object as NamedNode, nn(NAMESPACES.sh + 'path'))) {
|
|
358
|
+
// A shape on a relationship predicate constrains a relationship, drawn on the canvas.
|
|
359
|
+
if (path.object.termType === 'NamedNode' && (listed || !objectProperties.has(path.object.value))) {
|
|
360
|
+
offer(path.object.value, 'type');
|
|
361
|
+
if (atLeastOne) required.add(path.object.value);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// The model's concepts of its kind, this one included: what they have is counted (KD-9, KD-14). Its kind is its
|
|
368
|
+
// type and the types above it a concept can be of — not an abstract grouping (`arch:isAbstractClass`) nor core's —
|
|
369
|
+
// and a concept of any of those, subtypes included, is of its kind.
|
|
370
|
+
const kind = new Set(types.flatMap((t) => closure(t).filter((c) => c === t || this.placeable(c))));
|
|
371
|
+
const model = modelReader(store);
|
|
372
|
+
const facts = this.modelFacts(model);
|
|
373
|
+
const { models, records, pairs, pairOwners, pairNames } = facts;
|
|
374
|
+
const peers = new Set<string>();
|
|
375
|
+
for (const type of facts.types) {
|
|
376
|
+
if (!closure(type).some((c) => kind.has(c))) continue;
|
|
377
|
+
for (const q of model.quads(null, T.rdfType, nn(type))) peers.add(q.subject.value);
|
|
378
|
+
}
|
|
379
|
+
// Named, when it is not the concept's own type: the broadest of its kind.
|
|
380
|
+
const broadest = [...kind].find((k) => ![...kind].some((other) => other !== k && closure(k).includes(other)));
|
|
381
|
+
const over = broadest && !types.includes(broadest) ? this.labelOf(broadest) : undefined;
|
|
382
|
+
// Who of them has each property offered, and their values, each with the concepts that have it.
|
|
383
|
+
const holders = new Map<string, Set<string>>();
|
|
384
|
+
const valuesOf = new Map<string, Map<string, { value: Omit<ProposedValue, 'count'>; subjects: Set<string> }>>();
|
|
385
|
+
|
|
386
|
+
// Used in this model: literal-valued properties, anything in the model's
|
|
387
|
+
// namespace, and a link by a property no loaded vocabulary declares — on its
|
|
388
|
+
// concepts, not on the model resource (the tool's metadata).
|
|
389
|
+
const namespace = this.context.modelNamespace();
|
|
390
|
+
const usedInModel = new Set<string>();
|
|
391
|
+
const undeclared = new Map<string, boolean>();
|
|
392
|
+
const external = (p: string) => {
|
|
393
|
+
let is = undeclared.get(p);
|
|
394
|
+
if (is === undefined) {
|
|
395
|
+
is = isExternalLink(store, p, drawn);
|
|
396
|
+
undeclared.set(p, is);
|
|
397
|
+
}
|
|
398
|
+
return is;
|
|
399
|
+
};
|
|
400
|
+
for (const [p, use] of facts.uses) {
|
|
401
|
+
if (use.literal || (use.any && p.startsWith(namespace)) || (use.iri && external(p))) {
|
|
402
|
+
offer(p, 'model');
|
|
403
|
+
usedInModel.add(p);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
for (const iri of DOCUMENTATION_PROPERTIES) offer(iri, 'documentation');
|
|
408
|
+
|
|
409
|
+
// The narrower term, for the type: a property offered for it that has a subproperty offered for it too is not —
|
|
410
|
+
// the core's `arch:sourceMultiplicity`, where ArchiMate's `am4:sourceMultiplicity` applies (KD-19). Used in the
|
|
411
|
+
// model, it is still offered there.
|
|
412
|
+
// Decided on the offers as they stand, so that a chain (core, language, a team's own) leaves only its narrowest.
|
|
413
|
+
const forType = new Set([...groupOf].filter(([, group]) => group === 'type').map(([iri]) => iri));
|
|
414
|
+
for (const iri of forType) {
|
|
415
|
+
const narrower = store
|
|
416
|
+
.getQuads(null, T.subPropertyOf, nn(iri))
|
|
417
|
+
.some((q) => q.subject.value !== iri && forType.has(q.subject.value));
|
|
418
|
+
if (!narrower) continue;
|
|
419
|
+
if (usedInModel.has(iri)) groupOf.set(iri, 'model');
|
|
420
|
+
else groupOf.delete(iri);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// What the concept's peers have of what is offered: read by property, not every statement of every peer (KD-22).
|
|
424
|
+
for (const p of groupOf.keys()) {
|
|
425
|
+
for (const q of model.quads(null, nn(p), null)) {
|
|
426
|
+
const peer = q.subject.value;
|
|
427
|
+
if (!peers.has(peer) || models.has(peer) || pairs.has(peer) || records.has(peer)) continue;
|
|
428
|
+
const subjects = holders.get(p);
|
|
429
|
+
if (subjects) subjects.add(peer);
|
|
430
|
+
else holders.set(p, new Set([peer]));
|
|
431
|
+
const value = proposedValue(q.object);
|
|
432
|
+
if (value) {
|
|
433
|
+
const key = valueKey(value);
|
|
434
|
+
const byValue = valuesOf.get(p) ?? new Map();
|
|
435
|
+
valuesOf.set(p, byValue);
|
|
436
|
+
const known = byValue.get(key);
|
|
437
|
+
if (known) known.subjects.add(peer);
|
|
438
|
+
else byValue.set(key, { value, subjects: new Set([peer]) });
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Custom properties by name: offered when any concept has one, counted and with values over the type's.
|
|
444
|
+
const customHolders = new Map<string, Set<string>>();
|
|
445
|
+
const customValues = new Map<string, Map<string, { value: Omit<ProposedValue, 'count'>; subjects: Set<string> }>>();
|
|
446
|
+
for (const [pair, owners] of pairOwners) {
|
|
447
|
+
const name = pairNames.get(pair);
|
|
448
|
+
if (!name) continue;
|
|
449
|
+
if (!customHolders.has(name)) customHolders.set(name, new Set());
|
|
450
|
+
for (const owner of owners) {
|
|
451
|
+
if (!peers.has(owner)) continue;
|
|
452
|
+
customHolders.get(name)!.add(owner);
|
|
453
|
+
for (const { object: term } of model.quads(nn(pair), nn(PAIR_VALUE), null)) {
|
|
454
|
+
const value = proposedValue(term);
|
|
455
|
+
if (!value) continue;
|
|
456
|
+
const key = valueKey(value);
|
|
457
|
+
const byValue = customValues.get(name) ?? new Map();
|
|
458
|
+
customValues.set(name, byValue);
|
|
459
|
+
const known = byValue.get(key);
|
|
460
|
+
if (known) known.subjects.add(owner);
|
|
461
|
+
else byValue.set(key, { value, subjects: new Set([owner]) });
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const heading: Record<PropertyGroup, string> = {
|
|
467
|
+
type: `For ${typeLabel}`,
|
|
468
|
+
model: 'Used in this model',
|
|
469
|
+
documentation: 'Documentation',
|
|
470
|
+
more: 'More',
|
|
471
|
+
};
|
|
472
|
+
const mostUsed = (byValue: Map<string, { value: Omit<ProposedValue, 'count'>; subjects: Set<string> }> | undefined) => {
|
|
473
|
+
const found = [...(byValue?.values() ?? [])];
|
|
474
|
+
// Each its own concept's, and enough of them to say so: none proposed (KD-16).
|
|
475
|
+
if (found.length >= IDENTIFYING_VALUES && found.every(({ subjects }) => subjects.size === 1)) return [];
|
|
476
|
+
return found
|
|
477
|
+
.map(({ value, subjects }): ProposedValue => ({ ...value, count: subjects.size }))
|
|
478
|
+
// The same text in two languages or types: by language, then type, however the model was read (KD-22).
|
|
479
|
+
.sort(
|
|
480
|
+
(a, b) =>
|
|
481
|
+
b.count - a.count ||
|
|
482
|
+
a.value.localeCompare(b.value) ||
|
|
483
|
+
(a.language ?? '').localeCompare(b.language ?? '') ||
|
|
484
|
+
(a.datatype ?? '').localeCompare(b.datatype ?? '') ||
|
|
485
|
+
Number(Boolean(a.isIri)) - Number(Boolean(b.isIri)),
|
|
486
|
+
)
|
|
487
|
+
.slice(0, MAX_PROPOSED_VALUES);
|
|
488
|
+
};
|
|
489
|
+
const customCurie = curieOf(CUSTOM_PROPERTY, prefixes);
|
|
490
|
+
const documentation = new Set([...DOCUMENTATION_PROPERTIES, ...LINKING_PROPERTIES]);
|
|
491
|
+
const outside = (iri: string, group: PropertyGroup) =>
|
|
492
|
+
group === 'model' && !iri.startsWith(namespace) && !documentation.has(iri) && isExternalLink(store, iri, drawn);
|
|
493
|
+
// A property from outside that no concept of the type has: what the model's concepts have, counted over the model.
|
|
494
|
+
const modelValues = (iri: string) => {
|
|
495
|
+
const byValue = new Map<string, { value: Omit<ProposedValue, 'count'>; subjects: Set<string> }>();
|
|
496
|
+
for (const q of model.quads(null, nn(iri), null)) {
|
|
497
|
+
const subject = q.subject.value;
|
|
498
|
+
if (models.has(subject) || pairs.has(subject) || records.has(subject)) continue;
|
|
499
|
+
const value = proposedValue(q.object);
|
|
500
|
+
if (!value) continue;
|
|
501
|
+
const known = byValue.get(valueKey(value));
|
|
502
|
+
if (known) known.subjects.add(subject);
|
|
503
|
+
else byValue.set(valueKey(value), { value, subjects: new Set([subject]) });
|
|
504
|
+
}
|
|
505
|
+
return mostUsed(byValue);
|
|
506
|
+
};
|
|
507
|
+
return [
|
|
508
|
+
...[...groupOf].map(([iri, group]): PropertySuggestion => {
|
|
509
|
+
const description = this.descriptionOf(iri);
|
|
510
|
+
const count = holders.get(iri)?.size ?? 0;
|
|
511
|
+
const isOutside = outside(iri, group);
|
|
512
|
+
const inModel = count === 0 && isOutside ? modelValues(iri) : [];
|
|
513
|
+
return {
|
|
514
|
+
iri,
|
|
515
|
+
label: this.labelOf(iri),
|
|
516
|
+
curie: curieOf(iri, prefixes),
|
|
517
|
+
group,
|
|
518
|
+
groupLabel: heading[group],
|
|
519
|
+
...(description ? { description } : {}),
|
|
520
|
+
...(count > 0
|
|
521
|
+
? { usage: { count, of: peers.size, ...(over ? { over } : {}) }, values: mostUsed(valuesOf.get(iri)) }
|
|
522
|
+
: inModel.length > 0
|
|
523
|
+
? { values: inModel, valuesInModel: true as const }
|
|
524
|
+
: {}),
|
|
525
|
+
...(required.has(iri) ? { required: true as const } : {}),
|
|
526
|
+
...(isOutside ? { outside: true as const } : {}),
|
|
527
|
+
};
|
|
528
|
+
}),
|
|
529
|
+
...[...customHolders].map(([name, subjects]): PropertySuggestion => ({
|
|
530
|
+
iri: CUSTOM_PROPERTY,
|
|
531
|
+
customName: name,
|
|
532
|
+
label: name,
|
|
533
|
+
curie: customCurie,
|
|
534
|
+
group: 'model',
|
|
535
|
+
groupLabel: heading.model,
|
|
536
|
+
description: 'A custom property: a name and a value that no vocabulary declares.',
|
|
537
|
+
...(subjects.size > 0
|
|
538
|
+
? { usage: { count: subjects.size, of: peers.size, ...(over ? { over } : {}) }, values: mostUsed(customValues.get(name)) }
|
|
539
|
+
: {}),
|
|
540
|
+
})),
|
|
541
|
+
].sort((a, b) => GROUP_ORDER.indexOf(a.group) - GROUP_ORDER.indexOf(b.group) || compareProperties(a, b));
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/** What is read of the model whole: kept until the store tells of a write, where it can (KD-22). */
|
|
545
|
+
private modelFacts(model: ModelReader): ModelFacts {
|
|
546
|
+
if (this.facts) return this.facts;
|
|
547
|
+
const subjectsOf = (type: string) => new Set([...model.quads(null, T.rdfType, nn(type))].map((q) => q.subject.value));
|
|
548
|
+
const types = model.types();
|
|
549
|
+
const models = subjectsOf(IRI.Model);
|
|
550
|
+
// Provenance records are no concepts: their statements (the tool's `schema:softwareVersion`) are not properties to
|
|
551
|
+
// offer.
|
|
552
|
+
const records = new Set(types.filter((t) => t.startsWith(NAMESPACES.prov)).flatMap((t) => [...subjectsOf(t)]));
|
|
553
|
+
// Custom properties (KD-12): each pair's concepts — not the model resource's — and its name.
|
|
554
|
+
const pairs = new Set<string>();
|
|
555
|
+
const pairOwners = new Map<string, string[]>();
|
|
556
|
+
for (const q of model.quads(null, nn(CUSTOM_PROPERTY), null)) {
|
|
557
|
+
if (q.object.termType !== 'NamedNode') continue;
|
|
558
|
+
pairs.add(q.object.value);
|
|
559
|
+
if (!models.has(q.subject.value)) pairOwners.set(q.object.value, [...(pairOwners.get(q.object.value) ?? []), q.subject.value]);
|
|
560
|
+
}
|
|
561
|
+
const pairNames = new Map<string, string>();
|
|
562
|
+
for (const q of model.quads(null, nn(PAIR_NAME), null)) {
|
|
563
|
+
if (pairOwners.has(q.subject.value) && !pairNames.has(q.subject.value)) pairNames.set(q.subject.value, q.object.value);
|
|
564
|
+
}
|
|
565
|
+
// How the concepts use each property that may be offered; a pair's own statements are what its custom property
|
|
566
|
+
// says, not properties to offer.
|
|
567
|
+
const uses = new Map<string, { literal: boolean; iri: boolean; any: boolean }>();
|
|
568
|
+
for (const p of model.predicates()) {
|
|
569
|
+
if (!offerable(p)) continue;
|
|
570
|
+
const use = { literal: false, iri: false, any: false };
|
|
571
|
+
for (const q of model.quads(null, nn(p), null)) {
|
|
572
|
+
const subject = q.subject.value;
|
|
573
|
+
if (models.has(subject) || pairs.has(subject) || records.has(subject)) continue;
|
|
574
|
+
use.any = true;
|
|
575
|
+
if (q.object.termType === 'Literal') use.literal = true;
|
|
576
|
+
else if (q.object.termType === 'NamedNode') use.iri = true;
|
|
577
|
+
if (use.literal && use.iri) break;
|
|
578
|
+
}
|
|
579
|
+
if (use.any) uses.set(p, use);
|
|
580
|
+
}
|
|
581
|
+
const facts: ModelFacts = { models, records, pairs, pairOwners, pairNames, types, uses };
|
|
582
|
+
if (this.keepsFacts) this.facts = facts;
|
|
583
|
+
return facts;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* A property from typed text: a CURIE with a known prefix (`dcterms:source`,
|
|
588
|
+
* `m:owner`) or an absolute IRI; anything else is the name of a custom
|
|
589
|
+
* property, as typed (`Cost center` — KD-12). `undefined` for nothing typed.
|
|
590
|
+
*/
|
|
591
|
+
resolve(text: string): ResolvedProperty | undefined {
|
|
592
|
+
const input = text.trim();
|
|
593
|
+
if (!input) return undefined;
|
|
594
|
+
const prefixes = this.context.prefixes();
|
|
595
|
+
let iri: string | undefined;
|
|
596
|
+
const curie = /^([A-Za-z][\w.-]*)?:([\w.-]*)$/.exec(input);
|
|
597
|
+
if (curie && (curie[1] ?? '') in prefixes && curie[2]) iri = prefixes[curie[1] ?? ''] + curie[2];
|
|
598
|
+
else if (/^[A-Za-z][A-Za-z0-9+.-]*:\/\/\S+$/.test(input) || /^urn:\S+:\S+$/i.test(input)) iri = input;
|
|
599
|
+
if (iri) return { iri, curie: curieOf(iri, prefixes), label: this.labelOf(iri) };
|
|
600
|
+
return { iri: CUSTOM_PROPERTY, curie: curieOf(CUSTOM_PROPERTY, prefixes), label: input, customName: input };
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* A property from typed text, for a custom property made one (KReq 4.12, KD-15): a CURIE with a known prefix or an
|
|
605
|
+
* absolute IRI, as {@link resolve} reads them; a plain name — letters, digits, `_`, `-` and spaces, from a letter — a
|
|
606
|
+
* property in the model's namespace, its words run together (`Cost center` → `m:costCenter`). `undefined` for
|
|
607
|
+
* anything else (`Cost (EUR)`), and for nothing typed.
|
|
608
|
+
*/
|
|
609
|
+
resolveProperty(text: string): ResolvedProperty | undefined {
|
|
610
|
+
const resolved = this.resolve(text);
|
|
611
|
+
if (!resolved || resolved.customName === undefined) return resolved;
|
|
612
|
+
const input = text.trim();
|
|
613
|
+
if (!/^[A-Za-z][\w -]*$/.test(input)) return undefined;
|
|
614
|
+
const iri = this.context.modelNamespace() + camelCase(input);
|
|
615
|
+
return { iri, curie: curieOf(iri, this.context.prefixes()), label: this.labelOf(iri) };
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Whether a property's values are resources rather than text: one of the
|
|
620
|
+
* documentation properties that point at things ({@link LINKING_PROPERTIES}),
|
|
621
|
+
* an object property, or one whose range is a class rather than a datatype.
|
|
622
|
+
*/
|
|
623
|
+
takesLinks(iri: string): boolean {
|
|
624
|
+
if (LINKING_PROPERTIES.has(iri)) return true;
|
|
625
|
+
const subject = nn(iri);
|
|
626
|
+
if (this.store.getQuads(subject, T.rdfType, nn(NAMESPACES.owl + 'ObjectProperty')).length > 0) return true;
|
|
627
|
+
// A property no loaded vocabulary declares is a link where the model links by it (`schema:about`, an address).
|
|
628
|
+
if (iri !== CUSTOM_PROPERTY && !declared(this.store, iri)) {
|
|
629
|
+
const values = this.store.getQuads(null, subject, null).filter((q) => q.graph.termType === 'DefaultGraph');
|
|
630
|
+
return values.length > 0 && values.every((q) => q.object.termType === 'NamedNode');
|
|
631
|
+
}
|
|
632
|
+
return this.store
|
|
633
|
+
.getQuads(subject, nn(NAMESPACES.rdfs + 'range'))
|
|
634
|
+
.some((q) => q.object.termType === 'NamedNode' && !LITERAL_RANGES.has(q.object.value) && !q.object.value.startsWith(NAMESPACES.xsd));
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* The datatype a property's vocabulary declares as its range (`rdfs:range xsd:boolean`), for a value typed where
|
|
639
|
+
* no shape says: `undefined` when the range is text in general (`rdfs:Literal`), a class, or not declared.
|
|
640
|
+
*/
|
|
641
|
+
datatypeOf(iri: string): string | undefined {
|
|
642
|
+
return this.store
|
|
643
|
+
.getQuads(nn(iri), nn(NAMESPACES.rdfs + 'range'))
|
|
644
|
+
.find((q) => q.object.termType === 'NamedNode' && q.object.value.startsWith(NAMESPACES.xsd))?.object.value;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/** A property's IRI as it is shown: `prefix:local` when one of the prefixes covers it, else whole ({@link curieOf}). */
|
|
648
|
+
curie(iri: string): string {
|
|
649
|
+
return curieOf(iri, this.context.prefixes());
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Whether a concept can be of `type` itself, so that it is a kind to count by (KD-14): not an abstract grouping
|
|
654
|
+
* (`arch:isAbstractClass true`: ArchiMate's Application Domain Element), and not core's, OWL's or RDFS's.
|
|
655
|
+
*/
|
|
656
|
+
private placeable(type: string): boolean {
|
|
657
|
+
if ([NAMESPACES.arch, NAMESPACES.owl, NAMESPACES.rdfs].some((ns) => type.startsWith(ns))) return false;
|
|
658
|
+
return !this.store.getQuads(nn(type), nn(NAMESPACES.arch + 'isAbstractClass')).some((q) => q.object.value === 'true');
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/** The vocabulary's label for a property, else its local name in words. */
|
|
662
|
+
labelOf(iri: string): string {
|
|
663
|
+
const subject = nn(iri);
|
|
664
|
+
for (const predicate of [T.rdfsLabel, T.prefLabel]) {
|
|
665
|
+
const labels = this.store.getQuads(subject, predicate).map((q) => q.object as { value: string; language?: string });
|
|
666
|
+
const label = labels.find((l) => l.language === 'en') ?? labels.find((l) => !l.language) ?? labels[0];
|
|
667
|
+
// A label that is just the local name again (`decorSymbol`) reads no better than the name.
|
|
668
|
+
if (label && label.value !== localName(iri)) return label.value;
|
|
669
|
+
}
|
|
670
|
+
return sentenceCase(humanize(localName(iri)));
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
private descriptionOf(iri: string): string | undefined {
|
|
674
|
+
const subject = nn(iri);
|
|
675
|
+
for (const predicate of [T.definition, nn(NAMESPACES.rdfs + 'comment')]) {
|
|
676
|
+
const text = this.store.getQuads(subject, predicate)[0]?.object.value.trim();
|
|
677
|
+
if (text) return text;
|
|
678
|
+
}
|
|
679
|
+
return undefined;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* The model's triples by pattern (KD-22): from the copy of the model the store keeps, where it keeps one
|
|
685
|
+
* (`ObservableRdfStore.modelGraph`), read in place; else from the store's default graph.
|
|
686
|
+
*/
|
|
687
|
+
function modelReader(store: RdfStore): ModelReader {
|
|
688
|
+
const copy = (store as RdfStore & { modelGraph?(): N3Store }).modelGraph?.();
|
|
689
|
+
if (copy) {
|
|
690
|
+
const graph = DataFactory.defaultGraph();
|
|
691
|
+
return {
|
|
692
|
+
quads: (s, p, o) => copy.getQuads(s as never, p as never, o as never, graph) as unknown as Quad[],
|
|
693
|
+
predicates: () => copy.getPredicates(null, null, graph).map((t) => t.value),
|
|
694
|
+
types: () => copy.getObjects(null, T.rdfType as never, graph).filter((t) => t.termType === 'NamedNode').map((t) => t.value),
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
const graph = DataFactory.defaultGraph() as unknown as NamedNode;
|
|
698
|
+
return {
|
|
699
|
+
quads: (s, p, o) => store.getQuads(s as NamedNode | null, p as NamedNode | null, o as NamedNode | null, graph),
|
|
700
|
+
predicates: () => [...new Set(modelQuads(store).map((q) => q.predicate.value))],
|
|
701
|
+
types: () => [
|
|
702
|
+
...new Set(
|
|
703
|
+
store
|
|
704
|
+
.getQuads(null, T.rdfType, null, graph)
|
|
705
|
+
.filter((q) => q.object.termType === 'NamedNode')
|
|
706
|
+
.map((q) => q.object.value),
|
|
707
|
+
),
|
|
708
|
+
],
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Whether `p` is a property from outside the loaded vocabularies — `schema:about`, typed as an IRI — which the model's
|
|
714
|
+
* use of it offers again, with a link as its value as with text (KD-13). A loaded vocabulary's link is offered by its
|
|
715
|
+
* domain instead; one a relationship class draws is drawn on the canvas, and a custom property's link to its pair, or
|
|
716
|
+
* RDF's own (a list's cells), is no property to add.
|
|
717
|
+
*/
|
|
718
|
+
function isExternalLink(store: RdfStore, p: string, drawn: ReadonlySet<string>): boolean {
|
|
719
|
+
if (p === CUSTOM_PROPERTY || p.startsWith(NAMESPACES.rdf) || drawn.has(p)) return false;
|
|
720
|
+
return !declared(store, p);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/** Whether a loaded vocabulary — a named graph — says anything of `p`. */
|
|
724
|
+
function declared(store: RdfStore, p: string): boolean {
|
|
725
|
+
return store.getQuads(nn(p), null, null).some((q) => q.graph.termType !== 'DefaultGraph');
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/** Whether a property may be offered at all. */
|
|
729
|
+
function offerable(iri: string): boolean {
|
|
730
|
+
return !NOT_OFFERED.has(iri) && !NOT_OFFERED_NAMESPACES.some((ns) => iri.startsWith(ns));
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/** A value's identity among those proposed: whether it is an IRI, its datatype, its language and its text. */
|
|
734
|
+
function valueKey(value: Omit<ProposedValue, 'count'>): string {
|
|
735
|
+
return `${value.isIri ? '<' : '"'}${value.datatype ?? ''}@${value.language ?? ''} ${value.value}`;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/** A value proposed as it is written: a literal or an IRI; nothing else is model data. */
|
|
739
|
+
function proposedValue(term: Term): Omit<ProposedValue, 'count'> | undefined {
|
|
740
|
+
if (term.termType === 'NamedNode') return { value: term.value, isIri: true };
|
|
741
|
+
if (term.termType !== 'Literal') return undefined;
|
|
742
|
+
const language = term.language || undefined;
|
|
743
|
+
const datatype = !language && term.datatype.value !== NAMESPACES.xsd + 'string' ? term.datatype.value : undefined;
|
|
744
|
+
return { value: term.value, ...(datatype ? { datatype } : {}), ...(language ? { language } : {}) };
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* `Cost center` → `costCenter`: the words run together, each after the first from a capital, the first from a small
|
|
749
|
+
* letter unless it is an acronym (`SLA tier` → `SLATier`).
|
|
750
|
+
*/
|
|
751
|
+
function camelCase(words: string): string {
|
|
752
|
+
const [first = '', ...rest] = words.trim().split(/\s+/);
|
|
753
|
+
const head = /^[A-Z]{2}/.test(first) ? first : first.charAt(0).toLowerCase() + first.slice(1);
|
|
754
|
+
return head + rest.map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join('');
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/** A property as it is shown: its IRI, that IRI prefixed when a prefix covers it (`curie`), and its name. */
|
|
758
|
+
export interface ShownProperty {
|
|
759
|
+
iri: string;
|
|
760
|
+
curie: string;
|
|
761
|
+
label: string;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* The order of properties by what identifies them as shown (KD-10): by prefixed name, as text (`ad:hasDecisionGoal`
|
|
766
|
+
* before `ad:justification`, whatever their names), those no prefix covers after them by their IRI; then by name —
|
|
767
|
+
* the custom properties, which all are `schema:additionalProperty`, by theirs; then by IRI.
|
|
768
|
+
*/
|
|
769
|
+
export function compareProperties(a: ShownProperty, b: ShownProperty): number {
|
|
770
|
+
const whole = (p: ShownProperty) => (p.curie === p.iri ? 1 : 0);
|
|
771
|
+
return whole(a) - whole(b) || a.curie.localeCompare(b.curie) || a.label.localeCompare(b.label) || a.iri.localeCompare(b.iri);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/** The IRI as `prefix:local` when a prefix covers it with a local name Turtle can write. */
|
|
775
|
+
export function curieOf(iri: string, prefixes: PrefixMap): string {
|
|
776
|
+
let best: string | undefined;
|
|
777
|
+
let bestLength = 0;
|
|
778
|
+
for (const [prefix, namespace] of Object.entries(prefixes)) {
|
|
779
|
+
if (!iri.startsWith(namespace) || namespace.length <= bestLength) continue;
|
|
780
|
+
const local = iri.slice(namespace.length);
|
|
781
|
+
if (/^[\w-]*$/.test(local)) {
|
|
782
|
+
best = `${prefix}:${local}`;
|
|
783
|
+
bestLength = namespace.length;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
return best ?? iri;
|
|
787
|
+
}
|