query-73e93d41dfcd232acd4c2dc017c61634
Filtering wikipedia articles by language in a preferred order). English is preferred, then the the article in the native language for the country. So far I have (Q36)Poland in (Q23413)castle I want to get a single Wikipedia article for each place (say
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 bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item ?itemLabel ?langcode ?article WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
{
SELECT DISTINCT ?item ?langcode ?article WHERE {
?item wdt:P31 wd:Q23413.
?item wdt:P17 wd:Q36.
?item wdt:P17 ?country.
OPTIONAL {
?country wdt:P37 ?officiallanguage. ?officiallanguage wdt:P424 ?langcode.
?article schema:about ?item .
?article schema:inLanguage ?lang ;
schema:isPartOf [ wikibase:wikiGroup "wikipedia" ] .
#FILTER(?lang in ('en', ?langcode)) .
FILTER(?lang in ('en', 'pl')) .
}
}
LIMIT 10
}
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v6("?article"):::projected
v3("?country")
v2("?item"):::projected
v1("?lang")
v5("?langcode"):::projected
v4("?officiallanguage")
a1((" "))
c8(["wd:Q23413"]):::iri
c10(["wd:Q36"]):::iri
c2(["bd:serviceParam"]):::iri
c4(["#91;AUTO_LANGUAGE#93;"]):::literal
c16(["wikipedia"]):::literal
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c2 --"wikibase:language"--> c4
end
v2 --"wdt:P31"--> c8
v2 --"wdt:P17"--> c10
v2 --"wdt:P17"--> v3
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P37".-> v4
v4 --"wdt:P424"--> v5
v6 --"schema:about"--> v2
v6 --"schema:inLanguage"--> v1
a1 --"wikibase:wikiGroup"--> c16
v6 --"schema:isPartOf"--> a1
end