From a5a94769a71fdb70042343560e913b6c81bf4ba5 Mon Sep 17 00:00:00 2001 From: Boris De Vloed Date: Fri, 25 Aug 2023 16:25:12 +0200 Subject: [PATCH] cleanup leidinggevenden --- ...x-duplicated-leidinggevenden-values.sparql | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 config/migrations/2023/20230825123000-fix-duplicated-leidinggevenden-values.sparql diff --git a/config/migrations/2023/20230825123000-fix-duplicated-leidinggevenden-values.sparql b/config/migrations/2023/20230825123000-fix-duplicated-leidinggevenden-values.sparql new file mode 100644 index 0000000..e29c44e --- /dev/null +++ b/config/migrations/2023/20230825123000-fix-duplicated-leidinggevenden-values.sparql @@ -0,0 +1,117 @@ +# Every value that is in the admin unit graph but NOT in the landing graph means that it has not been +# ingested via the consumer, and has to be cleared out + +DELETE { + GRAPH { + ?contactPoint ?predicate ?value . + } +} WHERE { + GRAPH { + ?s a ; + / ?contactPoint. + ?contactPoint ?predicate ?value . + } + + FILTER NOT EXISTS { + GRAPH { + ?contactPoint ?predicate ?value . + } + } +} + +; + +DELETE { + GRAPH { + ?bestuursfunctie ?predicate ?value . + } +} WHERE { + GRAPH { + ?s a ; + ?bestuursfunctie. + ?bestuursfunctie ?predicate ?value . + } + + FILTER NOT EXISTS { + GRAPH { + ?bestuursfunctie ?predicate ?value . + } + } +} + +; + +DELETE { + GRAPH { + ?s ?predicate ?value . + } +} WHERE { + VALUES ?predicate { + + + + + + } + + GRAPH { + ?s a ; + ?predicate ?value . + } + + FILTER NOT EXISTS { + GRAPH { + ?s a ; + ?predicate ?value . + } + } +} + +; + +# Now, handling dates is more complex as dates in OP are datetimes in Loket + +DELETE { + GRAPH { + ?s ?predicate ?date . + } +} WHERE { + VALUES ?predicate { + + + } + + GRAPH { + ?s a ; + ?predicate ?date . + } + + FILTER NOT EXISTS { + GRAPH { + ?s a ; + ?predicate ?datetime . + } + + BIND(?datetime + xsd:duration('PT2H') as ?dateInOurTimezone) + + # convert to strings + BIND(STR(year(?dateInOurTimezone)) AS ?year) + BIND(STR(month(?dateInOurTimezone)) AS ?month) + BIND(STR(day(?dateInOurTimezone)) AS ?day) + + # pad with zeros + BIND(CONCAT("00", ?year) AS ?paddedYear) + BIND(CONCAT("0000", ?month) AS ?paddedMonth) + BIND(CONCAT("00", ?day) AS ?paddedDay) + + # extract the right number of digits from the padded strings + BIND(SUBSTR(?paddedYear, STRLEN(?paddedYear)-3) AS ?fourDigitYear) + BIND(SUBSTR(?paddedDay, STRLEN(?paddedDay)-1) AS ?twoDigitDay) + BIND(SUBSTR(?paddedMonth, STRLEN(?paddedMonth)-1) AS ?twoDigitMonth) + + # put it all back together + BIND(xsd:date(CONCAT(?fourDigitYear, "-", ?twoDigitMonth, "-", ?twoDigitDay)) as ?datetimeToDate) + + FILTER (?datetimeToDate = ?date) + } +} \ No newline at end of file