-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexemplar_execution.py
More file actions
621 lines (540 loc) · 22.4 KB
/
Copy pathexemplar_execution.py
File metadata and controls
621 lines (540 loc) · 22.4 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
# Supposing that all the classes developed for the project
# are contained in the file 'impl.py', then:
# 1) Importing all the classes for handling the relational database
from impl import CategoryUploadHandler, CategoryQueryHandler
# 2) Importing all the classes for handling graph database
from impl import JournalUploadHandler, JournalQueryHandler
# 3) Importing the class for dealing with mashup queries
from impl import BasicQueryEngine, FullQueryEngine
import sqlite3
import pandas as pd
# Once all the classes are imported, first create the relational
# database using the related source data
print("=" * 60)
print("STEP 1: Creating relational database")
print("=" * 60)
try:
rel_path = "relational.db"
cat = CategoryUploadHandler()
cat.setDbPathOrUrl(rel_path)
cat.pushDataToDb("data/scimago.json")
print("✓ SUCCESS: Relational database created and data uploaded")
except Exception as e:
print(f"✗ FAIL: Relational database creation failed - {e}")
# Then, create the graph database (remember first to run the
# Blazegraph instance) using the related source data
print("\n" + "=" * 60)
print("STEP 2: Creating graph database")
print("=" * 60)
try:
grp_endpoint = "http://192.168.78.117:9999/blazegraph/sparql" # Update with your Blazegraph endpoint
jou = JournalUploadHandler()
jou.setDbPathOrUrl(grp_endpoint)
jou.serializeToTTL("data/doaj.csv", "doaj.ttl")
jou.pushDataToDb("data/doaj.csv")
print("✓ SUCCESS: Graph database handler created and data serialized to TTL")
except Exception as e:
print(f"✗ FAIL: Graph database creation failed - {e}")
# In the next passage, create the query handlers for both
# the databases, using the related classes
print("\n" + "=" * 60)
print("STEP 3: Creating query handlers")
print("=" * 60)
try:
cat_qh = CategoryQueryHandler()
cat_qh.setDbPathOrUrl(rel_path)
print("✓ SUCCESS: Category query handler created")
except Exception as e:
print(f"✗ FAIL: Category query handler creation failed - {e}")
try:
jou_qh = JournalQueryHandler()
jou_qh.setDbPathOrUrl(grp_endpoint)
print("✓ SUCCESS: Journal query handler created")
except Exception as e:
print(f"✗ FAIL: Journal query handler creation failed - {e}")
# Finally, create a advanced mashup object for asking
# about data
print("\n" + "=" * 60)
print("STEP 4: Creating basic query engine")
print("=" * 60)
try:
que = BasicQueryEngine()
que.addCategoryHandler(cat_qh)
que.addJournalHandler(jou_qh)
print("✓ SUCCESS: Basic query engine created and handlers added")
except Exception as e:
print(f"✗ FAIL: Basic query engine creation failed - {e}")
# Execute ALL queries from BasicQueryEngine
print("\n" + "=" * 80)
print("STEP 5: Testing ALL BasicQueryEngine Methods")
print("=" * 80)
# =============================================================================
# JOURNAL-RELATED METHODS
# =============================================================================
print("\n" + "-" * 60)
print("JOURNAL-RELATED METHODS")
print("-" * 60)
print("\n1. getAllJournals()")
try:
result = que.getAllJournals()
if result is not None:
count = len(result) if hasattr(result, '__len__') else 'unknown'
print(f"✓ SUCCESS: Retrieved {count} journal(s)")
else:
print("✓ SUCCESS: Query executed (returned None)")
except Exception as e:
print(f"✗ FAIL: getAllJournals() failed - {e}")
print("\n2. getJournalsWithTitle('Journal')")
try:
result = que.getJournalsWithTitle("Journal")
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} journal(s) with 'Journal' in title")
except Exception as e:
print(f"✗ FAIL: getJournalsWithTitle() failed - {e}")
print("\n3. getJournalsPublishedBy('University')")
try:
result = que.getJournalsPublishedBy("University")
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} journal(s) published by 'University'")
except Exception as e:
print(f"✗ FAIL: getJournalsPublishedBy() failed - {e}")
print("\n4. getJournalsWithLicense({'CC BY'})")
try:
result = que.getJournalsWithLicense({"CC BY"})
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} journal(s) with CC BY license")
except Exception as e:
print(f"✗ FAIL: getJournalsWithLicense() failed - {e}")
print("\n5. getJournalsWithAPC()")
try:
result = que.getJournalsWithAPC()
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} journal(s) with APC")
except Exception as e:
print(f"✗ FAIL: getJournalsWithAPC() failed - {e}")
print("\n6. getJournalsWithDOAJSeal()")
try:
result = que.getJournalsWithDOAJSeal()
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} journal(s) with DOAJ seal")
except Exception as e:
print(f"✗ FAIL: getJournalsWithDOAJSeal() failed - {e}")
# =============================================================================
# CATEGORY-RELATED METHODS
# =============================================================================
print("\n" + "-" * 60)
print("CATEGORY-RELATED METHODS")
print("-" * 60)
print("\n7. getAllCategories()")
try:
result = que.getAllCategories()
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Retrieved {count} category/categories")
except Exception as e:
print(f"✗ FAIL: getAllCategories() failed - {e}")
print("\n8. getAllAreas()")
try:
result = que.getAllAreas()
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Retrieved {count} area(s)")
except Exception as e:
print(f"✗ FAIL: getAllAreas() failed - {e}")
print("\n9. getCategoriesWithQuartile({'Q1'})")
try:
result = que.getCategoriesWithQuartile({"Q1"})
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} category/categories with Q1 quartile")
except Exception as e:
print(f"✗ FAIL: getCategoriesWithQuartile() failed - {e}")
print("\n10. getCategoriesAssignedToAreas({'Medicine'})")
try:
result = que.getCategoriesAssignedToAreas({"Medicine"})
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} category/categories in Medicine area")
except Exception as e:
print(f"✗ FAIL: getCategoriesAssignedToAreas() failed - {e}")
print("\n11. getAreasAssignedToCategories({'Artificial Intelligence'})")
try:
result = que.getAreasAssignedToCategories({"Artificial Intelligence"})
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} area(s) for Artificial Intelligence")
except Exception as e:
print(f"✗ FAIL: getAreasAssignedToCategories() failed - {e}")
# --- CHECK SQLITE SIDE ---
conn = sqlite3.connect(rel_path)
df_sqlite = pd.read_sql_query("""
SELECT DISTINCT identifiers
FROM categories
WHERE category_id = 'Artificial Intelligence'
AND quartile = 'Q1'
LIMIT 10
""", conn)
conn.close()
print("SQLite identifiers for AI/Q1:")
print(df_sqlite)
# --- CHECK GRAPH SIDE ---
df_graph = jou_qh.getAllJournals()
print("\nGraph identifiers (first 10):")
print(df_graph['identifier'].head(10))
import sqlite3
conn = sqlite3.connect(rel_path)
df_sqlite = pd.read_sql_query("SELECT DISTINCT identifiers FROM categories", conn)
conn.close()
sqlite_ids = set(df_sqlite['identifiers'].str.strip())
df_graph = jou_qh.getAllJournals()
graph_ids = set()
for val in df_graph['identifier'].dropna():
for part in val.split(';'):
graph_ids.add(part.strip())
overlap = sqlite_ids.intersection(graph_ids)
print(f"SQLite has {len(sqlite_ids)} unique identifiers")
print(f"Graph has {len(graph_ids)} unique identifiers")
print(f"Overlap: {len(overlap)} common identifiers")
print("Sample overlap:", list(overlap)[:10])
# =============================================================================
# ENTITY LOOKUP METHODS
# =============================================================================
print("\n" + "-" * 60)
print("ENTITY LOOKUP METHODS")
print("-" * 60)
print("\n12. getEntityById('Artificial Intelligence')")
try:
result = que.getEntityById("Artificial Intelligence")
if result is None:
print("✓ SUCCESS: Query executed - No entity found with that ID")
else:
entity_type = type(result).__name__
print(f"✓ SUCCESS: Found entity of type {entity_type}")
except Exception as e:
print(f"✗ FAIL: getEntityById('Artificial Intelligence') failed - {e}")
print("\n13. getEntityById('2532-8816') [Journal ISSN]")
try:
result = que.getEntityById("2532-8816")
if result is not None:
entity_type = type(result).__name__
print(f"✓ SUCCESS: Found entity of type {entity_type}")
else:
print("✓ SUCCESS: Query executed - No entity found")
except Exception as e:
print(f"✗ FAIL: getEntityById('2532-8816') failed - {e}")
print("\n14. getEntityById('Medicine') [Area]")
try:
result = que.getEntityById("Medicine")
if result is not None:
entity_type = type(result).__name__
print(f"✓ SUCCESS: Found entity of type {entity_type}")
else:
print("✓ SUCCESS: Query executed - No entity found")
except Exception as e:
print(f"✗ FAIL: getEntityById('Medicine') failed - {e}")
# =============================================================================
# HELPER METHODS
# =============================================================================
print("\n" + "-" * 60)
print("HELPER METHODS")
print("-" * 60)
print("\n15. getCategoriesByJournalId('2532-8816')")
try:
result = que.getCategoriesByJournalId("2532-8816")
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} category/categories for journal")
except Exception as e:
print(f"✗ FAIL: getCategoriesByJournalId() failed - {e}")
print("\n16. getAreasByJournalId('2532-8816')")
try:
result = que.getAreasByJournalId("2532-8816")
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} area(s) for journal")
except Exception as e:
print(f"✗ FAIL: getAreasByJournalId() failed - {e}")
# =============================================================================
# HANDLER MANAGEMENT METHODS
# =============================================================================
print("\n" + "-" * 60)
print("HANDLER MANAGEMENT METHODS")
print("-" * 60)
print("\n17. cleanJournalHandlers()")
try:
result = que.cleanJournalHandlers()
if result:
print("✓ SUCCESS: Journal handlers cleaned")
# Re-add handler for remaining tests
que.addJournalHandler(jou_qh)
else:
print("✗ FAIL: cleanJournalHandlers() returned False")
except Exception as e:
print(f"✗ FAIL: cleanJournalHandlers() failed - {e}")
print("\n18. cleanCategoryHandlers()")
try:
result = que.cleanCategoryHandlers()
if result:
print("✓ SUCCESS: Category handlers cleaned")
# Re-add handler for remaining tests
que.addCategoryHandler(cat_qh)
else:
print("✗ FAIL: cleanCategoryHandlers() returned False")
except Exception as e:
print(f"✗ FAIL: cleanCategoryHandlers() failed - {e}")
# DEBUG: test getLicence on a real ISSN
result = que.getEntityById("1991-9468") # replace with a real ISSN from your data
print("Entity type:", type(result))
if result is not None:
print("getLicence:", result.getLicence())
else:
print("No entity found - check the ISSN exists in Blazegraph")
# =============================================================================
# SUMMARY - BASICQUERYENGINE
# =============================================================================
print("\n" + "=" * 80)
print("BASICQUERYENGINE METHODS TESTED")
print("=" * 80)
# #############################################################################
# FULLQUERYENGINE TESTS
# #############################################################################
print("\n\n" + "=" * 80)
print("STEP 6: Testing ALL FullQueryEngine Methods")
print("=" * 80)
print("\n" + "=" * 60)
print("Creating FullQueryEngine instance")
print("=" * 60)
try:
full_que = FullQueryEngine()
full_que.addCategoryHandler(cat_qh)
full_que.addJournalHandler(jou_qh)
print("✓ SUCCESS: FullQueryEngine created and handlers added")
except Exception as e:
print(f"✗ FAIL: FullQueryEngine creation failed - {e}")
# =============================================================================
# FULLQUERYENGINE MASHUP METHODS
# =============================================================================
print("\n" + "-" * 60)
print("FULLQUERYENGINE MASHUP METHODS")
print("-" * 60)
print("\n19. getJournalsInCategoriesWithQuartile({'Artificial Intelligence', 'Oncology'}, {'Q1'})")
try:
result = full_que.getJournalsInCategoriesWithQuartile(
{"Artificial Intelligence", "Oncology"},
{"Q1"}
)
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} journal(s) in AI/Oncology with Q1 quartile")
except Exception as e:
print(f"✗ FAIL: getJournalsInCategoriesWithQuartile() failed - {e}")
print("\n20. getJournalsInCategoriesWithQuartile({'Medicine'}, {'Q2'})")
try:
result = full_que.getJournalsInCategoriesWithQuartile(
{"Medicine"},
{"Q2"}
)
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} journal(s) in Medicine with Q2 quartile")
except Exception as e:
print(f"✗ FAIL: getJournalsInCategoriesWithQuartile() failed - {e}")
print("\n21. getJournalsInAreasWithLicense({'Medicine'}, {'CC BY'})")
try:
result = full_que.getJournalsInAreasWithLicense(
{"Medicine"},
{"CC BY"}
)
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} journal(s) in Medicine area with CC BY license")
except Exception as e:
print(f"✗ FAIL: getJournalsInAreasWithLicense() failed - {e}")
print("\n22. getJournalsInAreasWithLicense({'Computer Science', 'Engineering'}, {'CC BY-SA'})")
try:
result = full_que.getJournalsInAreasWithLicense(
{"Computer Science", "Engineering"},
{"CC BY-SA"}
)
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} journal(s) in CS/Engineering with CC BY-SA license")
except Exception as e:
print(f"✗ FAIL: getJournalsInAreasWithLicense() failed - {e}")
print("\n23. getDiamondJournalsInAreasAndCategoriesWithQuartile({'Medicine'}, {'Oncology'}, {'Q1'})")
try:
result = full_que.getDiamondJournalsInAreasAndCategoriesWithQuartile(
{"Medicine"},
{"Oncology"},
{"Q1"}
)
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} diamond journal(s) in Medicine/Oncology with Q1")
except Exception as e:
print(f"✗ FAIL: getDiamondJournalsInAreasAndCategoriesWithQuartile() failed - {e}")
print("\n24. getDiamondJournalsInAreasAndCategoriesWithQuartile({'Computer Science'}, {'Artificial Intelligence'}, {'Q1', 'Q2'})")
try:
result = full_que.getDiamondJournalsInAreasAndCategoriesWithQuartile(
{"Computer Science"},
{"Artificial Intelligence"},
{"Q1", "Q2"}
)
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Found {count} diamond journal(s) in CS/AI with Q1/Q2")
except Exception as e:
print(f"✗ FAIL: getDiamondJournalsInAreasAndCategoriesWithQuartile() failed - {e}")
# =============================================================================
# FULLQUERYENGINE HELPER METHODS
# =============================================================================
print("\n" + "-" * 60)
print("FULLQUERYENGINE HELPER METHODS")
print("-" * 60)
print("\n25. _parse_list_field('identifier1; identifier2; identifier3')")
try:
result = full_que._parse_list_field("identifier1; identifier2; identifier3")
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Parsed into {count} elements")
except Exception as e:
print(f"✗ FAIL: _parse_list_field() failed - {e}")
print("\n26. _parse_list_field('English, Spanish, French')")
try:
result = full_que._parse_list_field("English, Spanish, French")
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Parsed into {count} elements")
except Exception as e:
print(f"✗ FAIL: _parse_list_field() failed - {e}")
print("\n27. _parse_list_field(None)")
try:
result = full_que._parse_list_field(None)
if result == []:
print("✓ SUCCESS: None parsed to empty list")
else:
print(f"✗ FAIL: Expected empty list, got {result}")
except Exception as e:
print(f"✗ FAIL: _parse_list_field(None) failed - {e}")
# =============================================================================
# FULLQUERYENGINE - INHERITED BASICQUERYENGINE METHODS
# =============================================================================
print("\n" + "-" * 60)
print("INHERITED METHODS (from BasicQueryEngine)")
print("-" * 60)
print("\n28. FullQueryEngine.getAllJournals()")
try:
result = full_que.getAllJournals()
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Retrieved {count} journal(s)")
except Exception as e:
print(f"✗ FAIL: getAllJournals() failed - {e}")
print("\n29. FullQueryEngine.getAllCategories()")
try:
result = full_que.getAllCategories()
count = len(result) if result and hasattr(result, '__len__') else 0
print(f"✓ SUCCESS: Retrieved {count} category/categories")
except Exception as e:
print(f"✗ FAIL: getAllCategories() failed - {e}")
print("\n30. FullQueryEngine.getEntityById('Medicine')")
try:
result = full_que.getEntityById("Medicine")
if result is not None:
entity_type = type(result).__name__
print(f"✓ SUCCESS: Found entity of type {entity_type}")
else:
print("✓ SUCCESS: Query executed - No entity found")
except Exception as e:
print(f"✗ FAIL: getEntityById() failed - {e}")
# Test 1 - getJournalsInCategoriesWithQuartile
result = full_que.getJournalsInCategoriesWithQuartile(
{"Artificial Intelligence"}, {"Q1"}
)
print(f"getJournalsInCategoriesWithQuartile: {len(result)} journals")
if result:
print(f" First journal: {result[0].getTitle()} | license: {result[0].getLicence()}")
# Test 2 - getJournalsInAreasWithLicense
result = full_que.getJournalsInAreasWithLicense(
{"Computer Science"}, {"CC BY"}
)
print(f"getJournalsInAreasWithLicense: {len(result)} journals")
if result:
print(f" First journal: {result[0].getTitle()} | license: {result[0].getLicence()}")
# Test 3 - getDiamondJournalsInAreasAndCategoriesWithQuartile
result = full_que.getDiamondJournalsInAreasAndCategoriesWithQuartile(
{"Computer Science"}, {"Artificial Intelligence"}, {"Q1"}
)
print(f"getDiamondJournalsInAreasAndCategoriesWithQuartile: {len(result)} journals")
if result:
print(f" First journal: {result[0].getTitle()} | APC: {result[0].hasAPC()}")
# =============================================================================
# FINAL SUMMARY
# =============================================================================
print("\n" + "=" * 80)
print("EXECUTION COMPLETE - ALL BASICQUERYENGINE & FULLQUERYENGINE METHODS TESTED")
print("=" * 80)
print("\nSummary:")
print("- BasicQueryEngine: 18 methods tested")
print("- FullQueryEngine: 12 methods tested (3 mashup + 3 helper + 6 inheritance)")
print("- Total: 30 test cases executed")
print("=" * 80)
import sqlite3
# Step 1: check what SQLite returns for a category we know exists
conn = sqlite3.connect(rel_path)
df_test = pd.read_sql_query("""
SELECT DISTINCT identifiers
FROM categories
WHERE category_id = 'Artificial Intelligence'
AND quartile = 'Q1'
LIMIT 5
""", conn)
conn.close()
print("Step 1 - SQLite identifiers for AI/Q1:")
print(df_test)
# Step 2: take one of those identifiers and check if the graph finds it
test_id = df_test['identifiers'].iloc[0]
print(f"\nStep 2 - Looking for '{test_id}' in graph...")
df_journal = jou_qh.getById(test_id)
print(f"Graph result for {test_id}:")
print(df_journal)
# Step 3: check if that same id is in the overlap set
print(f"\nStep 3 - Is '{test_id}' in the overlap set?", test_id.strip() in overlap)
import sqlite3
conn = sqlite3.connect(rel_path)
df_ai = pd.read_sql_query("""
SELECT DISTINCT identifiers
FROM categories
WHERE category_id = 'Artificial Intelligence'
AND quartile = 'Q1'
""", conn)
conn.close()
ai_ids = set(df_ai['identifiers'].str.strip())
df_graph = jou_qh.getAllJournals()
graph_ids = set()
for val in df_graph['identifier'].dropna():
for part in val.split(';'):
graph_ids.add(part.strip())
ai_overlap = ai_ids.intersection(graph_ids)
print(f"AI/Q1 has {len(ai_ids)} identifiers in SQLite")
print(f"Of those, {len(ai_overlap)} exist in the graph")
print("Matching ones:", list(ai_overlap)[:10])
import sqlite3
# Simulate exactly what getJournalsInCategoriesWithQuartile does internally
category_ids = {"Artificial Intelligence"}
quartiles = {"Q1"}
# Step 1: what does the SQLite query return?
conn = sqlite3.connect(rel_path)
df_identifiers = pd.read_sql_query("""
SELECT DISTINCT identifiers
FROM categories
WHERE category_id IN ('Artificial Intelligence')
AND quartile IN ('Q1')
""", conn)
conn.close()
print("Step 1 - SQLite query result:")
print(df_identifiers.head(10))
# Step 2: what does _parse_list_field do to those identifiers?
wanted = set()
for val in df_identifiers['identifiers']:
for part in str(val).replace(';', ',').split(','):
part = part.strip()
if part:
wanted.add(part)
print(f"\nStep 2 - wanted_identifiers after parsing: {len(wanted)} ids")
print("Sample:", list(wanted)[:5])
# Step 3: what does getAllJournals return from graph?
df_journals = jou_qh.getAllJournals()
print(f"\nStep 3 - Graph returned {len(df_journals)} rows")
print("Sample identifiers:", df_journals['identifier'].head(5).tolist())
# Step 4: how many graph rows match wanted_identifiers?
matches = 0
for val in df_journals['identifier'].dropna():
row_ids = [p.strip() for p in str(val).replace(';', ',').split(',')]
if any(rid in wanted for rid in row_ids):
matches += 1
print(f"\nStep 4 - Graph rows matching wanted_identifiers: {matches}")