-
Notifications
You must be signed in to change notification settings - Fork 10
/
queries.py
510 lines (314 loc) · 14.4 KB
/
queries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
from SPARQLWrapper import SPARQLWrapper, JSON
from IPython.display import display
import pandas as pd
import json
import numpy as np
from pandas.io.json import json_normalize
import matplotlib.pyplot as plt
pd.options.display.max_colwidth = 100
pd.options.display.max_rows = 999
def execute_query(sparqlQuery):
sparql = SPARQLWrapper("http://localhost:8082/sparql")
sparql.setQuery(sparqlQuery)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
results_df = json_normalize(results["results"]["bindings"])
# results_df = results_df[results_df['o.type'] == "uri"]
# results_df = results_df.drop(['o.datatype','o.type', 'o.xml:lang','p.type'],axis=1)
# results_df = results_df[['p.value','o.value','countS.value']]
# results_df['countS.value'] = results_df['countS.value'].astype(int)
# results_df = results_df[results_df['countS.value'] > 1]
return results_df
### Number of publications by year across all conferences
yearCount = """
Select count(distinct ?s) as ?Count ?year where {
?s a <https://github.com/deepcurator/DCC/Publication> .
?s <https://github.com/deepcurator/DCC/conferenceSeries> ?o .
?s <https://github.com/deepcurator/DCC/yearOfPublication> ?year .
}Group by ?year ORDER by DESC(?year)
"""
results_df = execute_query(yearCount)
results_df = results_df.drop(['Count.datatype', 'Count.type', 'year.datatype',
'year.type'],axis=1)
results_df.columns
results_df.head()
results_df = results_df.astype(int)
ax = results_df.plot(kind='bar',x='year.value',y='Count.value',color='blue')
ax.set(xlabel = "Years", ylabel = "Publication Counts")
#### Number of publications by conference series and by year
conferenceyear = """
Select count(distinct ?s) as ?Count ?conference ?year where {
?s a <https://github.com/deepcurator/DCC/Publication> .
?s <https://github.com/deepcurator/DCC/conferenceSeries> ?conference .
?s <https://github.com/deepcurator/DCC/yearOfPublication> ?year .
}
"""
results_df = execute_query(conferenceyear)
results_df.columns
results_df = results_df.drop(['Count.datatype', 'Count.type', 'conference.type','year.datatype',
'year.type'],axis=1)
results_df.head()
results_df["Count.value"] = pd.to_numeric(results_df["Count.value"])
results_df["year.value"] = pd.to_numeric(results_df["year.value"])
results_df.groupby(['conference.value','year.value']).size().unstack().plot(kind='bar',stacked='True')
plt.show()
### Year and platform
platformyear = """
Select count(?platform) as ?countplatform ?platform ?year where {
?s a <https://github.com/deepcurator/DCC/Publication> .
?s <https://github.com/deepcurator/DCC/conferenceSeries> ?conference .
?s <https://github.com/deepcurator/DCC/yearOfPublication> ?year .
?s <https://github.com/deepcurator/DCC/platform> ?platform .
}
group by ?platform ?year order by DESC(?year)
"""
results_df = execute_query(platformyear)
results_df.columns
results_df = results_df.drop(['countplatform.datatype', 'countplatform.type', 'platform.type' ,'year.datatype','year.type'],axis=1)
results_df.head()
results_df.groupby(['platform.value','year.value']).size().unstack().plot(kind='bar',stacked='True')
plt.show()
#### Trends in year for pytorch
platformtrends = """
Select count(?platform) as ?pytorch ?platform ?year where {
?s a <https://github.com/deepcurator/DCC/Publication> .
?s <https://github.com/deepcurator/DCC/conferenceSeries> ?conference .
?s <https://github.com/deepcurator/DCC/yearOfPublication> ?year .
?s <https://github.com/deepcurator/DCC/platform> ?platform .
FILTER(STR(?platform) ="pytorch")
}
group by ?platform ?year order by DESC(?year)
"""
results_df = execute_query(platformtrends)
results_df.columns
results_df.head()
results_df = results_df.drop(['pytorch.datatype', 'platform.type','pytorch.type', 'platform.type','year.datatype',
'year.type'],axis=1)
results_df.head()
results_df["pytorch.value"] = pd.to_numeric(results_df["pytorch.value"])
results_df["year.value"] = pd.to_numeric(results_df["year.value"])
# results_df.groupby(['platform.value','year.value']).size().unstack().plot(kind='bar',stacked='True')
ax = results_df.plot(kind='bar',x='year.value',y='pytorch.value',color='blue')
ax.set(xlabel = "Years", ylabel = "Platform")
# results_df["Count.value"] = pd.to_numeric(results_df["Count.value"])
# results_df["year.value"] = pd.to_numeric(results_df["year.value"])
# plt.show()
#### Trends in year for tensorflow
platformtrends = """
Select count(?platform) as ?tensorflow ?platform ?year where {
?s a <https://github.com/deepcurator/DCC/Publication> .
?s <https://github.com/deepcurator/DCC/conferenceSeries> ?conference .
?s <https://github.com/deepcurator/DCC/yearOfPublication> ?year .
?s <https://github.com/deepcurator/DCC/platform> ?platform .
FILTER(STR(?platform) ="tensorflow")
}
group by ?platform ?year order by DESC(?year)
"""
results_df = execute_query(platformtrends)
results_df.columns
results_df.head()
results_df = results_df.drop(['tensorflow.datatype', 'platform.type','tensorflow.type', 'platform.type','year.datatype',
'year.type'],axis=1)
results_df.head()
results_df["tensorflow.value"] = pd.to_numeric(results_df["tensorflow.value"])
results_df["year.value"] = pd.to_numeric(results_df["year.value"])
# results_df.groupby(['platform.value','year.value']).size().unstack().plot(kind='bar',stacked='True')
ax = results_df.plot(kind='bar',x='year.value',y='tensorflow.value',color='blue')
ax.set(xlabel = "Years", ylabel = "Platform")
#### Function trends across conferences
functiontrends = """
Select count(?type) as ?counttype ?type ?conference where {
?s <https://github.com/deepcurator/DCC/conferenceSeries> ?conference .
?s <https://github.com/deepcurator/DCC/yearOfPublication> ?year .
?s <https://github.com/deepcurator/DCC/hasRepository> ?repository .
?repository <https://github.com/deepcurator/DCC/hasFunction> ?y.
?y a ?type .
FILTER(!(STR(?type) = "https://github.com/deepcurator/DCC/UserDefined")).
}group by ?type ?conference ORDER by DESC(?counttype)
"""
results_df = execute_query(functiontrends)
results_df.columns
results_df = results_df.drop(['counttype.datatype', 'conference.type','counttype.type', 'type.type',
],axis=1)
results_df.head()
results_df["counttype.value"] = pd.to_numeric(results_df["counttype.value"])
results_df = results_df[results_df['counttype.value'] > 1000]
# results_df["year.value"] = pd.to_numeric(results_df["year.value"])
# results_df.groupby(['type.value','counttype.value']).size().unstack().plot(kind='bar',stacked='True',legend='False')
# Second plot
ax = results_df.plot(kind='bar',x='type.value',y='counttype.value',color='blue')
ax.set(xlabel = "TF Functions", ylabel = "Count")
#### Function trends across years
functionyeartrends = """
Select count(?type) as ?counttype ?type ?year where {
?s <https://github.com/deepcurator/DCC/conferenceSeries> ?conference .
?s <https://github.com/deepcurator/DCC/yearOfPublication> ?year .
?s <https://github.com/deepcurator/DCC/hasRepository> ?repository .
?repository <https://github.com/deepcurator/DCC/hasFunction> ?y.
?y a ?type .
FILTER(!(STR(?type) = "https://github.com/deepcurator/DCC/UserDefined")).
}group by ?type ?year ORDER by DESC(?counttype)
"""
results_df = execute_query(functionyeartrends)
results_df.columns
results_df = results_df.drop(['counttype.datatype', 'year.type','counttype.type', 'type.type',
],axis=1)
results_df.head()
results_df["counttype.value"] = pd.to_numeric(results_df["counttype.value"])
results_df = results_df[results_df['counttype.value'] > 1000]
# results_df["year.value"] = pd.to_numeric(results_df["year.value"])
# results_df.groupby(['counttype.value','year.value']).size().unstack().plot(kind='bar',stacked='True',legend='False')
ax = results_df.plot(kind='bar',x='type.value',y='counttype.value',color='blue')
ax.set(xlabel = "TF Functions", ylabel = "Count")
## CSO Queries :
# The first query shows all the CSO objects and the different modalities
# CSO concepts are linked to image and text modalities
csoquery1 = """
Select ?cso ?type where {
?o <https://github.com/deepcurator/DCC/hasCSOEquivalent> ?cso .
?o a ?type .
}
"""
results_df = execute_query(csoquery1)
results_df.columns
results_df = results_df.drop(['cso.type', 'type.type'],axis=1)
results_df.head()
## Queries that shows publications and CSO entities for modalities
## Deep dive into the CSO text
csoquery2 = """
Select ?publication count(?cso) as ?countcso where {
?publication a <https://github.com/deepcurator/DCC/Publication> .
?publication <https://github.com/deepcurator/DCC/hasEntity> ?entity .
?entity <https://github.com/deepcurator/DCC/hasCSOEquivalent> ?cso .
}order by DESC(?countcso)
"""
results_df = execute_query(csoquery2)
results_df.columns
results_df = results_df.drop(['countcso.datatype', 'countcso.type','publication.type'],axis=1)
results_df.head()
csoimagequery = """
Select distinct ?publication ?cso where {
?publication <https://github.com/deepcurator/DCC/hasFigure> ?f .
?component <https://github.com/deepcurator/DCC/partOf> ?f .
?component <https://github.com/deepcurator/DCC/hasCSOEquivalent> ?cso.
}
"""
results_df = execute_query(csoimagequery)
results_df.columns
results_df = results_df.drop(['cso.type', 'publication.type'],axis=1)
results_df.head()
## Query that shows types and CSO objects
csoquery3 = """
Select ?type ?cso where {
?s a <https://github.com/deepcurator/DCC/Publication> .
?s <https://github.com/deepcurator/DCC/hasEntity> ?o .
?o a ?type .
?o <https://github.com/deepcurator/DCC/hasCSOEquivalent> ?cso .
}
"""
results_df = execute_query(csoquery3)
results_df.columns
results_df = results_df.drop(['cso.type', 'type.type'],axis=1)
results_df.head()
# Given a CSO topic, how are many of them are aligned to the text and image entities
csoquery4 = """
Select distinct ?type count(distinct ?cso) as ?csocount where {
?s a <https://github.com/deepcurator/DCC/Publication> .
?s <https://github.com/deepcurator/DCC/hasEntity> ?o .
?o a ?type .
?o <https://github.com/deepcurator/DCC/hasCSOEquivalent> ?cso .
}order by desc(?csocount)
"""
results_df = execute_query(csoquery4)
results_df.columns
results_df = results_df.drop(['csocount.datatype', 'csocount.type','type.type'],axis=1)
results_df.head()
## Given a particular machine learning task, what datasets would you recommend?
task_dataset_query = """
Select distinct ?task ?dataset where {
?publication <https://github.com/deepcurator/DCC/hasEntity> ?taskentity .
?publication <https://github.com/deepcurator/DCC/hasEntity> ?dataset.
?taskentity a <https://github.com/deepcurator/DCC/Task> .
?dataset a <https://github.com/deepcurator/DCC/Material> .
?taskentity <https://github.com/deepcurator/DCC/hasCSOEquivalent> ?task .
}group by ?task ?dataset
"""
task_dataset_query_analogous = """
Select distinct ?tasktext ?datasettext where {
?publication <https://github.com/deepcurator/DCC/hasEntity> ?taskentity .
?publication <https://github.com/deepcurator/DCC/hasEntity> ?dataset.
?taskentity a <https://github.com/deepcurator/DCC/Task> .
?dataset a <https://github.com/deepcurator/DCC/Material> .
?taskentity <https://github.com/deepcurator/DCC/hasText> ?tasktext .
?dataset <https://github.com/deepcurator/DCC/hasText> ?datasettext .
}
"""
results_df = execute_query(task_dataset_query)
results_df.columns
results_df = results_df.drop(['dataset.type', 'task.type'],axis=1)
results_df.head()
# results_df.tail(20)
## Top ML methods for tasks from the Knowledge graph
## They show the cso equivalents
method_task_query = """
Select distinct ?method ?task where {
?publication <https://github.com/deepcurator/DCC/hasEntity> ?methodentity .
?publication <https://github.com/deepcurator/DCC/hasEntity> ?taskentity.
?taskentity a <https://github.com/deepcurator/DCC/Task> .
?methodentity a <https://github.com/deepcurator/DCC/Method> .
?methodentity <https://github.com/deepcurator/DCC/hasCSOEquivalent> ?method .
?taskentity <https://github.com/deepcurator/DCC/hasCSOEquivalent> ?task .
}group by ?method ?task
"""
results_df = execute_query(method_task_query)
results_df.columns
results_df = results_df.drop(['method.type', 'task.type'],axis=1)
results_df.head()
### Top DL methods and the associated tensorflow functions used for implementation
method_tf_query = """
Select count(?type) as ?counttype ?method ?type where {
?s <https://github.com/deepcurator/DCC/hasEntity> ?methodentity .
?methodentity a <https://github.com/deepcurator/DCC/Method> .
?methodentity <https://github.com/deepcurator/DCC/hasCSOEquivalent> ?method .
?s <https://github.com/deepcurator/DCC/hasRepository> ?repository .
?repository <https://github.com/deepcurator/DCC/hasFunction> ?y.
?y a ?type .
FILTER(!(STR(?type) = "https://github.com/deepcurator/DCC/UserDefined")).
}group by ?method ?type ORDER by DESC(?counttype)
"""
results_df = execute_query(method_tf_query)
results_df.columns
results_df = results_df.drop(['counttype.datatype','counttype.type','method.type', 'type.type'],axis=1)
results_df.head()
### Top DL tasks and the associated tensorflow functions used for implementation
task_tf_query = """
Select count(?type) as ?counttype ?task ?type where {
?s <https://github.com/deepcurator/DCC/hasEntity> ?taskentity .
?taskentity <https://github.com/deepcurator/DCC/hasCSOEquivalent> ?task .
?taskentity a <https://github.com/deepcurator/DCC/Task> .
?s <https://github.com/deepcurator/DCC/hasRepository> ?repository .
?repository <https://github.com/deepcurator/DCC/hasFunction> ?y.
?y a ?type .
FILTER(!(STR(?type) = "https://github.com/deepcurator/DCC/UserDefined")).
}group by ?task ?type ORDER by DESC(?counttype)
"""
results_df = execute_query(task_tf_query)
results_df.columns
results_df = results_df.drop(['counttype.datatype','counttype.type','task.type', 'type.type'],axis=1)
results_df.head()
## Image component specific tensorflow functions
image_tf_query = """
Select count(?type) as ?counttype ?cso ?type where {
?s <https://github.com/deepcurator/DCC/hasFigure> ?f .
?component <https://github.com/deepcurator/DCC/partOf> ?f .
?component <https://github.com/deepcurator/DCC/hasCSOEquivalent> ?cso.
?s <https://github.com/deepcurator/DCC/hasRepository> ?repository .
?repository <https://github.com/deepcurator/DCC/hasFunction> ?y.
?y a ?type .
FILTER(!(STR(?type) = "https://github.com/deepcurator/DCC/UserDefined")).
}group by ?cso ?type ORDER by DESC(?counttype)
"""
results_df = execute_query(image_tf_query)
results_df.columns
results_df = results_df.drop(['counttype.datatype','counttype.type','cso.type', 'type.type'],axis=1)
results_df.head()