-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryEngine.py
More file actions
762 lines (637 loc) · 31.9 KB
/
QueryEngine.py
File metadata and controls
762 lines (637 loc) · 31.9 KB
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
from Entities import Journal, Category, Area
from Handlers import JournalQueryHandler, CategoryQueryHandler, CategoryUploadHandler, JournalUploadHandler
import re
import pandas as pd
class BasicQueryEngine(object):
"""
BasicQueryEngine is a class that provides methods to query and manipulate journal and category data.
It allows for adding and cleaning query handlers, retrieving journals and categories based on various criteria,
and getting entities by their IDs.
Attributes:
journalQuery (list): A list of journal query handlers.
categoryQuery (list): A list of category query handlers.
Methods:
cleanJournalHandlers(): Cleans the journal query handlers.
cleanCategoryHandlers(): Cleans the category query handlers.
addJournalHandler(handler): Adds a journal query handler to the list.
addCategoryHandler(handler): Adds a category query handler to the list.
getEntityById(id): Retrieves a journal or category entity by its ID.
getAllJournals(): Retrieves all journal entities.
getJournalsWithTitle(partialTitle): Retrieves journals with a title that contains the specified partial title.
getJournalsPublishedBy(partialName): Retrieves journals published by a publisher with a name that contains the specified partial name.
getJournalsWithLicense(licenses): Retrieves journals with a specific license.
getJournalsWithAPC(): Retrieves journals with an Article Processing Charge (APC).
getJournalsWithDOAJSeal(): Retrieves journals with a DOAJ seal.
getAllCategories(): Retrieves all category entities.
getAllAreas(): Retrieves all area entities.
getCategoriesWithQuartile(quartiles): Retrieves categories with a specific quartile.
getCategoriesAssignedToAreas(area_ids): Retrieves categories assigned to specific areas.
getAreasAssignedToCategories(category_ids): Retrieves areas assigned to specific categories.
"""
def __init__(self, journalQuery=None, categoryQuery=None):
self.journalQuery = journalQuery if journalQuery is not None else []
self.categoryQuery = categoryQuery if categoryQuery is not None else []
def cleanJournalHandlers(self):
"""
Cleans the journal query handlers by resetting the journalQuery list.
"""
self.journalQuery = []
return True
def cleanCategoryHandlers(self):
"""
Cleans the category query handlers by resetting the categoryQuery list.
"""
self.categoryQuery = []
return True
def addJournalHandler(self, handler):
"""
Adds a journal query handler to the list of journal query handlers.
Args:
handler (JournalQueryHandler): The journal query handler to be added.
Returns:
bool: True if the handler was added successfully, False otherwise.
"""
self.journalQuery.append(handler)
return True
def addCategoryHandler(self, handler):
"""
Adds a category query handler to the list of category query handlers.
Args:
handler (CategoryQueryHandler): The category query handler to be added.
Returns:
bool: True if the handler was added successfully, False otherwise.
"""
self.categoryQuery.append(handler)
return True
def getEntityById(self, id):
"""
Retrieves a journal or category or area entity by its ID.
If the ID matches the pattern for a journal, it retrieves the journal and its categories and areas.
Args:
id (str): The ID of the journal or category to be retrieved.
Returns:
identity (Journal or Category or Area): The journal or category entity corresponding to the ID.
"""
if re.fullmatch(r"(?=.*\d)[\dX]{4}-[\dX]{4}", id):
found_journal = False
journal = None
for j_queryHandler in self.journalQuery:
journalWithId_df = j_queryHandler.getById(id)
if not journalWithId_df.empty:
for _, row in journalWithId_df.iterrows():
id_list = []
if pd.notna(row['issn']) == True:
id_list.append(row['issn'])
if pd.notna(row['eissn']) == True:
id_list.append(row['eissn'])
found_journal = True
journal = Journal(id_list, row['title'], row['language'], row['seal'], row['license'], row['apc'], row['publisher'])
if found_journal:
for c_queryHandler in self.categoryQuery:
categoryWithId_df = c_queryHandler.getById(id)
if not categoryWithId_df.empty:
cat_l = []
area_l = []
for _, row in categoryWithId_df.iterrows():
category = Category([row['category_id']])
area = Area(row['area_id'])
cat_l.append(category)
area_l.append(area)
journal.setCategories(cat_l)
journal.setAreas(area_l)
else:
category = None
area = None
return journal
category = None
area = None
for c_queryHandler in self.categoryQuery:
categoryWithId_df = c_queryHandler.getById(id)
if not categoryWithId_df.empty:
if id in categoryWithId_df['category_id'].values:
category = Category([id])
return category
elif id in categoryWithId_df['area_id'].values:
area = Area([id])
return area
# else:
# category = None
# area = None
return None
def getAllJournals(self) -> list[Journal]:
"""
Retrieves all journal entities from the journal query handlers.
Args:
None
Returns:
list[Journal]: A list of all journal entities.
"""
alljournals = []
for j_queryHandler in self.journalQuery:
journals_df = j_queryHandler.getAllJournals()
if not journals_df.empty:
for _, row in journals_df.iterrows():
id = []
if pd.notna(row['issn']) == True:
id.append(row['issn'])
if pd.notna(row['eissn']) == True:
id.append(row['eissn'])
journal = Journal(id, row['title'], row['language'], row['seal'], row['license'], row['apc'], row['publisher'])
alljournals.append(journal)
return alljournals
def getJournalsWithTitle(self, partialTitle) -> list[Journal]:
journalsWithTitle = []
for j_queryHandler in self.journalQuery:
journals_df = j_queryHandler.getJournalsWithTitle(partialTitle)
if not journals_df.empty:
for _, row in journals_df.iterrows():
id = []
if pd.notna(row['issn']) == True:
id.append(row['issn'])
if pd.notna(row['eissn']) == True:
id.append(row['eissn'])
journal = Journal(id, row['title'], row['language'], row['seal'], row['license'], row['apc'], row['publisher'])
journalsWithTitle.append(journal)
return journalsWithTitle
def getJournalsPublishedBy(self, partialName) -> list[Journal]:
journalsPublishedBy = []
for j_queryHandler in self.journalQuery:
journals_df = j_queryHandler.getJournalsPublishedBy(partialName)
if not journals_df.empty:
for _, row in journals_df.iterrows():
id = []
if pd.notna(row['issn']) == True:
id.append(row['issn'])
if pd.notna(row['eissn']) == True:
id.append(row['eissn'])
journal = Journal(id, row['title'], row['language'], row['seal'], row['license'], row['apc'], row['publisher'])
journalsPublishedBy.append(journal)
return journalsPublishedBy
def getJournalsWithLicense(self, licenses) -> list[Journal]:
journalsWithLicense = []
for j_queryHandler in self.journalQuery:
journals_df = j_queryHandler.getJournalsWithLicense(licenses)
if not journals_df.empty:
for _, row in journals_df.iterrows():
id = []
if pd.notna(row['issn']) == True:
id.append(row['issn'])
if pd.notna(row['eissn']) == True:
id.append(row['eissn'])
journal = Journal(id, row['title'], row['language'], row['seal'], row['license'], row['apc'], row['publisher'])
journalsWithLicense.append(journal)
return journalsWithLicense
def getJournalsWithAPC(self) -> list[Journal]:
journalsWithAPC = []
for j_queryHandler in self.journalQuery:
journals_df = j_queryHandler.getJournalsWithAPC()
if not journals_df.empty:
for _, row in journals_df.iterrows():
id = []
if pd.notna(row['issn']) == True:
id.append(row['issn'])
if pd.notna(row['eissn']) == True:
id.append(row['eissn'])
journal = Journal(id, row['title'], row['language'], row['seal'], row['license'], row['apc'], row['publisher'])
journalsWithAPC.append(journal)
return journalsWithAPC
def getJournalsWithDOAJSeal(self) -> list[Journal]:
journalsWithDOAJSeal = []
for j_queryHandler in self.journalQuery:
journals_df = j_queryHandler.getJournalsWithDOAJSeal()
if not journals_df.empty:
for _, row in journals_df.iterrows():
id = []
if pd.notna(row['issn']) == True:
id.append(row['issn'])
if pd.notna(row['eissn']) == True:
id.append(row['eissn'])
journal = Journal(id, row['title'], row['language'], row['seal'], row['license'], row['apc'], row['publisher'])
journalsWithDOAJSeal.append(journal)
return journalsWithDOAJSeal
def getAllCategories(self) -> list[Category]:
"""
Retrieves all category entities from the category query handlers.
Args:
None
Returns:
list[Category]: A list of all category entities.
"""
allCategories = []
for c_queryHandler in self.categoryQuery:
categories_df = c_queryHandler.getAllCategories()
if not categories_df.empty:
for _, row in categories_df.iterrows():
category = Category([row['category_id']], row['journal_quartile_dict'])
allCategories.append(category)
return allCategories
def getAllAreas(self) -> list[Area]:
"""
Retrieves all area entities from the category query handlers.
Args:
None
Returns:
list[Area]: A list of all area entities.
"""
allAreas = []
for a_queryHandler in self.categoryQuery:
areas_df = a_queryHandler.getAllAreas()
if not areas_df.empty:
for _, row in areas_df.iterrows():
areas = Area([row['area_id']], row['journal'])
allAreas.append(areas)
return allAreas
def getCategoriesWithQuartile(self, quartiles) -> list[Category]:
"""
Retrieves categories with a specific quartile from the category query handlers.
Args:
quartiles (set): A set of quartiles to filter categories by.
Returns:
list[Category]: A list of categories with the specified quartile.
"""
categoriesWithQuartile = []
for c_queryHandler in self.categoryQuery:
categories_df = c_queryHandler.getCategoriesWithQuartile(quartiles)
if not categories_df.empty:
for _, row in categories_df.iterrows():
category = Category([row['category_id']], row['journal_quartile_dict'])
categoriesWithQuartile.append(category)
return categoriesWithQuartile
def getCategoriesAssignedToAreas(self, area_ids) -> list[Category]:
"""
Retrieves categories assigned to specific areas from the category query handlers.
Args:
area_ids (set): A set of area IDs to filter categories by.
Returns:
list[Category]: A list of categories assigned to the specified areas.
"""
categoriesAssignedToAreas = []
for c_queryHandler in self.categoryQuery:
categories_df = c_queryHandler.getCategoriesAssignedToAreas(area_ids)
if not categories_df.empty:
for _, row in categories_df.iterrows():
category = Category([row['category_id']], row['journal_quartile_dict'])
categoriesAssignedToAreas.append(category)
return categoriesAssignedToAreas
def getAreasAssignedToCategories(self, category_ids) -> list[Area]:
"""
Retrieves areas assigned to specific categories from the category query handlers.
Args:
category_ids (set): A set of category IDs to filter areas by.
Returns:
list[Area]: A list of areas assigned to the specified categories.
"""
areasAssignedToCategories = []
for c_queryHandler in self.categoryQuery:
areas_df = c_queryHandler.getAreasAssignedToCategories(category_ids)
if not areas_df.empty:
for _, row in areas_df.iterrows():
area = Area([row['area_id']], row['journal'])
areasAssignedToCategories.append(area)
return areasAssignedToCategories
class FullQueryEngine(BasicQueryEngine):
"""
FullQueryEngine is a subclass of BasicQueryEngine that provides additional methods to query and manipulate journal and category data.
Attributes:
journalQuery (list): A list of journal query handlers.
categoryQuery (list): A list of category query handlers.
Methods:
__init__(journalQuery=None, categoryQuery=None): Initializes the FullQueryEngine with optional journal and category query handlers.
getJournalsInCategoriesWithQuartile(category_ids, quartiles): Retrieves journals in specific categories with quartiles.
getJournalsInAreasWithLicense(areas_ids, licenses): Retrieves journals in specific areas with licenses.
getDiamondJournalsInAreasAndCategoriesWithQuartile(areas_ids, category_ids, quartiles): Retrieves diamond journals in areas and categories with quartiles.
"""
def __init__(self, journalQuery=None, categoryQuery=None):
super().__init__(journalQuery, categoryQuery)
def getJournalsInCategoriesWithQuartile(self, category_ids, quartiles) -> list[Journal]:
"""
Retrieves journals in specific categories with quartiles from the journal and category query handlers.
Args:
category_ids (set): A set of category IDs to filter journals by.
quartiles (set): A set of quartiles to filter journals by.
Returns:
list[Journal]: A list of journals in the specified categories with the specified quartiles.
"""
journals = []
if len(category_ids) == 0 and len(quartiles) == 0:
cat_l = self.getAllCategories()
area_l = self.getAllAreas()
for j in self.getAllJournals():
journal_cat_l= []
journal_area_l = []
for c in cat_l:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
elif len(category_ids) == 0:
catWithQ_l = self.getCategoriesWithQuartile(quartiles)
area_l = self.getAllAreas()
for j in self.getAllJournals():
journal_cat_l= []
journal_area_l = []
for c in catWithQ_l:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
elif len(quartiles) == 0:
cat_l = self.getAllCategories()
area_l = self.getAllAreas()
for j in self.getAllJournals():
journal_cat_l= []
journal_area_l = []
for c in cat_l:
if c.getIds()[0] in category_ids:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
else:
catWithQ_l = self.getCategoriesWithQuartile(quartiles)
area_l = self.getAllAreas()
for j in self.getAllJournals():
journal_cat_l= []
journal_area_l = []
for c in catWithQ_l:
if c.getIds()[0] in category_ids:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
def getJournalsInAreasWithLicense(self, areas_ids, licenses) -> list[Journal]:
"""
Retrieves journals in specific areas with licenses from the journal and category query handlers.
Args:
areas_ids (set): A set of area IDs to filter journals by.
licenses (set): A set of licenses to filter journals by.
Returns:
list[Journal]: A list of journals in the specified areas with the specified licenses.
"""
journals = []
if len(areas_ids) == 0 and len(licenses) == 0:
cat_l = self.getAllCategories()
area_l = self.getAllAreas()
for j in self.getAllJournals():
journal_cat_l= []
journal_area_l = []
for c in cat_l:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
elif len(areas_ids) == 0:
cat_l = self.getAllCategories()
area_l = self.getAllAreas()
for j in self.getJournalsWithLicense(licenses):
journal_cat_l= []
journal_area_l = []
for c in cat_l:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
elif len(licenses) == 0:
cat_l = self.getAllCategories()
area_l = self.getAllAreas()
for j in self.getAllJournals():
journal_cat_l= []
journal_area_l = []
for c in cat_l:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if a.getIds()[0] in areas_ids:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l and journal_area_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
else:
cat_l = self.getAllCategories()
area_l = self.getAllAreas()
for j in self.getJournalsWithLicense(licenses):
journal_cat_l= []
journal_area_l = []
for c in cat_l:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if a.getIds()[0] in areas_ids:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l and journal_area_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
def getDiamondJournalsInAreasAndCategoriesWithQuartile(self, areas_ids, category_ids, quartiles) -> list[Journal]:
"""
Retrieves diamond journals in specific areas and categories with quartiles from the journal and category query handlers.
Args:
areas_ids (set): A set of area IDs to filter journals by.
category_ids (set): A set of category IDs to filter journals by.
quartiles (set): A set of quartiles to filter journals by.
Returns:
list[Journal]: A list of diamond journals in the specified areas and categories with the specified quartiles.
"""
# First get all diamond journals (journals without APC)
allJournals = self.getAllJournals()
diamondJournals = [j for j in allJournals if not j.hasAPC()]
journals = []
# Case 1: No filters specified (all areas, categories, and quartiles)
if len(areas_ids) == 0 and len(category_ids) == 0 and len(quartiles) == 0:
cat_l = self.getAllCategories()
area_l = self.getAllAreas()
for j in diamondJournals:
journal_cat_l = []
journal_area_l = []
for c in cat_l:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
# Case 2: Only quartiles specified
elif len(areas_ids) == 0 and len(category_ids) == 0:
catWithQ_l = self.getCategoriesWithQuartile(quartiles)
area_l = self.getAllAreas()
for j in diamondJournals:
journal_cat_l = []
journal_area_l = []
for c in catWithQ_l:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
# Case 3: Only categories specified
elif len(areas_ids) == 0 and len(quartiles) == 0:
# Get areas assigned to the specified categories
area_l = self.getAreasAssignedToCategories(category_ids)
cat_l = self.getAllCategories()
for j in diamondJournals:
journal_cat_l = []
journal_area_l = []
# Get categories for this journal
for c in cat_l:
if c.getIds()[0] in category_ids:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
# Get areas for this journal
for a in area_l:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
# Case 4: Only areas specified
elif len(category_ids) == 0 and len(quartiles) == 0:
# Get categories assigned to the specified areas
cat_l = self.getCategoriesAssignedToAreas(areas_ids)
area_l = self.getAllAreas()
for j in diamondJournals:
journal_cat_l = []
journal_area_l = []
# Get categories for this journal
for c in cat_l:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
# Get areas for this journal
for a in area_l:
if a.getIds()[0] in areas_ids:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l and journal_area_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
# Case 5: Categories and quartiles specified
elif len(areas_ids) == 0:
catWithQ_l = self.getCategoriesWithQuartile(quartiles)
area_l = self.getAllAreas()
for j in diamondJournals:
journal_cat_l = []
journal_area_l = []
for c in catWithQ_l:
if c.getIds()[0] in category_ids:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
# Case 6: Areas and categories specified
elif len(quartiles) == 0:
cat_l = self.getAllCategories()
area_l = self.getAllAreas()
for j in diamondJournals:
journal_cat_l = []
journal_area_l = []
for c in cat_l:
if c.getIds()[0] in category_ids:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if a.getIds()[0] in areas_ids:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l and journal_area_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
# Case 7: Areas and quartiles specified
elif len(category_ids) == 0:
catWithQ_l = self.getCategoriesWithQuartile(quartiles)
area_l = self.getAllAreas()
for j in diamondJournals:
journal_cat_l = []
journal_area_l = []
for c in catWithQ_l:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if a.getIds()[0] in areas_ids:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l and journal_area_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals
# Case 8: All filters specified
else:
catWithQ_l = self.getCategoriesWithQuartile(quartiles)
area_l = self.getAllAreas()
for j in diamondJournals:
journal_cat_l = []
journal_area_l = []
for c in catWithQ_l:
if c.getIds()[0] in category_ids:
if j.getIds()[0] in c.getJournalQuartile().keys():
journal_cat_l.append(Category(c.getIds(), quartile=c.getQuartileWithJournal(j.getIds()[0])))
for a in area_l:
if a.getIds()[0] in areas_ids:
if j.getIds()[0] in a.getJournal():
journal_area_l.append(a)
if journal_cat_l and journal_area_l:
j.setCategories(journal_cat_l)
j.setAreas(journal_area_l)
journals.append(j)
return journals