sparql-examples

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

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

173

rq turtle/ttl

Taxon aspect: co occurring taxa

Use at

PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
#title: Taxa that co-occur with the target taxon in the literature
PREFIX target: <http://www.wikidata.org/entity/Q12024>

SELECT ?count (CONCAT("/topics/",SUBSTR(STR(target:), 32), ",", SUBSTR(STR(?taxon), 32)) AS ?countUrl)
       ?taxon ?taxonLabel (CONCAT("/taxon/", SUBSTR(STR(?taxon), 32)) AS ?taxonUrl)
       ?example_work ?example_workLabel (CONCAT("/work/", SUBSTR(STR(?example_work), 32)) AS ?example_workUrl)
WITH {
  SELECT (COUNT(?work) AS ?count) ?taxon (SAMPLE(?work) AS ?example_work) WHERE {
    # Find works for the specific queried topic
	?work wdt:P921 target: .
    
    # Find co-occuring topics
    ?work wdt:P921 ?taxon .
    
    # Filter for taxa
    ?taxon wdt:P105 ?taxonrank .
    
    # Avoid listing the queried topic itself
    FILTER (target: != ?taxon)
  }
  GROUP BY ?taxon
} AS %result
WHERE {
  # Label the results
  INCLUDE %result
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" . } 
}
ORDER BY DESC(?count)
LIMIT 200

graph TD