knowledgepixels / nanodash

A web client to browse and publish nanopublications.
GNU Affero General Public License v3.0
27 stars 2 forks source link

Add OLS API concepts/properties resolution in Nanopublications Templates #34

Closed vemonet closed 3 years ago

vemonet commented 3 years ago

I added a small block of code to resolve the EBI Ontology Lookup Service API in Template.java

It uses a if statement to check for OLS API URL, and grab the response to populate the select. So we can easily refactor this code as we wish later, maybe a small list of hadoc functions to resolve different types of APIs):

} else if (apiString.startsWith("https://www.ebi.ac.uk/ols/api/select")) {
    // Resolve EBI Ontology Lookup Service
    // e.g. https://www.ebi.ac.uk/ols/api/select?q=interacts%20with 
    // response.docs.[].iri/label
    JSONArray responseArray = json.getJSONObject("response").getJSONArray("docs");
    for (int i = 0; i < responseArray.length(); i++) {
        String uri = responseArray.getJSONObject(i).getString("iri");
        String label = responseArray.getJSONObject(i).getString("label");
        if (!values.contains(uri)) {
            values.add(uri);
            labelMap.put(uri, label);
        }
    }
}

It can be implemented this way in a template:

:uri a nt:GuidedChoicePlaceholder ;
    nt:possibleValuesFromApi "https://www.ebi.ac.uk/ols/api/select?q=" . 

Or only search in a specific ontology (e.g. the Relation Ontology ro):

:uri a nt:GuidedChoicePlaceholder ;
    nt:possibleValuesFromApi "https://www.ebi.ac.uk/ols/api/select?ontology=ro&q=" .

See this template as example: http://localhost:37373/publish?1&template=http://purl.org/np/RA8AXz5jnk5caKG-RnOT39_RD_WmPG4chQc2cBoiIzQ_U

The response time of the API is quite good!

nanobench_ols_api