Skip to content

Instantly share code, notes, and snippets.

@sandervd
Last active May 23, 2023 07:57
Show Gist options
  • Save sandervd/2fee4c403d5a492e6b1b235d3bbaae48 to your computer and use it in GitHub Desktop.
Save sandervd/2fee4c403d5a492e6b1b235d3bbaae48 to your computer and use it in GitHub Desktop.
DELETE {
?s ?p1 ?bn .
?bn ?p2 ?o .
}
INSERT {
?s ?p1 ?nbn .
?nbn ?p2 ?o .
}
WHERE {
{
SELECT ?bn (count(?s) as ?number)
WHERE {
?s ?p ?bn
FILTER isBlank(?bn)
}
GROUP BY(?bn)
}
FILTER (?number > 1)
{
{
?s ?p1 ?bn .
BIND (BNODE() as ?nbn)
}
?bn ?p2 ?o
}
}
@sandervd
Copy link
Author

In order to be able to represent a graph as a set of key-value pairs, blank nodes should only occur once in the object position.
This SPARQL construct duplicates the blank nodes, so that they occur only once as object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment