query-b92bd054891ed27eb7044719e54fd3ba
Cannot make schema:isPartOf optionalI this query I would like to make the part that retrieves the Wikipedia links optional, thus including all language Wikipedias but adding Wikipedia links to only those that have articles. How to make that part optional? Just adding OPTIONAL around the part times out. Omitting the section works as well. (from ?topiclink... to AS ?article).
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 schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?item ?language ?topicSitelink ?code ?article ?label WHERE {
?item wdt:P31 wd:Q10876391.
?item wdt:P856 ?itemLink .
?item wdt:P407 ?lang .
BIND(SUBSTR(STR(?lang), 32 ) AS ?language)
BIND(STRAFTER(STRBEFORE(STR(?itemLink), "."),"//") AS ?code)
BIND(wd:Q1071518 AS ?topic) .
?topicSitelink schema:isPartOf ?itemLink;
schema:about ?topic.
BIND(replace(wikibase:decodeUri(STRAFTER(STR(?topicSitelink), "wiki/" )),"_"," ") AS ?article)
OPTIONAL{ ?topic rdfs:label ?label filter (lang(?label) = ?code).}
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v9("?article"):::projected
v7("?code"):::projected
v3("?item"):::projected
v4("?itemLink")
v1("?label"):::projected
v5("?lang")
v6("?language"):::projected
v7("?topic")
v8("?topicSitelink"):::projected
c2(["wd:Q10876391"]):::iri
v3 --"wdt:P31"--> c2
v3 --"wdt:P856"--> v4
v3 --"wdt:P407"--> v5
bind0[/"substring(str(?lang),'32^^xsd:integer')"/]
v5 --o bind0
bind0 --as--o v6
bind1[/"substring-after(substring-before(str(?itemLink),'.'),'//')"/]
v4 --o bind1
bind1 --as--o v7
bind2[/"'wd:Q1071518'"/]
bind2 --as--o v7
v8 --"schema:isPartOf"--> v4
v8 --"schema:about"--> v7
bind3[/"replace(http://wikiba.se/ontology#decodeUri(substring-after(str(?topicSitelink),'wiki/')),'_',' ')"/]
v8 --o bind3
bind3 --as--o v9
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v7 -."rdfs:label".-> v1
end