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.

logi-kal
  • 7,107
  • 6
  • 31
  • 43
Junge
  • 437
  • 6
  • 14
  • 1
    Use `skos:altLabel` instead of `rdfs:aliases`, and probably your next question will be about "Query timeout limit reached". – Stanislav Kralin Oct 20 '17 at 14:02
  • 1
    But this works: `SELECT * {wd:Q567 skos:altLabel ?altLabel . FILTER (contains(?altLabel, "Angela Kasner"@en)) }` – Stanislav Kralin Oct 20 '17 at 14:11
  • 1
    Also, replacing `rdfs:aliases` with `rdfs:labels` doesn't seem to work. (Returns "No matching records found") – Emre Sevinç Oct 20 '17 at 14:11
  • @EmreSevinç, obviously you know that `rdfs:label` should be instead of `rdfs:labels`. – Stanislav Kralin Oct 20 '17 at 17:02
  • @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. – UninformedUser Oct 20 '17 at 19:39
  • This works nicely. Would you mind putting an answer - maybe containing a link to "https://www.w3.org/TR/rdf-schema/", "https://www.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. – Junge Oct 23 '17 at 06:49
  • @Junge, also Wikidata magic label service can produce these aliases (in addition to labels): https://m.mediawiki.org/wiki/Wikidata_query_service/User_Manual#Extensions – Stanislav Kralin Oct 24 '17 at 18:03
  • BTW, you could use [python-wdqs](https://github.com/yuvipanda/python-wdqs) (instead of [tag:sparqlwrapper]) working with Wikidata. IMHO, it is more convenient. [Example](http://paws-public.wmflabs.org/paws-public/User:Luitzen/Motto.ipynb). – Stanislav Kralin Aug 19 '18 at 17:17

1 Answers1

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
Michail Michailidis
  • 11,792
  • 6
  • 63
  • 106