Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@knudmoeller
Last active March 7, 2019 16:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save knudmoeller/fce8421b38f37217c86908aede0f54cd to your computer and use it in GitHub Desktop.
Save knudmoeller/fce8421b38f37217c86908aede0f54cd to your computer and use it in GitHub Desktop.
Wikidata Query to find edible products of plants
SELECT ?ediblething ?ediblethingLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
wd:Q158657 wdt:P171+ ?parent_taxon . # Q158657 is "Malus pumila", the tree we want to find fruit for
?ediblething
wdt:P1582 ?parent_taxon ;
wdt:P279 ?superthing .
?superthing wdt:P361 wd:Q21925565 .
}
LIMIT 100
# wdt:P171 - parent taxon
# wdt:p1582 - natural product of taxon
# wdt:P279 - subclass of
# wdt:P361 - part of
# wd:Q21925565 - fruit and vegetables
# wd:Q3314483 - fruit
# alternatively:
ASK {
wd:Q158657 wdt:P171+ ?parent_taxon . # Q158657 is "Malus pumila", the tree we want to find fruit for
?ediblething
wdt:P1582 ?parent_taxon ;
wdt:P279 ?superthing .
?superthing wdt:P361 wd:Q21925565 .
}
# or: get number of species of plant with edible things
SELECT (COUNT(DISTINCT ?plant) AS ?count) WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?plant wdt:P171+ ?parent_taxon . # Q158657 is "Malus pumila", the tree we want to find fruit for
?ediblething
wdt:P1582 ?parent_taxon ;
wdt:P279 ?superthing .
?superthing wdt:P361 wd:Q21925565 .
}
# => 49718
# and now: get species with labels that have fruits
SELECT DISTINCT ?plant ?plantLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?plant
wdt:P171* ?parent_taxon ;
wdt:P105 wd:Q7432 .
?ediblething
wdt:P1582 ?parent_taxon ;
wdt:P279 wd:Q3314483 .
}
ORDER BY ?plantLabel
LIMIT 2000
# ~1400 results
#
SELECT DISTINCT ?plant ?plantLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "de". }
?plant wdt:P171 ?parent_taxon .
FILTER(
?plant = wd:Q10951249
|| ?plant = wd:Q131517
|| ?plant = wd:Q13189701
|| ?plant = wd:Q13189864
|| ?plant = wd:Q13189
|| ?plant = wd:Q146281
|| ?plant = wd:Q1470571
|| ?plant = wd:Q149332
|| ?plant = wd:Q157960
|| ?plant = wd:Q158657
|| ?plant = wd:Q1591053
|| ?plant = wd:Q165137
|| ?plant = wd:Q1683370
|| ?plant = wd:Q17238257
|| ?plant = wd:Q1743596
|| ?plant = wd:Q21326071
|| ?plant = wd:Q21370443
|| ?plant = wd:Q3079266
|| ?plant = wd:Q37453
|| ?plant = wd:Q44120
|| ?plant = wd:Q47161
|| ?plant = wd:Q4992558
|| ?plant = wd:Q5990804
|| ?plant = wd:Q886464
)
}
ORDER BY ?plantLabel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment