Created
October 5, 2016 16:36
-
-
Save jindrichmynarz/25df5bf262530806bc7b98fa688f70df to your computer and use it in GitHub Desktop.
Blank nodes to hash-based IRIs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE { | |
?bnode ?outP ?outO . | |
?inS ?inP ?bnode . | |
} | |
INSERT { | |
?iri ?outP ?outO . | |
?inS ?inP ?iri . | |
} | |
WHERE { | |
{ | |
SELECT ?bnode ?iri | |
WHERE { | |
{ | |
SELECT ?bnode | |
(SAMPLE(?_class) AS ?class) | |
(SHA1(CONCAT(GROUP_CONCAT(STR(?p); separator = ""), | |
GROUP_CONCAT(STR(?o); separator = ""))) AS ?hash) | |
WHERE { | |
?bnode ?p ?o . | |
FILTER isBlank(?bnode) | |
OPTIONAL { | |
?bnode a ?_class . | |
} | |
} | |
GROUP BY ?bnode | |
} | |
# Your base namespace for resources: | |
BIND ("http://linked.opendata.cz/resource/" AS ?ns) | |
# Extract the local name of the resource's class and convert it to kebab-case. | |
BIND (LCASE(REPLACE(COALESCE(REPLACE(STR(?class), "^.*[/#]([^/#]+)$", "$1"), "thing"), | |
"(\\p{Ll})(\\p{Lu})", "$1-$2")) | |
AS ?classLocalName) | |
# The newly minted hash-based IRIs follow the pattern {namespace}/{class name}/{hash}. | |
BIND (IRI(CONCAT(?ns, ?classLocalName, "/", ?hash)) AS ?iri) | |
} | |
} | |
?bnode ?outP ?outO . | |
OPTIONAL { | |
?inS ?inP ?bnode . | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment