Search Mailing List Archives


Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[bioontology-support] [BioPortal] Feedback from marwa811

Michael Dorf mdorf at stanford.edu
Thu Sep 3 09:13:42 PDT 2020


Sorry, my email client scrambled the formatting of the code snippet in my previous email, for some reason:

JsonNode ontologies = jsonToNode(get(link));

for (JsonNode ontology : ontologies) {
// put a breakpoint here and see what get(ontology.get("links").get("metrics").asText()) returns in each of these cases
// don’t automatically call jsonToNode() on the result, but instead handle each case individually

// alternatively, you can do try {} catch {} on these exceptions and skip the ontology if necessary
JsonNode metrics = null;

try {
metrics = jsonToNode(get(ontology.get("links").get("metrics").asText()));
} catch(FileNotFoundException e) {
// your code handling here for file not found
// ....
continue;
} catch(NullPointerException e) {
// your code handling here for null pointer exception
// ....
continue;
} catch(Exception e) {
// your code handling for all other exceptions
// ....
continue; // or exit or whatever
}
}

Michael

On Sep 3, 2020, at 9:09 AM, Michael Dorf <mdorf at stanford.edu<mailto:mdorf at stanford.edu>> wrote:

Hi Marwa,

No problem, we are here to help. I’ve looked at both ontologies that you’ve mentioned, and they each represent a different case.

IDO metrics API call (http://data.bioontology.org/ontologies/IDO/metrics) returns and empty set with a status 200 (OK):

{ }

CST metrics API call (http://data.bioontology.org/ontologies/CST/metrics) returns an error with a status 404 (Not Found), which points to an existing ontology object that’s missing its core data (submission):

{

  *
-
"errors": [
     *   "Ontology CST submission not found."
],
  *   "status": 404

}

You should have a handling in your code for each of these cases. You need to examine the metrics response object that you get for each ontology before making further calls on that object:

JsonNode ontologies = jsonToNode(get(link));
for (JsonNode ontology : ontologies) {// put a breakpoint here and see what get(ontology.get("links").get("metrics").asText()) returns in each of these cases // don’t automatically call jsonToNode() on the result, but instead handle each case individually
// alternatively, you can do try {} catch {} on these exceptions and skip the ontology if necessary JsonNode metrics = null;
try { metrics = jsonToNode(get(ontology.get("links").get("metrics").asText()));} catch(FileNotFoundException e) {// your code handling here for file not found// ....continue;} catch(NullPointerException e) {// your code handling here for null pointer exception// ....continue;} catch(Exception e) {// your code handling for all other exceptions// ....continue; // or exit or whatever}}


Keep in mind, these are just some ideas. My point is you should always examine the response of a call first and make a decision based on that response instead of making a blind call on that response.

Hope this gives you some pointers (vs NullPointers :-))

Michael



On Sep 1, 2020, at 3:51 PM, support at bioontology.org<mailto:support at bioontology.org> wrote:


Name: marwa811

Email: marwa.abdelrehem at fci.au.edu.eg<mailto:marwa.abdelrehem at fci.au.edu.eg>

Location: https%3A%2F%2Fbioportal.bioontology.org<http://2fbioportal.bioontology.org/>%2Fontologies%2FIDO

Feedback:

Hi,
I hope you are patient with me, since I am asking a lot in some "coding" details for Bioportal REST API.
Now I want to get "metrics" for any ontology. But what I discovered when running the code is that some ontologies don't have metrics link or file!! e.g. IDO and CST ontologies.
in this case, a file not found exception hits me "even if I am checking if the jsonnode object is null"
JsonNode metrics=null;
metrics = jsonToNode(get(ontology.get("links").get("metrics").asText()));

if(metrics != null)
{
String ontmetrics= "Classes: "+metrics.get("classes").asText() + "\n" ;
// Print out all the metrics
System.out.println(ontmetrics);
}
else
System.out.println("No available metrics for this ontology");
here the second line of the code throws the Filenotfound exception ..how to handle this?

_______________________________________________
bioontology-support mailing list
bioontology-support at lists.stanford.edu<mailto:bioontology-support at lists.stanford.edu>
https://mailman.stanford.edu/mailman/listinfo/bioontology-support

_______________________________________________
bioontology-support mailing list
bioontology-support at lists.stanford.edu<mailto:bioontology-support at lists.stanford.edu>
https://mailman.stanford.edu/mailman/listinfo/bioontology-support

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.stanford.edu/pipermail/bioontology-support/attachments/20200903/7d1d6313/attachment-0001.html>


More information about the bioontology-support mailing list