Skip to content

Instantly share code, notes, and snippets.

@balhoff
Created March 6, 2024 17:10
Show Gist options
  • Save balhoff/7010180149e21b3fd7cb2597f3a8a4c6 to your computer and use it in GitHub Desktop.
Save balhoff/7010180149e21b3fd7cb2597f3a8a4c6 to your computer and use it in GitHub Desktop.
A SPARQL update to replace blank nodes with IRIs
PREFIX ex: <http://example.org/>
INSERT {
?node ex:skolem ?iri .
}
WHERE {
{
SELECT DISTINCT ?node
WHERE {
{ ?node ?p1 ?o1 . }
UNION
{ ?s2 ?p2 ?node . }
FILTER(isBlank(?node))
}
}
BIND (UUID() AS ?iri)
}
;
DELETE {
?node ?p ?o .
}
INSERT {
?iri ?p ?o .
}
WHERE {
?node ex:skolem ?iri .
?node ?p ?o .
FILTER(?p != ex:skolem)
}
;
DELETE {
?s ?p ?node .
}
INSERT {
?s ?p ?iri .
}
WHERE {
?node ex:skolem ?iri .
?s ?p ?node .
FILTER(?p != ex:skolem)
}
;
DELETE WHERE {
?node ex:skolem ?iri .
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment