query-d40367dd86177895b11f979976fb30fd

rq turtle/ttl

Access Wikidata property qualifiersHello, . Here is my current code (I know I don't need the GROUP BY here, this is only a snippet of my full code): https://www.wikidata.org/wiki/Q312I am trying to associate a company's headquarters location to the company. I would like to store, e.g. for Apple Inc., Apple Park in ?location. Currently I am getting the city, Cupertino, (from 'headquarters location' property) and then referring to the 'location' property. I understand why this doesn't work; Cupertino is not associated with Apple Park on the Cupertino page, only the Apple Inc. page. Apple Inc:

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT 
  (?company AS ?companyID)
  ?companyLabel
  ?locationLabel
  (?city AS ?cityID)
  ?cityLabel
  ?stateLabel
WHERE 
{
  VALUES ?company {wd:Q312 wd:Q3884 wd:Q2283 wd:Q380 wd:Q95}

  ?company wdt:P159 ?city . # company hq location

  OPTIONAL { ?city wdt:P276 ?location . } # the HQ name is stored in hqlocation.location

  ?city wdt:P131+ ?state . # located in territorial entity
  ?state wdt:P31 wd:Q35657 . # territorial entity is instance of 'state'

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?company ?companyLabel ?locationLabel ?city ?cityLabel ?stateLabel ?ceo
ORDER BY ASC(?companyLabel)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?city"):::projected v7("?cityID") v2("?company"):::projected v6("?companyID") v1("?companyLabel"):::projected v4("?location") v5("?state") c7(["bd:serviceParam"]):::iri c9(["#91;AUTO_LANGUAGE#93;,en"]):::literal c5(["wd:Q35657"]):::iri bind0[/VALUES ?company/] bind0-->v2 bind00(["wd:Q312"]) bind00 --> bind0 bind01(["wd:Q3884"]) bind01 --> bind0 bind02(["wd:Q2283"]) bind02 --> bind0 bind03(["wd:Q380"]) bind03 --> bind0 bind04(["wd:Q95"]) bind04 --> bind0 v2 --"wdt:P159"--> v3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."wdt:P276".-> v4 end v3 --"wdt:P131"--> v5 v5 --"wdt:P31"--> c5 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c7 --"wikibase:language"--> c9 end bind1[/"?company"/] v2 --o bind1 bind1 --as--o v6 bind2[/"?city"/] v3 --o bind2 bind2 --as--o v7