diff --git a/config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250707132349-chore--extract-scopes-for-worship-organisations.sparql b/config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250707132349-chore--extract-scopes-for-worship-organisations.sparql new file mode 100644 index 0000000..07a5da9 --- /dev/null +++ b/config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250707132349-chore--extract-scopes-for-worship-organisations.sparql @@ -0,0 +1,112 @@ +PREFIX ere: +PREFIX org: +PREFIX besluit: + +# This migration extracts the relations between (central) worship services and +# their locations according to the rules provided by business. These links are +# inserted into a temporary graph for further processing. + +# Worship services +## Municipality organised +INSERT { + GRAPH { + ?ws besluit:werkingsgebied ?scope . + } +} WHERE { + GRAPH { + ?ws a ere:BestuurVanDeEredienst ; + ere:typeEredienst ?worshipType . + VALUES ?worshipType { + # Anglicaans + # Israƫlitisch + # Protestants + # Rooms-Katholiek + } + + ?involvement a ere:BetrokkenLokaleBesturen ; + org:organization ?ws ; + ere:typebetrokkenheid ?involvementType . + VALUES ?involvementType { + # Mede-financierend + # Toezichthoudend + } + ?org ere:betrokkenBestuur ?involvement . + } + GRAPH { + ?org besluit:werkingsgebied ?scope . + } +} +; +## Province organised +INSERT { + GRAPH { + ?ws besluit:werkingsgebied ?scope . + } +} WHERE { + GRAPH { + ?ws a ere:BestuurVanDeEredienst ; + ere:typeEredienst ?worshipType . + VALUES ?worshipType { + # Islamitisch + # Orthodox + } + + ?involvement a ere:BetrokkenLokaleBesturen ; + org:organization ?ws ; + ere:typebetrokkenheid ?involvementType . + VALUES ?involvementType { + # Adviserend + } + ?org ere:betrokkenBestuur ?involvement . + } + GRAPH { + ?org besluit:werkingsgebied ?scope . + } +} +; +# Central worship services +## Municipality organised +INSERT { + GRAPH { + ?ws besluit:werkingsgebied ?scope . + } +} WHERE { + GRAPH { + ?ws a ere:CentraalBestuurVanDeEredienst ; + ere:typeEredienst ?worshipType . + VALUES ?worshipType { + # Rooms-Katholiek + } + + ?involvement a ere:BetrokkenLokaleBesturen ; + org:organization ?ws ; + ere:typebetrokkenheid ?involvementType . + VALUES ?involvementType { + # Toezichthoudend + } + ?org ere:betrokkenBestuur ?involvement . + } + GRAPH { + ?org besluit:werkingsgebied ?scope . + } +} +; +## Province organised +## Note: Business requested to use the location for the municipality of Ghent as +## default value. They will update it manually afterwards. +INSERT { + GRAPH { + ?ws besluit:werkingsgebied ?locationGhent . + } +} WHERE { + GRAPH { + ?ws a ere:CentraalBestuurVanDeEredienst ; + ere:typeEredienst ?worshipType . + VALUES ?worshipType { + # Islamitisch + # Orthodox + } + + BIND(URI("http://data.lblod.info/id/werkingsgebieden/ce94eeae827cdc5c00f3f2f4276ff628580edefb3aa5861e4669b0c5d93adc57") AS ?locationGhent) + } +} diff --git a/config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250709140704-feat--set-scope-for-worship-organisations-with-single-location.sparql b/config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250709140704-feat--set-scope-for-worship-organisations-with-single-location.sparql new file mode 100644 index 0000000..c1355dd --- /dev/null +++ b/config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250709140704-feat--set-scope-for-worship-organisations-with-single-location.sparql @@ -0,0 +1,24 @@ +PREFIX besluit: + +# This migration sets the scope of operation for worship organisations that have +# single, already existing, location as scope. This migration depends on +# `20250707132349-chore--extract-scopes-for-worship-organisations` being +# executed first, as it uses the data created by the migration. +INSERT { + GRAPH { + ?ws besluit:werkingsgebied ?scope . + } +} WHERE { + { + SELECT DISTINCT ?ws (count(DISTINCT ?scope) as ?count) + WHERE { + GRAPH { + ?ws besluit:werkingsgebied ?scope . + } + } + } + FILTER (?count = 1) + GRAPH { + ?ws besluit:werkingsgebied ?scope . + } +} diff --git a/config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250709160017-feat--set-scope-for-worship-organisations-with-multiple-locations.sparql b/config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250709160017-feat--set-scope-for-worship-organisations-with-multiple-locations.sparql new file mode 100644 index 0000000..c8d2754 --- /dev/null +++ b/config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250709160017-feat--set-scope-for-worship-organisations-with-multiple-locations.sparql @@ -0,0 +1,49 @@ +PREFIX prov: +PREFIX mu: +PREFIX ext: +PREFIX geo: +PREFIX besluit: +PREFIX rdfs: + +# This migration sets the scope of operation for worship organisations that have +# multiple location as scope. It creates new aggregate locations to contain the +# already existing municipality/province level ones. This migration depends on +# `20250707132349-chore--extract-scopes-for-worship-organisations` being +# executed first, as it uses the data created by the migration. +INSERT { + GRAPH { + ?location a prov:Location ; + mu:uuid ?locationUuid ; + rdfs:label ?scopeLabel ; + ext:werkingsgebiedNiveau """Samengesteld werkingsgebied""" . + ?scope geo:sfWithin ?location . + } + GRAPH { + ?ws besluit:werkingsgebied ?location . + } +} WHERE { + { + SELECT DISTINCT ?ws (count(DISTINCT ?scope) AS ?count) (GROUP_CONCAT(?uuid," ") AS ?scopeUuids) (GROUP_CONCAT(?label,", ") AS ?scopeLabel) + WHERE { + GRAPH { + ?ws besluit:werkingsgebied ?scope . + } + GRAPH { + ?scope mu:uuid ?uuid ; + rdfs:label ?label . + } + } + } + FILTER (?count > 1) + GRAPH { + ?ws besluit:werkingsgebied ?scope . + } + # NOTE (10/07/2025): The SPARQL specification does not specify any order for + # `GROUP_CONCAT`. But virtuoso does seem to concatenate elements always in the + # same order. Therefore, this way of generating a UUID is a bit of a hack to + # ensure that new locations that contain the same locations will receive the + # same UUUID, which results in the same location resource being inserted + # twice. + BIND (STR(SHA256(?scopeUuids)) AS ?locationUuid) + BIND (URI(CONCAT("http://data.lblod.info/id/werkingsgebieden/", ?locationUuid)) AS ?location) +} diff --git a/config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250710095207-chore--clear-temp-graph-worship-scopes.sparql b/config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250710095207-chore--clear-temp-graph-worship-scopes.sparql new file mode 100644 index 0000000..0ec8f78 --- /dev/null +++ b/config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250710095207-chore--clear-temp-graph-worship-scopes.sparql @@ -0,0 +1 @@ +CLEAR GRAPH