Loading/Accessing FOODON ontology directly within Python

163 views
Skip to first unread message

Nick Lindberg

unread,
Jun 23, 2020, 2:50:19 PM6/23/20
to FoodOn Farm-to-Fork Food Ontology Consortium
Hello,

I've followed and successfully replicated the actions of creating a SPARQL query inside Protoge using the tutorial on the FOODON reuse page.  

I've also looked in to OWL related packages within Python, and have successfully 'loaded' the FOODON ontology from within Python using the OwlReady2 package, however, I can't seem to completely figure out how to tie that together to get the ontology for a specific food item.

Essentially-- I have the spreadsheets that link food items to "FOODON_*" tags, and I want to be able to query a food item from within a Python script and have the ontology mapping returned much like you can do from one of the three or four publically hosted ontology explorers such as ontobee at U of Michigan.

Anybody have experience doing something like this programmatically?  Otherwise I'll have to stick to trying to do it somewhat programmatically via SPARQL from within Protoge or potentially the Protoge API, which seems like kind of a hack.

Thank you.  I did search a ton for this but couldn't find much.

Nick

Damion Dooley

unread,
Jun 23, 2020, 3:06:08 PM6/23/20
to Nick Lindberg, FoodOn Farm-to-Fork Food Ontology Consortium
Hi Nick,

There are a few ways to go:

For running a SPARQL query and getting tabular results:

##To run SPARQL queries

As Protege's sparql query engine has some odd startup phase that often stalls protege on large ontologies, one may need to launch sparql queries via command line directly. Here is an example using http://robot.obolibrary.org/query.html

robot query --input foodon-merged.owl --query owl_get_labels.sparql test.tsv --format TSV

The example “owl_get_labels.sparql” query is located in the FoodOn /src/ontology/ folder. Robot is handy for many other things too, including updating annotations and merging content in owl ontologies.

The other way to go is to use rdflib directly in python. It provides comprehensive querying and rdf or tabular results.  A stand-alone example is here:


Now I can’t recall if that’s been upgraded to python 3. If not then this code is probably a better version but it is geared to more specific vocabulary work, and involves another module, onto helper.py which does the same stuff as ontology_query.py .


Hope this helps?!

Damion



--
You received this message because you are subscribed to the Google Groups "FoodOn Farm-to-Fork Food Ontology Consortium" group.
To unsubscribe from this group and stop receiving emails from it, send an email to foodon-consort...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/foodon-consortium/5574c819-ea8c-4d9a-b408-5469d06f60e0o%40googlegroups.com.

Nick Lindberg

unread,
Jun 24, 2020, 3:50:45 PM6/24/20
to FoodOn Farm-to-Fork Food Ontology Consortium
Damion,

This is incredibly helpful!  I should have mentioned that command line access was the real goal here (Python being a mere convenience.). I'm screwing around with the robot tool right now and may have a few more questions, but this definitely points me in the right direction.

Nick
To unsubscribe from this group and stop receiving emails from it, send an email to foodon-c...@googlegroups.com.

Damion Dooley

unread,
Jun 26, 2020, 3:31:54 PM6/26/20
to FoodOn Farm-to-Fork Food Ontology Consortium
My one followup to that was, if the objective is to fetch one or more branches of vocabulary from FoodOn or another OBOFoundry ontology from the command line, then besides robot, you can try python command line ontofetch which doesn't even need a sparql query.  It returns standard label definition, parent(s), synonyms for a branch of terms.

Ammar HDAIFEH

unread,
Jun 26, 2020, 3:32:44 PM6/26/20
to Nick Lindberg, FoodOn Farm-to-Fork Food Ontology Consortium
Hi

sorry but i am confusing, what is  FOODON , OWL , SPARQL !!!

my best regards

Ammar  




--
You received this message because you are subscribed to the Google Groups "FoodOn Farm-to-Fork Food Ontology Consortium" group.
To unsubscribe from this group and stop receiving emails from it, send an email to foodon-consort...@googlegroups.com.

Damion Dooley

unread,
Jun 26, 2020, 3:51:07 PM6/26/20
to FoodOn Farm-to-Fork Food Ontology Consortium
Hi Ammar,

I can explain briefly the abbreviations and a few links:

OWL https://www.w3.org/OWL/: a specification format for describing an ontology. An Ontology expressed in OWL can be used to describe data or model database structure even, so that records contain ontology vocabulary.

FoodOn: https://foodon.org/, an ontology about food.

SPARQL https://www.w3.org/TR/rdf-sparql-query/: A querying language that can apply to RDF/XML structured data.  OWL ontologies and databases that use them can be expressed in RDF/XML.

d.

On Friday, 26 June 2020 12:32:44 UTC-7, Ammar HDAIFEH wrote:
Hi

sorry but i am confusing, what is  FOODON , OWL , SPARQL !!!

my best regards

Ammar  


Reply all
Reply to author
Forward
0 new messages