@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.
Files changed (365) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +11 -0
  3. package/README.md +96 -2
  4. package/assets/arch-decision/arch-decision-metamodel.ttl +44 -0
  5. package/assets/arch-decision/arch-decision-onto.ttl +1566 -0
  6. package/assets/arch-decision/arch-decision-shapes.ttl +582 -0
  7. package/assets/arch-decision/arch-decision-tax.ttl +129 -0
  8. package/assets/arch-processes/arch-processes-metamodel.ttl +42 -0
  9. package/assets/arch-processes/arch-processes-tax.ttl +136 -0
  10. package/assets/arch-processes/archProcesses-shapes.ttl +189 -0
  11. package/assets/arch-processes/archProcesses.ttl +953 -0
  12. package/assets/archimate3/archimate3.2-element-shapes.ttl +379 -0
  13. package/assets/archimate3/archimate3.2-metamodel.ttl +205 -0
  14. package/assets/archimate3/archimate3.2-notation.ttl +1503 -0
  15. package/assets/archimate3/archimate3.2-onto.ttl +1579 -0
  16. package/assets/archimate3/archimate3.2-presentation-contexts.ttl +90 -0
  17. package/assets/archimate3/archimate3.2-principle-shapes.ttl +923 -0
  18. package/assets/archimate3/archimate3.2-questions.ttl +1125 -0
  19. package/assets/archimate3/archimate3.2-reference-data.ttl +74 -0
  20. package/assets/archimate3/archimate3.2-relationship-shapes.ttl +30956 -0
  21. package/assets/archimate3/archimate3.2-relationship-tables.ttl +5992 -0
  22. package/assets/archimate3/archimate3.2-tax.ttl +724 -0
  23. package/assets/archimate3/archimate3.2-viewpoint-shapes.ttl +59 -0
  24. package/assets/archimate3/archimate3.2-viewpoints.ttl +793 -0
  25. package/assets/archimate3/icons/and-junction.svg +3 -0
  26. package/assets/archimate3/icons/application-collaboration.svg +22 -0
  27. package/assets/archimate3/icons/application-component.svg +18 -0
  28. package/assets/archimate3/icons/application-event.svg +15 -0
  29. package/assets/archimate3/icons/application-function.svg +14 -0
  30. package/assets/archimate3/icons/application-interaction.svg +17 -0
  31. package/assets/archimate3/icons/application-interface.svg +16 -0
  32. package/assets/archimate3/icons/application-process.svg +14 -0
  33. package/assets/archimate3/icons/application-service.svg +14 -0
  34. package/assets/archimate3/icons/artifact.svg +16 -0
  35. package/assets/archimate3/icons/assessment.svg +17 -0
  36. package/assets/archimate3/icons/business-actor.svg +22 -0
  37. package/assets/archimate3/icons/business-collaboration.svg +21 -0
  38. package/assets/archimate3/icons/business-event.svg +15 -0
  39. package/assets/archimate3/icons/business-function.svg +14 -0
  40. package/assets/archimate3/icons/business-interaction.svg +18 -0
  41. package/assets/archimate3/icons/business-interface.svg +16 -0
  42. package/assets/archimate3/icons/business-object.svg +14 -0
  43. package/assets/archimate3/icons/business-process.svg +15 -0
  44. package/assets/archimate3/icons/business-role.svg +16 -0
  45. package/assets/archimate3/icons/business-service.svg +14 -0
  46. package/assets/archimate3/icons/capability.svg +40 -0
  47. package/assets/archimate3/icons/communication-network.svg +18 -0
  48. package/assets/archimate3/icons/constraint.svg +18 -0
  49. package/assets/archimate3/icons/contract.svg +13 -0
  50. package/assets/archimate3/icons/course-of-action.svg +20 -0
  51. package/assets/archimate3/icons/data-object.svg +14 -0
  52. package/assets/archimate3/icons/deliverable.svg +11 -0
  53. package/assets/archimate3/icons/device.svg +18 -0
  54. package/assets/archimate3/icons/distribution-network.svg +19 -0
  55. package/assets/archimate3/icons/driver.svg +24 -0
  56. package/assets/archimate3/icons/equipment.svg +31 -0
  57. package/assets/archimate3/icons/facility.svg +16 -0
  58. package/assets/archimate3/icons/gap.svg +22 -0
  59. package/assets/archimate3/icons/glyphs/activity.svg +3 -0
  60. package/assets/archimate3/icons/glyphs/actor.svg +14 -0
  61. package/assets/archimate3/icons/glyphs/application-component.svg +12 -0
  62. package/assets/archimate3/icons/glyphs/artifact.svg +9 -0
  63. package/assets/archimate3/icons/glyphs/assessment.svg +9 -0
  64. package/assets/archimate3/icons/glyphs/capability.svg +32 -0
  65. package/assets/archimate3/icons/glyphs/cloud-gear.svg +3 -0
  66. package/assets/archimate3/icons/glyphs/collaboration.svg +15 -0
  67. package/assets/archimate3/icons/glyphs/communication-network.svg +12 -0
  68. package/assets/archimate3/icons/glyphs/constraint.svg +10 -0
  69. package/assets/archimate3/icons/glyphs/contract.svg +5 -0
  70. package/assets/archimate3/icons/glyphs/course-of-action.svg +12 -0
  71. package/assets/archimate3/icons/glyphs/data-object.svg +4 -0
  72. package/assets/archimate3/icons/glyphs/deliverable.svg +3 -0
  73. package/assets/archimate3/icons/glyphs/device.svg +10 -0
  74. package/assets/archimate3/icons/glyphs/distribution-network.svg +11 -0
  75. package/assets/archimate3/icons/glyphs/driver.svg +16 -0
  76. package/assets/archimate3/icons/glyphs/equipment.svg +22 -0
  77. package/assets/archimate3/icons/glyphs/event.svg +6 -0
  78. package/assets/archimate3/icons/glyphs/facility.svg +7 -0
  79. package/assets/archimate3/icons/glyphs/function.svg +6 -0
  80. package/assets/archimate3/icons/glyphs/gap.svg +14 -0
  81. package/assets/archimate3/icons/glyphs/goal.svg +10 -0
  82. package/assets/archimate3/icons/glyphs/grouping.svg +4 -0
  83. package/assets/archimate3/icons/glyphs/interaction.svg +10 -0
  84. package/assets/archimate3/icons/glyphs/interface.svg +8 -0
  85. package/assets/archimate3/icons/glyphs/location.svg +6 -0
  86. package/assets/archimate3/icons/glyphs/material.svg +12 -0
  87. package/assets/archimate3/icons/glyphs/meaning.svg +3 -0
  88. package/assets/archimate3/icons/glyphs/node.svg +8 -0
  89. package/assets/archimate3/icons/glyphs/object.svg +4 -0
  90. package/assets/archimate3/icons/glyphs/outcome.svg +16 -0
  91. package/assets/archimate3/icons/glyphs/path.svg +10 -0
  92. package/assets/archimate3/icons/glyphs/person-silhouette.svg +3 -0
  93. package/assets/archimate3/icons/glyphs/plateau.svg +8 -0
  94. package/assets/archimate3/icons/glyphs/principle.svg +12 -0
  95. package/assets/archimate3/icons/glyphs/process.svg +6 -0
  96. package/assets/archimate3/icons/glyphs/product.svg +4 -0
  97. package/assets/archimate3/icons/glyphs/representation.svg +4 -0
  98. package/assets/archimate3/icons/glyphs/requirement.svg +6 -0
  99. package/assets/archimate3/icons/glyphs/resource.svg +14 -0
  100. package/assets/archimate3/icons/glyphs/role.svg +6 -0
  101. package/assets/archimate3/icons/glyphs/service.svg +6 -0
  102. package/assets/archimate3/icons/glyphs/stakeholder.svg +6 -0
  103. package/assets/archimate3/icons/glyphs/system-software.svg +14 -0
  104. package/assets/archimate3/icons/glyphs/value-stream.svg +3 -0
  105. package/assets/archimate3/icons/glyphs/value.svg +3 -0
  106. package/assets/archimate3/icons/glyphs/work-package.svg +4 -0
  107. package/assets/archimate3/icons/goal.svg +18 -0
  108. package/assets/archimate3/icons/grouping.svg +12 -0
  109. package/assets/archimate3/icons/implementation-event.svg +15 -0
  110. package/assets/archimate3/icons/location.svg +14 -0
  111. package/assets/archimate3/icons/material.svg +21 -0
  112. package/assets/archimate3/icons/meaning.svg +11 -0
  113. package/assets/archimate3/icons/node.svg +14 -0
  114. package/assets/archimate3/icons/or-junction.svg +3 -0
  115. package/assets/archimate3/icons/outcome.svg +25 -0
  116. package/assets/archimate3/icons/path.svg +18 -0
  117. package/assets/archimate3/icons/plateau.svg +16 -0
  118. package/assets/archimate3/icons/principle.svg +21 -0
  119. package/assets/archimate3/icons/product.svg +12 -0
  120. package/assets/archimate3/icons/representation.svg +12 -0
  121. package/assets/archimate3/icons/requirement.svg +14 -0
  122. package/assets/archimate3/icons/resource.svg +23 -0
  123. package/assets/archimate3/icons/stakeholder.svg +15 -0
  124. package/assets/archimate3/icons/system-software.svg +22 -0
  125. package/assets/archimate3/icons/technology-collaboration.svg +22 -0
  126. package/assets/archimate3/icons/technology-event.svg +15 -0
  127. package/assets/archimate3/icons/technology-function.svg +14 -0
  128. package/assets/archimate3/icons/technology-interaction.svg +18 -0
  129. package/assets/archimate3/icons/technology-interface.svg +16 -0
  130. package/assets/archimate3/icons/technology-process.svg +14 -0
  131. package/assets/archimate3/icons/technology-service.svg +14 -0
  132. package/assets/archimate3/icons/value-stream.svg +11 -0
  133. package/assets/archimate3/icons/value.svg +11 -0
  134. package/assets/archimate3/icons/work-package.svg +12 -0
  135. package/assets/archimate4/archimate4-element-shapes.ttl +404 -0
  136. package/assets/archimate4/archimate4-metamodel.ttl +179 -0
  137. package/assets/archimate4/archimate4-notation.ttl +1147 -0
  138. package/assets/archimate4/archimate4-onto.ttl +1559 -0
  139. package/assets/archimate4/archimate4-presentation-contexts.ttl +60 -0
  140. package/assets/archimate4/archimate4-principle-shapes.ttl +893 -0
  141. package/assets/archimate4/archimate4-questions.ttl +1224 -0
  142. package/assets/archimate4/archimate4-reference-data.ttl +56 -0
  143. package/assets/archimate4/archimate4-relationship-shapes.ttl +16920 -0
  144. package/assets/archimate4/archimate4-relationship-tables.ttl +3200 -0
  145. package/assets/archimate4/archimate4-tax.ttl +749 -0
  146. package/assets/archimate4/archimate4-viewpoint-shapes.ttl +55 -0
  147. package/assets/archimate4/archimate4-viewpoints.ttl +777 -0
  148. package/assets/archimate4/icons/and-junction.svg +3 -0
  149. package/assets/archimate4/icons/application-component.svg +18 -0
  150. package/assets/archimate4/icons/application-interface.svg +16 -0
  151. package/assets/archimate4/icons/artifact.svg +16 -0
  152. package/assets/archimate4/icons/assessment.svg +17 -0
  153. package/assets/archimate4/icons/business-actor.svg +22 -0
  154. package/assets/archimate4/icons/business-interface.svg +16 -0
  155. package/assets/archimate4/icons/business-object.svg +14 -0
  156. package/assets/archimate4/icons/capability.svg +40 -0
  157. package/assets/archimate4/icons/collaboration.svg +21 -0
  158. package/assets/archimate4/icons/communication-network.svg +18 -0
  159. package/assets/archimate4/icons/course-of-action.svg +20 -0
  160. package/assets/archimate4/icons/data-object.svg +14 -0
  161. package/assets/archimate4/icons/deliverable.svg +11 -0
  162. package/assets/archimate4/icons/device.svg +18 -0
  163. package/assets/archimate4/icons/distribution-network.svg +19 -0
  164. package/assets/archimate4/icons/driver.svg +24 -0
  165. package/assets/archimate4/icons/equipment.svg +31 -0
  166. package/assets/archimate4/icons/event.svg +15 -0
  167. package/assets/archimate4/icons/facility.svg +16 -0
  168. package/assets/archimate4/icons/function.svg +13 -0
  169. package/assets/archimate4/icons/glyphs/activity.svg +3 -0
  170. package/assets/archimate4/icons/glyphs/actor.svg +14 -0
  171. package/assets/archimate4/icons/glyphs/application-component.svg +12 -0
  172. package/assets/archimate4/icons/glyphs/artifact.svg +9 -0
  173. package/assets/archimate4/icons/glyphs/assessment.svg +9 -0
  174. package/assets/archimate4/icons/glyphs/capability.svg +32 -0
  175. package/assets/archimate4/icons/glyphs/cloud-gear.svg +3 -0
  176. package/assets/archimate4/icons/glyphs/collaboration.svg +15 -0
  177. package/assets/archimate4/icons/glyphs/communication-network.svg +12 -0
  178. package/assets/archimate4/icons/glyphs/constraint.svg +10 -0
  179. package/assets/archimate4/icons/glyphs/contract.svg +5 -0
  180. package/assets/archimate4/icons/glyphs/course-of-action.svg +12 -0
  181. package/assets/archimate4/icons/glyphs/data-object.svg +4 -0
  182. package/assets/archimate4/icons/glyphs/deliverable.svg +3 -0
  183. package/assets/archimate4/icons/glyphs/device.svg +10 -0
  184. package/assets/archimate4/icons/glyphs/distribution-network.svg +11 -0
  185. package/assets/archimate4/icons/glyphs/driver.svg +16 -0
  186. package/assets/archimate4/icons/glyphs/equipment.svg +22 -0
  187. package/assets/archimate4/icons/glyphs/event.svg +6 -0
  188. package/assets/archimate4/icons/glyphs/facility.svg +7 -0
  189. package/assets/archimate4/icons/glyphs/function.svg +6 -0
  190. package/assets/archimate4/icons/glyphs/gap.svg +14 -0
  191. package/assets/archimate4/icons/glyphs/goal.svg +10 -0
  192. package/assets/archimate4/icons/glyphs/grouping.svg +4 -0
  193. package/assets/archimate4/icons/glyphs/interaction.svg +10 -0
  194. package/assets/archimate4/icons/glyphs/interface.svg +8 -0
  195. package/assets/archimate4/icons/glyphs/location.svg +6 -0
  196. package/assets/archimate4/icons/glyphs/material.svg +12 -0
  197. package/assets/archimate4/icons/glyphs/meaning.svg +3 -0
  198. package/assets/archimate4/icons/glyphs/node.svg +8 -0
  199. package/assets/archimate4/icons/glyphs/object.svg +4 -0
  200. package/assets/archimate4/icons/glyphs/outcome.svg +16 -0
  201. package/assets/archimate4/icons/glyphs/path.svg +10 -0
  202. package/assets/archimate4/icons/glyphs/person-silhouette.svg +3 -0
  203. package/assets/archimate4/icons/glyphs/plateau.svg +8 -0
  204. package/assets/archimate4/icons/glyphs/principle.svg +12 -0
  205. package/assets/archimate4/icons/glyphs/process.svg +6 -0
  206. package/assets/archimate4/icons/glyphs/product.svg +4 -0
  207. package/assets/archimate4/icons/glyphs/representation.svg +4 -0
  208. package/assets/archimate4/icons/glyphs/requirement.svg +6 -0
  209. package/assets/archimate4/icons/glyphs/resource.svg +14 -0
  210. package/assets/archimate4/icons/glyphs/role.svg +6 -0
  211. package/assets/archimate4/icons/glyphs/service.svg +6 -0
  212. package/assets/archimate4/icons/glyphs/stakeholder.svg +6 -0
  213. package/assets/archimate4/icons/glyphs/system-software.svg +14 -0
  214. package/assets/archimate4/icons/glyphs/value-stream.svg +3 -0
  215. package/assets/archimate4/icons/glyphs/value.svg +3 -0
  216. package/assets/archimate4/icons/glyphs/work-package.svg +4 -0
  217. package/assets/archimate4/icons/goal.svg +18 -0
  218. package/assets/archimate4/icons/grouping.svg +12 -0
  219. package/assets/archimate4/icons/location.svg +14 -0
  220. package/assets/archimate4/icons/material.svg +21 -0
  221. package/assets/archimate4/icons/meaning.svg +11 -0
  222. package/assets/archimate4/icons/node.svg +14 -0
  223. package/assets/archimate4/icons/or-junction.svg +3 -0
  224. package/assets/archimate4/icons/outcome.svg +25 -0
  225. package/assets/archimate4/icons/path.svg +18 -0
  226. package/assets/archimate4/icons/plateau.svg +16 -0
  227. package/assets/archimate4/icons/principle.svg +21 -0
  228. package/assets/archimate4/icons/process.svg +15 -0
  229. package/assets/archimate4/icons/product.svg +12 -0
  230. package/assets/archimate4/icons/requirement.svg +14 -0
  231. package/assets/archimate4/icons/resource.svg +23 -0
  232. package/assets/archimate4/icons/role.svg +16 -0
  233. package/assets/archimate4/icons/service.svg +13 -0
  234. package/assets/archimate4/icons/stakeholder.svg +15 -0
  235. package/assets/archimate4/icons/system-software.svg +22 -0
  236. package/assets/archimate4/icons/technology-interface.svg +16 -0
  237. package/assets/archimate4/icons/value-stream.svg +11 -0
  238. package/assets/archimate4/icons/value.svg +11 -0
  239. package/assets/archimate4/icons/work-package.svg +12 -0
  240. package/assets/basic/basic-metamodel.ttl +100 -0
  241. package/assets/basic/basic-notation-bubble.ttl +175 -0
  242. package/assets/basic/basic-notation.ttl +172 -0
  243. package/assets/basic/basic-onto.ttl +171 -0
  244. package/assets/basic/basic-presentation-contexts.ttl +70 -0
  245. package/assets/basic/basic-tax.ttl +130 -0
  246. package/assets/basic/icons/aggregation.svg +7 -0
  247. package/assets/basic/icons/association.svg +6 -0
  248. package/assets/basic/icons/element.svg +5 -0
  249. package/assets/basic/icons/glyphs/aggregation.svg +6 -0
  250. package/assets/basic/icons/glyphs/association.svg +5 -0
  251. package/assets/basic/icons/glyphs/element.svg +5 -0
  252. package/assets/basic/icons/glyphs/relationship.svg +5 -0
  253. package/assets/basic/icons/relationship.svg +7 -0
  254. package/assets/basic/notation-bubble/icons/aggregation.svg +7 -0
  255. package/assets/basic/notation-bubble/icons/association.svg +6 -0
  256. package/assets/basic/notation-bubble/icons/element.svg +5 -0
  257. package/assets/basic/notation-bubble/icons/glyphs/aggregation.svg +6 -0
  258. package/assets/basic/notation-bubble/icons/glyphs/association.svg +5 -0
  259. package/assets/basic/notation-bubble/icons/glyphs/element.svg +5 -0
  260. package/assets/basic/notation-bubble/icons/glyphs/relationship.svg +5 -0
  261. package/assets/basic/notation-bubble/icons/relationship.svg +7 -0
  262. package/assets/catalog.ttl +7302 -0
  263. package/assets/core/core-notation.ttl +131 -0
  264. package/assets/core/core-onto.ttl +2811 -0
  265. package/assets/core/core-questions.ttl +957 -0
  266. package/assets/core/core-shapes.ttl +915 -0
  267. package/assets/core/core-vis-onto.ttl +1408 -0
  268. package/assets/core/core-vis-shapes.ttl +840 -0
  269. package/assets/core-vis/markers/circle-dot.svg +3 -0
  270. package/assets/core-vis/markers/closed-arrowhead.svg +3 -0
  271. package/assets/core-vis/markers/filled-diamond.svg +3 -0
  272. package/assets/core-vis/markers/half-arrowhead.svg +3 -0
  273. package/assets/core-vis/markers/hollow-arrowhead.svg +3 -0
  274. package/assets/core-vis/markers/hollow-diamond.svg +3 -0
  275. package/assets/core-vis/markers/open-arrowhead.svg +3 -0
  276. package/fixtures/interoperability/archimate4-demo.trig +259 -0
  277. package/fixtures/interoperability/expected-findings.json +26 -0
  278. package/fixtures/interoperability/shop-seed.ttl +225 -0
  279. package/package.json +136 -4
  280. package/scripts/sync-assets.mjs +252 -0
  281. package/src/conformance.ts +66 -0
  282. package/src/import-export/model-io.ts +426 -0
  283. package/src/index.ts +11 -0
  284. package/src/metamodel-manager/asset-sources.ts +754 -0
  285. package/src/metamodel-manager/bundled-assets.ts +599 -0
  286. package/src/metamodel-manager/catalogue.ts +114 -0
  287. package/src/metamodel-manager/class-hierarchy.ts +155 -0
  288. package/src/metamodel-manager/index.ts +65 -0
  289. package/src/metamodel-manager/interfaces.ts +422 -0
  290. package/src/metamodel-manager/metamodel-completeness.ts +162 -0
  291. package/src/metamodel-manager/metamodel-loader.ts +864 -0
  292. package/src/metamodel-manager/notation-resolver.ts +284 -0
  293. package/src/metamodel-manager/notation.ts +659 -0
  294. package/src/metamodel-manager/palette-generator.ts +882 -0
  295. package/src/metamodel-manager/property-shapes.ts +290 -0
  296. package/src/metamodel-manager/taxonomy.ts +904 -0
  297. package/src/metamodel-manager/type-guide.ts +241 -0
  298. package/src/metamodel-manager/viewpoint-manager.ts +147 -0
  299. package/src/model-manager/appearance.ts +389 -0
  300. package/src/model-manager/cascade.ts +246 -0
  301. package/src/model-manager/clipboard.ts +566 -0
  302. package/src/model-manager/context-names.ts +108 -0
  303. package/src/model-manager/custom-properties.ts +549 -0
  304. package/src/model-manager/derivations.ts +166 -0
  305. package/src/model-manager/direct-permissions.ts +182 -0
  306. package/src/model-manager/drawing-order.ts +119 -0
  307. package/src/model-manager/element-manager.ts +69 -0
  308. package/src/model-manager/element-pictures.ts +118 -0
  309. package/src/model-manager/field-names.ts +42 -0
  310. package/src/model-manager/folders.ts +354 -0
  311. package/src/model-manager/grid.ts +6 -0
  312. package/src/model-manager/index.ts +43 -0
  313. package/src/model-manager/interfaces.ts +417 -0
  314. package/src/model-manager/iri-conformance.ts +183 -0
  315. package/src/model-manager/label-expression.ts +233 -0
  316. package/src/model-manager/legacy-migration.ts +200 -0
  317. package/src/model-manager/missing-references.ts +86 -0
  318. package/src/model-manager/model-diff-text.ts +150 -0
  319. package/src/model-manager/model-diff.ts +534 -0
  320. package/src/model-manager/model-merge.ts +1160 -0
  321. package/src/model-manager/model-namespace.ts +199 -0
  322. package/src/model-manager/model-operations.ts +132 -0
  323. package/src/model-manager/model-queries.ts +616 -0
  324. package/src/model-manager/model-session.ts +759 -0
  325. package/src/model-manager/multiplicity.ts +74 -0
  326. package/src/model-manager/nested-resources.ts +145 -0
  327. package/src/model-manager/own-metamodel.ts +157 -0
  328. package/src/model-manager/placement-copy.ts +116 -0
  329. package/src/model-manager/property-catalog.ts +787 -0
  330. package/src/model-manager/proposal-order.ts +203 -0
  331. package/src/model-manager/provenance.ts +396 -0
  332. package/src/model-manager/questions.ts +470 -0
  333. package/src/model-manager/rdf-scope.ts +97 -0
  334. package/src/model-manager/relationship-graph.ts +462 -0
  335. package/src/model-manager/relationship-manager.ts +962 -0
  336. package/src/model-manager/relationship-table.ts +189 -0
  337. package/src/model-manager/relationship-validity.ts +261 -0
  338. package/src/model-manager/resource-edits.ts +28 -0
  339. package/src/model-manager/short-hash.ts +104 -0
  340. package/src/model-manager/snapshot-lines.ts +88 -0
  341. package/src/model-manager/version-history.ts +205 -0
  342. package/src/model-manager/view-from-results.ts +81 -0
  343. package/src/model-manager/view-manager.ts +1410 -0
  344. package/src/model-manager/vocabulary.ts +279 -0
  345. package/src/rdf-engine/finding-shape.ts +23 -0
  346. package/src/rdf-engine/graph-scope.ts +163 -0
  347. package/src/rdf-engine/index.ts +7 -0
  348. package/src/rdf-engine/interfaces.ts +144 -0
  349. package/src/rdf-engine/iri.ts +203 -0
  350. package/src/rdf-engine/localized-text.ts +13 -0
  351. package/src/rdf-engine/namespaces.ts +41 -0
  352. package/src/rdf-engine/observable-store.ts +631 -0
  353. package/src/rdf-engine/rdf-store.ts +508 -0
  354. package/src/rdf-engine/shacl-validator.ts +602 -0
  355. package/src/rdf-engine/shape-reach.ts +140 -0
  356. package/src/rdf-engine/shape-switches.ts +165 -0
  357. package/src/rdf-engine/single-valued.ts +219 -0
  358. package/src/rdf-engine/sparql-constraints.ts +334 -0
  359. package/src/rdf-engine/term-codec.ts +51 -0
  360. package/src/rdf-engine/ttl-parser.ts +51 -0
  361. package/src/rdf-engine/ttl-serializer.ts +79 -0
  362. package/src/rdf-engine/turtle-writer.ts +284 -0
  363. package/src/rdf-engine/validation-engine.ts +682 -0
  364. package/src/rdf-engine/validation-service.ts +184 -0
  365. package/src/rdf-engine/validation.worker.ts +47 -0
