Maintenance: Our production K8s cluster at JSC will be undergoing an update tonight, starting after 23:00 CEST. The cluster will be temporarily unavailable for approximately 20 minutes, and prod instances running at rke2-1-jsccloud may experience a brief downtime. Thank you for your understanding.


Programming Interface Application (API)

Version 8.1 by oschmid on 2022/07/05 13:10

Programmatic access (API)

The EBRAINS Knowledge Graph provides convenient tools and APIs for the implementation of queries into your scripts. 

Request permission

To be able to access the Knowledge Graph (KG) programmatically, you only require an EBRAINS account. Register for an account here: https://ebrains.eu/register/ and log in.

Writing Knowledge Graph queries

A query for the Knowledge Graph is defined declaratively in JSON-LD and always executed against a specific data structure (e.g. a "Dataset version") allowing the graph to be traversed.

In the snippet below, we can see that we first define the semantical context for the query with "@context", which belongs to the namespace "https://schema.hbp.eu/graphQuery/".

{
 "@context": {
   "@vocab": "https://core.kg.ebrains.eu/vocab/query/",
   "query": "https://schema.hbp.eu/myQuery/",
   "propertyName": {
     "@id": "propertyName",
     "@type": "@id"
    },
   "path": {
     "@id": "path",
     "@type": "@id"
    }
  },
 "meta": {
   "type": "https://openminds.ebrains.eu/core/DatasetVersion",
   "responseVocab": "https://schema.hbp.eu/myQuery/"
  },
 "structure": {
   "propertyName": "query:DatasetVersionTitle",
   "path": "https://openminds.ebrains.eu/vocab/shortName"
  }
}

Query Builder

The query builder allows you to make, save, and reuse complex queries without any knowledge of graph query languages.

Go to the Query Builder: https://query.kg.ebrains.eu

Select a category

A query for the Knowledge Graph is always executed against a specific data structure (e.g. a "Dataset version"). First select the data structure for your query.

Step 1: Select a category

Select an experimental approach

Similar to the faceted filters in the Knowledge Graph Search UI, we can refine our query by defining the experimental approach of our interest, for example electrophysiology.

To ensure that all dataset versions with electrophysiology are queried, and none of the dataset versions without electrophysiology, we make this property required and we apply a filter to the label we are searching for (i.e. electrophysiology).

Step 2: Select modality

Select species

Similarly, we can refine our query for mice only.

Step 3: Select species

Access detailed metadata

Following 

Step 4: Access detailed metadata

The above query in the Query Builder is written below:

{
 "@context": {
   "@vocab": "https://core.kg.ebrains.eu/vocab/query/",
   "query": "https://schema.hbp.eu/myQuery/",
   "propertyName": {
     "@id": "propertyName",
     "@type": "@id"
    },
   "path": {
     "@id": "path",
     "@type": "@id"
    }
  },
 "meta": {
   "type": "https://openminds.ebrains.eu/core/DatasetVersion",
   "responseVocab": "https://schema.hbp.eu/myQuery/"
  },
 "structure": [
    {
     "propertyName": "query:experimentalApproach",
     "path": "https://openminds.ebrains.eu/vocab/experimentalApproach",
     "required": true,
     "structure": {
       "propertyName": "query:name",
       "path": "https://openminds.ebrains.eu/vocab/name",
       "required": true,
       "filter": {
         "op": "CONTAINS",
         "value": "electrophysiology"
        }
      }
    },
    {
     "propertyName": "query:studiedSpecimen",
     "path": "https://openminds.ebrains.eu/vocab/studiedSpecimen",
     "structure": [
        {
         "propertyName": "query:species",
         "path": "https://openminds.ebrains.eu/vocab/species",
         "required": true,
         "structure": [
            {
             "propertyName": "query:name",
             "path": "https://openminds.ebrains.eu/vocab/name"
            },
            {
             "propertyName": "query:species",
             "path": "https://openminds.ebrains.eu/vocab/species",
             "required": true,
             "structure": {
               "propertyName": "query:name",
               "path": "https://openminds.ebrains.eu/vocab/name",
               "required": true,
               "filter": {
                 "op": "CONTAINS",
                 "value": "mus musculus"
                }
              }
            }
          ]
        },
        {
         "propertyName": "query:lookupLabel",
         "path": "https://openminds.ebrains.eu/vocab/lookupLabel"
        },
        {
         "propertyName": "query:biologicalSex",
         "path": "https://openminds.ebrains.eu/vocab/biologicalSex",
         "structure": {
           "propertyName": "query:name",
           "path": "https://openminds.ebrains.eu/vocab/name",
           "required": true,
           "filter": {
             "op": "CONTAINS",
             "value": "male"
            }
          }
        },
        {
         "propertyName": "query:studiedState",
         "path": "https://openminds.ebrains.eu/vocab/studiedState",
         "structure": [
            {
             "propertyName": "query:lookupLabel",
             "path": "https://openminds.ebrains.eu/vocab/lookupLabel"
            },
            {
             "propertyName": "query:age",
             "path": "https://openminds.ebrains.eu/vocab/age",
             "structure": [
                {
                 "propertyName": "query:value",
                 "path": "https://openminds.ebrains.eu/vocab/value"
                },
                {
                 "propertyName": "query:unit",
                 "path": "https://openminds.ebrains.eu/vocab/unit",
                 "structure": {
                   "propertyName": "query:name",
                   "path": "https://openminds.ebrains.eu/vocab/name"
                  }
                }
              ]
            },
            {
             "propertyName": "query:ageCategory",
             "path": "https://openminds.ebrains.eu/vocab/ageCategory",
             "structure": {
               "propertyName": "query:name",
               "path": "https://openminds.ebrains.eu/vocab/name"
              }
            },
            {
             "propertyName": "query:attribute",
             "path": "https://openminds.ebrains.eu/vocab/attribute",
             "structure": {
               "propertyName": "query:name",
               "path": "https://openminds.ebrains.eu/vocab/name"
              }
            }
          ]
        }
      ]
    }
  ]
}