sparql-examples

A set of SPARQL examples that are used in different TGX resources

View the Project on GitHub BiGCAT-UM/sparql-examples

009

rq turtle/ttl

Map with organizations with retracted articles.

Use at

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?organization ?organizationLabel ?geo ?count ?layer
WHERE {
  {
    SELECT DISTINCT ?organization (SAMPLE(?geo_) AS ?geo)
	  (COUNT(DISTINCT ?work) AS ?count)
	WHERE {
      ?work wdt:P2860 / wdt:P31 wd:Q45182324 ;
          wdt:P50 ?author .
      ?author ( wdt:P108| wdt:P463 | wdt:P1416 ) / wdt:P361* ?organization .
      ?organization (wdt:P625 | ((wdt:P276|wdt:P159)/wdt:P625)) ?geo_ .
    } GROUP BY ?organization ?geo_
      ORDER BY DESC (?count)
      LIMIT 2000
  }
  ?organization rdfs:label ?organizationLabel . FILTER (LANG(?organizationLabel) = "en") .
  BIND(IF( (?count < 1), "No results", IF((?count < 2), "1 result", IF((?count < 11), "1 < results ≤ 10", IF((?count < 101), "10 < results ≤ 100", IF((?count < 1001), "100 < results ≤ 1000", IF((?count < 10001), "1000 < results ≤ 10000", "over 10000 results") ) ) ) )) AS ?layer )
 }
ORDER BY DESC (?count)
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v4("?author")
  v8("?count"):::projected 
  v7("?geo"):::projected 
  v6("?geo_")
  v8("?layer"):::projected 
  v5("?organization"):::projected 
  v2("?organizationLabel"):::projected 
  v3("?work")
  a1((" "))
  a2((" "))
  a3((" "))
  c4(["wd:Q45182324"]):::iri 
  f0[["?organizationLabel = 'en'"]]
  f0 --> v2
  v3 --"wdt:P2860"-->  a1
  a1 --"wdt:P31"-->  c4
  v3 --"wdt:P50"-->  v4
  subgraph union0[" Union "]
  subgraph union0l[" "]
    style union0l fill:#abf,stroke-dasharray: 3 3;
    subgraph union1[" Union "]
    subgraph union1l[" "]
      style union1l fill:#abf,stroke-dasharray: 3 3;
      v4 --"wdt:P1416"-->  a2
    end
    subgraph union1r[" "]
      style union1r fill:#abf,stroke-dasharray: 3 3;
      v4 --"wdt:P463"-->  a2
    end
    union1r <== or ==> union1l
    end
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    v4 --"wdt:P108"-->  a2
  end
  union0r <== or ==> union0l
  end
  a2 --"wdt:P361"-->  v5
  subgraph union2[" Union "]
  subgraph union2l[" "]
    style union2l fill:#abf,stroke-dasharray: 3 3;
    subgraph union3[" Union "]
    subgraph union3l[" "]
      style union3l fill:#abf,stroke-dasharray: 3 3;
      v5 --"wdt:P159"-->  a3
    end
    subgraph union3r[" "]
      style union3r fill:#abf,stroke-dasharray: 3 3;
      v5 --"wdt:P276"-->  a3
    end
    union3r <== or ==> union3l
    end
    a3 --"wdt:P625"-->  v6
  end
  subgraph union2r[" "]
    style union2r fill:#abf,stroke-dasharray: 3 3;
    v5 --"wdt:P625"-->  v6
  end
  union2r <== or ==> union2l
  end
  bind3[/"sample(?geo_)"/]
  v6 --o bind3
  bind3 --as--o v7
  bind4[/"count(?work)"/]
  v3 --o bind4
  bind4 --as--o v8
  v5 --"rdfs:label"-->  v2
  bind5[/"if(?count < '1^^xsd:integer','No results',if(?count < '2^^xsd:integer','1 result',if(?count < '11^^xsd:integer','1 < results ≤ 10',if(?count < '101^^xsd:integer','10 < results ≤ 100',if(?count < '1001^^xsd:integer','100 < results ≤ 1000',if(?count < '10001^^xsd:integer','1000 < results ≤ 10000','over 10000 results'))))))"/]
  v8 --o bind5
  bind5 --as--o v8