arrow

From NeuroLex

Jump to: navigation, search

The SPARQL endpoint is hosted at http://rdf-stage.neuinfo.org/. You will need to go to "control panel" and select /ds before you will be able to issue a SPARQL 1.1 query.

It contains triples generated from the NeuroLex RDF export that is exposed at http://neurolex.org/OWL/nlx_stage_all.rdf. The RDF is refreshed every hour both as a file and within the endpoint in order to facilitate changes on the wiki being usable for external SPARQL reasoning in near-realtime.

We demonstrate a simple query that retrieves all known things located in the Granular layer of cerebellar cortex.

prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix property: <http://neurolex.org/wiki/Special:URIResolver/Property-3A>

select DISTINCT ?name ?id where 
{?x property:Id "birnlex_779"^^xsd:string .     # the id corresponds to the Granular layer of cerebellar cortex
?cells property:Located_in ?x.                  # find anything using the Located_in property (typically only cells)
?cells property:Label ?name.                    # get the name of the triples matched above from the label
?cells property:Id ?id}                         # get the id of the triples matched above

To execute the above query, place it in the dialog box "Query text" and press "Run Query". By default the result is displayed in JSON. Switch to "text" to see results as below:

-------------------------------------------------------------------------------------------------------------------------------------
| name                                                                 | id                                                         |
=====================================================================================================================================
| "Cerebellum granule cell"^^<http://www.w3.org/2001/XMLSchema#string> | "nifext_128"^^<http://www.w3.org/2001/XMLSchema#string>    |
| "Cerebellum Golgi cell"^^<http://www.w3.org/2001/XMLSchema#string>   | "sao1415726815"^^<http://www.w3.org/2001/XMLSchema#string> |
| "Cerebellum Lugaro cell"^^<http://www.w3.org/2001/XMLSchema#string>  | "nifext_133"^^<http://www.w3.org/2001/XMLSchema#string>    |
-------------------------------------------------------------------------------------------------------------------------------------

Here results binding to "name" provide the name of the entity that match the query and results binding to "id" show their NIF IDs.

Queries can be run programmatically in Python using the SPARQLWrapper library. The query above can be run using the script below:

from SPARQLWrapper import SPARQLWrapper, JSON

sparql = SPARQLWrapper("http://rdf-stage.neuinfo.org/ds/query")
sparql.setQuery("""
   prefix xsd: <http://www.w3.org/2001/XMLSchema#>
   prefix property: <http://neurolex.org/wiki/Special:URIResolver/Property-3A>

   select DISTINCT ?name ?id where 
   {?x property:Id "birnlex_779"^^xsd:string .     # the id corresponds to the Granular layer of cerebellar cortex
   ?cells property:Located_in ?x.                  # find anything using the Located_in property (typically only cells)
   ?cells property:Label ?name.                    # get the name of the triples matched above from the label
   ?cells property:Id ?id}                         # get the id of the triples matched above
""")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()

for result in results["results"]["bindings"]:
    print result["b"]['value']

More advanced query examples can be found on another page



bookmark