sparql-examples

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

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

177

rq turtle/ttl

Taxon aspect: parent taxa

Use at

PREFIX bd: <http://www.bigdata.com/rdf#>
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 wikibase: <http://wikiba.se/ontology#>
PREFIX target: <http://www.wikidata.org/entity/Q12024>

SELECT
  (COUNT(?middle) AS ?distance)
  (GROUP_CONCAT(DISTINCT ?rank_label_; separator=", ") AS ?rank)
  ?parent ?parentLabel ?parentDescription
{
  target: wdt:P171* ?middle .
  ?middle wdt:P171+ ?parent .
  ?parent wdt:P105 ?rank_ .
  OPTIONAL {
    ?rank_ rdfs:label ?rank_label_ . FILTER (LANG(?rank_label_) = 'en')
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }
}
GROUP BY ?parent ?parentLabel ?parentDescription
ORDER BY ?distance

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v6("?distance")
  v3("?middle"):::projected 
  v4("?parent"):::projected 
  v6("?rank")
  v5("?rank_")
  v2("?rank_label_"):::projected 
  c2([http://www.wikidata.org/entity/Q12024]):::iri 
  c7([http://www.bigdata.com/rdf#serviceParam]):::iri 
  c9(["#91;AUTO_LANGUAGE#93;,mul,en"]):::literal 
  c2 --"p:direct/P171"-->  v3
  v3 --"p:direct/P171"-->  v4
  v4 --"p:direct/P105"-->  v5
  subgraph optional0["(optional)"]
  style optional0 fill:#bbf,stroke-dasharray: 5 5;
    v5 -."rdfs:label".->  v2
  end
  subgraph s1["http://wikiba.se/ontology#label"]
    style s1 stroke-width:4px;
    c7 --"wikibase:language"-->  c9
  end
  bind2[/"count(?middle)"/]
  v3 --o bind2
  bind2 --as--o v6
  bind3[/"?rank_label_"/]
  v2 --o bind3
  bind3 --as--o v6