Querying: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
(2 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://tinyurl.com/2n3vmss7 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 .  
   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 ==


This is not working. [https://tinyurl.com/2lo9yejm run]
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 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/>
  PREFIX wd-wd: <http://www.wikidata.org/entity/>
  PREFIX wd: <http://www.wikidata.org/entity/>
  PREFIX wd-wdt: <http://www.wikidata.org/prop/direct/>
  PREFIX wdt: <http://www.wikidata.org/prop/direct/>
 
  SELECT ?sancak ?vilayet
  SELECT ?sancak ?sancakLabel ?vilayet ?vilayetLabel
  WHERE  
  WHERE {
{
  ?sancak ogt:P6 og:Q4 . # item must be a sanjak
   ?sancak wdt:P4 ?link .  
   ?sancak ogt:P4 ?c . # finds reference URL to wikidata
    SERVICE <https://query.wikidata.org/sparql> {
  BIND(IRI(REPLACE(REPLACE(REPLACE(STR(?c), "Property:", ""), "/wiki/", "/entity/"), "https://", "http://")) AS ?wd_c) # produces proper URL for query form
      ?link wd-wdt:P131 ?vilayet .
  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