通过QID获取房产?

时间:2017-01-07 23:23:39

标签: sparql wikidata wikidata-api

我可以通过标签获取项目及其属性:

SELECT distinct ?item ?itemLabel ?itemDescription
(SAMPLE(?DR) as ?DR) (SAMPLE(?article)as ?article)
WHERE {?item wdt:P31 wd:Q5. 
?item ?label "Einstein"@en 
OPTIONAL{?item wdt:P569 ?DR .}
?article schema:about ?item .
?article schema:inLanguage "en" .
?article schema:isPartOf <https://en.wikipedia.org/>.
OPTIONAL{?item wdt:P570 ?RIP .}
OPTIONAL{?item wdt:P18 ?image .}
SERVICE wikibase:label
{ bd:serviceParam wikibase:language "en". }}
GROUP BY ?item ?itemLabel ?itemDescription

Wikidata Query Services

如何使用QID代替标签?

3 个答案:

答案 0 :(得分:2)

使用URI代替变量?item将获得基于Albert Einstein实体的信息:

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

SELECT DISTINCT  ?item ?itemLabel ?itemDescription (SAMPLE(?DR) AS ?DRSample) (SAMPLE(?article) AS ?articleSample)
WHERE
  { ?article  schema:about       ?item ;
              schema:inLanguage  "en" ;
              schema:isPartOf    <https://en.wikipedia.org/>
    FILTER ( ?item = <http://www.wikidata.org/entity/Q937> )
    OPTIONAL
      { ?item  wdt:P569  ?DR }
    OPTIONAL
      { ?item  wdt:P570  ?RIP }
    OPTIONAL
      { ?item  wdt:P18  ?image }
    SERVICE wikibase:label
      { bd:serviceParam
                  wikibase:language  "en"
      }
  }
GROUP BY ?item ?itemLabel ?itemDescription

答案 1 :(得分:1)

如果您已经拥有所需实体的QID并只是查找其属性和标签,那么最好使用Wikidata API wbgetentities module

在A.爱因斯坦(Q937)案例中,这会给出以下API调用: https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q937&format=json

答案 2 :(得分:1)

您可以使用BIND

来利用已知的QID
BIND(wd:Q937 AS ?item).
...