JupyterLab : We are currently experiencing unexpected issues following a recent system update, and as a result, the Lab @ JSC is temporarily unavailable. We apologize for the inconvenience this may cause. In the meantime, we kindly ask users to use the Lab @ Cineca as an alternative.


Version 9.2 by oschmid on 2022/07/05 13:20

Show last authors
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 only require an EBRAINS account. Register for an account here: [[https:~~/~~/ebrains.eu/register/>>https://ebrains.eu/register/]] and log in.
8
9 === Writing Knowledge Graph queries ===
10
11 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.
12
13 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/".//
14
15 {{code language="python"}}
16 {
17 "@context": {
18 "@vocab": "https://core.kg.ebrains.eu/vocab/query/",
19 "query": "https://schema.hbp.eu/myQuery/",
20 "propertyName": {
21 "@id": "propertyName",
22 "@type": "@id"
23 },
24 "path": {
25 "@id": "path",
26 "@type": "@id"
27 }
28 },
29 "meta": {
30 "type": "https://openminds.ebrains.eu/core/DatasetVersion",
31 "responseVocab": "https://schema.hbp.eu/myQuery/"
32 },
33 "structure": {
34 "propertyName": "query:DatasetVersionTitle",
35 "path": "https://openminds.ebrains.eu/vocab/shortName"
36 }
37 }
38 {{/code}}
39
40
41 ==== Query Builder ====
42
43 The query builder allows you to make, save, and reuse complex queries without any knowledge of graph query languages.
44
45 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]]
46
47 (% class="wikigeneratedid" id="HSelectacategory" %)
48 **Select a category**
49
50 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.
51
52 [[image:QB1.png||alt="Step 1: Select a category" height="520" width="700"]]
53
54 (% class="wikigeneratedid" id="HSelectanexperimentalapproach" %)
55 **Select an experimental approach**
56
57 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.
58
59 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).
60
61 [[image:QBstep2.png||alt="Step 2: Select modality" height="541" width="700"]]
62
63 (% class="wikigeneratedid" id="HSelectspecies" %)
64 **Select species**
65
66 Similarly, we can refine our query for mice only.
67
68 [[image:QBstep3.png||alt="Step 3: Select species" height="543" width="700"]]
69
70
71 (% class="wikigeneratedid" id="HAccessdetailedmetadata" %)
72 **Access detailed metadata**
73
74 (% class="wikigeneratedid" id="H" %)
75 Following
76
77 ==== [[image:QB4.png||alt="Step 4: Access detailed metadata" height="432" width="700"]] ====
78
79 ==== ====
80
81 The above query in the Query Builder is written below:
82
83 {{code language="python"}}
84 {
85 "@context": {
86 "@vocab": "https://core.kg.ebrains.eu/vocab/query/",
87 "query": "https://schema.hbp.eu/myQuery/",
88 "propertyName": {
89 "@id": "propertyName",
90 "@type": "@id"
91 },
92 "path": {
93 "@id": "path",
94 "@type": "@id"
95 }
96 },
97 "meta": {
98 "type": "https://openminds.ebrains.eu/core/DatasetVersion",
99 "responseVocab": "https://schema.hbp.eu/myQuery/"
100 },
101 "structure": [
102 {
103 "propertyName": "query:experimentalApproach",
104 "path": "https://openminds.ebrains.eu/vocab/experimentalApproach",
105 "required": true,
106 "structure": {
107 "propertyName": "query:name",
108 "path": "https://openminds.ebrains.eu/vocab/name",
109 "required": true,
110 "filter": {
111 "op": "CONTAINS",
112 "value": "electrophysiology"
113 }
114 }
115 },
116 {
117 "propertyName": "query:studiedSpecimen",
118 "path": "https://openminds.ebrains.eu/vocab/studiedSpecimen",
119 "structure": [
120 {
121 "propertyName": "query:species",
122 "path": "https://openminds.ebrains.eu/vocab/species",
123 "required": true,
124 "structure": [
125 {
126 "propertyName": "query:name",
127 "path": "https://openminds.ebrains.eu/vocab/name"
128 },
129 {
130 "propertyName": "query:species",
131 "path": "https://openminds.ebrains.eu/vocab/species",
132 "required": true,
133 "structure": {
134 "propertyName": "query:name",
135 "path": "https://openminds.ebrains.eu/vocab/name",
136 "required": true,
137 "filter": {
138 "op": "CONTAINS",
139 "value": "mus musculus"
140 }
141 }
142 }
143 ]
144 },
145 {
146 "propertyName": "query:lookupLabel",
147 "path": "https://openminds.ebrains.eu/vocab/lookupLabel"
148 },
149 {
150 "propertyName": "query:biologicalSex",
151 "path": "https://openminds.ebrains.eu/vocab/biologicalSex",
152 "structure": {
153 "propertyName": "query:name",
154 "path": "https://openminds.ebrains.eu/vocab/name",
155 "required": true,
156 "filter": {
157 "op": "CONTAINS",
158 "value": "male"
159 }
160 }
161 },
162 {
163 "propertyName": "query:studiedState",
164 "path": "https://openminds.ebrains.eu/vocab/studiedState",
165 "structure": [
166 {
167 "propertyName": "query:lookupLabel",
168 "path": "https://openminds.ebrains.eu/vocab/lookupLabel"
169 },
170 {
171 "propertyName": "query:age",
172 "path": "https://openminds.ebrains.eu/vocab/age",
173 "structure": [
174 {
175 "propertyName": "query:value",
176 "path": "https://openminds.ebrains.eu/vocab/value"
177 },
178 {
179 "propertyName": "query:unit",
180 "path": "https://openminds.ebrains.eu/vocab/unit",
181 "structure": {
182 "propertyName": "query:name",
183 "path": "https://openminds.ebrains.eu/vocab/name"
184 }
185 }
186 ]
187 },
188 {
189 "propertyName": "query:ageCategory",
190 "path": "https://openminds.ebrains.eu/vocab/ageCategory",
191 "structure": {
192 "propertyName": "query:name",
193 "path": "https://openminds.ebrains.eu/vocab/name"
194 }
195 },
196 {
197 "propertyName": "query:attribute",
198 "path": "https://openminds.ebrains.eu/vocab/attribute",
199 "structure": {
200 "propertyName": "query:name",
201 "path": "https://openminds.ebrains.eu/vocab/name"
202 }
203 }
204 ]
205 }
206 ]
207 }
208 ]
209 }
210 {{/code}}
211
212