[bioontology-support] [BioPortal] Feedback from marwa811

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[bioontology-support] [BioPortal] Feedback from marwa811

support

Name: marwa811

Email: [hidden email]

Location: https%3A%2F%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
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/bioontology-support
Reply | Threaded
Open this post in threaded view
|

Re: [bioontology-support] [BioPortal] Feedback from marwa811

Michael Dorf
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/metricsreturns 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, [hidden email] wrote:

Name: marwa811

[hidden email]

Location: https%3A%2F%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
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/bioontology-support


_______________________________________________
bioontology-support mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/bioontology-support
Reply | Threaded
Open this post in threaded view
|

Re: [bioontology-support] [BioPortal] Feedback from marwa811

Michael Dorf
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 <[hidden email]> 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/metricsreturns 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, [hidden email] wrote:

Name: marwa811

[hidden email]

Location: https%3A%2F%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
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/bioontology-support

_______________________________________________
bioontology-support mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/bioontology-support


_______________________________________________
bioontology-support mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/bioontology-support
Reply | Threaded
Open this post in threaded view
|

Re: [bioontology-support] [BioPortal] Feedback from marwa811

Michael Dorf
Hi Marwa,

I am sorry, I can’t validate your specific code. All I can do is guide you in the right direction. If you’re getting "Unreachable catch block for FileNotFoundException”, that means that NONE of the statements in this code

 JsonNode metrics = jsonToNode(get(ontology.get("links").get("metrics").asText()));
 
throws that exception. So if you did encounter FileNotFoundException previously, it must have been some other statement in your code that threw it.

You are making too many compound calls here, so it’s unclear which one of them is the source of your exception. I would break it down to individual statements for troubleshooting. Surround these in a generic try/catch/Exception block and see which of those lines throws an exception and what that exception is:

try  {
    links = ontology.get("links").get("metrics").asText();
    response = get(links);
    metrics = jsonToNode(response);
}  catch (Exception e)  {
    System.out.println(e.getClass().getCanonicalName());
}

This will give you the list of the possible exception types that this code would throw, and you can then decide which of these warrants a specific catch vs those that should be left for the generic "catch (Exception e)” block. I would highly recommend reviewing the Java exception hierarchy and precedence (this looks like a good doc: https://www.tutorialspoint.com/java/java_exceptions.htm).

Michael


On Sep 4, 2020, at 3:39 AM, Marwa Hussein <[hidden email]> wrote:

Hi Micheal,

Thanks for your reply, although I ofcourse tried the try-catch statements before sending you, actually the problem is that catch(FileNotFoundException) gives me a compilation error (Unreachable catch block for FileNotFoundException. This exception is never thrown from the try statement body) that's why I removed it from the code snippet I sent you. I don't know what is the reason for that although the catch(NullPointerException) doesn't cause this error?

try {
    JsonNode metrics = jsonToNode(get(ontology.get("links").get("metrics").asText()));
    } catch(FileNotFoundException e){
    System.out.println("No available metrics for this ontology (file not found)");
    }   catch(NullPointerException e){
    System.out.println("No available metrics for this ontology (null pointer)");
    }
I searched for a solution for this error and tried some solutions but none of them solved the error .. maybe you have an answer for that.

Regards, 
Marwa

From: Michael Dorf <[hidden email]>
Sent: Thursday, September 3, 2020 6:13 PM
To: [hidden email] <[hidden email]>
Cc: Marwa Hussein <[hidden email]>
Subject: Re: [bioontology-support] [BioPortal] Feedback from marwa811
 
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 <[hidden email]> 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/metricsreturns 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, [hidden email] wrote:

Name: marwa811 
Location: https%3A%2F%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
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/bioontology-support

_______________________________________________
bioontology-support mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/bioontology-support


_______________________________________________
bioontology-support mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/bioontology-support