Wiki source code of Programming Interface Application
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | == Programmatic access (API) == |
| 2 | |||
| 3 | The EBRAINS Knowledge Graph provides convenient tools and APIs for the implementation of queries into your scripts. | ||
| 4 | |||
| 5 | **Request permission** | ||
| 6 | |||
| 7 | To be able to access the Knowledge Graph (KG) programmatically, you require: | ||
| 8 | |||
| 9 | 1. An EBRAINS account. Register for an account here: [[https:~~/~~/ebrains.eu/register/>>https://ebrains.eu/register/]] | ||
| 10 | 1. Register and request credentials for your KG client by emailing support@ebrains.eu | ||
| 11 | |||
| 12 | === Query Builder === | ||
| 13 | |||
| 14 | The query builder allows you to make, save, and reuse complex queries without any knowledge of graph query languages. | ||
| 15 | |||
| 16 | Go to the Query Builder: [[https:~~/~~/query.kg.ebrains.eu>>https://query.kg.ebrains.eu/#state=6a41dd5b-3cf9-4263-8a65-83d41f27677a&session_state=638c33f5-4551-4d70-8b1d-a5c900aa62d0&code=300f25d8-caac-4576-9a21-195ccc93fd31.638c33f5-4551-4d70-8b1d-a5c900aa62d0.4214dba9-b6d0-4331-9837-3e75a10cda14]] | ||
| 17 | |||
| 18 | ==== Select a category ==== | ||
| 19 | |||
| 20 | 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. | ||
| 21 | |||
| 22 | [[image:QB1.png||alt="Step 1: Select a category" height="520" width="700"]] | ||
| 23 | |||
| 24 | ==== Select an experimental approach ==== | ||
| 25 | |||
| 26 | Similar to the facetted filters in the Knowledge Graph Search UI, we can refine our query by defining the experimental approach of our interest, for example electrophysiology. | ||
| 27 | |||
| 28 | 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). | ||
| 29 | |||
| 30 | [[image:QBstep2.png||alt="Step 2: Select modality" height="541" width="700"]] | ||
| 31 | |||
| 32 | ==== Select species ==== | ||
| 33 | |||
| 34 | Similarly, we can refine our query for mice only. | ||
| 35 | |||
| 36 | [[image:QBstep3.png||alt="Step 3: Select species" height="543" width="700"]] | ||
| 37 | |||
| |
5.2 | 38 | |
| |
1.1 | 39 | ==== Access detailed metadata ==== |
| 40 | |||
| |
5.2 | 41 | (% class="wikigeneratedid" id="H" %) |
| 42 | Following | ||
| |
1.1 | 43 | |
| |
5.2 | 44 | ==== [[image:QB4.png||alt="Step 4: Access detailed metadata" height="432" width="700"]] ==== |
| |
1.1 | 45 | |
| |
5.2 | 46 | ==== ==== |
| 47 | |||
| 48 | The above query in the Query Builder is written below: | ||
| 49 | |||
| |
1.1 | 50 | {{code language="python"}} |
| |
5.2 | 51 | { |
| 52 | "@context": { | ||
| 53 | "@vocab": "https://core.kg.ebrains.eu/vocab/query/", | ||
| 54 | "query": "https://schema.hbp.eu/myQuery/", | ||
| 55 | "propertyName": { | ||
| 56 | "@id": "propertyName", | ||
| 57 | "@type": "@id" | ||
| 58 | }, | ||
| 59 | "path": { | ||
| 60 | "@id": "path", | ||
| 61 | "@type": "@id" | ||
| 62 | } | ||
| 63 | }, | ||
| 64 | "meta": { | ||
| 65 | "type": "https://openminds.ebrains.eu/core/DatasetVersion", | ||
| 66 | "responseVocab": "https://schema.hbp.eu/myQuery/" | ||
| 67 | }, | ||
| 68 | "structure": [ | ||
| 69 | { | ||
| 70 | "propertyName": "query:experimentalApproach", | ||
| 71 | "path": "https://openminds.ebrains.eu/vocab/experimentalApproach", | ||
| 72 | "required": true, | ||
| 73 | "structure": { | ||
| 74 | "propertyName": "query:name", | ||
| 75 | "path": "https://openminds.ebrains.eu/vocab/name", | ||
| 76 | "required": true, | ||
| 77 | "filter": { | ||
| 78 | "op": "CONTAINS", | ||
| 79 | "value": "electrophysiology" | ||
| 80 | } | ||
| 81 | } | ||
| 82 | }, | ||
| 83 | { | ||
| 84 | "propertyName": "query:studiedSpecimen", | ||
| 85 | "path": "https://openminds.ebrains.eu/vocab/studiedSpecimen", | ||
| 86 | "structure": [ | ||
| 87 | { | ||
| 88 | "propertyName": "query:species", | ||
| 89 | "path": "https://openminds.ebrains.eu/vocab/species", | ||
| 90 | "required": true, | ||
| 91 | "structure": [ | ||
| 92 | { | ||
| 93 | "propertyName": "query:name", | ||
| 94 | "path": "https://openminds.ebrains.eu/vocab/name" | ||
| 95 | }, | ||
| 96 | { | ||
| 97 | "propertyName": "query:species", | ||
| 98 | "path": "https://openminds.ebrains.eu/vocab/species", | ||
| 99 | "required": true, | ||
| 100 | "structure": { | ||
| 101 | "propertyName": "query:name", | ||
| 102 | "path": "https://openminds.ebrains.eu/vocab/name", | ||
| 103 | "required": true, | ||
| 104 | "filter": { | ||
| 105 | "op": "CONTAINS", | ||
| 106 | "value": "mus musculus" | ||
| 107 | } | ||
| 108 | } | ||
| 109 | } | ||
| 110 | ] | ||
| 111 | }, | ||
| 112 | { | ||
| 113 | "propertyName": "query:lookupLabel", | ||
| 114 | "path": "https://openminds.ebrains.eu/vocab/lookupLabel" | ||
| 115 | }, | ||
| 116 | { | ||
| 117 | "propertyName": "query:biologicalSex", | ||
| 118 | "path": "https://openminds.ebrains.eu/vocab/biologicalSex", | ||
| 119 | "structure": { | ||
| 120 | "propertyName": "query:name", | ||
| 121 | "path": "https://openminds.ebrains.eu/vocab/name", | ||
| 122 | "required": true, | ||
| 123 | "filter": { | ||
| 124 | "op": "CONTAINS", | ||
| 125 | "value": "male" | ||
| 126 | } | ||
| 127 | } | ||
| 128 | }, | ||
| 129 | { | ||
| 130 | "propertyName": "query:studiedState", | ||
| 131 | "path": "https://openminds.ebrains.eu/vocab/studiedState", | ||
| 132 | "structure": [ | ||
| 133 | { | ||
| 134 | "propertyName": "query:lookupLabel", | ||
| 135 | "path": "https://openminds.ebrains.eu/vocab/lookupLabel" | ||
| 136 | }, | ||
| 137 | { | ||
| 138 | "propertyName": "query:age", | ||
| 139 | "path": "https://openminds.ebrains.eu/vocab/age", | ||
| 140 | "structure": [ | ||
| 141 | { | ||
| 142 | "propertyName": "query:value", | ||
| 143 | "path": "https://openminds.ebrains.eu/vocab/value" | ||
| 144 | }, | ||
| 145 | { | ||
| 146 | "propertyName": "query:unit", | ||
| 147 | "path": "https://openminds.ebrains.eu/vocab/unit", | ||
| 148 | "structure": { | ||
| 149 | "propertyName": "query:name", | ||
| 150 | "path": "https://openminds.ebrains.eu/vocab/name" | ||
| 151 | } | ||
| 152 | } | ||
| 153 | ] | ||
| 154 | }, | ||
| 155 | { | ||
| 156 | "propertyName": "query:ageCategory", | ||
| 157 | "path": "https://openminds.ebrains.eu/vocab/ageCategory", | ||
| 158 | "structure": { | ||
| 159 | "propertyName": "query:name", | ||
| 160 | "path": "https://openminds.ebrains.eu/vocab/name" | ||
| 161 | } | ||
| 162 | }, | ||
| 163 | { | ||
| 164 | "propertyName": "query:attribute", | ||
| 165 | "path": "https://openminds.ebrains.eu/vocab/attribute", | ||
| 166 | "structure": { | ||
| 167 | "propertyName": "query:name", | ||
| 168 | "path": "https://openminds.ebrains.eu/vocab/name" | ||
| 169 | } | ||
| 170 | } | ||
| 171 | ] | ||
| 172 | } | ||
| 173 | ] | ||
| 174 | } | ||
| 175 | ] | ||
| 176 | } | ||
| |
1.1 | 177 | {{/code}} |
| 178 | |||
| 179 |