Querying: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
(6 intermediate revisions by the same user not shown)
Line 7: Line 7:
Declare these namespaces at the start of every query:
Declare these namespaces at the start of every query:


  PREFIX wd: <https://ottgaz.org/entity/>
  PREFIX og: <https://ottgaz.org/entity/>
  PREFIX wdt: <https://ottgaz.org/prop/direct/>
  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://ottgaz.org/query/#PREFIX%20wd%3A%20%3Chttps%3A%2F%2Fottgaz.org%2Fentity%2F%3E%0APREFIX%20wdt%3A%20%3Chttps%3A%2F%2Fottgaz.org%2Fprop%2Fdirect%2F%3E%0A%0ASELECT%20%3Fvilayet%20%3FvilayetLabel%0AWHERE%20%0A%7B%0A%20%20%3Fvilayet%20wdt%3AP6%20wd%3AQ5%20.%20%0A%20%20optional%20%7B%20%0A%20%20%20%20%20%3Fvilayet%20rdfs%3Alabel%20%3FvilayetLabel%0A%20%20%20%20%20filter%20langMatches%28lang%28%3FvilayetLabel%29%2C%20%22en%22%29%0A%20%20%20%7D%0A%7D run]
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 wdt:P6 wd:Q5 .  
   ?vilayet ogt:P6 og:Q5 .  
   optional {  
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
      ?vilayet rdfs:label ?vilayetLabel
}
      filter langMatches(lang(?vilayetLabel), "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. [https://tinyurl.com/2ehssccv 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
  }
  }
  }

Navigation menu