Skip to content

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

Merged
tkuhn merged 2 commits into
knowledgepixels:masterfrom
vemonet:add-ols-api
Nov 20, 2020
Merged

Add OLS API concepts/properties resolution in Nanopublications Templates#34
tkuhn merged 2 commits into
knowledgepixels:masterfrom
vemonet:add-ols-api

Conversation

@vemonet

@vemonet vemonet commented Nov 19, 2020

Copy link
Copy Markdown
Contributor

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

@tkuhn
tkuhn merged commit b1b19cf into knowledgepixels:master Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants