Querying: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 7: | Line 7: | ||
Declare these namespaces at the start of every query: | Declare these namespaces at the start of every query: | ||
PREFIX | PREFIX og: <https://ottgaz.org/entity/> | ||
PREFIX | PREFIX ogt: <https://ottgaz.org/prop/direct/> | ||
== Sample queries == | == Sample queries == | ||
=== Label === | === Label === | ||
All items that are vilayets, as well as their English language label. [https://tinyurl.com/ | All items that are vilayets, as well as their English language label. [https://tinyurl.com/2pren5e2 run] | ||
SELECT ?vilayet ?vilayetLabel | SELECT ?vilayet ?vilayetLabel | ||
WHERE | WHERE | ||
{ | { | ||
?vilayet | ?vilayet ogt:P6 og:Q5 . | ||
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } | SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } | ||
} | } | ||
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/ | 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/2ehssccv run] | ||
PREFIX | PREFIX og: <https://ottgaz.org/entity/> | ||
PREFIX | PREFIX ogt: <https://ottgaz.org/prop/direct/> | ||
PREFIX | PREFIX wd: <http://www.wikidata.org/entity/> | ||
PREFIX | PREFIX wdt: <http://www.wikidata.org/prop/direct/> | ||
SELECT ?sancak ?sancakLabel ?vilayet ?vilayetLabel | SELECT ?sancak ?sancakLabel ?vilayet ?vilayetLabel | ||
WHERE { | WHERE { | ||
?sancak | ?sancak ogt:P6 og:Q4 . # item must be a sanjak | ||
?sancak | ?sancak ogt: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 | 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> { | SERVICE <https://query.wikidata.org/sparql> { | ||
?wd_c | ?wd_c wdt:P131 ?vilayet . # finds containing vilayet in Wikidata | ||
SERVICE wikibase:label { | SERVICE wikibase:label { | ||
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". | bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". |
Revision as of 19:17, 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 og: <https://ottgaz.org/entity/> PREFIX ogt: <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 ogt:P6 og: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 og: <https://ottgaz.org/entity/> PREFIX ogt: <https://ottgaz.org/prop/direct/> PREFIX wd: <http://www.wikidata.org/entity/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> SELECT ?sancak ?sancakLabel ?vilayet ?vilayetLabel WHERE { ?sancak ogt:P6 og:Q4 . # item must be a sanjak ?sancak ogt: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 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 } }