query-d4c5f192b977d155b3651e7b4b713958

rq turtle/ttl

TEMPLATE={"template":"Video games whose developer is headquartered in ?country but with a different country of origin","variables":{"?country":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q6256 . }"} } } SELECT DISTINCT ?item ?itemLabel ?dev ?devLabel ?hq ?hqLabel ?country_originLabel WHERE { BIND(wd:Q142 AS ?country) ?item (wdt:P31/(wdt:P279*)) wd:Q7889; wdt:P178 ?dev. ?dev wdt:P17 ?country. OPTIONAL { ?dev wdt:P159 ?hq. } FILTER(NOT EXISTS { ?item wdt:P495 ?country. }) OPTIONAL { ?item wdt:P495 ?country_origin } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }

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#>
#TEMPLATE={"template":"Video games whose developer is headquartered in ?country but with a different country of origin","variables":{"?country":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q6256 . }"} } }
SELECT DISTINCT ?item ?itemLabel ?dev ?devLabel ?hq ?hqLabel ?country_originLabel WHERE {
  BIND(wd:Q142 AS ?country)
  ?item (wdt:P31/(wdt:P279*)) wd:Q7889;
    wdt:P178 ?dev.
  ?dev wdt:P17 ?country.
  OPTIONAL { ?dev wdt:P159 ?hq. }
  FILTER(NOT EXISTS { ?item wdt:P495 ?country. })
  OPTIONAL {
    ?item wdt:P495 ?country_origin
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?country") v5("?country_origin") v3("?dev"):::projected v4("?hq"):::projected v1("?item"):::projected a1((" ")) c9(["bd:serviceParam"]):::iri c4(["wd:Q7889"]):::iri c11(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"wdt:P495"--> e0v2 e0v2("?country"):::projected e0v1("?item"):::projected end f0--EXISTS--> f0e0 f0 --> v1 f0 --> c1 f0 --> v3 v1 --"wdt:P495"--> v3 bind1[/"'wd:Q142'"/] bind1 --as--o v3 v1 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c4 v1 --"wdt:P178"--> v3 v3 --"wdt:P17"--> v3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."wdt:P159".-> v4 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P495".-> v5 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end