diff --git a/vis_services/lib/paper_network.py b/vis_services/lib/paper_network.py index fc69ebd..783b00f 100644 --- a/vis_services/lib/paper_network.py +++ b/vis_services/lib/paper_network.py @@ -252,6 +252,9 @@ def get_papernetwork(solr_data, max_groups, weighted=True, equalization=False, d del R # In practice we don't need to fill the diagonal with zeros, because we won't be using it fill_diagonal(C, 0) + # If the matrix C is all zeros, we there is no co-citation network + if ((C == 0).all()): + return None # Compile the list of links links = [] link_dict = {} diff --git a/vis_services/tests/stubdata/test_input/paper_network_without_cocitations.json b/vis_services/tests/stubdata/test_input/paper_network_without_cocitations.json new file mode 100644 index 0000000..6fdae27 --- /dev/null +++ b/vis_services/tests/stubdata/test_input/paper_network_without_cocitations.json @@ -0,0 +1,137 @@ +{ + "responseHeader": { + "status": 0, + "QTime": 43, + "params": { + "q": "*:*", + "fl": "bibcode,scix_id,title,first_author,year,citation_count,read_count,reference", + "start": "0", + "internal_logging_params": "X-Amzn-Trace-Id=Root=1-6900db96-51632fd74232f4175843bd71", + "fq": "{!bitset}", + "rows": "2000", + "wt": "json" + } + }, + "response": { + "numFound": 5, + "start": 0, + "numFoundExact": true, + "docs": [ + { + "bibcode": "2025EPJQT..12...30B", + "read_count": 0, + "reference": [ + "2014EPJQT...1....1M", + "2014EPJQT...1...10J", + "2015EPJQT...2...19T", + "2015EPJQT...2...23H", + "2016EPJQT...3....5K", + "2020EPJQT...7....6E", + "2021EPJQT...8....6C", + "2021EPJQT...8...24K", + "2024EPJQT..11...86L", + "2025EPJQT..12...16B" + ], + "citation_count": 0, + "first_author": "Bongs, Kai", + "title": [ + "Celebrating the International Year of Quantum Science and Technology" + ], + "year": "2025", + "scix_id": "scix:5YAQ-6RW3-9ZAQ" + }, + { + "bibcode": "2025Meas..25618270J", + "first_author": "Jin, Xingyun", + "title": [ + "Transverse thermoelectric effect in tilted YBa2Cu3O7-\u03b4 films: Towards high-power, high-frequency pulsed-laser detection" + ], + "year": "2025", + "read_count": 0, + "reference": [ + "1990ApPhL..56.1914S", + "1992ApPhL..60..501L", + "2012ApSS..258.7330W", + "2014ApPhA.114.1075M", + "2020ApPhL.117l3902S", + "2020JMemS..29...36T", + "2022ApPhL.121t4102C", + "2022Senso..22.5294L", + "2023FlDy...58..779P", + "2024ApPhL.125d4102S" + ], + "citation_count": 1, + "scix_id": "scix:700N-JRBX-JZQ5" + }, + { + "bibcode": "2025ThApC.156..514I", + "first_author": "Ibrahim, Rabha W.", + "title": [ + "A generalized fractional system for modeling climate change and emissions: analysis, numerical solutions with a case study" + ], + "year": "2025", + "read_count": 0, + "reference": [ + "2022ThApC.148..881H", + "2023IJCli..43.3538L", + "2023JOES....8..308S", + "2023ResPh..5407031C", + "2024CNSNS.12807657C", + "2024ECSS..30208771A", + "2025ClDy...63...86S", + "2025NatSR..1527063A", + "2025PhyS..100a5299S", + "2025ScTEn.96078254M" + ], + "citation_count": 1, + "scix_id": "scix:7B5F-RYSQ-XNB1" + }, + { + "bibcode": "2025OptL...50.5961A", + "read_count": 0, + "reference": [ + "2008PhRvL.100r8102C", + "2009PhRvE..80c1403G", + "2012OptLE..50..366G", + "2016AmJPh..84..202G", + "2016NatSR...634383V", + "2016SMat...12.2858V", + "2019ApOpt..58.6549F", + "2021JBO....26i0601H", + "2022iSci...25j5122A", + "2023Meas..21913263N" + ], + "citation_count": 0, + "first_author": "Asghari, Mahsa", + "title": [ + "Speckle pattern analysis using differential dynamic matrix" + ], + "year": "2025", + "scix_id": "scix:18YE-BSB7-20DE" + }, + { + "bibcode": "2025TUSTI.16406865Y", + "read_count": 0, + "reference": [ + "1950PhT.....3d..35R", + "1979JNNFM...5...79R", + "2005JRheo..49..705R", + "2014EngSt..70..218T", + "2015EngSt.101..698T", + "2015MiEng..71..120G", + "2018GmTun..11..236H", + "2020TUSTI..9603212L", + "2022AcRhe..61..163P", + "2024UndSp..14..285Y" + ], + "citation_count": 0, + "first_author": "Yang, Xing", + "title": [ + "Investigation of synchronous backfill flow behind the segment wall of double-shield TBM utilizing rheological properties of self-compacting concrete backfill material" + ], + "year": "2025", + "scix_id": "scix:7XBC-783C-7XAN" + } + ] + } +} \ No newline at end of file diff --git a/vis_services/tests/test_endpoints.py b/vis_services/tests/test_endpoints.py index 969191f..ba298b1 100644 --- a/vis_services/tests/test_endpoints.py +++ b/vis_services/tests/test_endpoints.py @@ -14,6 +14,7 @@ STUBDATA_DIR = PROJECT_HOME + "/vis_services/tests/stubdata" solr_data = json.load(open(STUBDATA_DIR + "/test_input/paper_network_before_groups_func_large.json")) +solr_data_err = json.load(open(STUBDATA_DIR + "/test_input/paper_network_without_cocitations.json")) wordcloud = json.load(open(STUBDATA_DIR + "/test_output/wordcloud.json")) class TestExpectedResults(TestCase): @@ -167,6 +168,24 @@ def test_paper_network_200(self): self.assertTrue(r.status_code == 200) + @httpretty.activate + def test_paper_network_empty(self): + '''test query for generating a paper network''' + SOLRQUERY_URL = self.app.config.get("VIS_SERVICE_BIGQUERY_PATH") + query_params = {'bibcodes': ['2025Meas..25618270J', '2025EPJQT..12...30B', '2025TUSTI.16406865Y', '2025OptL...50.5961A', '2025ThApC.156..514I']} + httpretty.register_uri( + httpretty.POST, SOLRQUERY_URL, + content_type='application/json', + status=200, + body='%s'%json.dumps(solr_data_err)) + r = self.client.post( + url_for('papernetwork'), + content_type='application/json', + data=json.dumps(query_params)) + expected_output = {'Error': 'Empty network.'} + self.assertTrue(r.status_code == 200) + self.assertTrue(r.json == expected_output) + @httpretty.activate def test_paper_network_solr_error(self): '''test query for generating a paper network - Solr comes back with an HTTP error code'''