Skip to content

Instantly share code, notes, and snippets.

@sandervd
Created August 26, 2022 15:25
Show Gist options
  • Save sandervd/9e0395518a4f48d241e6515f90ed1a65 to your computer and use it in GitHub Desktop.
Save sandervd/9e0395518a4f48d241e6515f90ed1a65 to your computer and use it in GitHub Desktop.
PREFIX ex: <http://example.com/>
# This query deletes an aggregate (entity with all its blanknodes)
DELETE {
?object_id ?property ?value
}
WHERE {
{
# Build a list of all blanknodes reachable from the root (max depth 7)
SELECT ?root ?l1 ?l2 ?l3 ?l4 ?l5 ?l6 ?l7
WHERE {
BIND (ex:replace_me_with_entity_id AS ?root) .
?root ?p1 ?l1 .
FILTER ( isBlank(?l1) ) .
OPTIONAL {
?l1 ?p2 ?l2 .
FILTER ( isBlank(?l2) ) .
OPTIONAL {
?l2 ?p3 ?l3 .
FILTER ( isBlank(?l3) ) .
OPTIONAL {
?l3 ?p4 ?l4 .
FILTER ( isBlank(?l4) ) .
OPTIONAL {
?l4 ?p5 ?l5 .
FILTER ( isBlank(?l5) ) .
OPTIONAL {
?l5 ?p6 ?l6 .
FILTER ( isBlank(?l6) ) .
OPTIONAL {
?l6 ?p7 ?l7 .
FILTER ( isBlank(?l7) ) .
}
}
}
}
}
}
}
}
# Aggregate all the identifiers of all levels into 1 variable (object_id).
{
{BIND (?root as ?object_id)}
UNION {BIND (?l1 as ?object_id)}
UNION {BIND (?l2 as ?object_id)}
UNION {BIND (?l3 as ?object_id)}
UNION {BIND (?l4 as ?object_id)}
UNION {BIND (?l5 as ?object_id)}
UNION {BIND (?l6 as ?object_id)}
UNION {BIND (?l7 as ?object_id)}
FILTER (bound(?object_id)).
# Get all properties and values of the entity
?object_id ?property ?value .
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment