sparql-examples

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

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

039

rq turtle/ttl

Chemical-element aspect: data

Use at

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

SELECT DISTINCT ?description ?value ?valueUrl
WHERE {
  {
    SELECT
      (1 AS ?order)
      ("Named after" AS ?description)
      (GROUP_CONCAT(?value_; separator=", ") AS ?value)
      (CONCAT("../topic/", GROUP_CONCAT(?q; separator=",")) AS ?valueUrl)
    {
      BIND(1 AS ?dummy)
      target: wdt:P138 ?iri .
      BIND(SUBSTR(STR(?iri), 32) AS ?q) 
      ?iri rdfs:label ?value_string . 
      FILTER (LANG(?value_string) = 'en')
      BIND(COALESCE(?value_string, ?q) AS ?value_)
    }
    GROUP BY ?dummy
  }
  UNION
  {
    SELECT
      (2 AS ?order)
      ("Discoverer" AS ?description)
      (GROUP_CONCAT(?value_; separator=", ") AS ?value)
      (CONCAT("../topic/", GROUP_CONCAT(?q; separator=",")) AS ?valueUrl)
    {
      BIND(1 AS ?dummy)
      target: wdt:P61 ?iri .
      BIND(SUBSTR(STR(?iri), 32) AS ?q) 
      ?iri rdfs:label ?value_string . 
      FILTER (LANG(?value_string) = 'en')
      BIND(COALESCE(?value_string, ?q) AS ?value_)
    }
    GROUP BY ?dummy
  }
  UNION
  {
    SELECT
      (3 AS ?order)
      ("Oxidation states" AS ?description)
      (GROUP_CONCAT(?value_; separator=", ") AS ?value)
    {
      BIND(1 AS ?dummy)
      target: wdt:P1121 ?value_ .
    }
    GROUP BY ?dummy
  }
  UNION
  {
    SELECT
      (4 AS ?order)
      ("Electron configuration" AS ?description)
      (GROUP_CONCAT(?value_; separator=", ") AS ?value)
    {
      BIND(1 AS ?dummy)
      target: wdt:P8000 ?value_ .
    }
    GROUP BY ?dummy
  }
} 
ORDER BY ?order

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v7("?_anon_d5635a4148474aba9b1ec2d6f2e48935289")
  v11("?_anon_d5635a4148474aba9b1ec2d6f2e48935292")
  v12("?description"):::projected 
  v12("?dummy")
  v4("?iri")
  v12("?order")
  v11("?q")
  v12("?value"):::projected 
  v12("?valueUrl"):::projected 
  v11("?value_")
  v2("?value_string")
  c2([http://www.wikidata.org/entity/Q1098]):::iri 
  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;
      subgraph union2[" Union "]
      subgraph union2l[" "]
        style union2l fill:#abf,stroke-dasharray: 3 3;
        bind0[/"'1^^xsd:integer'"/]
        bind0 --as--o v12
        c2 --"p:direct/P8000"-->  v11
        bind2[/"'4^^xsd:integer'"/]
        bind2 --as--o v12
        bind3[/"'Electron configuration'"/]
        bind3 --as--o v12
        bind4[/"?value_"/]
        v11 --o bind4
        bind4 --as--o v12
      end
      subgraph union2r[" "]
        style union2r fill:#abf,stroke-dasharray: 3 3;
        bind5[/"'1^^xsd:integer'"/]
        bind5 --as--o v12
        c2 --"p:direct/P1121"-->  v11
        bind7[/"'3^^xsd:integer'"/]
        bind7 --as--o v12
        bind8[/"'Oxidation states'"/]
        bind8 --as--o v12
        bind9[/"?value_"/]
        v11 --o bind9
        bind9 --as--o v12
      end
      union2r <== or ==> union2l
      end
    end
    subgraph union1r[" "]
      style union1r fill:#abf,stroke-dasharray: 3 3;
      f10[["?value_string = 'en'"]]
      f10 --> v2
      bind11[/"'1^^xsd:integer'"/]
      bind11 --as--o v12
      c2 --"p:direct/P61"-->  v4
      bind12[/"substring(str(?iri),'32^^xsd:integer')"/]
      v4 --o bind12
      bind12 --as--o v11
      v4 --"rdfs:label"-->  v2
      bind13[/"?value_string?q"/]
      v2 --o bind13
      v11 --o bind13
      bind13 --as--o v11
      bind16[/"?q"/]
      v11 --o bind16
      bind16 --as--o v11
      bind17[/"'2^^xsd:integer'"/]
      bind17 --as--o v12
      bind18[/"'Discoverer'"/]
      bind18 --as--o v12
      bind19[/"?value_"/]
      v11 --o bind19
      bind19 --as--o v12
      bind20[/"concat('../topic/',)"/]
      null --o bind20
      bind20 --as--o v12
    end
    union1r <== or ==> union1l
    end
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    f21[["?value_string = 'en'"]]
    f21 --> v2
    bind22[/"'1^^xsd:integer'"/]
    bind22 --as--o v12
    c2 --"p:direct/P138"-->  v4
    bind23[/"substring(str(?iri),'32^^xsd:integer')"/]
    v4 --o bind23
    bind23 --as--o v11
    v4 --"rdfs:label"-->  v2
    bind24[/"?value_string?q"/]
    v2 --o bind24
    v11 --o bind24
    bind24 --as--o v11
    bind27[/"?q"/]
    v11 --o bind27
    bind27 --as--o v7
    bind28[/"'1^^xsd:integer'"/]
    bind28 --as--o v12
    bind29[/"'Named after'"/]
    bind29 --as--o v12
    bind30[/"?value_"/]
    v11 --o bind30
    bind30 --as--o v12
    bind31[/"concat('../topic/',)"/]
    null --o bind31
    bind31 --as--o v12
  end
  union0r <== or ==> union0l
  end