query-345c83ca25e9911efb8f9da051ee42da

rq turtle/ttl

TODO

Use at

PREFIX mwapi: <http://wikiba.se/ontology#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?item ?itemLabel (GROUP_CONCAT(DISTINCT ?instance_ofLabel; separator="; ") AS ?event_types) ?time ?start ?end ?time_precision ?sort_key

WHERE
{

{
  SELECT ?item
  WHERE
  {
    SERVICE wikibase:mwapi
    {
      bd:serviceParam wikibase:api "Generator" .
      bd:serviceParam wikibase:endpoint "en.wikipedia.org" .
      bd:serviceParam mwapi:titles "Timeline of Japanese history" .
      bd:serviceParam mwapi:generator "links" .
      bd:serviceParam mwapi:gpllimit "max" .
      bd:serviceParam mwapi:gplnamespace "0" .
      ?item wikibase:apiOutputItem mwapi:item .
    }
    FILTER BOUND(?item)
  }
}  OPTIONAL { ?item wdt:P31 ?instance_of }
  ?item wdt:P31 / wdt:P279* wd:Q1190554 .  # Must be events
  OPTIONAL { ?item p:P585 / psv:P585 [wikibase:timeValue ?time ; wikibase:timePrecision ?time_prec] }
  OPTIONAL { ?item p:P580 / psv:P580 [wikibase:timeValue ?start ; wikibase:timePrecision ?start_prec] }
  OPTIONAL { ?item p:P582 / psv:P582 [wikibase:timeValue ?end ; wikibase:timePrecision ?end_prec] }
  BIND (COALESCE(?time, ?start, ?end) AS ?sort_key)
  FILTER BOUND(?sort_key) # Must have a time
  BIND (COALESCE(?time_prec, ?start_prec, ?end_prec) AS ?prec)
  BIND (IF(?prec = 11, "day", IF(?prec = 10, "month", IF(?prec = 9, "year", "other"))) AS ?time_precision)
  SERVICE wikibase:label
  {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,ja" .
    ?item rdfs:label ?itemLabel .
    ?instance_of rdfs:label ?instance_ofLabel .
  }
}
GROUP BY ?item ?itemLabel ?time ?start ?end ?time_precision ?sort_key
ORDER BY ?sort_key ?end

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?end"):::projected v9("?end_prec") v14("?event_types") v4("?instance_of") v13("?instance_ofLabel"):::projected v3("?item"):::projected v12("?itemLabel"):::projected v10("?prec") v10("?sort_key"):::projected v7("?start"):::projected v8("?start_prec") v5("?time"):::projected v6("?time_prec") v11("?time_precision"):::projected a1((" ")) a3((" ")) a2((" ")) a5((" ")) a4((" ")) a7((" ")) a6((" ")) c16(["mwapi:item"]):::iri c19(["wd:Q1190554"]):::iri c8(["Timeline of Japanese history"]):::literal c6(["en.wikipedia.org"]):::literal c2(["bd:serviceParam"]):::iri c10(["links"]):::literal c12(["max"]):::literal c30(["#91;AUTO_LANGUAGE#93;,en,ja"]):::literal c14(["0"]):::literal c4(["Generator"]):::literal f0[["bound(?sort_key)"]] f0 --> v10 f1[["bound(?item)"]] f1 --> v3 subgraph s1["http://wikiba.se/ontology#mwapi"] style s1 stroke-width:4px; c2 --"mwapi:api"--> c4 c2 --"mwapi:endpoint"--> c6 c2 --"mwapi:titles"--> c8 c2 --"mwapi:generator"--> c10 c2 --"mwapi:gpllimit"--> c12 c2 --"mwapi:gplnamespace"--> c14 v3 --"mwapi:apiOutputItem"--> c16 end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:direct/P31".-> v4 end v3 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c19 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; a2 -."mwapi:timeValue".-> v5 a2 --"mwapi:timePrecision"--> v6 v3 --"p:P585"--> a3 a3 --"p:statement/value/P585"--> a2 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; a4 -."mwapi:timeValue".-> v7 a4 --"mwapi:timePrecision"--> v8 v3 --"p:P580"--> a5 a5 --"p:statement/value/P580"--> a4 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; a6 -."mwapi:timeValue".-> v2 a6 --"mwapi:timePrecision"--> v9 v3 --"p:P582"--> a7 a7 --"p:statement/value/P582"--> a6 end bind2[/"?time?start?end"/] v5 --o bind2 v7 --o bind2 v2 --o bind2 bind2 --as--o v10 bind3[/"?time_prec?start_prec?end_prec"/] v6 --o bind3 v8 --o bind3 v9 --o bind3 bind3 --as--o v10 bind4[/"if(?prec = '11^^xsd:integer','day',if(?prec = '10^^xsd:integer','month',if(?prec = '9^^xsd:integer','year','other')))"/] v10 --o bind4 bind4 --as--o v11 subgraph s2["http://wikiba.se/ontology#label"] style s2 stroke-width:4px; c2 --"mwapi:language"--> c30 v3 --"rdfs:label"--> v12 v4 --"rdfs:label"--> v13 end bind6[/"?instance_ofLabel"/] v13 --o bind6 bind6 --as--o v14