Skip to content

Instantly share code, notes, and snippets.

@GridexX
Created January 13, 2025 10:56
Show Gist options
  • Save GridexX/6d282913b8baf45ec0e3d1c2283dfb5b to your computer and use it in GitHub Desktop.
Save GridexX/6d282913b8baf45ec0e3d1c2283dfb5b to your computer and use it in GitHub Desktop.
Modelize StarWars Ontology into DB
SELECT
?property
(COUNT(DISTINCT ?planet) as ?planetCount)
(MAX(?valueCountPerPlanet) as ?maxValuesPerPlanet)
(COUNT(DISTINCT ?planetWithMultiple) as ?planetsWithMultipleValues)
(GROUP_CONCAT(DISTINCT ?datatype; separator=", ") as ?datatypes)
(GROUP_CONCAT(DISTINCT ?objectType; separator=", ") as ?objectTypes)
(SAMPLE(GROUP_CONCAT(DISTINCT ?value; separator=", ")) as ?exampleValues)
WHERE {
?planet a voc:Planet ;
?property ?value .
# Count values per planet
{
SELECT ?planet ?property (COUNT(?value) as ?valueCountPerPlanet)
WHERE {
?planet a voc:Planet ;
?property ?value .
}
GROUP BY ?planet ?property
}
# Identify planets with multiple values
OPTIONAL {
SELECT ?planet ?property
WHERE {
?planet a voc:Planet ;
?property ?value .
}
GROUP BY ?planet ?property
HAVING (COUNT(?value) > 1)
} BIND(?planet as ?planetWithMultiple)
OPTIONAL {
?value a ?objectType .
}
BIND(datatype(?value) as ?datatype)
}
GROUP BY ?property
ORDER BY DESC(?planetCount)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment