From 8143aac736c8a090f413162b8c8f84c9c0915869 Mon Sep 17 00:00:00 2001 From: mirdono Date: Tue, 17 Dec 2024 11:00:15 +0100 Subject: [PATCH] chore: regenerate full addresses to reflect address changes This migration regenerates the `locn:fullAddress` triples for addresses in a municipality involved in a merger. In essences this migration updates the `locn:fullAddress` triple for each address changed by the migrations in the previous commit. Notes - The migration is split over two queries, one for addresses without a box number and one for addresses with a box number. This avoids complicating the query with conditional logic at the cost of code duplication in the queries. - In the existing full address triples two different notations are used to separate the box and building number. OP currently separates them simply by a space, which is what this migration matches for. But some historical data uses a dash "-" to separate building and box number. Consequently, this migration might match more address resources than strictly updated for the municipality merges. --- ...ddress-triple-for-changed-addresses.sparql | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 config/migrations-triggering-indexing/2024/20241217082404-mergers-2025--update-addresses/20241217083314-regenerate-full-address-triple-for-changed-addresses.sparql diff --git a/config/migrations-triggering-indexing/2024/20241217082404-mergers-2025--update-addresses/20241217083314-regenerate-full-address-triple-for-changed-addresses.sparql b/config/migrations-triggering-indexing/2024/20241217082404-mergers-2025--update-addresses/20241217083314-regenerate-full-address-triple-for-changed-addresses.sparql new file mode 100644 index 0000000..5f2659d --- /dev/null +++ b/config/migrations-triggering-indexing/2024/20241217082404-mergers-2025--update-addresses/20241217083314-regenerate-full-address-triple-for-changed-addresses.sparql @@ -0,0 +1,92 @@ +PREFIX locn: +PREFIX adres: +PREFIX organisatie: +PREFIX org: + +DELETE { + GRAPH ?g { + ?address locn:fullAddress ?fullAddress. + } +} INSERT { + GRAPH ?g { + ?address locn:fullAddress ?newFullAddress. + } +} WHERE { + GRAPH ?g { + ?address locn:fullAddress ?fullAddress; + locn:thoroughfare ?street; + adres:Adresvoorstelling.huisnummer ?buildingNo; + locn:postCode ?postalCode; + adres:gemeentenaam ?municipality; + adres:land ?country. + FILTER NOT EXISTS { ?address adres:Adresvoorstelling.busnummer ?boxNo. } + FILTER (EXISTS { ?site organisatie:bestaatUit ?address. } || + EXISTS { ?site org:siteAddress/locn:address ?address. }) + FILTER (?municipality IN ( + "Antwerpen", + "Pajottegem", + "Wingene", + "Tielt", + "Nazareth-De Pinte", + "Lochristi", + "Lokeren", + "Merelbeke-Melle", + "Beveren-Kruibeke-Zwijndrecht", + "Bilzen-Hoeselt", + "Tongeren-Borgloon", + "Tessenderlo-Ham", + "Hasselt" + )) + BIND (CONCAT(?street, " ", ?buildingNo, ", ", ?postalCode, " ", ?municipality, ", ", ?country) AS ?newFullAddress) + FILTER (?fullAddress != ?newFullAddress) + } + + VALUES ?g { + + + } +} +; +DELETE { + GRAPH ?g { + ?address locn:fullAddress ?fullAddress. + } +} INSERT { + GRAPH ?g { + ?address locn:fullAddress ?newFullAddress. + } +} WHERE { + GRAPH ?g { + ?address locn:fullAddress ?fullAddress; + locn:thoroughfare ?street; + adres:Adresvoorstelling.huisnummer ?buildingNo; + adres:Adresvoorstelling.busnummer ?boxNo; + locn:postCode ?postalCode; + adres:gemeentenaam ?municipality; + adres:land ?country. + FILTER (EXISTS { ?site organisatie:bestaatUit ?address. } || + EXISTS { ?site org:siteAddress/locn:address ?address. }) + FILTER (?municipality IN ( + "Antwerpen", + "Pajottegem", + "Wingene", + "Tielt", + "Nazareth-De Pinte", + "Lochristi", + "Lokeren", + "Merelbeke-Melle", + "Beveren-Kruibeke-Zwijndrecht", + "Bilzen-Hoeselt", + "Tongeren-Borgloon", + "Tessenderlo-Ham", + "Hasselt" + )) + BIND (CONCAT(?street, " ", ?buildingNo, " ", ?boxNo, ", ", ?postalCode, " ", ?municipality, ", ", ?country) AS ?newFullAddress) + FILTER (?fullAddress != ?newFullAddress) + } + + VALUES ?g { + + + } +}