lotus-sparql-examples

A set of SPARQL examples that are used in LOTUS

View the Project on GitHub lotusnprod/lotus-sparql-examples

wd_nps_per_author_2

rq turtle/ttl

Top 30 authors reporting the most natural products (sample of 10,000).

Use at


PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX hint: <http://www.bigdata.com/queryHints#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
#title: Top 30 authors reporting the most natural products (sample of 10,000).
#defaultView:BubbleChart
SELECT ?authorLabel ?nationalityLabel ?rgb (COUNT(DISTINCT ?compound) AS ?count) WHERE {
    {
        SELECT DISTINCT ?compound ?art WHERE {
            {
                SELECT DISTINCT ?compound WHERE {
                    ?compound wdt:P235 ?inchikey.
                    SERVICE bd:sample {
                        ?compound wdt:P703 ?taxon_with_compound.
                        bd:serviceParam bd:sample.limit 10000 .
                    }
                }
            }
            hint:Prior hint:runFirst "true".
            ?compound p:P703 ?stmt.
            ?stmt (prov:wasDerivedFrom/pr:P248) ?art.
        }
    }
    hint:Prior hint:runFirst true.
    ?art wdt:P50 ?author.
    ?author wdt:P21 ?gender;
    wdt:P27 ?nationality.
    BIND(IF(?gender = wd:Q6581097, "2994D2", "D71D62") AS ?rgb)
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }
}
GROUP BY ?authorLabel ?nationalityLabel ?rgb
ORDER BY DESC (?count)
LIMIT 30

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v6("?art")
  v7("?author")
  v2("?compound"):::projected 
  v11("?count")
  v8("?gender")
  v3("?inchikey")
  v9("?nationality")
  v10("?rgb"):::projected 
  v5("?stmt")
  v4("?taxon_with_compound")
  a1((" "))
  c7([http://www.bigdata.com/queryHints#Prior]):::iri 
  c19(["#91;AUTO_LANGUAGE#93;,mul,en"]):::literal 
  c4([http://www.bigdata.com/rdf#serviceParam]):::iri 
  c6(["10000^^xsd:integer"]):::literal 
  c9(["true"]):::literal 
  c13(["true^^xsd:boolean"]):::literal 
  v2 --"p:direct/P235"-->  v3
  subgraph s1["http://www.bigdata.com/rdf#sample"]
    style s1 stroke-width:4px;
    v2 --"p:direct/P703"-->  v4
    c4 --http://www.bigdata.com/rdf#sample.limit-->  c6
  end
  c7 --http://www.bigdata.com/queryHints#runFirst-->  c9
  v2 --"p:P703"-->  v5
  v5 --"prov:wasDerivedFrom"-->  a1
  a1 --"p:reference/P248"-->  v6
  c7 --http://www.bigdata.com/queryHints#runFirst-->  c13
  v6 --"p:direct/P50"-->  v7
  v7 --"p:direct/P21"-->  v8
  v7 --"p:direct/P27"-->  v9
  bind0[/"if(?gender = 'wd:Q6581097','2994D2','D71D62')"/]
  v8 --o bind0
  bind0 --as--o v10
  subgraph s2["http://wikiba.se/ontology#label"]
    style s2 stroke-width:4px;
    c4 --"wikibase:language"-->  c19
  end
  bind2[/"count(?compound)"/]
  v2 --o bind2
  bind2 --as--o v11