Skip to content

Instantly share code, notes, and snippets.

@jindrichmynarz
Created October 5, 2016 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jindrichmynarz/c034e879775fbb3b4f55af35f3f57342 to your computer and use it in GitHub Desktop.
Save jindrichmynarz/c034e879775fbb3b4f55af35f3f57342 to your computer and use it in GitHub Desktop.
Fuse equivalent resources by hash
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