I am trying to construct a Wikidata query to find all properties of a certain type that are used on a given Wikidata item. Specifically, I'd like a list of links to authority identifiers from various organisations for a person.
I've started by finding all properties that are a kind of authority record, along with their labels, link patterns, etc. This works great:
SELECT ?auth ?authLabel ?desc ?linkPattern ?countryLabel ?remoteID WHERE {
?auth wdt:P31 wd:Q19595382; # Properties of type "person authority"
schema:description ?desc; # Plain-english description
wdt:P1630 ?linkPattern . # Link pattern
OPTIONAL { ?auth wdt:P17 ?country. } # Country of origin, if you have it
FILTER((LANG(?desc)) = "en")
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
This gives me a list of every person authority in Wikidata, with its ancillary information, which is a good starting point. However, what I want is this list but only showing the records for a particular person.
I thought that this would work, as Wikidata SPARQL queries should be able to handle variables as predicates:
SELECT ?auth ?authLabel ?desc ?linkPattern ?countryLabel ?remoteID WHERE {
?auth wdt:P31 wd:Q19595382;
schema:description ?desc;
wdt:P1630 ?linkPattern .
wd:Q5145349 ?auth ?remoteID . # <-- Authority record property must appear in person Q5145349 (Colin McCahon)
OPTIONAL { ?auth wdt:P17 ?country. }
FILTER((LANG(?desc)) = "en")
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
but this returns zero results. No errors, just empty.
The only clue I've got is that the list of property IDs, even though they are properties, is returned with a "wd:" prefix, rather than the "wdt:" prefix/namespace usually used by predicates, so maybe it needs to be re-cast into a different type/namespace somehow. But I am not sure if that matters.
There might be a way of doing this with filters or other post-query cleverness, but what I've written in the second example (keeping my person item as part of the graph) seems preferable. And I'd definitely like to keep it in a single query.
Any help would be welcomed. I've searched a lot without finding an example that addresses this case of turning a subject into a predicate within the same query. Thanks!