Created
October 5, 2016 16:47
-
-
Save jindrichmynarz/c034e879775fbb3b4f55af35f3f57342 to your computer and use it in GitHub Desktop.
Fuse equivalent resources by hash
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
PREFIX : <http://example.com/> | |
DELETE { | |
?r ?outP ?outO . | |
?inS ?inP ?r . | |
} | |
WHERE { | |
{ | |
SELECT (SAMPLE(?r) AS ?sampleR) ?hash | |
WHERE { | |
{ | |
SELECT ?r | |
# Compute hashes from resource's description. | |
(SHA1(CONCAT(GROUP_CONCAT(STR(?p); separator = ""), | |
GROUP_CONCAT(STR(?o); separator = ""))) AS ?hash) | |
WHERE { | |
# Select resources to fuse. | |
?r a :C ; | |
?p ?o . | |
} | |
GROUP BY ?r | |
} | |
} | |
GROUP BY ?hash | |
} | |
# Hashes must be computed twice, since we cannot have both | |
# the aggregate (?sampleR) and the aggregated bindings (?r). | |
{ | |
SELECT ?r | |
(SHA1(CONCAT(GROUP_CONCAT(STR(?p); separator = ""), | |
GROUP_CONCAT(STR(?o); separator = ""))) AS ?hash) | |
WHERE { | |
?r a :C ; | |
?p ?o . | |
} | |
GROUP BY ?r | |
} | |
FILTER (!sameTerm(?r, ?sampleR)) | |
?r ?outP ?outO . | |
OPTIONAL { | |
?inS ?inP ?r . | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment