@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.
Files changed (366) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +11 -0
  3. package/README.md +102 -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 +917 -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 +895 -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 +7406 -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 +851 -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 +475 -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/native-load.ts +37 -0
  353. package/src/rdf-engine/observable-store.ts +609 -0
  354. package/src/rdf-engine/rdf-store.ts +520 -0
  355. package/src/rdf-engine/shacl-validator.ts +602 -0
  356. package/src/rdf-engine/shape-reach.ts +140 -0
  357. package/src/rdf-engine/shape-switches.ts +165 -0
  358. package/src/rdf-engine/single-valued.ts +219 -0
  359. package/src/rdf-engine/sparql-constraints.ts +349 -0
  360. package/src/rdf-engine/term-codec.ts +51 -0
  361. package/src/rdf-engine/ttl-parser.ts +51 -0
  362. package/src/rdf-engine/ttl-serializer.ts +79 -0
  363. package/src/rdf-engine/turtle-writer.ts +284 -0
  364. package/src/rdf-engine/validation-engine.ts +747 -0
  365. package/src/rdf-engine/validation-service.ts +186 -0
  366. package/src/rdf-engine/validation.worker.ts +47 -0
@@ -0,0 +1,904 @@
1
+ /**
2
+ * Multi-axis SKOS taxonomy resolution.
3
+ *
4
+ * A real ArchiMate taxonomy classifies the *same* element class along several orthogonal
5
+ * axes at once — "Layer", "Aspect", "Domain". Grouping by a
6
+ * single `skos:broader` hop collapses those axes and lets one silently overwrite another.
7
+ *
8
+ * This module resolves each axis separately and records, for every palette class, its group
9
+ * under every axis (`groupsByAxis`) plus a default `group` taken from the first (preferred) axis.
10
+ *
11
+ * Axes are inferred **structurally** from the graph shape — never from IRI or label pattern
12
+ * matching — so it works across metamodels; a concept the metamodel manifest's
13
+ * `arch:paletteGrouping` names is an axis as well:
14
+ *
15
+ * - `leaf` — an element type, which the ontology declares: a child that is not a SKOS concept (the
16
+ * class itself), or a SKOS concept with no children that stands for a class (rdfs:seeAlso
17
+ * or the same local name).
18
+ * A concept with nothing under it and no class behind it is an empty concept, no leaf.
19
+ * - `group` — a SKOS concept that directly holds at least one leaf (e.g. "Business Layer")
20
+ * - `axis` — a SKOS concept that holds no leaf itself, every concept-child of which classifies
21
+ * something, at least one of them directly (e.g. "Layer"); an empty concept-child is
22
+ * left out of the count
23
+ * - a group under no axis and no other group (e.g. "Junction", a top concept of its own) is kept
24
+ * as a standalone axis of its one group, so its members are classified; it is no way of grouping
25
+ *
26
+ * An axis's groups take the order of the ISO 25964 thesaurus array whose `iso-thes:superOrdinate`
27
+ * is the axis: an ordered collection that lists them (meta's DD-36). The classification stays in
28
+ * `skos:broader`/`skos:narrower`; the array only orders it, and an axis without one has no order.
29
+ *
30
+ * Groups may nest. The published ArchiMate 4.0 aspect axis nests three deep
31
+ * (`Structure` → `Active Structure` → `Internal Active Structure` → members), so members are
32
+ * collected transitively beneath each of the axis's direct children.
33
+ *
34
+ * The module deliberately operates directly on an n3 {@link Store} and has no dependency on the
35
+ * application's `RdfStore` abstraction, so it can be exercised against hand-written Turtle.
36
+ */
37
+
38
+ import { DataFactory, Store, type NamedNode, type Term } from 'n3';
39
+ import { selectLocalizedLiteral } from '../rdf-engine/localized-text.js';
40
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
41
+
42
+ const { namedNode } = DataFactory;
43
+
44
+ /**
45
+ * `arch:` core namespace. Verified identical to the source implementation's `CORE`
46
+ * constant (`https://meta.linked.archi/core#`).
47
+ */
48
+ const CORE = NAMESPACES.arch;
49
+ const SKOS_NS = NAMESPACES.skos;
50
+
51
+ const RDF_TYPE = `${NAMESPACES.rdf}type`;
52
+ const RDFS_LABEL = `${NAMESPACES.rdfs}label`;
53
+ const RDFS_COMMENT = `${NAMESPACES.rdfs}comment`;
54
+ const RDFS_SUBCLASS = `${NAMESPACES.rdfs}subClassOf`;
55
+ const RDFS_SEE_ALSO = `${NAMESPACES.rdfs}seeAlso`;
56
+ const OWL_CLASS = `${NAMESPACES.owl}Class`;
57
+
58
+ const SKOS_PREF_LABEL = `${SKOS_NS}prefLabel`;
59
+ const SKOS_DEFINITION = `${SKOS_NS}definition`;
60
+ const SKOS_NARROWER = `${SKOS_NS}narrower`;
61
+ const SKOS_BROADER = `${SKOS_NS}broader`;
62
+ const SKOS_IN_SCHEME = `${SKOS_NS}inScheme`;
63
+ const SKOS_TOP_CONCEPT_OF = `${SKOS_NS}topConceptOf`;
64
+ const SKOS_HAS_TOP_CONCEPT = `${SKOS_NS}hasTopConcept`;
65
+ const SKOS_CONCEPT = `${SKOS_NS}Concept`;
66
+ const SKOS_CONCEPT_SCHEME = `${SKOS_NS}ConceptScheme`;
67
+ const SKOS_MEMBER = `${SKOS_NS}member`;
68
+ const SKOS_MEMBER_LIST = `${SKOS_NS}memberList`;
69
+ const RDF_FIRST = `${NAMESPACES.rdf}first`;
70
+ const RDF_REST = `${NAMESPACES.rdf}rest`;
71
+ /**
72
+ * ISO 25964's SKOS extension: a thesaurus array names, with this, the concept whose narrower concepts it
73
+ * lists — an axis's array gives the order of its groups. Not in NAMESPACES, which also prefixes saved files.
74
+ */
75
+ const ISO_THES_SUPER_ORDINATE = 'http://purl.org/iso25964/skos-thes#superOrdinate';
76
+
77
+ const ARCH_CONCEPT_CLASSIFICATION = `${CORE}conceptClassification`;
78
+ /** The axes a metamodel's palette groups by, main one first (an ordered collection of axis concepts). */
79
+ const ARCH_PALETTE_GROUPING = `${CORE}paletteGrouping`;
80
+ /** The abstractness flag actually published in the Linked.Archi ontologies. */
81
+ const ARCH_IS_ABSTRACT_CLASS = `${CORE}isAbstractClass`;
82
+ const CORE_ELEMENT = `${CORE}Element`;
83
+ const CORE_VIEW = 'https://meta.linked.archi/core#View';
84
+ const CORE_MODEL_CONCEPT = `${CORE}ModelConcept`;
85
+ const CORE_QUALIFIED_RELATIONSHIP = `${CORE}QualifiedRelationship`;
86
+
87
+ /**
88
+ * Namespace consulted only by the OWL-only fallback grouping heuristic, which has no taxonomy
89
+ * to work from and therefore has to guess from the ArchiMate superclass hierarchy.
90
+ */
91
+ const ARCHIMATE_ONTO = 'https://meta.linked.archi/archimate4/onto#';
92
+
93
+ /** Local names that denote relationship classes rather than palette elements. */
94
+ const RELATIONSHIP_FRAGMENTS = new Set([
95
+ 'Access',
96
+ 'Aggregation',
97
+ 'Assignment',
98
+ 'Association',
99
+ 'Composition',
100
+ 'DirectedAssociation',
101
+ 'Flow',
102
+ 'Influence',
103
+ 'ReadAccess',
104
+ 'ReadWriteAccess',
105
+ 'Realization',
106
+ 'Serving',
107
+ 'Specialization',
108
+ 'Triggering',
109
+ 'WriteAccess',
110
+ ]);
111
+
112
+ /** Local names that denote abstract scaffolding classes rather than palette elements. */
113
+ const ABSTRACT_FRAGMENTS = new Set([
114
+ 'Element',
115
+ 'ActiveStructureElement',
116
+ 'BehaviorElement',
117
+ 'PassiveStructureElement',
118
+ 'CompositeElement',
119
+ 'CommonDomainElement',
120
+ 'BusinessDomainElement',
121
+ 'ApplicationDomainElement',
122
+ 'TechnologyDomainElement',
123
+ 'StrategyElement',
124
+ 'MotivationElement',
125
+ 'ImplementationAndMigrationDomainElement',
126
+ 'InternalActiveStructureElement',
127
+ 'ExternalActiveStructureElement',
128
+ ]);
129
+
130
+ /** A classification axis together with its member-to-group mapping. */
131
+ export interface TaxonomyAxis {
132
+ /** IRI of the axis concept (or of the scheme, for a synthesised single axis). */
133
+ iri: string;
134
+ /** Human-readable axis label, e.g. "Layer". */
135
+ label: string;
136
+ /**
137
+ * A group under no axis — ArchiMate's Junction, a top concept of its own — kept as an axis of its one
138
+ * group so that its members are classified. It is no way of grouping: a palette does not offer it, and
139
+ * gives its members a section of that group's name.
140
+ */
141
+ standalone?: boolean;
142
+ /**
143
+ * Taxonomy member IRI to its position, 0 first, in the thesaurus array under the group that lists it —
144
+ * ArchiMate's :StructuralStrength under Structural Relationship. Absent for a member no such array lists.
145
+ */
146
+ memberRanks?: Map<string, number>;
147
+ /**
148
+ * Taxonomy member IRI to group label under this axis.
149
+ *
150
+ * The label is the *nearest* group that lists the member. When the axis nests its groups
151
+ * (`Structure` → `Active Structure` → `Internal Active Structure` → members) that is the
152
+ * innermost concept, so the label a member carries is always the label of the concept that
153
+ * actually names it. See {@link topGroups} for the coarse, axis-level bucket.
154
+ */
155
+ groups: Map<string, string>;
156
+ /**
157
+ * Taxonomy member IRI to the label of the axis's *direct* child group the member descends
158
+ * from — the coarse bucket, identical to {@link groups} for a flat axis.
159
+ *
160
+ * Kept alongside `groups` so a UI can render a two-level palette (section = `topGroups`
161
+ * entry, subsection = `groups` entry) without walking the taxonomy again.
162
+ */
163
+ topGroups: Map<string, string>;
164
+ /**
165
+ * Taxonomy member IRI to the position, 0 first, of the axis's direct child group it descends from,
166
+ * in the axis's thesaurus array; empty for an axis without one, and no entry for a group it does not list.
167
+ */
168
+ ranks: Map<string, number>;
169
+ }
170
+
171
+ /** The palette section of the element types no classification names. */
172
+ export const UNCLASSIFIED_GROUP = 'Other';
173
+
174
+ /** An instantiable palette class resolved from the taxonomy and the OWL ontology. */
175
+ export interface SemanticClass {
176
+ /** IRI of the OWL class that gets instantiated. */
177
+ iri: string;
178
+ label: string;
179
+ definition?: string;
180
+ /** Direct `rdfs:subClassOf` parents. */
181
+ superClasses: string[];
182
+ /** Transitive `rdfs:subClassOf` closure (excluding the class itself). */
183
+ transitiveSuperClasses: string[];
184
+ /** Group label under the default (first) classification axis. */
185
+ group: string;
186
+ /** Group label per classification axis IRI — the dual-classification result. */
187
+ groupsByAxis: Record<string, string>;
188
+ /** Position of the class's group per ordered axis IRI ({@link TaxonomyAxis.ranks}). */
189
+ ranksByAxis: Record<string, number>;
190
+ /**
191
+ * Position of the class within its group per axis IRI, where the group orders its members with an array
192
+ * of its own ({@link TaxonomyAxis.memberRanks}) — ArchiMate 4.0's Common Domain.
193
+ */
194
+ memberRanksByAxis?: Record<string, number>;
195
+ isAbstract: boolean;
196
+ /** No classification names the class, though one names others: it is listed under "Other". */
197
+ unclassified?: boolean;
198
+ }
199
+
200
+ /** An RDF list's named items, in order (cycle-safe). */
201
+ function listItems(store: Store, head: Term): string[] {
202
+ const items: string[] = [];
203
+ const seen = new Set<string>();
204
+ for (let cell: Term | undefined = head; cell && !seen.has(cell.value) && cell.value !== `${NAMESPACES.rdf}nil`; ) {
205
+ seen.add(cell.value);
206
+ const first = store.getObjects(cell, namedNode(RDF_FIRST), null)[0];
207
+ if (first && isNamedNode(first)) items.push(first.value);
208
+ cell = store.getObjects(cell, namedNode(RDF_REST), null)[0];
209
+ }
210
+ return items;
211
+ }
212
+
213
+ /** A collection's members: its `skos:memberList` in order, then any `skos:member` not in it. */
214
+ function collectionMembers(store: Store, collection: Term): { members: string[]; ordered: boolean } {
215
+ const head = store.getObjects(collection, namedNode(SKOS_MEMBER_LIST), null)[0];
216
+ const listed = head ? listItems(store, head) : [];
217
+ const unlisted = store
218
+ .getObjects(collection, namedNode(SKOS_MEMBER), null)
219
+ .filter(isNamedNode)
220
+ .map((term) => term.value)
221
+ .filter((iri) => !listed.includes(iri));
222
+ return { members: unique([...listed, ...unlisted]), ordered: listed.length > 0 };
223
+ }
224
+
225
+ /**
226
+ * The axes a loaded metamodel's palette groups by, main one first (`arch:paletteGrouping`): the first
227
+ * metamodel's, in load order, that names any; without `metamodelIris`, any metamodel's. Empty when none does.
228
+ */
229
+ export function paletteGroupingOf(store: Store, metamodelIris: readonly string[] = []): string[] {
230
+ const subjects = metamodelIris.length > 0
231
+ ? metamodelIris.map((iri) => namedNode(iri))
232
+ : store.getSubjects(namedNode(ARCH_PALETTE_GROUPING), null, null);
233
+ for (const subject of subjects) {
234
+ for (const grouping of store.getObjects(subject, namedNode(ARCH_PALETTE_GROUPING), null)) {
235
+ const { members } = collectionMembers(store, grouping);
236
+ if (members.length > 0) return members;
237
+ }
238
+ }
239
+ return [];
240
+ }
241
+
242
+ /**
243
+ * Builds the classification axes present in a SKOS taxonomy.
244
+ *
245
+ * The taxonomy is walked using both `skos:narrower` and the inverse of `skos:broader`, so the
246
+ * result is independent of which direction the source data chose to model the hierarchy.
247
+ *
248
+ * Axis detection requires every concept-child of a candidate to classify at least one member
249
+ * (transitively) *and* at least one of them to list members directly. The first condition keeps a
250
+ * half-empty branch from being called an axis; the second is what keeps a mixed root — the top
251
+ * concept that parents several axes — from being reported as an axis itself, since an axis's own
252
+ * children are wrappers that list nothing. A candidate nested inside another candidate is
253
+ * discarded, so a sub-group of an axis is never mistaken for an axis of its own.
254
+ *
255
+ * When the taxonomy is flat (groups but no axis wrapper) a single axis labelled "Classification"
256
+ * is synthesised from every group in the scheme.
257
+ *
258
+ * A concept the palette grouping names (`arch:paletteGrouping`) is an axis whatever its shape;
259
+ * one inferred beneath it is not. Each axis's groups are ranked by its thesaurus array (`ranks`).
260
+ *
261
+ * Axes are ordered by the metamodel whose classification they belong to, in load order — so a
262
+ * language added beside another (Basic beside ArchiMate) never becomes the default grouping of
263
+ * the first one's palette — then by that metamodel's `arch:paletteGrouping`, then by label; the
264
+ * first axis becomes the default classification.
265
+ *
266
+ * @param store n3 store holding the taxonomy (and, optionally, the metamodel manifest).
267
+ * @param metamodelIris The loaded `arch:Metamodel` subjects, in load order. Without them,
268
+ * any metamodel's palette grouping orders the axes, then their labels.
269
+ * @returns The discovered axes, ordered by preference. Empty when no concept scheme is present.
270
+ */
271
+ export function buildClassificationAxes(
272
+ store: Store, metamodelIris: readonly string[] = [], preferredLanguage = 'en',
273
+ ): TaxonomyAxis[] {
274
+ // Prefer the scheme(s) the metamodel manifest points at; otherwise take every declared scheme.
275
+ const schemes = new Set<string>();
276
+ for (const quad of store.getQuads(null, namedNode(ARCH_CONCEPT_CLASSIFICATION), null, null)) {
277
+ if (quad.object.termType === 'NamedNode') schemes.add(quad.object.value);
278
+ }
279
+ const named = schemes.size > 0;
280
+ if (!named) {
281
+ for (const quad of store.getQuads(null, namedNode(RDF_TYPE), namedNode(SKOS_CONCEPT_SCHEME), null)) {
282
+ if (quad.subject.termType === 'NamedNode') schemes.add(quad.subject.value);
283
+ }
284
+ }
285
+ if (schemes.size === 0) return [];
286
+
287
+ const schemeConcepts = new Set<string>();
288
+ for (const schemeIri of schemes) {
289
+ for (const term of store.getSubjects(namedNode(SKOS_IN_SCHEME), namedNode(schemeIri), null)) {
290
+ addNamed(schemeConcepts, term);
291
+ }
292
+ for (const term of store.getSubjects(namedNode(SKOS_TOP_CONCEPT_OF), namedNode(schemeIri), null)) {
293
+ addNamed(schemeConcepts, term);
294
+ }
295
+ for (const term of store.getObjects(namedNode(schemeIri), namedNode(SKOS_HAS_TOP_CONCEPT), null)) {
296
+ addNamed(schemeConcepts, term);
297
+ }
298
+ }
299
+ // Anything typed skos:Concept counts too — some data omits inScheme on intermediate nodes.
300
+ // When the manifest names its classification schemes, only a concept beneath one of theirs:
301
+ // a concept of another scheme (a viewpoint catalogue, a scope scheme) is no axis of the palette.
302
+ const typedConcepts = new Set<string>();
303
+ for (const term of store.getSubjects(namedNode(RDF_TYPE), namedNode(SKOS_CONCEPT), null)) {
304
+ addNamed(typedConcepts, term);
305
+ }
306
+ if (!named) {
307
+ for (const iri of typedConcepts) schemeConcepts.add(iri);
308
+ } else {
309
+ const queue = [...schemeConcepts];
310
+ while (queue.length > 0) {
311
+ const current = queue.shift() as string;
312
+ const below = [
313
+ ...store.getObjects(namedNode(current), namedNode(SKOS_NARROWER), null),
314
+ ...store.getSubjects(namedNode(SKOS_BROADER), namedNode(current), null),
315
+ ];
316
+ for (const term of below) {
317
+ if (term.termType !== 'NamedNode' || !typedConcepts.has(term.value) || schemeConcepts.has(term.value)) continue;
318
+ schemeConcepts.add(term.value);
319
+ queue.push(term.value);
320
+ }
321
+ }
322
+ }
323
+
324
+ const isConcept = (iri: string): boolean => schemeConcepts.has(iri);
325
+
326
+ const skosChildrenOf = (conceptIri: string): string[] => {
327
+ const narrower = store
328
+ .getObjects(namedNode(conceptIri), namedNode(SKOS_NARROWER), null)
329
+ .filter(isNamedNode)
330
+ .map((term) => term.value);
331
+ const broaderInverse = store
332
+ .getSubjects(namedNode(SKOS_BROADER), namedNode(conceptIri), null)
333
+ .filter(isNamedNode)
334
+ .map((term) => term.value);
335
+ return unique([...narrower, ...broaderInverse]);
336
+ };
337
+
338
+ // A third style of listing members (DoDAF's, UAF's and the ML extension's taxonomies): a concept with nothing
339
+ // under it names the classes it groups with `rdfs:seeAlso` — "Capability Viewpoint" names Capability, Capability
340
+ // Increment and Desired Effect. One class named so may be the class the concept stands for (ArchiMate's style,
341
+ // below); several are its members, and then every sibling written the same way is a group too, the one that
342
+ // names a single class with it.
343
+ const seeAlsoClassesOf = (conceptIri: string): string[] =>
344
+ store
345
+ .getObjects(namedNode(conceptIri), namedNode(RDFS_SEE_ALSO), null)
346
+ .filter(isNamedNode)
347
+ .map((term) => term.value)
348
+ .filter((iri) => store.getQuads(namedNode(iri), namedNode(RDF_TYPE), namedNode(OWL_CLASS), null).length > 0);
349
+ const seeAlsoGroups = new Map<string, string[]>();
350
+ for (const concept of schemeConcepts) {
351
+ if (skosChildrenOf(concept).length > 0 || seeAlsoClassesOf(concept).length < 2) continue;
352
+ const parents = unique([
353
+ ...store.getObjects(namedNode(concept), namedNode(SKOS_BROADER), null).filter(isNamedNode).map((term) => term.value),
354
+ ...store.getSubjects(namedNode(SKOS_NARROWER), namedNode(concept), null).filter(isNamedNode).map((term) => term.value),
355
+ ]);
356
+ for (const sibling of [concept, ...parents.flatMap(skosChildrenOf)]) {
357
+ if (!schemeConcepts.has(sibling) || seeAlsoGroups.has(sibling) || skosChildrenOf(sibling).length > 0) continue;
358
+ const classes = seeAlsoClassesOf(sibling);
359
+ if (classes.length > 0) seeAlsoGroups.set(sibling, classes);
360
+ }
361
+ }
362
+
363
+ const childrenOf = (conceptIri: string): string[] => seeAlsoGroups.get(conceptIri) ?? skosChildrenOf(conceptIri);
364
+
365
+ const conceptChildrenOf = (conceptIri: string): string[] => childrenOf(conceptIri).filter(isConcept);
366
+
367
+ /** Broader direction: `skos:broader` plus the inverse of `skos:narrower`. */
368
+ const parentsOf = (conceptIri: string): string[] => {
369
+ const broader = store
370
+ .getObjects(namedNode(conceptIri), namedNode(SKOS_BROADER), null)
371
+ .filter(isNamedNode)
372
+ .map((term) => term.value);
373
+ const narrowerInverse = store
374
+ .getSubjects(namedNode(SKOS_NARROWER), namedNode(conceptIri), null)
375
+ .filter(isNamedNode)
376
+ .map((term) => term.value);
377
+ return unique([...broader, ...narrowerInverse]);
378
+ };
379
+
380
+ const isOwlClassIri = (iri: string): boolean =>
381
+ store.getQuads(namedNode(iri), namedNode(RDF_TYPE), namedNode(OWL_CLASS), null).length > 0;
382
+
383
+ let classFragments: Set<string> | undefined;
384
+ /**
385
+ * A concept that stands for an ontology class, as `buildClasses` resolves it: `rdfs:seeAlso` from the
386
+ * concept to the class or back, or a class of the same local name.
387
+ */
388
+ const standsForClass = (iri: string): boolean => {
389
+ if (store.getObjects(namedNode(iri), namedNode(RDFS_SEE_ALSO), null).some((term) => isOwlClassIri(term.value))) return true;
390
+ if (store.getSubjects(namedNode(RDFS_SEE_ALSO), namedNode(iri), null).some((term) => isOwlClassIri(term.value))) return true;
391
+ classFragments ??= new Set(
392
+ store.getSubjects(namedNode(RDF_TYPE), namedNode(OWL_CLASS), null).filter(isNamedNode).map((term) => iriFragment(term.value)),
393
+ );
394
+ const fragment = iriFragment(iri);
395
+ return fragment !== '' && classFragments.has(fragment);
396
+ };
397
+
398
+ // A member is an element type, which the ontology declares. Two modelling styles list one:
399
+ // - skos:narrower points straight at the OWL class (a non-concept node) — meta's taxonomies;
400
+ // - skos:narrower points at a terminal SKOS concept that stands for the class (rdfs:seeAlso, or
401
+ // the same local name).
402
+ // A concept with nothing under it and no class behind it is an empty concept: a concept, not an
403
+ // element type (ArchiMate 3.2's ArchiMate Element once its dimensions moved out from under it).
404
+ const isMemberLeaf = (iri: string): boolean =>
405
+ !isConcept(iri) || (childrenOf(iri).length === 0 && standsForClass(iri));
406
+ /** A concept with nothing under it that stands for no class: it classifies nothing, yet. */
407
+ const isEmptyConcept = (iri: string): boolean => isConcept(iri) && childrenOf(iri).length === 0 && !isMemberLeaf(iri);
408
+ const membersOf = (conceptIri: string): string[] => childrenOf(conceptIri).filter(isMemberLeaf);
409
+
410
+ const labelOf = (iri: string): string => labelFor(store, iri, preferredLanguage);
411
+
412
+ /** A concept that lists at least one member itself. */
413
+ const isGroup = (iri: string): boolean => isConcept(iri) && membersOf(iri).length > 0;
414
+
415
+ /**
416
+ * Every leaf member beneath `rootIri`, paired with the label of the nearest group listing it.
417
+ *
418
+ * Breadth-first so a member listed by the root itself wins over the same member reappearing
419
+ * deeper down, and cycle-safe: published SKOS should be a tree, but a `broader`/`narrower` loop
420
+ * must not spin here. `blocked` seeds the visited set — the caller passes the axis so a back
421
+ * edge out of the sub-tree is not followed.
422
+ */
423
+ const collectMembers = (rootIri: string, blocked: Iterable<string>): Array<[string, string]> => {
424
+ const found: Array<[string, string]> = [];
425
+ const seen = new Set<string>(blocked);
426
+ const queue: string[] = [];
427
+ if (!seen.has(rootIri)) {
428
+ seen.add(rootIri);
429
+ queue.push(rootIri);
430
+ }
431
+ while (queue.length > 0) {
432
+ const current = queue.shift();
433
+ if (current === undefined) break;
434
+ const currentLabel = labelOf(current);
435
+ for (const child of childrenOf(current)) {
436
+ if (isMemberLeaf(child)) {
437
+ found.push([child, currentLabel]);
438
+ } else if (!seen.has(child)) {
439
+ seen.add(child);
440
+ queue.push(child);
441
+ }
442
+ }
443
+ }
444
+ return found;
445
+ };
446
+
447
+ /** True when a concept classifies at least one member, directly or through a sub-group. */
448
+ const holdsMembersCache = new Map<string, boolean>();
449
+ const holdsMembers = (conceptIri: string): boolean => {
450
+ const cached = holdsMembersCache.get(conceptIri);
451
+ if (cached !== undefined) return cached;
452
+ const result = collectMembers(conceptIri, []).length > 0;
453
+ holdsMembersCache.set(conceptIri, result);
454
+ return result;
455
+ };
456
+
457
+ /**
458
+ * Candidate axes: a concept that lists no member of its own, whose concept-children all
459
+ * classify something, at least one of them directly.
460
+ *
461
+ * The "at least one directly" clause is what separates an axis from the root above it. An
462
+ * axis's children are groups and a group lists members; a root's children are axes and an axis
463
+ * lists nothing.
464
+ */
465
+ const axisCandidates = new Set<string>();
466
+ // Named by the palette grouping: an axis as published, whatever its shape, if any group is under it.
467
+ const namedAxes = new Set(
468
+ paletteGroupingOf(store, metamodelIris).filter(
469
+ (iri) => isConcept(iri) && conceptChildrenOf(iri).some((child) => holdsMembers(child)),
470
+ ),
471
+ );
472
+ for (const concept of namedAxes) axisCandidates.add(concept);
473
+ for (const concept of schemeConcepts) {
474
+ if (isGroup(concept)) continue;
475
+ // An empty concept beside the groups says nothing either way, so it does not stop its parent being an axis.
476
+ const conceptChildren = conceptChildrenOf(concept).filter((child) => !isEmptyConcept(child));
477
+ if (conceptChildren.length === 0) continue;
478
+ if (!conceptChildren.every((child) => holdsMembers(child))) continue;
479
+ if (!conceptChildren.some((child) => isGroup(child))) continue;
480
+ axisCandidates.add(concept);
481
+ }
482
+
483
+ /** True when `conceptIri` sits below another candidate — then that outer one is the axis. */
484
+ const hasCandidateAncestor = (conceptIri: string): boolean => {
485
+ const seen = new Set<string>([conceptIri]);
486
+ const queue = [...parentsOf(conceptIri)];
487
+ while (queue.length > 0) {
488
+ const current = queue.shift();
489
+ if (current === undefined) break;
490
+ if (seen.has(current)) continue;
491
+ seen.add(current);
492
+ if (axisCandidates.has(current)) return true;
493
+ queue.push(...parentsOf(current));
494
+ }
495
+ return false;
496
+ };
497
+
498
+ const axisConcepts = [...axisCandidates].filter((concept) => namedAxes.has(concept) || !hasCandidateAncestor(concept));
499
+
500
+ /** A concept's narrower concepts in order: the first thesaurus array under it (`iso-thes:superOrdinate`) that lists any. */
501
+ const orderOf = (axisIri: string): string[] => {
502
+ for (const array of store.getSubjects(namedNode(ISO_THES_SUPER_ORDINATE), namedNode(axisIri), null)) {
503
+ const { members, ordered } = collectionMembers(store, array);
504
+ if (ordered && members.length > 0) return members;
505
+ }
506
+ return [];
507
+ };
508
+
509
+ const buildAxis = (axisIri: string): TaxonomyAxis => {
510
+ const groups = new Map<string, string>();
511
+ const topGroups = new Map<string, string>();
512
+ const ranks = new Map<string, number>();
513
+ const order = orderOf(axisIri);
514
+ for (const groupIri of conceptChildrenOf(axisIri)) {
515
+ if (!holdsMembers(groupIri)) continue;
516
+ const topLabel = labelOf(groupIri);
517
+ const rank = order.indexOf(groupIri);
518
+ // Transitive: a member nested any number of sub-groups down still belongs to this branch.
519
+ for (const [member, groupLabel] of collectMembers(groupIri, [axisIri])) {
520
+ if (groups.has(member)) continue;
521
+ groups.set(member, groupLabel);
522
+ topGroups.set(member, topLabel);
523
+ if (rank >= 0) ranks.set(member, rank);
524
+ }
525
+ }
526
+ // Within a group, its members' order: the thesaurus array under the group itself (iso-thes:superOrdinate),
527
+ // where it has one — the nearest group's, as a member nested deeper is listed by its own group's array.
528
+ const memberRanks = new Map<string, number>();
529
+ const seen = new Set<string>([axisIri]);
530
+ const queue = [...conceptChildrenOf(axisIri)];
531
+ while (queue.length > 0) {
532
+ const concept = queue.shift() as string;
533
+ if (seen.has(concept)) continue;
534
+ seen.add(concept);
535
+ orderOf(concept).forEach((member, index) => {
536
+ if (groups.has(member) && !memberRanks.has(member)) memberRanks.set(member, index);
537
+ });
538
+ queue.push(...conceptChildrenOf(concept));
539
+ }
540
+ return { iri: axisIri, label: labelOf(axisIri), groups, topGroups, ranks, memberRanks };
541
+ };
542
+
543
+ let axes = axisConcepts.map(buildAxis).filter((axis) => axis.groups.size > 0);
544
+
545
+ // A group under no axis and no other group — ArchiMate's Junction, a top concept of its own — classifies
546
+ // its members all the same: an element type the taxonomy lists is one, wherever it lists it.
547
+ if (axes.length > 0) {
548
+ const axisSet = new Set(axisConcepts);
549
+ const underAxisOrGroup = (conceptIri: string): boolean => {
550
+ const seen = new Set<string>([conceptIri]);
551
+ const queue = [...parentsOf(conceptIri)];
552
+ while (queue.length > 0) {
553
+ const current = queue.shift() as string;
554
+ if (seen.has(current)) continue;
555
+ seen.add(current);
556
+ if (axisSet.has(current) || isGroup(current)) return true;
557
+ queue.push(...parentsOf(current));
558
+ }
559
+ return false;
560
+ };
561
+ for (const concept of schemeConcepts) {
562
+ if (!isGroup(concept) || axisSet.has(concept) || underAxisOrGroup(concept)) continue;
563
+ const label = labelOf(concept);
564
+ const groups = new Map<string, string>();
565
+ for (const [member, groupLabel] of collectMembers(concept, [])) if (!groups.has(member)) groups.set(member, groupLabel);
566
+ if (groups.size === 0) continue;
567
+ const topGroups = new Map([...groups.keys()].map((member) => [member, label] as [string, string]));
568
+ axes.push({ iri: concept, label, groups, topGroups, ranks: new Map(), standalone: true });
569
+ }
570
+ }
571
+
572
+ // Flat taxonomy: groups but no axis wrapper — synthesise one axis over every group.
573
+ if (axes.length === 0) {
574
+ const groups = new Map<string, string>();
575
+ for (const concept of schemeConcepts) {
576
+ if (!isGroup(concept)) continue;
577
+ const groupLabel = labelOf(concept);
578
+ for (const member of membersOf(concept)) {
579
+ if (!groups.has(member)) groups.set(member, groupLabel);
580
+ }
581
+ }
582
+ if (groups.size > 0) {
583
+ const [firstScheme] = [...schemes];
584
+ // Nothing nests here, so every group is its own top-level group.
585
+ axes = [{ iri: firstScheme ?? '', label: 'Classification', groups, topGroups: new Map(groups), ranks: new Map() }];
586
+ }
587
+ }
588
+
589
+ // The first-loaded language's axes first: a language added beside it must not
590
+ // become the default grouping of its palette. An axis ranks by the first
591
+ // loaded metamodel whose arch:conceptClassification is the axis's scheme, or
592
+ // whose arch:paletteGrouping names it.
593
+ const schemeRank = new Map<string, number>();
594
+ const groupingRank = new Map<string, number>();
595
+ metamodelIris.forEach((metamodelIri, index) => {
596
+ for (const scheme of store.getObjects(namedNode(metamodelIri), namedNode(ARCH_CONCEPT_CLASSIFICATION), null)) {
597
+ if (!schemeRank.has(scheme.value)) schemeRank.set(scheme.value, index);
598
+ }
599
+ for (const axisIri of paletteGroupingOf(store, [metamodelIri])) {
600
+ if (!groupingRank.has(axisIri)) groupingRank.set(axisIri, index);
601
+ }
602
+ });
603
+ // Within a language, the palette grouping's order: the axes it names first, the main one first.
604
+ const grouping = paletteGroupingOf(store, metamodelIris);
605
+ const groupingPosition = (axisIri: string): number => {
606
+ const position = grouping.indexOf(axisIri);
607
+ return position < 0 ? Number.MAX_SAFE_INTEGER : position;
608
+ };
609
+ const rankOf = (axisIri: string): number => {
610
+ let rank = groupingRank.get(axisIri) ?? Number.MAX_SAFE_INTEGER;
611
+ for (const scheme of [
612
+ ...store.getObjects(namedNode(axisIri), namedNode(SKOS_IN_SCHEME), null),
613
+ ...store.getObjects(namedNode(axisIri), namedNode(SKOS_TOP_CONCEPT_OF), null),
614
+ ...store.getSubjects(namedNode(SKOS_HAS_TOP_CONCEPT), namedNode(axisIri), null),
615
+ ]) {
616
+ rank = Math.min(rank, schemeRank.get(scheme.value) ?? Number.MAX_SAFE_INTEGER);
617
+ }
618
+ return rank;
619
+ };
620
+ axes.sort(
621
+ (a, b) =>
622
+ rankOf(a.iri) - rankOf(b.iri) ||
623
+ Number(a.standalone ?? false) - Number(b.standalone ?? false) ||
624
+ groupingPosition(a.iri) - groupingPosition(b.iri) ||
625
+ a.label.localeCompare(b.label),
626
+ );
627
+
628
+ return axes;
629
+ }
630
+
631
+ /**
632
+ * Builds the instantiable palette classes for a set of classification axes.
633
+ *
634
+ * The taxonomy decides which concepts appear and how they are grouped; the OWL ontology supplies
635
+ * the class that is actually instantiated. The two are joined by {@link resolveOwlClass}-style
636
+ * resolution: same IRI, forward `rdfs:seeAlso`, reverse `rdfs:seeAlso`, then local-name match.
637
+ *
638
+ * Excluded from the result: classes in the `arch:` core namespace, classes flagged
639
+ * `arch:isAbstractClass true`, and relationship classes (transitive-closure hit on
640
+ * `arch:QualifiedRelationship`, or a well-known relationship local name).
641
+ *
642
+ * When `axes` is empty — or its schemes classify none of the classes — there is no taxonomy to drive grouping, so
643
+ * the function falls back to an OWL-only walk over the non-abstract subclasses of `arch:Element` / `arch:ModelConcept`.
644
+ *
645
+ * @param store n3 store holding the taxonomy and the OWL ontology.
646
+ * @param axes Axes from {@link buildClassificationAxes}; the first supplies the default group.
647
+ * @returns Palette classes sorted by group then label.
648
+ */
649
+ export function buildClasses(store: Store, axes: TaxonomyAxis[], preferredLanguage = 'en'): SemanticClass[] {
650
+ const allClassIris = new Set<string>();
651
+ for (const term of store.getSubjects(namedNode(RDF_TYPE), namedNode(OWL_CLASS), null)) {
652
+ addNamed(allClassIris, term);
653
+ }
654
+ for (const term of store.getSubjects(null, namedNode(RDFS_SUBCLASS), null)) {
655
+ addNamed(allClassIris, term);
656
+ }
657
+
658
+ const superClassMap = new Map<string, string[]>();
659
+ for (const iri of allClassIris) {
660
+ const supers = store
661
+ .getObjects(namedNode(iri), namedNode(RDFS_SUBCLASS), null)
662
+ .filter(isNamedNode)
663
+ .map((term) => term.value);
664
+ superClassMap.set(iri, unique(supers));
665
+ }
666
+
667
+ const isOwlClass = (iri: string): boolean =>
668
+ store.getQuads(namedNode(iri), namedNode(RDF_TYPE), namedNode(OWL_CLASS), null).length > 0;
669
+
670
+ /** Resolves a taxonomy member IRI to the instantiable OWL class it stands for. */
671
+ const resolveOwlClass = (memberIri: string): string | null => {
672
+ // 1. The member is itself an owl:Class.
673
+ if (isOwlClass(memberIri)) return memberIri;
674
+ // 2. Forward rdfs:seeAlso from the SKOS concept to the OWL class.
675
+ const forward = store
676
+ .getObjects(namedNode(memberIri), namedNode(RDFS_SEE_ALSO), null)
677
+ .filter(isNamedNode)
678
+ .find((term) => isOwlClass(term.value));
679
+ if (forward) return forward.value;
680
+ // 3. Reverse rdfs:seeAlso from the OWL class back to the SKOS concept.
681
+ const reverse = store
682
+ .getSubjects(namedNode(RDFS_SEE_ALSO), namedNode(memberIri), null)
683
+ .filter(isNamedNode)
684
+ .find((term) => isOwlClass(term.value));
685
+ if (reverse) return reverse.value;
686
+ // 4. Last resort: same local name in a different namespace.
687
+ const fragment = iriFragment(memberIri);
688
+ if (fragment) {
689
+ const candidate = [...allClassIris].find((cls) => iriFragment(cls) === fragment);
690
+ if (candidate) return candidate;
691
+ }
692
+ return null;
693
+ };
694
+
695
+ if (axes.length > 0) {
696
+ // The union of leaf members across every axis is the set of palette element concepts.
697
+ const memberIris = new Set<string>();
698
+ for (const axis of axes) {
699
+ for (const member of axis.groups.keys()) memberIris.add(member);
700
+ }
701
+
702
+ const seenOwl = new Set<string>();
703
+ const taxonomyResult: SemanticClass[] = [];
704
+ for (const memberIri of memberIris) {
705
+ const owlClassIri = resolveOwlClass(memberIri);
706
+ if (!owlClassIri || seenOwl.has(owlClassIri)) continue;
707
+ // A core class (arch:Element, arch:QualifiedRelationship) is never a palette
708
+ // type: languages specialise it — Basic's Node and Connection are the
709
+ // generic ones — and a taxonomy listing one does not make it one.
710
+ if (owlClassIri.startsWith(CORE)) continue;
711
+
712
+ if (isAbstractClass(store, owlClassIri)) continue;
713
+
714
+ const closure = computeClosure(owlClassIri, superClassMap);
715
+ // By its superclasses; by a well-known relationship name only where they do not say it is an element
716
+ // (EA on a Page's Realization, a phase of a process, is one).
717
+ const isRelationship =
718
+ owlClassIri === CORE_QUALIFIED_RELATIONSHIP ||
719
+ closure.includes(CORE_QUALIFIED_RELATIONSHIP) ||
720
+ (RELATIONSHIP_FRAGMENTS.has(iriFragment(owlClassIri)) && !closure.includes(CORE_ELEMENT));
721
+ if (isRelationship) continue;
722
+
723
+ seenOwl.add(owlClassIri);
724
+
725
+ // Record the group under each axis; the first axis provides the default group.
726
+ const groupsByAxis: Record<string, string> = {};
727
+ const ranksByAxis: Record<string, number> = {};
728
+ const memberRanksByAxis: Record<string, number> = {};
729
+ for (const axis of axes) {
730
+ const group = axis.groups.get(memberIri);
731
+ if (group) groupsByAxis[axis.iri] = group;
732
+ const rank = axis.ranks.get(memberIri);
733
+ if (rank !== undefined) ranksByAxis[axis.iri] = rank;
734
+ const memberRank = axis.memberRanks?.get(memberIri);
735
+ if (memberRank !== undefined) memberRanksByAxis[axis.iri] = memberRank;
736
+ }
737
+ const primaryAxis = axes[0];
738
+ const defaultGroup =
739
+ (primaryAxis ? groupsByAxis[primaryAxis.iri] : undefined) ?? Object.values(groupsByAxis)[0] ?? 'Other';
740
+
741
+ taxonomyResult.push({
742
+ iri: owlClassIri,
743
+ label: labelFor(store, memberIri, preferredLanguage, owlClassIri),
744
+ definition: definitionFor(store, memberIri, preferredLanguage) ?? definitionFor(store, owlClassIri, preferredLanguage),
745
+ superClasses: superClassMap.get(owlClassIri) ?? [],
746
+ transitiveSuperClasses: closure,
747
+ group: defaultGroup,
748
+ groupsByAxis,
749
+ ranksByAxis,
750
+ ...(Object.keys(memberRanksByAxis).length > 0 ? { memberRanksByAxis } : {}),
751
+ isAbstract: false,
752
+ });
753
+ }
754
+
755
+ // Schemes that classify no class at all are no taxonomy of these classes — core's question stages are all a
756
+ // metamodel without a classification of its own has — so the OWL walk alone finds them. Where the schemes
757
+ // classify some, the element classes they leave out — a metamodel loaded beside this one with no classification,
758
+ // or one whose classification is incomplete — follow under "Other": a type the ontology defines is one to draw.
759
+ if (taxonomyResult.length > 0) {
760
+ const classified = taxonomyResult.sort((a, b) => a.group.localeCompare(b.group) || a.label.localeCompare(b.label));
761
+ const rest = owlWalk()
762
+ .filter((cls) => !seenOwl.has(cls.iri))
763
+ .map((cls) => ({ ...cls, group: UNCLASSIFIED_GROUP, unclassified: true }));
764
+ return [...classified, ...rest.sort((a, b) => a.label.localeCompare(b.label))];
765
+ }
766
+ }
767
+
768
+ // Fallback: no taxonomy of these classes — the OWL walk, grouped by a guess from each class's name.
769
+ return owlWalk().sort((a, b) => a.group.localeCompare(b.group) || a.label.localeCompare(b.label));
770
+
771
+ /** Every non-abstract subclass of `arch:Element` that is no relationship type and no core class. */
772
+ function owlWalk(): SemanticClass[] {
773
+ const result: SemanticClass[] = [];
774
+ for (const iri of allClassIris) {
775
+ const closure = computeClosure(iri, superClassMap);
776
+ const isSubOfElement = closure.includes(CORE_ELEMENT) || closure.includes(CORE_MODEL_CONCEPT);
777
+ if (!isSubOfElement) continue;
778
+ if (iri === CORE_ELEMENT || iri === CORE_MODEL_CONCEPT) continue;
779
+ if (iri.startsWith(CORE)) continue;
780
+ // A kind of view (BPMN's diagram) is a model concept and no element: nothing to place on a diagram.
781
+ if (closure.includes(CORE_VIEW)) continue;
782
+
783
+ const fragment = iriFragment(iri);
784
+ const isRelationship =
785
+ closure.includes(CORE_QUALIFIED_RELATIONSHIP) || (RELATIONSHIP_FRAGMENTS.has(fragment) && !closure.includes(CORE_ELEMENT));
786
+ if (isRelationship) continue;
787
+
788
+ if (isAbstractClass(store, iri) || ABSTRACT_FRAGMENTS.has(fragment)) continue;
789
+
790
+ result.push({
791
+ iri,
792
+ label: labelFor(store, iri, preferredLanguage),
793
+ definition: definitionFor(store, iri, preferredLanguage),
794
+ superClasses: superClassMap.get(iri) ?? [],
795
+ transitiveSuperClasses: closure,
796
+ group: groupFor(iri, closure),
797
+ groupsByAxis: {},
798
+ ranksByAxis: {},
799
+ isAbstract: false,
800
+ });
801
+ }
802
+ return result;
803
+ }
804
+ }
805
+
806
+ /**
807
+ * Tests whether a class closure satisfies a domain/range constraint.
808
+ * `arch:Element` and `arch:ModelConcept` are treated as universally permissive.
809
+ *
810
+ * @param closure The class IRI plus its transitive superclasses.
811
+ * @param allowedIri The constraint IRI to check against.
812
+ */
813
+ export function matchesClass(closure: string[], allowedIri: string): boolean {
814
+ if (allowedIri === CORE_ELEMENT || allowedIri === CORE_MODEL_CONCEPT) return true;
815
+ return closure.includes(allowedIri);
816
+ }
817
+
818
+ /** True when the class carries `arch:isAbstractClass true`. */
819
+ function isAbstractClass(store: Store, iri: string): boolean {
820
+ return store
821
+ .getObjects(namedNode(iri), namedNode(ARCH_IS_ABSTRACT_CLASS), null)
822
+ .some((term) => term.value === 'true');
823
+ }
824
+
825
+ /** Transitive `rdfs:subClassOf` closure of `iri`, excluding `iri` itself. */
826
+ function computeClosure(iri: string, superClassMap: Map<string, string[]>): string[] {
827
+ const seen = new Set<string>();
828
+ const stack = [...(superClassMap.get(iri) ?? [])];
829
+ while (stack.length) {
830
+ const current = stack.pop();
831
+ if (!current || seen.has(current)) continue;
832
+ seen.add(current);
833
+ for (const parent of superClassMap.get(current) ?? []) stack.push(parent);
834
+ }
835
+ return [...seen];
836
+ }
837
+
838
+ /** Group heuristic used only by the OWL-only fallback, where no taxonomy exists. */
839
+ function groupFor(iri: string, closure: string[]): string {
840
+ const has = (fragment: string): boolean => closure.includes(`${ARCHIMATE_ONTO}${fragment}`) || iri.endsWith(fragment);
841
+ if (has('BusinessDomainElement')) return 'Business';
842
+ if (has('ApplicationDomainElement')) return 'Application';
843
+ if (has('TechnologyDomainElement')) return 'Technology';
844
+ if (has('StrategyElement')) return 'Strategy';
845
+ if (has('MotivationElement')) return 'Motivation';
846
+ if (has('ImplementationAndMigrationDomainElement')) return 'Implementation & Migration';
847
+ if (has('CommonDomainElement')) return 'Common';
848
+
849
+ // Last fallback: derive the group from the class's namespace.
850
+ const hashIdx = iri.lastIndexOf('#');
851
+ if (hashIdx > 0) {
852
+ const ns = iri.slice(0, hashIdx);
853
+ const lastSegment = ns.split('/').pop() ?? '';
854
+ if (lastSegment && lastSegment !== 'onto') return fragmentToLabel(lastSegment);
855
+ }
856
+ return 'Other';
857
+ }
858
+
859
+ /** A taxonomy member and its ontology class can each supply a label. */
860
+ function labelFor(store: Store, iri: string, preferredLanguage: string, classIri = iri): string {
861
+ const subjects = iri === classIri ? [iri] : [iri, classIri];
862
+ for (const predicate of [SKOS_PREF_LABEL, RDFS_LABEL]) {
863
+ const terms = subjects.flatMap(subject => store.getObjects(namedNode(subject), namedNode(predicate), null));
864
+ const literal = selectLocalizedLiteral(terms, preferredLanguage);
865
+ if (literal) return literal.value;
866
+ }
867
+ return fragmentToLabel(iriFragment(classIri));
868
+ }
869
+
870
+ /** Definition: `skos:definition`, then `rdfs:comment`. */
871
+ function definitionFor(store: Store, iri: string, preferredLanguage: string): string | undefined {
872
+ for (const predicate of [SKOS_DEFINITION, RDFS_COMMENT]) {
873
+ const literal = selectLocalizedLiteral(store.getObjects(namedNode(iri), namedNode(predicate), null), preferredLanguage);
874
+ if (literal) return literal.value;
875
+ }
876
+ return undefined;
877
+ }
878
+
879
+ /** Local name of an IRI: the part after the last `#`, or after the last `/`. */
880
+ function iriFragment(iri: string): string {
881
+ return iri.includes('#') ? iri.slice(iri.lastIndexOf('#') + 1) : iri.slice(iri.lastIndexOf('/') + 1);
882
+ }
883
+
884
+ /** Humanises a local name: `BusinessActor` becomes `Business Actor`. */
885
+ function fragmentToLabel(fragment: string): string {
886
+ return fragment
887
+ .replace(/([a-z])([A-Z])/g, '$1 $2')
888
+ .replace(/[-_]/g, ' ')
889
+ .replace(/\s+/g, ' ')
890
+ .trim();
891
+ }
892
+
893
+ /** Adds `term.value` to `set` when the term is a named node. */
894
+ function addNamed(set: Set<string>, term: Term): void {
895
+ if (isNamedNode(term)) set.add(term.value);
896
+ }
897
+
898
+ function isNamedNode<T extends Term>(term: T): term is Extract<T, NamedNode> {
899
+ return term.termType === 'NamedNode';
900
+ }
901
+
902
+ function unique<T>(items: T[]): T[] {
903
+ return [...new Set(items)];
904
+ }