From 76f6bd6f4f919a3eac2e06252a0c01a0b53665d2 Mon Sep 17 00:00:00 2001 From: Moritz Schubotz Date: Fri, 18 Oct 2024 14:43:14 +0200 Subject: [PATCH] Revert "Open aire dev" --- src/zbmath_rest2oai/restApi_software_Json.py | 150 +++--- test/data/software/Test_Result_Codemeta.xml | 389 +++++++------- test/data/software/software_with_swhid_2.json | 143 ------ test/data/software/software_with_swhid_2.xml | 121 ----- xslt/software/xslt-software-Codemeta.xslt | 473 +++++++++--------- 5 files changed, 489 insertions(+), 787 deletions(-) delete mode 100644 test/data/software/software_with_swhid_2.json delete mode 100644 test/data/software/software_with_swhid_2.xml diff --git a/src/zbmath_rest2oai/restApi_software_Json.py b/src/zbmath_rest2oai/restApi_software_Json.py index c4e50c50..4f62d480 100644 --- a/src/zbmath_rest2oai/restApi_software_Json.py +++ b/src/zbmath_rest2oai/restApi_software_Json.py @@ -1,76 +1,74 @@ - -import json - -import requests - -from swhid import parse_csv_to_dict - - -# Main function to handle the API request, CSV parsing, and JSON modification -def process_metadata(csv_file_path, api_url, output_path=None): - # Extract the swmathid from the API URL - swmathid = int(api_url.split('/')[-1]) # This extracts the number after 'software/' - - # Make a GET request to the API - response = requests.get(api_url) - - # Check if the request was successful (status code 200) - if response.status_code == 200: - # Parse the response JSON content - data = response.json() - - # Parse the CSV and get the dictionary of swmathid to swhid - swmathid_to_swhid = parse_csv_to_dict(csv_file_path) - - # Prepare the output log - output_log = [] - - # Check if the swmathid from the API exists in the CSV mapping - if swmathid in swmathid_to_swhid: - matched_swhid = swmathid_to_swhid[swmathid] - - # Modify the JSON structure with the matched swhid - swhdeposit_data = { - "swhdeposit:deposit": { - "swhdeposit:reference": { - "swhdeposit:object": { - "@swhid": matched_swhid - } - }, - "swhdeposit:metadata-provenance": { - "schema:url": "https://staging.swmath.org/" # Split or modify the URL as needed - } - } - } - - # Merge this into the original JSON - data.update(swhdeposit_data) - - # Add a log entry for success - output_log.append(f"swmathid {swmathid} matched to swhid: {matched_swhid}") - else: - # If no match is found - output_log.append(f"swmathid {swmathid} not found in the CSV file.") - - # Save the modified JSON data to a file - output_json_filename = 'output_with_swhid.json' - with open(output_path, 'w') as json_file: - json.dump(data, json_file, indent=4, ensure_ascii=False) - print(f"Data successfully saved to {output_json_filename}") - - # Save the output log to a file - # output_log_filename = 'process_log.txt' - with open(output_log_filename, 'w') as log_file: - for log_entry in output_log: - log_file.write(log_entry + '\n') - print(f"Log successfully saved to {output_log_filename}") - else: - print(f"Failed to retrieve data. Status code: {response.status_code}") - - -csv_file_path = '../../test/data/software/swh_swmath.csv' # Path to your CSV file -api_url = 'https://api.zbmath.org/v1/software/825' # API URL, can be generalized for any software ID -output_path = '../../test/data/software/software_with_swhid.json' -output_log_filename = '../../test/data/software/logfile.txt' -process_metadata(csv_file_path, api_url, output_path) - +import json + +import requests + +from swhid import parse_csv_to_dict + + +# Main function to handle the API request, CSV parsing, and JSON modification +def process_metadata(csv_file_path, api_url, output_path=None): + # Extract the swmathid from the API URL + swmathid = int(api_url.split('/')[-1]) # This extracts the number after 'software/' + + # Make a GET request to the API + response = requests.get(api_url) + + # Check if the request was successful (status code 200) + if response.status_code == 200: + # Parse the response JSON content + data = response.json() + + # Parse the CSV and get the dictionary of swmathid to swhid + swmathid_to_swhid = parse_csv_to_dict(csv_file_path) + + # Prepare the output log + output_log = [] + + # Check if the swmathid from the API exists in the CSV mapping + if swmathid in swmathid_to_swhid: + matched_swhid = swmathid_to_swhid[swmathid] + + # Modify the JSON structure with the matched swhid + swhdeposit_data = { + "swhdeposit:deposit": { + "swhdeposit:reference": { + "swhdeposit:object": { + "@swhid": matched_swhid + } + }, + "swhdeposit:metadata-provenance": { + "schema:url": "https://staging.swmath.org/" # Split or modify the URL as needed + } + } + } + + # Merge this into the original JSON + data.update(swhdeposit_data) + + # Add a log entry for success + output_log.append(f"swmathid {swmathid} matched to swhid: {matched_swhid}") + else: + # If no match is found + output_log.append(f"swmathid {swmathid} not found in the CSV file.") + + # Save the modified JSON data to a file + output_json_filename = 'output_with_swhid.json' + with open(output_path, 'w') as json_file: + json.dump(data, json_file, indent=4, ensure_ascii=False) + print(f"Data successfully saved to {output_json_filename}") + + # Save the output log to a file + # output_log_filename = 'process_log.txt' + with open(output_log_filename, 'w') as log_file: + for log_entry in output_log: + log_file.write(log_entry + '\n') + print(f"Log successfully saved to {output_log_filename}") + else: + print(f"Failed to retrieve data. Status code: {response.status_code}") + + +csv_file_path = '../../test/data/software/swh_swmath.csv' # Path to your CSV file +api_url = 'https://api.zbmath.org/v1/software/825' # API URL, can be generalized for any software ID +output_path = '../../test/data/software/software_with_swhid.json' +output_log_filename = '../../test/data/software/logfile.txt' +process_metadata(csv_file_path, api_url, output_path) diff --git a/test/data/software/Test_Result_Codemeta.xml b/test/data/software/Test_Result_Codemeta.xml index 6976fff8..9462f4ae 100644 --- a/test/data/software/Test_Result_Codemeta.xml +++ b/test/data/software/Test_Result_Codemeta.xml @@ -1,197 +1,192 @@ - - - - zbmath-825 - - - - - - https://staging.swmath.org/ - - - - Developers, The Sage - The Sage - Developers - Stein, William - William - Stein - Joyner, David - David - Joyner - Kohel, David - David - Kohel - Cremona, John - John - Cremona - Eröcal, Burçin - Burçin - Eröcal - - SageMath - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - http://www.sagemath.org - https://github.com/sagemath/sage - orms - Python - Cython - Sage - Open Source - Interfaces - None - - schema:PropertyValue - 255 - - None - - schema:PropertyValue - zbmath-825 - - - 05 - 11 - 14 - 20 - 68 - 00 - 01 - 03 - 06 - 12 - 13 - 15 - 16 - 17 - 18 - 19 - 22 - 26 - 28 - 30 - 31 - 32 - 33 - 34 - 35 - 37 - 39 - 40 - 41 - 42 - 43 - 44 - 46 - 47 - 49 - 51 - 52 - 53 - 54 - 55 - 57 - 58 - 60 - 62 - 65 - 70 - 74 - 76 - 78 - 80 - 81 - 82 - 83 - 85 - 86 - 90 - 91 - 92 - 93 - 94 - 97 - - - 2829 - - - Magma - 540 - GAP - 320 - GitHub - 23170 - OEIS - 7248 - SINGULAR - 866 - PARI/GP - 680 - Sage-Combinat - 16448 - Macaulay2 - 537 - Mathematica - 554 - Maple - 545 - LMFDB - 7249 - Python - 14460 - ecdata - 27596 - nauty - 611 - Traces - 7823 - DLMF - 4968 - Maxima - 560 - Gfan - 4698 - MathOverflow - 23728 - SciPy - 6293 - - - 7045592 - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - 2019 - 6418360 - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - 2015 - 6532438 - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - 2013 - 6462232 - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - 2013 - 6114556 - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - 2012 - 5785538 - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - 2010 - 5380273 - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - 2008 - - https://zbmath.org/software/825 - - + + zbmath-825 + + + + + + https://staging.swmath.org/ + + + + + Developers + The Sage + + + Stein + William + + + Joyner + David + + + Kohel + David + + + Cremona + John + + + Eröcal + Burçin + + + SageMath + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + http://www.sagemath.org + https://github.com/sagemath/sage + orms + Python + Cython + Sage + Open Source + Interfaces + None + 255 + None + 05 + 11 + 14 + 20 + 68 + 00 + 01 + 03 + 06 + 12 + 13 + 15 + 16 + 17 + 18 + 19 + 22 + 26 + 28 + 30 + 31 + 32 + 33 + 34 + 35 + 37 + 39 + 40 + 41 + 42 + 43 + 44 + 46 + 47 + 49 + 51 + 52 + 53 + 54 + 55 + 57 + 58 + 60 + 62 + 65 + 70 + 74 + 76 + 78 + 80 + 81 + 82 + 83 + 85 + 86 + 90 + 91 + 92 + 93 + 94 + 97 + 2829 + + Magma + 540 + GAP + 320 + GitHub + 23170 + OEIS + 7248 + PARI/GP + 680 + SINGULAR + 866 + Sage-Combinat + 16448 + Macaulay2 + 537 + Mathematica + 554 + Maple + 545 + LMFDB + 7249 + Python + 14460 + ecdata + 27596 + nauty + 611 + Traces + 7823 + Maxima + 560 + DLMF + 4968 + Gfan + 4698 + MathOverflow + 23728 + SciPy + 6293 + + + + 7045592 + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + 2019 + + 6418360 + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + 2015 + + 6532438 + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + 2013 + + 6462232 + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + 2013 + + 6114556 + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + 2012 + + 5785538 + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + 2010 + + 5380273 + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + zbMATH Open Web Interface contents unavailable due to conflicting licenses. + 2008 + + https://zbmath.org/software/825 + diff --git a/test/data/software/software_with_swhid_2.json b/test/data/software/software_with_swhid_2.json deleted file mode 100644 index 6aaeffa4..00000000 --- a/test/data/software/software_with_swhid_2.json +++ /dev/null @@ -1,143 +0,0 @@ -{ - "result": { - "articles_count": 150, - "authors": [ - "Jr, Frank E Harrell" - ], - "classification": [ - "62", - "65", - "68", - "91", - "92", - "00", - "20", - "37", - "41", - "60", - "81", - "82", - "83", - "86", - "90", - "93", - "94" - ], - "dependencies": "R; Hmisc (≥ 3.7), survival (≥ 2.36-3)", - "description": "zbMATH Open Web Interface contents unavailable due to conflicting licenses.", - "homepage": "http://cran.r-project.org/web/packages/rms/", - "id": 4532, - "keywords": [], - "license_terms": "GPL (≥ 2)", - "name": "rms", - "operating_systems": null, - "orms_id": null, - "programming_languages": null, - "related_software": [ - { - "id": 771, - "name": "R" - }, - { - "id": 6377, - "name": "SAS" - }, - { - "id": 4364, - "name": "survival" - }, - { - "id": 8159, - "name": "glmnet" - }, - { - "id": 6029, - "name": "Stata" - }, - { - "id": 4490, - "name": "VGAM" - }, - { - "id": 11049, - "name": "ElemStatLearn" - }, - { - "id": 4557, - "name": "ggplot2" - }, - { - "id": 12561, - "name": "ordinal" - }, - { - "id": 18788, - "name": "SAS/STAT" - }, - { - "id": 11008, - "name": "BayesDA" - }, - { - "id": 19105, - "name": "bootstrap" - }, - { - "id": 19099, - "name": "brms" - }, - { - "id": 2892, - "name": "S-PLUS" - }, - { - "id": 4479, - "name": "MASS (R)" - }, - { - "id": 4074, - "name": "UCI-ml" - }, - { - "id": 8068, - "name": "timereg" - }, - { - "id": 4586, - "name": "KernSmooth" - }, - { - "id": 4351, - "name": "CRAN" - }, - { - "id": 20527, - "name": "ordinalNet" - } - ], - "source_code": "https://github.com/cran/rms", - "standard_articles": [], - "zbmath_url": "https://zbmath.org/software/4532" - }, - "status": { - "execution": "successful request", - "execution_bool": true, - "internal_code": "ok", - "last_id": null, - "nr_total_results": 1, - "nr_request_results": 1, - "query_execution_time_in_seconds": 0.10137176513671875, - "status_code": 200, - "time_stamp": "2024-10-17T17:48:07Z" - }, - "swhdeposit:deposit": { - "swhdeposit:reference": { - "swhdeposit:object": { - "@swhid": "swh:1:snp:3f97c8fa7714065b16fa022ae54522c6b783e3a3" - } - }, - "swhdeposit:metadata-provenance": { - "schema:url": "https://staging.swmath.org/" - } - } -} \ No newline at end of file diff --git a/test/data/software/software_with_swhid_2.xml b/test/data/software/software_with_swhid_2.xml deleted file mode 100644 index b8b13d8d..00000000 --- a/test/data/software/software_with_swhid_2.xml +++ /dev/null @@ -1,121 +0,0 @@ - - - 150 - Jr, Frank E Harrell - 62 - 65 - 68 - 91 - 92 - 00 - 20 - 37 - 41 - 60 - 81 - 82 - 83 - 86 - 90 - 93 - 94 - - - - - - https://staging.swmath.org/ - - - R; Hmisc (≥ 3.7), survival (≥ 2.36-3) - zbMATH Open Web Interface contents unavailable due to conflicting licenses. - http://cran.r-project.org/web/packages/rms/ - 4532 - GPL (≥ 2) - rms - None - None - None - - 771 - R - - - 6377 - SAS - - - 4364 - survival - - - 8159 - glmnet - - - 6029 - Stata - - - 4490 - VGAM - - - 11049 - ElemStatLearn - - - 4557 - ggplot2 - - - 12561 - ordinal - - - 18788 - SAS/STAT - - - 11008 - BayesDA - - - 19105 - bootstrap - - - 19099 - brms - - - 2892 - S-PLUS - - - 4479 - MASS (R) - - - 4074 - UCI-ml - - - 8068 - timereg - - - 4586 - KernSmooth - - - 4351 - CRAN - - - 20527 - ordinalNet - - https://github.com/cran/rms - https://zbmath.org/software/4532 - diff --git a/xslt/software/xslt-software-Codemeta.xslt b/xslt/software/xslt-software-Codemeta.xslt index c0303cd1..4460ba02 100644 --- a/xslt/software/xslt-software-Codemeta.xslt +++ b/xslt/software/xslt-software-Codemeta.xslt @@ -1,250 +1,223 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - zbmath- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - schema:PropertyValue - - - - - - - - - - - - - - - schema:PropertyValue - - zbmath- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + zbmath- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file