How to query Wikidata items using its labels?

前端 未结 4 593
逝去的感伤
逝去的感伤 2021-02-05 15:55

How can I query Wikidata to get all items that have labels contain a word? I tried this but didn\'t work; it retrieved nothing.

SELECT ?item ?itemLabel WHERE {
          


        
4条回答
  •  借酒劲吻你
    2021-02-05 16:26

    As of today (June 2020), the best way to do this seems to be using these CirrusSearch extensions. The following does a substring search in all English labels and comes back with 10,000 results in <20 seconds. I believe it also searches in aliases and descriptions.

    SELECT DISTINCT ?item ?label
    WHERE
    {
      SERVICE wikibase:mwapi
      {
        bd:serviceParam wikibase:endpoint "www.wikidata.org";
                        wikibase:api "Generator";
                        mwapi:generator "search";
                        mwapi:gsrsearch "inlabel:city"@en;
                        mwapi:gsrlimit "max".
        ?item wikibase:apiOutputItem mwapi:title.
      }
      ?item rdfs:label ?label. FILTER( LANG(?label)="en" )
    
    }
    

提交回复
热议问题