SPARQL query that fetches all the food products only

13 views
Skip to first unread message

Ma N

unread,
Jan 31, 2023, 4:43:24 PM1/31/23
to FoodOn Farm-to-Fork Food Ontology Consortium
Is there a succinct way to only query the food products extremities?

Can we query a list of the most specific food products in the ontology such as:
- avocado (whole, raw)
- guacamole
- ...

Maybe a SPARQL query that queries the edges of the RDF graph rooted at the food product class?

Thank you for the help!

Ma N

unread,
Feb 3, 2023, 2:30:15 PM2/3/23
to FoodOn Farm-to-Fork Food Ontology Consortium
Found it!


PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT DISTINCT ?cls ?label

WHERE {
    ?cls rdfs:label ?label .
    ?cls rdfs:subClassOf* <http://purl.obolibrary.org/obo/FOODON_00001002> .
    ?cls rdfs:subClassOf ?sup .
    FILTER NOT EXISTS { ?sub rdfs:subClassOf ?cls FILTER(?sub != ?cls && ?sub != owl:Nothing) }
}

Fetches all the extremities of the subtree rooted at the food product class

Damion Dooley

unread,
Feb 3, 2023, 2:35:56 PM2/3/23
to FoodOn Farm-to-Fork Food Ontology Consortium
Thanks for reporting your solution!  I wanted to mention that we're doing another wave of curation on FoodOn, this time fashioning templates that animal and plant foods should fit in, generally.  This will bring a lot more consistency per plant and animal type to what you retrieve in querying the "leaf" extremities.  At moment the extremity content is manually managed in protege or via "robot" tables, rather than via templates.
Reply all
Reply to author
Forward
0 new messages