Using Wikidata label service in federated queries

醉酒当歌 提交于 2019-12-10 19:48:37

问题


I'm wondering if it is possible to use Wikidata label service in a federated query. E.g., the following query

# Query from a local SPARQL enpoint

select ?item ?itemLabel
where {
    SERVICE <https://query.wikidata.org/sparql> {
        ?item wdt:P31 wd:Q146.
        SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    }

}

returns empty ?itemLabels. How can I get also ?itemLabels in my resultset?


回答1:


You could also use the manual mode, it's just one line more in your case:

PREFIX       wdt:  <http://www.wikidata.org/prop/direct/>
PREFIX        wd:  <http://www.wikidata.org/entity/>
PREFIX        bd:  <http://www.bigdata.com/rdf#>
PREFIX  wikibase:  <http://wikiba.se/ontology#>
PREFIX      rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT * {
  SERVICE <https://query.wikidata.org/sparql> {
    ?item wdt:P31 wd:Q146
    SERVICE wikibase:label { bd:serviceParam wikibase:language "it". ?item rdfs:label ?label }
  }
}

Try on FactForge




回答2:


Include some of the things that are nominally optional... Here's the full query I just ran through URIBurner.com, and its results.

PREFIX       wdt:  <http://www.wikidata.org/prop/direct/>
PREFIX        wd:  <http://www.wikidata.org/entity/>
PREFIX        bd:  <http://www.bigdata.com/rdf#>
PREFIX  wikibase:  <http://wikiba.se/ontology#>

SELECT *
WHERE
  {
    SERVICE <https://query.wikidata.org/sparql>
      {
        SELECT ?item ?itemLabel 
        WHERE 
          {
            ?item wdt:P31 wd:Q146 .
            SERVICE wikibase:label
              { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
          }
      }
  }


来源:https://stackoverflow.com/questions/53012303/using-wikidata-label-service-in-federated-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!