Last active
December 1, 2025 20:50
-
-
Save ewg118/b4ab10c6221af0f6be6a25f66735830f to your computer and use it in GitHub Desktop.
Wikidata basic hierarchy query
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 ?concept ?conceptLabel (GROUP_CONCAT(DISTINCT(?altLabel); separator = "|") AS ?altLabels) ?parent ?parentLabel (GROUP_CONCAT(DISTINCT(?parentAltLabel); separator = "|") AS ?parentAltLabels) WHERE { | |
| BIND (<http://www.wikidata.org/entity/Q2102> as ?concept) | |
| ?concept wdt:P279+|wdt:P31 ?parent . | |
| FILTER NOT EXISTS {?parent wdt:P31 wd:Q19478619} | |
| FILTER NOT EXISTS {?parent wdt:P31 wd:Q124711104} | |
| FILTER NOT EXISTS {?parent wdt:P279 wd:Q27043950} | |
| OPTIONAL {?concept skos:altLabel ?altLabel FILTER (langMatches(lang(?altLabel), "en")) } | |
| OPTIONAL {?parent skos:altLabel ?parentAltLabel FILTER (langMatches(lang(?parentAltLabel), "en")) } | |
| SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } | |
| } GROUP BY ?concept ?conceptLabel ?parent ?parentLabel |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
XML API: https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q37122&sites=enwiki&format=xml