Querying: Difference between revisions

From ottgaz.org
Jump to navigation Jump to search
Line 27: Line 27:
  }
  }


=== Start and end dates ===
=== Duration, start and end dates ===
Every region with a start date, as well as end/latest dates where supplied. [https://tinyurl.com/2gn56lb4 run]
Duration between start and end date of every region with a start date, as well as region type. [https://tinyurl.com/2k8h75bz run]


PREFIX og: <https://ottgaz.org/entity/>
PREFIX ogs: <https://ottgaz.org/entity/statement/>
PREFIX ogv: <https://ottgaz.org/value/>
PREFIX ogt: <https://ottgaz.org/prop/direct/>
PREFIX ogp: <https://ottgaz.org/prop/>
PREFIX ogps: <https://ottgaz.org/prop/statement/>
  PREFIX ogpq: <https://ottgaz.org/prop/qualifier/>
  PREFIX ogpq: <https://ottgaz.org/prop/qualifier/>
SELECT ?regionLabel ?statusLabel (YEAR(?starttime) as ?start) (YEAR(?endtime) as ?end) ?duration
WHERE
{
  ?region ogt:P6 og:Q1.
  ?region ogp:P15 ?statement.
  ?statement ogps:P15 ?status.
  ?statement ogpq:P7 ?starttime.
  OPTIONAL{?statement ogpq:P8 ?endtime.}
  OPTIONAL{?statement ogpq:P22 ?endtime.}
  BIND(year(?endtime)-year(?starttime) as ?duration )
   
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY desc(?duration)


  SELECT ?regionLabel ?statusLabel ?starttime ?endtime
  SELECT ?regionLabel ?statusLabel ?starttime ?endtime

Revision as of 02:47, 6 January 2023

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 ogs: <https://ottgaz.org/entity/statement/>
PREFIX ogv: <https://ottgaz.org/value/>
PREFIX ogt: <https://ottgaz.org/prop/direct/>
PREFIX ogp: <https://ottgaz.org/prop/>
PREFIX ogps: <https://ottgaz.org/prop/statement/>
PREFIX ogpq: <https://ottgaz.org/prop/qualifier/>

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" }
}

Duration, start and end dates

Duration between start and end date of every region with a start date, as well as region type. run

PREFIX ogpq: <https://ottgaz.org/prop/qualifier/>
SELECT ?regionLabel ?statusLabel (YEAR(?starttime) as ?start) (YEAR(?endtime) as ?end) ?duration
WHERE 
{
 ?region ogt:P6 og:Q1.
 ?region ogp:P15 ?statement.
 ?statement ogps:P15 ?status.
 ?statement ogpq:P7 ?starttime.
 OPTIONAL{?statement ogpq:P8 ?endtime.}
 OPTIONAL{?statement ogpq:P22 ?endtime.}
 BIND(year(?endtime)-year(?starttime) as ?duration )
   
 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY desc(?duration)


SELECT ?regionLabel ?statusLabel ?starttime ?endtime
WHERE 
{
  ?region ogt:P6 og:Q1.
  ?region ogp:P15 ?statement.
  ?statement ogps:P15 ?status.
  ?statement ogpq:P7 ?starttime.
  OPTIONAL{?statement ogpq:P8 ?endtime.}
  OPTIONAL{?statement ogpq:P22 ?endtime.}
   
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY ?starttime

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
  }
}