query-220c312dc889d3eb88f553a2bc53abef
15:10, 5 January 2016 (UTC)) talk (Jobu0101. --OPTIONAL { ?country wdt:P36 ?capital . ?capital enLabel ?capitalLabel}Since ?capital ist OPTIONAL here I can't access ?capitalLabel. Is there another way to print the label? Something like 18:25, 6 January 2016 (UTC)) talk (Jheald -- Wikidata:SPARQL_query_service/queries#Optional_requirementsSee 18:53, 6 January 2016 (UTC) Jura--- Oh no, it doesn't work either. 18:51, 6 January 2016 (UTC) Jura--- seems to work better, if the spouses have no label in the target language. Something like [..]: Thank you. I updated my query: Jheald@
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?country ?countryLabel ?capital ?capital_label WHERE {
?country wdt:P31 wd:Q3624078 .
FILTER NOT EXISTS { ?country wdt:P31 wd:Q3024240 } .
OPTIONAL { ?country wdt:P36 ?capital} .
?capital rdfs:label ?capital_label FILTER (lang(?capital_label) = "en") .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
} ORDER BY ?countryLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?capital"):::projected
v2("?capital_label"):::projected
v3("?country"):::projected
v1("?countryLabel"):::projected
c3(["wd:Q3024240"]):::iri
c4(["wd:Q3624078"]):::iri
c8(["bd:serviceParam"]):::iri
c1(["en"]):::literal
f0[["?capital_label = 'en'"]]
f0 --> v2
f1[["not "]]
subgraph f1e0["Exists Clause"]
e0v1 --"wdt:P31"--> e0c2
e0v1("?country"):::projected
e0c2(["wd:Q3024240"]):::iri
end
f1--EXISTS--> f1e0
f1 --> v3
f1 --> c2
f1 --> c3
v3 --"wdt:P31"--> c3
v3 --"wdt:P31"--> c4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P36".-> v4
end
v4 --"rdfs:label"--> v2
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c8 --"wikibase:language"--> c1
end