This gist is part of the tutorial about modelizing a Star Wars Ontolofy into SurrealDB
Created
January 13, 2025 10:56
-
-
Save GridexX/6d282913b8baf45ec0e3d1c2283dfb5b to your computer and use it in GitHub Desktop.
Modelize StarWars Ontology into DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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