Querying: Difference between revisions
Jump to navigation
Jump to search
Line 24: | Line 24: | ||
== Federated query with Wikidata == | == Federated query with Wikidata == | ||
For every sanjak in Ottgaz, this query fetches the vilayet or eyalet to which Wikidata says it belongs. Thanks to Lucas Werkmeister for help. [https://tinyurl.com/2hwkfuza run] | |||
PREFIX wd: <https://ottgaz.org/entity/> | PREFIX wd: <https://ottgaz.org/entity/> | ||
Line 31: | Line 31: | ||
PREFIX wd-wdt: <http://www.wikidata.org/prop/direct/> | PREFIX wd-wdt: <http://www.wikidata.org/prop/direct/> | ||
SELECT ?sancak ?vilayet | SELECT ?sancak ?sancakLabel ?vilayet ?vilayetLabel | ||
WHERE | WHERE { | ||
?sancak wdt:P6 wd:Q4 . # item must be a sanjak | |||
?sancak wdt:P4 ? | ?sancak wdt:P4 ?c . # finds reference URL to wikidata | ||
BIND(IRI(REPLACE(REPLACE(REPLACE(STR(?c), "Property:", ""), "/wiki/", "/entity/"), "https://", "http://")) AS ?wd_c) # produces proper URL for query form | |||
SERVICE <https://query.wikidata.org/sparql> { | |||
?wd_c wd-wdt:P131 ?vilayet . # finds containing vilayet in Wikidata | |||
SERVICE wikibase:label { | |||
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". | |||
?vilayet rdfs:label ?vilayetLabel. # finds label in Wikidata | |||
} | } | ||
} | |||
SERVICE wikibase:label { | |||
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". | |||
?sancak rdfs:label ?sancakLabel. # finds label in Ottgaz | |||
} | |||
} | } |
Revision as of 18:55, 4 October 2022
Run SPARQL queries via the Ottgaz Query Service.
Remember: SPARQL is currently case sensitive, as elastic search is disabled in wikibase.cloud.
Namespace
Declare these namespaces at the start of every query:
PREFIX wd: <https://ottgaz.org/entity/> PREFIX wdt: <https://ottgaz.org/prop/direct/>
Sample queries
Label
All items that are vilayets, as well as their English language label. run
SELECT ?vilayet ?vilayetLabel WHERE { ?vilayet wdt:P6 wd:Q5 . SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } }
Federated query with Wikidata
For every sanjak in Ottgaz, this query fetches the vilayet or eyalet to which Wikidata says it belongs. Thanks to Lucas Werkmeister for help. run
PREFIX wd: <https://ottgaz.org/entity/> PREFIX wdt: <https://ottgaz.org/prop/direct/> PREFIX wd-wd: <http://www.wikidata.org/entity/> PREFIX wd-wdt: <http://www.wikidata.org/prop/direct/> SELECT ?sancak ?sancakLabel ?vilayet ?vilayetLabel WHERE { ?sancak wdt:P6 wd:Q4 . # item must be a sanjak ?sancak wdt:P4 ?c . # finds reference URL to wikidata BIND(IRI(REPLACE(REPLACE(REPLACE(STR(?c), "Property:", ""), "/wiki/", "/entity/"), "https://", "http://")) AS ?wd_c) # produces proper URL for query form SERVICE <https://query.wikidata.org/sparql> { ?wd_c wd-wdt:P131 ?vilayet . # finds containing vilayet in Wikidata SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". ?vilayet rdfs:label ?vilayetLabel. # finds label in Wikidata } } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". ?sancak rdfs:label ?sancakLabel. # finds label in Ottgaz } }