From 1936ce746ad91bf8816a93ccfe660dd91d66d397 Mon Sep 17 00:00:00 2001 From: physikerwelt Date: Thu, 17 Oct 2024 23:22:56 +0200 Subject: [PATCH] Add classification for software --- src/zbmath_rest2oai/getAsXml.py | 6 ++++-- test/test_extract_tags.py | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/zbmath_rest2oai/getAsXml.py b/src/zbmath_rest2oai/getAsXml.py index be8cafd5..6261c760 100644 --- a/src/zbmath_rest2oai/getAsXml.py +++ b/src/zbmath_rest2oai/getAsXml.py @@ -59,12 +59,14 @@ def apply_zbmath_api_fixes(result, prefix): def extract_tags(result): - mscs = result.get('msc', []) tags = [] - for msc in mscs: + for msc in result.get('msc', []): msc0 = msc['code'][:2] if msc0 not in tags: tags.append(msc0) + for msc in result.get('classification', []): + if msc not in tags: + tags.append(msc) tags.sort() if result.get('database') == 'JFM': tags.append('JFM') diff --git a/test/test_extract_tags.py b/test/test_extract_tags.py index 53b7e198..27b5af47 100644 --- a/test/test_extract_tags.py +++ b/test/test_extract_tags.py @@ -4,16 +4,24 @@ from zbmath_rest2oai.getAsXml import extract_tags -API_SOURCE = 'https://api.zbmath.org/v1/document/_structured_search?page=0&results_per_page=10&zbmath%20id=2500495' - - class PlainXmlTest(unittest.TestCase): - def test_similarity(self): + @staticmethod + def test_jfm_doc(): headers = {'Accept': 'application/json'} - r = requests.get(API_SOURCE, headers=headers) + r = requests.get( + 'https://api.zbmath.org/v1/document/_structured_search?page=0&results_per_page=10&zbmath%20id=2500495', + headers=headers) real_tags = extract_tags(r.json()['result'][0]) assert real_tags == ['11', 'JFM'] + @staticmethod + def test_software(): + headers = {'Accept': 'application/json'} + r = requests.get( + 'https://api.zbmath.org/v1/software/12', + headers=headers) + real_tags = extract_tags(r.json()['result']) + assert real_tags == ['60', '65', '78', '82'] if __name__ == '__main__': unittest.main()