query-1efef1f60bfdbdac694819ce615ca9f4
Content
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Tree
SELECT
?randomQid
?typeName
?property
?propertyLabel
# We get the unique values for ?type, to avoid having to copmute
# STRAFTER on the same values.
# We computer STRAFTER on the unique values for ?type
# We get the count of the properties with each type for sorting the results.
# This is a hacky way to get a unique identifier for each type. We
# need this to happen so that the results are correctly grouped in
# #defaultView:Tree. #defaultView:Tree doesn't do the grouping when
# the top level of the rows are not Wikidata entities.
#
# I tried using UUID() and STRUUID() for getting a unique value, but
# as I mentioned #defaultView:Tree only groups the items when the
# identifier represent Wikidata entities (i.e. start with P, Q or L
# and what follows are only numbers).
# Convert the identifier that we hackily obtained into a Wikidata item
# so that the top group is shown in #defaultView:Tree
{
{
SELECT ?property ?type {
?property wikibase:propertyType ?type.
}
}
{
SELECT ?type ?typeName {
{
SELECT DISTINCT ?type {
{
SELECT ?property ?type {
?property wikibase:propertyType ?type.
}
}
}
}
BIND(STRAFTER(STR(?type), STR(wikibase:)) AS ?typeName).
}
}
{
SELECT ?type (COUNT(*) AS ?count) {
{
SELECT ?property ?type {
?property wikibase:propertyType ?type.
}
}
}
GROUP BY ?type
}
{
SELECT ?type ?randomQid {
{
SELECT ?type (MAX(?Pid) AS ?maxPid) {
INCLUDE %0.
BIND(STRAFTER(STR(?property), 'http://www.wikidata.org/entity/P') AS ?Pid).
}
GROUP BY ?type
}
BIND(URI(CONCAT('http://www.wikidata.org/entity/P', ?maxPid)) AS ?randomQid).
}
}
SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE]"}.
}
ORDER BY DESC(?count) ASC(LCASE(?propertyLabel))