Sean
Sean

Reputation: 3450

How to query Wikidata using SPARQL using entity names and also check alternative labels?

I'm trying to query Wikidata using entity names. My goal is to get the Wikidata ID of the entity. Right now I have something like:

SELECT ?item
WHERE {
    ?item rdfs:label "name_of_thing"@en
}

and while this usually gets the job done I also want to check whether the label is contained in the alternative names on Wikidata.

For example, if I replace "name_of_thing" with "Philippines AirAsia" then I don't get any results, but the reason why is because "AirAsia Philippines" is the proper name of the entry, with "Philippines AirAsia" contained in the "Also known as" column in the Wikidata page.

I want to query the page and if the first fetch fails then check whether the name is contained in the "Also known as" column. How should I go about doing this? Thanks.

Upvotes: 3

Views: 945

Answers (1)

Karl Amort
Karl Amort

Reputation: 16394

The pipe operator works for me:

Query

SELECT ?item ?prefLabel WHERE {
        VALUES ?prefLabel { "AirAsia Philippines"@en }
        ?item rdfs:label|skos:altLabel ?prefLabel 
}

Upvotes: 1

Related Questions