From 387ef1eeea25dba2a929d28cd997d7654c34cd1a Mon Sep 17 00:00:00 2001 From: mirdono Date: Tue, 8 Jul 2025 15:44:12 +0200 Subject: [PATCH] feat: set scope of operation for worship administrative units Add migrations to set the initial scope of operation for worship administrative units. These migrations work in several steps: 1. Extract the necessary relations between worship administrative units and locations based on the rules provided by business and insert this data in a temporary graph. 2. For worship administrative units related to only a single location. Simply add the triple setting that location as its scope of operation. 3. For worship administrative units related to multiple locations. Create new location resources that aggregates all locations linked to a single worship administrative unit and set this new location resource as scope of operation. 4. Clear the temporary graph. --- ...ct-scopes-for-worship-organisations.sparql | 112 ++++++++++++++++++ ...-organisations-with-single-location.sparql | 24 ++++ ...ganisations-with-multiple-locations.sparql | 49 ++++++++ ...re--clear-temp-graph-worship-scopes.sparql | 1 + 4 files changed, 186 insertions(+) create mode 100644 config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250707132349-chore--extract-scopes-for-worship-organisations.sparql create mode 100644 config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250709140704-feat--set-scope-for-worship-organisations-with-single-location.sparql create mode 100644 config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250709160017-feat--set-scope-for-worship-organisations-with-multiple-locations.sparql create mode 100644 config/migrations/2025/20250707132349-feat--add-scope-for-operation-worship-organisations/20250710095207-chore--clear-temp-graph-worship-scopes.sparql 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