How to query Wikidata for "also known as"
Asked Answered
P

1

10

I would like to know how to query Wikidata by using the alias ("also known as").

Right now I am trying

SELECT ?item
WHERE
{
?item rdfs:aliases ?alias.
FILTER(CONTAINS(?alias, "Angela Kasner"@en))
}
LIMIT 5

This is simply a query that works if I replace rdfs:aliases by rdfs:labels.

I am trying this, because Help:Aliases says that aliases are searchable in the same way as labels, but I can't find any other resource on that nor can I find an example.

Prieto answered 20/10, 2017 at 13:50 Comment(8)
Use skos:altLabel instead of rdfs:aliases, and probably your next question will be about "Query timeout limit reached".Fluecure
But this works: SELECT * {wd:Q567 skos:altLabel ?altLabel . FILTER (contains(?altLabel, "Angela Kasner"@en)) }Fluecure
Also, replacing rdfs:aliases with rdfs:labels doesn't seem to work. (Returns "No matching records found")Infralapsarian
@EmreSevinç, obviously you know that rdfs:label should be instead of rdfs:labels.Fluecure
@EmreSevinç You should not use arbitrary URIs or how do you expect this should work? The RDFS vocabulary is well-defined and online available for reference. And if you use the label, you should think of exact match, i.e. use the literal as the object of the triple pattern. From my point of view, string containment in names wouldn't make sense and can lead to lots of wrong results.Linear
This works nicely. Would you mind putting an answer - maybe containing a link to "w3.org/TR/rdf-schema", "w3.org/TR/skos-reference/#L1045" or whatever you deem a good ressource? As for the "contains": This is a relict from when I tried to just modify a query I found. Thank you for the reminder.Prieto
@Junge, also Wikidata magic label service can produce these aliases (in addition to labels): m.mediawiki.org/wiki/Wikidata_query_service/…Fluecure
BTW, you could use python-wdqs (instead of sparqlwrapper) working with Wikidata. IMHO, it is more convenient. Example.Fluecure
D
9

This query might be helpful for someone querying also known as for properties:

SELECT ?property ?propertyLabel ?propertyDescription (GROUP_CONCAT(DISTINCT(?altLabel); separator = ", ") AS ?altLabel_list) WHERE {
    ?property a wikibase:Property .
    OPTIONAL { ?property skos:altLabel ?altLabel . FILTER (lang(?altLabel) = "en") }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" .}
 }
GROUP BY ?property ?propertyLabel ?propertyDescription
LIMIT 5000
Distich answered 6/3, 2018 at 11:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.