lotus-sparql-examples

A set of SPARQL examples that are used in LOTUS

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

wd_dishes_ingredients_diversity

rq turtle/ttl

Dishes with ingredients found in the most diverse taxa.

Use at


PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX hint: <http://www.bigdata.com/queryHints#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
#title: Dishes with ingredients found in the most diverse taxa.
SELECT DISTINCT ?dish ?dishLabel (COUNT(DISTINCT ?ingredient) AS ?ingredients) (COUNT(DISTINCT ?parent) AS ?parents) WHERE {
    {
        SELECT DISTINCT ?dish ?dishLabel ?ingredient ?taxon WHERE {
            {
                SELECT DISTINCT ?dish ?dishLabel ?ingredient WHERE {
                    hint:Query hint:optimizer "None".
                    ?dish wdt:P31 wd:Q746549;
                    (wdt:P527+) ?ingredient.
                    hint:Prior hint:gearing "forward".
                    SERVICE wikibase:label {
                        bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en".
                        ?dish rdfs:label ?dishLabel.
                    }
                }
            }
            hint:Prior hint:runFirst "true".
            ?ingredient (wdt:P186*) ?subingredient.
            {
                ?subingredient wdt:P31 wd:Q16521.
                BIND(?subingredient AS ?taxon)
            }
            UNION
            { ?subingredient wdt:P1582 ?taxon. }
        }
    }
    hint:Prior hint:runFirst true.
    ?taxon (wdt:P171*) ?parent.
}
GROUP BY ?dish ?dishLabel
ORDER BY DESC (?parents)

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v2("?dish"):::projected 
  v4("?dishLabel"):::projected 
  v3("?ingredient"):::projected 
  v8("?ingredients")
  v7("?parent"):::projected 
  v9("?parents")
  v5("?subingredient")
  v6("?taxon")
  c7([http://www.bigdata.com/queryHints#Prior]):::iri 
  c9(["forward"]):::literal 
  c13(["#91;AUTO_LANGUAGE#93;,mul,en"]):::literal 
  c5(["wd:Q746549"]):::iri 
  c11([http://www.bigdata.com/rdf#serviceParam]):::iri 
  c1([http://www.bigdata.com/queryHints#Query]):::iri 
  c16(["true"]):::literal 
  c20(["true^^xsd:boolean"]):::literal 
  c18(["wd:Q16521"]):::iri 
  c3(["None"]):::literal 
  c1 --http://www.bigdata.com/queryHints#optimizer-->  c3
  v2 --"wdt:P31"-->  c5
  v2 --"wdt:P527"-->  v3
  c7 --http://www.bigdata.com/queryHints#gearing-->  c9
  subgraph s1["http://wikiba.se/ontology#label"]
    style s1 stroke-width:4px;
    c11 --"wikibase:language"-->  c13
    v2 --"rdfs:label"-->  v4
  end
  c7 --http://www.bigdata.com/queryHints#runFirst-->  c16
  v3 --"wdt:P186"-->  v5
  subgraph union0[" Union "]
  subgraph union0l[" "]
    style union0l fill:#abf,stroke-dasharray: 3 3;
    v5 --"wdt:P1582"-->  v6
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    v5 --"wdt:P31"-->  c18
    bind0[/"?subingredient"/]
    v5 --o bind0
    bind0 --as--o v6
  end
  union0r <== or ==> union0l
  end
  c7 --http://www.bigdata.com/queryHints#runFirst-->  c20
  v6 --"wdt:P171"-->  v7
  bind3[/"count(?ingredient)"/]
  v3 --o bind3
  bind3 --as--o v8
  bind4[/"count(?parent)"/]
  v7 --o bind4
  bind4 --as--o v9