From 04298db9e57d1e7d1f84c380715a7a4789d9956b Mon Sep 17 00:00:00 2001 From: mirdono Date: Thu, 24 Oct 2024 12:41:43 +0200 Subject: [PATCH] fix: delete superfluous relations between APBs and municipalities A number of APBs were accidentally `org:linkedTo` all municipalities in municipality and an APB for which: - the APB is linked to more than 1 municipality; and - the municipality does not match that of the APB's primary site. The first condition avoids we remove `org:linkedTo` triples for APBs that were created by the users, as these are only linked with a single municipality. --- ...nks-between-apbs-and-municipalities.sparql | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 config/migrations/2024/20241024103653-delete-incorrect-links-between-apbs-and-municipalities.sparql diff --git a/config/migrations/2024/20241024103653-delete-incorrect-links-between-apbs-and-municipalities.sparql b/config/migrations/2024/20241024103653-delete-incorrect-links-between-apbs-and-municipalities.sparql new file mode 100644 index 0000000..1902e4f --- /dev/null +++ b/config/migrations/2024/20241024103653-delete-incorrect-links-between-apbs-and-municipalities.sparql @@ -0,0 +1,36 @@ +PREFIX besluit: +PREFIX org: +PREFIX organisatie: +PREFIX adres: +PREFIX skos: + +DELETE { + GRAPH { + ?municipality org:linkedTo ?apb . + } +} WHERE { + GRAPH { + ?apb a besluit:Bestuurseenheid; + org:classification ; # APB + org:hasPrimarySite/organisatie:bestaatUit/adres:gemeentenaam ?apbMunicipalityName . + ?municipality org:linkedTo ?apb . + # Filter APBs with more than 1 linked municipality, this avoids removing + # triples for APBs created by users. + { + SELECT DISTINCT ?apb + WHERE { + GRAPH { + ?municipality org:linkedTo ?apb . + } + } GROUP BY ?apb HAVING (COUNT(?municipality) > 1) + } + } + # Filter municipalities that are different from the APB's primary site's + # municipality + GRAPH { + ?municipality a besluit:Bestuurseenheid; + org:classification ; # municipality + skos:prefLabel ?municipalityName . + } + FILTER (?apbMunicipalityName != ?municipalityName) +}