@@ -0,0 +1,470 @@
1
+ /**
2
+ * Model questions: the `arch:ModelQuestion` individuals of the loaded question
3
+ * sets — the core set, and each metamodel's (`arch:hasQuestionSet`) — and how
4
+ * to turn one into a query the SPARQL tab can run.
5
+ *
6
+ * ## The contract (meta's DD-33)
7
+ *
8
+ * - The query text is in `sh:select` / `sh:construct` / `sh:ask`, without
9
+ * PREFIX lines (they come from `sh:prefixes` → `sh:declare`) and without a
10
+ * LIMIT (`arch:defaultLimit` is appended for browsing).
11
+ * - A parameter is an `sh:parameter` whose `sh:path` local name is the
12
+ * variable it binds (`arch:focus` → `?focus`). It is pre-bound by inserting
13
+ * `VALUES ?focus { <iri> }` as the first element of the outermost WHERE
14
+ * group. An optional parameter left unbound stays free and the question
15
+ * answers for "any"; a question whose required parameter is unbound is not
16
+ * asked.
17
+ * - Only declared parameters are bound: a result column may be called `?type`
18
+ * or `?view` without being a parameter.
19
+ * - A finding question (`arch:resultIsFinding`) lists problems against the
20
+ * concerns it addresses; `arch:findingFocus` names the column holding the
21
+ * concept each is about, `arch:findingSeverity` how serious it is.
22
+ *
23
+ * ## Where the questions are
24
+ *
25
+ * In their question set's named graph, as every metamodel document, or in the
26
+ * default graph when a question file is loaded as data; hence
27
+ * `{ P } UNION { GRAPH ?g { P } }` throughout.
28
+ */
29
+
30
+ import { DataFactory } from 'n3';
31
+ import type { NamedNode } from '@rdfjs/types';
32
+ import type { RdfStore, ValidationResult, ValidationSeverity } from '../rdf-engine/interfaces.js';
33
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
34
+ import { isSafeIri } from '../rdf-engine/graph-scope.js';
35
+
36
+ export type QuestionForm = 'select' | 'construct' | 'ask';
37
+
38
+ /** One declared parameter of a question. */
39
+ export interface QuestionParameter {
40
+ /** The variable it binds, without `?`. */
41
+ name: string;
42
+ optional: boolean;
43
+ order: number;
44
+ description?: string;
45
+ }
46
+
47
+ /** A model question, as the Questions menu, the model checks and a deliverable generator need it. */
48
+ export interface ModelQuestion {
49
+ iri: string;
50
+ /** The linked-archi-query catalogue name of its counterpart, e.g. `core/orphans`. */
51
+ identifier?: string;
52
+ /** The question itself. */
53
+ label: string;
54
+ description?: string;
55
+ /** What one row means. */
56
+ answers?: string;
57
+ /** What the answer does not settle. */
58
+ doesNotProve?: string;
59
+ /** IRI of its `arch:questionStage` concept. */
60
+ stage?: string;
61
+ form: QuestionForm;
62
+ /** The query text as stored, dedented. */
63
+ text: string;
64
+ /** Rows are findings: none means the concerns it addresses are met. */
65
+ isFinding: boolean;
66
+ /** `sh:Info`, `sh:Warning` or `sh:Violation`, for a finding. */
67
+ severity?: string;
68
+ /** The result column naming the concept each finding is about, without `?`. */
69
+ findingFocus?: string;
70
+ defaultLimit?: number;
71
+ concerns: string[];
72
+ stakeholders: string[];
73
+ viewpoints: string[];
74
+ purposes: string[];
75
+ /** Ontologies that must be loaded for the question to mean anything. */
76
+ metamodels: string[];
77
+ parameters: QuestionParameter[];
78
+ prefixes: Record<string, string>;
79
+ }
80
+
81
+ /** Parameter values: IRIs, one or several per variable. */
82
+ export type QuestionBindings = Record<string, string | readonly string[] | undefined>;
83
+
84
+ /** A required parameter was not given. */
85
+ export class MissingParameterError extends Error {
86
+ constructor(
87
+ readonly question: ModelQuestion,
88
+ readonly missing: string[],
89
+ ) {
90
+ super(`“${question.label}” needs ${missing.map((m) => `?${m}`).join(', ')}`);
91
+ this.name = 'MissingParameterError';
92
+ }
93
+ }
94
+
95
+ const ARCH = NAMESPACES.arch;
96
+ const SH = NAMESPACES.sh;
97
+ const SKOS = NAMESPACES.skos;
98
+ const DCTERMS = NAMESPACES.dcterms;
99
+
100
+ const PROLOGUE = `
101
+ PREFIX arch: <${ARCH}>
102
+ PREFIX sh: <${SH}>
103
+ PREFIX skos: <${SKOS}>
104
+ PREFIX dcterms: <${DCTERMS}>
105
+ `;
106
+
107
+ /** The order an investigation moves through (`arch:QuestionStageScheme`). */
108
+ export const QUESTION_STAGES = [
109
+ 'orientation',
110
+ 'resolution',
111
+ 'discovery',
112
+ 'analysis',
113
+ 'enrichment',
114
+ 'quality',
115
+ 'views',
116
+ ] as const;
117
+
118
+ /** The stage a question is in, by its concept's local name (`arch:QualityStage` → `quality`). */
119
+ export function stageOf(question: ModelQuestion): string | undefined {
120
+ const local = question.stage ? localName(question.stage).toLowerCase() : undefined;
121
+ return QUESTION_STAGES.find((s) => local === `${s}stage`);
122
+ }
123
+
124
+ /** `P` in the default graph or in any named graph, under its own graph variable. */
125
+ function anyGraph(pattern: string, g: string): string {
126
+ return `{ ${pattern} } UNION { GRAPH ?${g} { ${pattern} } }`;
127
+ }
128
+
129
+ type Row = Record<string, { value: string; language?: string } | undefined>;
130
+
131
+ function select(store: RdfStore, sparql: string): Row[] {
132
+ const result = store.query(sparql);
133
+ return result.type === 'bindings' ? (result.results as Row[]) : [];
134
+ }
135
+
136
+ function localName(iri: string): string {
137
+ return iri.slice(Math.max(iri.lastIndexOf('#'), iri.lastIndexOf('/')) + 1);
138
+ }
139
+
140
+ /** Remove the common leading indentation a Turtle long string carries. */
141
+ export function dedent(text: string): string {
142
+ const lines = text.replace(/^\s*\n/, '').replace(/\s+$/, '').split('\n');
143
+ const indents = lines.filter((l) => l.trim()).map((l) => /^ */.exec(l)![0].length);
144
+ const cut = indents.length ? Math.min(...indents) : 0;
145
+ return lines.map((l) => l.slice(cut)).join('\n');
146
+ }
147
+
148
+ /** Every model question in the store, ordered by stage then label. */
149
+ export function listQuestions(store: RdfStore): ModelQuestion[] {
150
+ const byIri = new Map<string, ModelQuestion>();
151
+
152
+ const core = select(
153
+ store,
154
+ `${PROLOGUE}
155
+ SELECT ?q ?formProp ?text WHERE {
156
+ VALUES ?formProp { sh:select sh:construct sh:ask }
157
+ ${anyGraph('?q a arch:ModelQuestion ; ?formProp ?text .', 'g0')}
158
+ }`,
159
+ );
160
+ for (const row of core) {
161
+ const iri = row.q?.value;
162
+ if (!iri || byIri.has(iri)) continue;
163
+ byIri.set(iri, {
164
+ iri,
165
+ label: localName(iri),
166
+ form: localName(row.formProp!.value) as QuestionForm,
167
+ text: dedent(row.text!.value),
168
+ isFinding: false,
169
+ concerns: [],
170
+ stakeholders: [],
171
+ viewpoints: [],
172
+ purposes: [],
173
+ metamodels: [],
174
+ parameters: [],
175
+ prefixes: {},
176
+ });
177
+ }
178
+ if (byIri.size === 0) return [];
179
+
180
+ // Single-valued annotations. One OPTIONAL each, so a missing one cannot
181
+ // empty the row and two present ones cannot multiply it.
182
+ const scalars: [keyof ModelQuestion, string][] = [
183
+ ['label', 'skos:prefLabel'],
184
+ ['identifier', 'dcterms:identifier'],
185
+ ['description', 'dcterms:description'],
186
+ ['answers', 'arch:answers'],
187
+ ['doesNotProve', 'arch:doesNotProve'],
188
+ ['stage', 'arch:questionStage'],
189
+ ['severity', 'arch:findingSeverity'],
190
+ ['findingFocus', 'arch:findingFocus'],
191
+ ];
192
+ const lists: [keyof ModelQuestion, string][] = [
193
+ ['concerns', 'arch:questionAddressesConcern'],
194
+ ['stakeholders', 'arch:questionTargetsStakeholder'],
195
+ ['viewpoints', 'arch:questionFitsViewpoint'],
196
+ ['purposes', 'arch:questionHasPurpose'],
197
+ ['metamodels', 'arch:requiresMetamodel'],
198
+ ];
199
+ const annotations = select(
200
+ store,
201
+ `${PROLOGUE}
202
+ SELECT ?q ?p ?o WHERE {
203
+ VALUES ?p { ${[...scalars, ...lists].map(([, p]) => p).join(' ')} arch:resultIsFinding arch:defaultLimit }
204
+ ${anyGraph('?q a arch:ModelQuestion ; ?p ?o .', 'g1')}
205
+ }`,
206
+ );
207
+ const expand = (curie: string) => {
208
+ const [prefix, local] = curie.split(':');
209
+ return ({ arch: ARCH, skos: SKOS, dcterms: DCTERMS } as Record<string, string>)[prefix!] + local;
210
+ };
211
+ const scalarOf = new Map(scalars.map(([key, curie]) => [expand(curie), key]));
212
+ const listOf = new Map(lists.map(([key, curie]) => [expand(curie), key]));
213
+ for (const row of annotations) {
214
+ const q = byIri.get(row.q!.value);
215
+ if (!q) continue;
216
+ const p = row.p!.value;
217
+ const o = row.o!;
218
+ const scalar = scalarOf.get(p);
219
+ const list = listOf.get(p);
220
+ if (scalar) {
221
+ // A stored label beats the IRI fallback; English beats another language; else the first wins.
222
+ const current = q[scalar] as string | undefined;
223
+ const replace =
224
+ scalar === 'label'
225
+ ? q.label === localName(q.iri) || (o.language === 'en' && current !== undefined)
226
+ : current === undefined || o.language === 'en';
227
+ if (replace) (q as unknown as Record<string, unknown>)[scalar] = o.value;
228
+ } else if (list) {
229
+ const values = q[list] as string[];
230
+ if (!values.includes(o.value)) values.push(o.value);
231
+ } else if (p === ARCH + 'resultIsFinding') q.isFinding = o.value === 'true';
232
+ else if (p === ARCH + 'defaultLimit') q.defaultLimit = Number(o.value);
233
+ }
234
+
235
+ // Parameters are blank nodes: the whole pattern stays inside one graph.
236
+ const params = select(
237
+ store,
238
+ `${PROLOGUE}
239
+ SELECT ?q ?path ?optional ?order ?description WHERE {
240
+ ${anyGraph(
241
+ `?q a arch:ModelQuestion ; sh:parameter ?param . ?param sh:path ?path .
242
+ OPTIONAL { ?param sh:optional ?optional }
243
+ OPTIONAL { ?param sh:order ?order }
244
+ OPTIONAL { ?param sh:description ?description }`,
245
+ 'g2',
246
+ )}
247
+ }`,
248
+ );
249
+ for (const row of params) {
250
+ const q = byIri.get(row.q!.value);
251
+ const name = localName(row.path!.value);
252
+ if (!q || q.parameters.some((p) => p.name === name)) continue;
253
+ q.parameters.push({
254
+ name,
255
+ optional: row.optional?.value === 'true',
256
+ order: Number(row.order?.value ?? q.parameters.length + 1),
257
+ ...(row.description ? { description: row.description.value } : {}),
258
+ });
259
+ }
260
+
261
+ const prefixes = select(
262
+ store,
263
+ `${PROLOGUE}
264
+ SELECT ?q ?prefix ?namespace WHERE {
265
+ ${anyGraph('?q a arch:ModelQuestion ; sh:prefixes ?declarer .', 'g3')}
266
+ ${anyGraph('?declarer sh:declare ?d . ?d sh:prefix ?prefix ; sh:namespace ?namespace .', 'g4')}
267
+ }`,
268
+ );
269
+ for (const row of prefixes) {
270
+ const q = byIri.get(row.q!.value);
271
+ if (q) q.prefixes[row.prefix!.value] ??= row.namespace!.value;
272
+ }
273
+
274
+ const rank = (q: ModelQuestion) => {
275
+ const i = QUESTION_STAGES.indexOf(stageOf(q) as (typeof QUESTION_STAGES)[number]);
276
+ return i < 0 ? QUESTION_STAGES.length : i;
277
+ };
278
+ return [...byIri.values()]
279
+ .map((q) => ({ ...q, parameters: q.parameters.sort((a, b) => a.order - b.order) }))
280
+ .sort((a, b) => rank(a) - rank(b) || a.label.localeCompare(b.label));
281
+ }
282
+
283
+ /**
284
+ * The questions worth offering: those whose ontologies are loaded, the ones
285
+ * fitting `viewpoint` (the open view's) first.
286
+ */
287
+ export function offeredQuestions(
288
+ questions: readonly ModelQuestion[],
289
+ loadedOntologies: ReadonlySet<string>,
290
+ viewpoint?: string,
291
+ ): ModelQuestion[] {
292
+ const available = questions.filter((q) => q.metamodels.every((m) => loadedOntologies.has(m)));
293
+ if (!viewpoint) return available;
294
+ const fits = (q: ModelQuestion) => (q.viewpoints.includes(viewpoint) ? 0 : 1);
295
+ return [...available].sort((a, b) => fits(a) - fits(b));
296
+ }
297
+
298
+ const bound = (v: QuestionBindings[string]) => (Array.isArray(v) ? v.length > 0 : !!v);
299
+
300
+ /** The required parameters `bindings` leaves unbound: why the question cannot be asked yet. */
301
+ export function missingParameters(question: ModelQuestion, bindings: QuestionBindings): string[] {
302
+ return question.parameters.filter((p) => !p.optional && !bound(bindings[p.name])).map((p) => p.name);
303
+ }
304
+
305
+ /** What a modeller does in the workbench to bind each parameter. */
306
+ export const PARAMETER_HINTS: Readonly<Record<string, string>> = {
307
+ focus: 'select an element',
308
+ model: 'open a model',
309
+ view: 'open a view',
310
+ viewpoint: 'open a view that follows a viewpoint',
311
+ conceptType: 'pick a type in the palette',
312
+ from: 'select two elements',
313
+ to: 'select two elements',
314
+ };
315
+
316
+ /** What to do before the question can be asked ("Select an element"); none when it can be. */
317
+ export function whatToSelect(question: ModelQuestion, bindings: QuestionBindings): string | undefined {
318
+ const hints = [...new Set(missingParameters(question, bindings).map((p) => PARAMETER_HINTS[p] ?? `bind ?${p}`))];
319
+ if (hints.length === 0) return undefined;
320
+ const text = hints.join(' and ');
321
+ return text.charAt(0).toUpperCase() + text.slice(1);
322
+ }
323
+
324
+ /**
325
+ * The viewpoint a view of the question's answer follows: the one viewpoint it
326
+ * fits, or else the viewpoint it was asked about (`?viewpoint`); none when
327
+ * that is not one.
328
+ */
329
+ export function viewpointOfAnswer(question: ModelQuestion, bindings: QuestionBindings = {}): string | undefined {
330
+ if (question.viewpoints.length === 1) return question.viewpoints[0];
331
+ if (question.viewpoints.length > 1 || !question.parameters.some((p) => p.name === 'viewpoint')) return undefined;
332
+ const value = bindings.viewpoint;
333
+ const values = Array.isArray(value) ? value : value ? [value] : [];
334
+ return values.length === 1 ? values[0] : undefined;
335
+ }
336
+
337
+ /** The outcome of running the model checks: findings as validation results, and what did not run. */
338
+ export interface ModelCheckRun {
339
+ /** One per finding: the concept in the question's `arch:findingFocus` column, once per question. */
340
+ results: ValidationResult[];
341
+ /** The checks that ran. */
342
+ ran: ModelQuestion[];
343
+ /** The checks that could not run, and why. */
344
+ failed: Array<{ question: ModelQuestion; reason: string }>;
345
+ /** The checks that stopped at their `arch:defaultLimit`: there may be more findings. */
346
+ capped: ModelQuestion[];
347
+ }
348
+
349
+ const SEVERITIES: Record<string, ValidationSeverity> = {
350
+ [SH + 'Violation']: 'Violation',
351
+ [SH + 'Warning']: 'Warning',
352
+ [SH + 'Info']: 'Info',
353
+ };
354
+
355
+ /**
356
+ * Ask each finding question and turn its rows into validation results: the
357
+ * concept from its `arch:findingFocus` column, the severity from
358
+ * `arch:findingSeverity` (a warning when it states none), the question as the
359
+ * message and its IRI as the source shape. A question whose required
360
+ * parameter `bindings` leaves unbound, or whose query fails, is reported in
361
+ * `failed`, not dropped.
362
+ */
363
+ export function runModelChecks(
364
+ store: RdfStore,
365
+ questions: readonly ModelQuestion[],
366
+ bindings: QuestionBindings = {},
367
+ ): ModelCheckRun {
368
+ const run: ModelCheckRun = { results: [], ran: [], failed: [], capped: [] };
369
+ for (const question of questions) {
370
+ if (!question.isFinding) continue;
371
+ const missing = whatToSelect(question, bindings);
372
+ if (missing) {
373
+ run.failed.push({ question, reason: missing });
374
+ continue;
375
+ }
376
+ const focus = question.findingFocus;
377
+ if (!focus || question.form !== 'select') {
378
+ run.failed.push({ question, reason: focus ? 'Not a SELECT question' : 'It names no arch:findingFocus column' });
379
+ continue;
380
+ }
381
+ let rows: Array<Record<string, { termType?: string; value: string } | undefined>>;
382
+ try {
383
+ const result = store.query(buildQuery(question, bindings));
384
+ rows = result.type === 'bindings' ? result.results : [];
385
+ } catch (err: unknown) {
386
+ run.failed.push({ question, reason: err instanceof Error ? err.message : String(err) });
387
+ continue;
388
+ }
389
+ run.ran.push(question);
390
+ if (question.defaultLimit && rows.length >= question.defaultLimit) run.capped.push(question);
391
+ const seen = new Set<string>();
392
+ for (const row of rows) {
393
+ const term = row[focus];
394
+ if (term?.termType !== 'NamedNode' || seen.has(term.value)) continue;
395
+ seen.add(term.value);
396
+ run.results.push({
397
+ focusNode: DataFactory.namedNode(term.value) as unknown as NamedNode,
398
+ // No property: a finding is about the concept.
399
+ resultPath: DataFactory.namedNode('') as unknown as NamedNode,
400
+ sourceShape: DataFactory.namedNode(question.iri) as unknown as NamedNode,
401
+ message: question.label,
402
+ severity: SEVERITIES[question.severity ?? ''] ?? 'Warning',
403
+ });
404
+ }
405
+ }
406
+ return run;
407
+ }
408
+
409
+ /**
410
+ * Blank out strings, IRIs and comments, keeping every offset, so keywords and
411
+ * braces can be found in what remains.
412
+ */
413
+ export function maskSparql(sparql: string): string {
414
+ const blank = (m: string) => m.replace(/[^\n]/g, ' ');
415
+ return sparql
416
+ .replace(/"""[\s\S]*?"""|'''[\s\S]*?'''|"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'/g, blank)
417
+ .replace(/<[^<>"{}|^`\\\s]*>/g, blank)
418
+ .replace(/#[^\n]*/g, blank);
419
+ }
420
+
421
+ /** Offset of the `{` opening the outermost WHERE group, or -1. */
422
+ function whereGroupStart(sparql: string): number {
423
+ const masked = maskSparql(sparql);
424
+ const where = /\bWHERE\b/i.exec(masked);
425
+ return masked.indexOf('{', where ? where.index + where[0].length : 0);
426
+ }
427
+
428
+ /**
429
+ * Pre-bind variables: `VALUES ?name { <iri> … }` as the first element of the
430
+ * outermost WHERE group. Unbound (undefined or empty) entries are left out.
431
+ */
432
+ export function prebind(sparql: string, bindings: QuestionBindings): string {
433
+ const clauses: string[] = [];
434
+ for (const [name, value] of Object.entries(bindings)) {
435
+ const iris = (Array.isArray(value) ? value : value ? [value] : []).filter(Boolean) as string[];
436
+ if (iris.length === 0) continue;
437
+ if (!/^\w+$/.test(name)) throw new Error(`Not a variable name: ${name}`);
438
+ for (const iri of iris) if (!isSafeIri(iri)) throw new Error(`Not an IRI that can be bound: ${iri}`);
439
+ clauses.push(`VALUES ?${name} { ${iris.map((i) => `<${i}>`).join(' ')} }`);
440
+ }
441
+ if (clauses.length === 0) return sparql;
442
+ const at = whereGroupStart(sparql);
443
+ if (at < 0) throw new Error('The query has no WHERE group to pre-bind into');
444
+ return `${sparql.slice(0, at + 1)}\n ${clauses.join('\n ')}${sparql.slice(at + 1)}`;
445
+ }
446
+
447
+ /**
448
+ * The full query text for a question: prefixes, the question with its declared
449
+ * parameters pre-bound, and — unless `limit` is `null` — a LIMIT.
450
+ */
451
+ export function buildQuery(
452
+ question: ModelQuestion,
453
+ bindings: QuestionBindings = {},
454
+ options: { limit?: number | null } = {},
455
+ ): string {
456
+ const missing = missingParameters(question, bindings);
457
+ if (missing.length > 0) throw new MissingParameterError(question, missing);
458
+
459
+ const own: QuestionBindings = {};
460
+ for (const p of question.parameters) if (bound(bindings[p.name])) own[p.name] = bindings[p.name];
461
+
462
+ const prologue = Object.entries(question.prefixes)
463
+ .sort(([a], [b]) => a.localeCompare(b))
464
+ .map(([prefix, ns]) => `PREFIX ${prefix}: <${ns}>`)
465
+ .join('\n');
466
+ let body = prebind(question.text, own);
467
+ const limit = options.limit === undefined ? question.defaultLimit : options.limit;
468
+ if (question.form !== 'ask' && limit && !/\bLIMIT\s+\d+\s*$/i.test(maskSparql(body))) body += `\nLIMIT ${limit}`;
469
+ return `${prologue}\n\n${body}\n`;
470
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Part of the model, as statements: what the RDF panel shows when it shows a
3
+ * view or a concept rather than the whole model (`ui/panels/rdf-panel.ts`), and
4
+ * what it writes when that is copied or downloaded.
5
+ *
6
+ * - A view: the view's own statements, those of every concept it presents
7
+ * (`arch:inView`), and its diagram — the nodes and links drawn in it
8
+ * (`arch-vis:view`), with their routes.
9
+ * - Concepts — a selection of one or several: their own statements and, given
10
+ * the open view, how they are drawn there.
11
+ *
12
+ * And, by IRI, what a view is about (`viewMembers`): the Validation tab's view
13
+ * scope.
14
+ *
15
+ * Read from the model graph only, so a vocabulary's statements about a type
16
+ * never appear. Each subject comes with what only it reaches — blank nodes and
17
+ * the cells and points of a route list — as a saved file has them.
18
+ */
19
+
20
+ import { DataFactory } from 'n3';
21
+ import type { NamedNode, Quad, Term } from '@rdfjs/types';
22
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
23
+ import { IRI, T, nn } from './vocabulary.js';
24
+
25
+ /** The default graph: the model. */
26
+ const MODEL_GRAPH = DataFactory.defaultGraph() as unknown as NamedNode;
27
+
28
+ /** Predicates whose objects are part of their subject: a route's list and its points. */
29
+ const LIST_PREDICATES = new Set([IRI.points, IRI.rdfFirst, IRI.rdfRest]);
30
+
31
+ const key = (term: Term): string => `${term.termType}:${term.value}`;
32
+
33
+ /** The statements of `subjects`, with the blank nodes and route lists they reach. */
34
+ export function statementsOf(store: RdfStore, subjects: Iterable<Term>): Quad[] {
35
+ const quads: Quad[] = [];
36
+ const seen = new Set<string>();
37
+ const queue = [...subjects];
38
+ while (queue.length > 0) {
39
+ const subject = queue.pop() as Term;
40
+ if (seen.has(key(subject))) continue;
41
+ seen.add(key(subject));
42
+ for (const q of store.getQuads(subject as NamedNode, null, null, MODEL_GRAPH)) {
43
+ quads.push(q);
44
+ const object = q.object;
45
+ const reached =
46
+ object.termType === 'BlankNode' ||
47
+ (object.termType === 'NamedNode' && LIST_PREDICATES.has(q.predicate.value) && object.value !== IRI.rdfNil);
48
+ if (reached && !seen.has(key(object))) queue.push(object);
49
+ }
50
+ }
51
+ return quads;
52
+ }
53
+
54
+ /** What a view covers: itself, the concepts it presents (`arch:inView`), and its diagram's nodes and links (`arch-vis:view`). */
55
+ export function viewSubjects(store: RdfStore, viewIri: string): Term[] {
56
+ const view = nn(viewIri);
57
+ return [
58
+ view,
59
+ ...store.getQuads(null, T.inView, view, MODEL_GRAPH).map((q) => q.subject),
60
+ ...store.getQuads(null, T.visView, view, MODEL_GRAPH).map((q) => q.subject),
61
+ ];
62
+ }
63
+
64
+ /**
65
+ * Everything a view is about, by IRI: what `viewSubjects` gives and the
66
+ * concepts its diagram draws — presented by geometry alone, as an older model
67
+ * may have them. The Validation tab's view scope (`ui/panels/validation-panel.ts`).
68
+ */
69
+ export function viewMembers(store: RdfStore, viewIri: string): Set<string> {
70
+ const members = new Set<string>();
71
+ for (const subject of viewSubjects(store, viewIri)) {
72
+ members.add(subject.value);
73
+ for (const predicate of [T.archElement, T.archRelationship]) {
74
+ for (const q of store.getQuads(subject as NamedNode, predicate, null, MODEL_GRAPH)) members.add(q.object.value);
75
+ }
76
+ }
77
+ return members;
78
+ }
79
+
80
+ /** A view's statements: its own, its concepts', and its diagram's. */
81
+ export function viewStatements(store: RdfStore, viewIri: string): Quad[] {
82
+ return statementsOf(store, viewSubjects(store, viewIri));
83
+ }
84
+
85
+ /** Concepts' statements — one IRI or a selection of several — and how they are drawn in the open view. */
86
+ export function conceptStatements(store: RdfStore, iris: string | readonly string[], viewIri?: string): Quad[] {
87
+ const concepts = (typeof iris === 'string' ? [iris] : [...iris]).map(nn);
88
+ const drawnHere = (q: Quad) =>
89
+ viewIri !== undefined && store.getQuads(q.subject as NamedNode, T.visView, nn(viewIri), MODEL_GRAPH).length > 0;
90
+ const drawings = concepts.flatMap((concept) =>
91
+ [
92
+ ...store.getQuads(null, T.archElement, concept, MODEL_GRAPH),
93
+ ...store.getQuads(null, T.archRelationship, concept, MODEL_GRAPH),
94
+ ].filter(drawnHere),
95
+ );
96
+ return statementsOf(store, [...concepts, ...drawings.map((q) => q.subject)]);
97
+ }