arrow

From NeuroLex

(Redirected from SparqlEndPoint)
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.


Contents

Example

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/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.

More advanced query examples can be found on another page

Python

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 # install e.g. with pip install SPARQLWrapper

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/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["name"]["value"]

Alternately, the rdflib python library has its own SPARQL processor. Some additional examples of this, which demonstrates pulling individual of pages of RDF out of NeuroLex rather than parsing the entire NeuroLex RDF graph, are available as an iPython Notebook.

Terms

A list of all terms can be generated from the endpoint.

The following query demonstrates this:

prefix property: <http://neurolex.org/wiki/Property-3A>

select DISTINCT ?name ?id where 
{?x property:Label ?name .
 ?x property:Id ?id} 

Note that using the "ORDER BY" modifier to sort by name will take an excessive amount of time. We recommend sorting the output on your end via an efficient script.


You can get this out in text or csv via these direct links.

Properties

A list of all properties can be generated with the following query:

select DISTINCT ?prop where 
{?x ?prop ?y} 


bookmark

*Note: Neurolex imports many terms and their ids from existing community ontologies, e.g., the Gene Ontology. Neurolex, however, is a dynamic site and any content beyond the identifier should not be presumed to reflect the content or views of the source ontology. Users should consult with the authoritative source for each ontology for current information.