Skip to content

Instantly share code, notes, and snippets.

@gtfierro
Created July 13, 2021 19:06
Show Gist options
  • Save gtfierro/0c8cf80225c0cddc2169a801e56a6c40 to your computer and use it in GitHub Desktop.
Save gtfierro/0c8cf80225c0cddc2169a801e56a6c40 to your computer and use it in GitHub Desktop.
import brickschema
g = brickschema.Graph()
g.parse("https://raw.githubusercontent.com/BrickSchema/Brick/master/shacl/BrickEntityShapeBase.ttl", format="ttl")
q = """SELECT ?cls ?path ?allowed WHERE {
?sh a sh:NodeShape .
?sh sh:targetClass ?cls .
?sh sh:property ?prop .
?prop sh:path ?path .
{
?prop sh:class ?allowed
}
UNION
{
?prop sh:or/rdf:rest*/rdf:first/sh:class ?allowed
}
}"""
for row in g.query(q):
print(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment