From 349ca7e662cf12535a0810b1e58211f3c2d221bf Mon Sep 17 00:00:00 2001 From: shirazos7 Date: Fri, 24 Jan 2025 16:07:14 +0100 Subject: [PATCH 1/8] adding function for source_year --- src/zbmath_rest2oai/getAsXml.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/zbmath_rest2oai/getAsXml.py b/src/zbmath_rest2oai/getAsXml.py index b1f29765..ccb3d98a 100644 --- a/src/zbmath_rest2oai/getAsXml.py +++ b/src/zbmath_rest2oai/getAsXml.py @@ -72,12 +72,24 @@ def extract_tags(result): tags.append('JFM') return tags - +def extract_year_from_source(source): + + if isinstance(source, dict): + if "series" in source and isinstance(source["series"], list): + for series in source["series"]: + if "year" in series: + return series["year"] + elif "book" in source and isinstance(source["book"], list): + for book in source["book"]: + if "year" in book: + return book["year"] + return None def add_references_to_software(api_uri, dict_res): list_articles_ids_to_soft = [] list_articles_ids_and_alter_ids_to_soft = [] list_references_year_alt = [] + source_year = None if "software" in api_uri: if api_uri.startswith("https://api.zbmath.org/v1/software/_all?start_after=")==False: soft_id=api_uri.split("/")[-1] @@ -106,6 +118,9 @@ def api_doc_endpoint(page): year = entry["datestamp"][:4] list_references_year_alt.append(year) + if "source" in entry: + source_year = extract_year_from_source(entry["source"]) + list_articles_ids_to_soft.extend(list_ids) list_articles_ids_and_alter_ids_to_soft.extend(list_ids_and_alter) @@ -113,9 +128,10 @@ def api_doc_endpoint(page): if isinstance(dict_res, dict): dict_res["references"] = list_articles_ids_to_soft - # Wrap it in a list to make it iterable for your existing loop dict_res["references_alt"] = list_articles_ids_and_alter_ids_to_soft dict_res["references_year_alt"] = list_references_year_alt + if source_year is not None: # Add source_year only if it was found + dict_res["source_year"] = source_year dict_res = [dict_res] return dict_res From 940bd394e7af7b4efc1bb712159d965b8be71cd1 Mon Sep 17 00:00:00 2001 From: shirazos7 Date: Fri, 24 Jan 2025 16:08:05 +0100 Subject: [PATCH 2/8] adding the source_year node in the xml --- test/data/software/plain_with_references.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/test/data/software/plain_with_references.xml b/test/data/software/plain_with_references.xml index 0964d626..1ec28263 100644 --- a/test/data/software/plain_with_references.xml +++ b/test/data/software/plain_with_references.xml @@ -442,6 +442,7 @@ deal.ii + 2005 2187846 From d27597a03756c142b508212ed78ce31f424aa92c Mon Sep 17 00:00:00 2001 From: shirazos7 Date: Fri, 24 Jan 2025 16:21:25 +0100 Subject: [PATCH 3/8] adding blank lines to fix a bug --- src/zbmath_rest2oai/getAsXml.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/zbmath_rest2oai/getAsXml.py b/src/zbmath_rest2oai/getAsXml.py index ccb3d98a..95ad5ca9 100644 --- a/src/zbmath_rest2oai/getAsXml.py +++ b/src/zbmath_rest2oai/getAsXml.py @@ -72,6 +72,7 @@ def extract_tags(result): tags.append('JFM') return tags + def extract_year_from_source(source): if isinstance(source, dict): @@ -85,6 +86,7 @@ def extract_year_from_source(source): return book["year"] return None + def add_references_to_software(api_uri, dict_res): list_articles_ids_to_soft = [] list_articles_ids_and_alter_ids_to_soft = [] From b2cfdc3f8b0c2fc72819600f33ac9a11581aff1d Mon Sep 17 00:00:00 2001 From: shirazos7 Date: Fri, 24 Jan 2025 16:48:44 +0100 Subject: [PATCH 4/8] adjusting the source_year lines to avoid bugs --- src/zbmath_rest2oai/getAsXml.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/zbmath_rest2oai/getAsXml.py b/src/zbmath_rest2oai/getAsXml.py index 95ad5ca9..93d236bc 100644 --- a/src/zbmath_rest2oai/getAsXml.py +++ b/src/zbmath_rest2oai/getAsXml.py @@ -121,7 +121,8 @@ def api_doc_endpoint(page): list_references_year_alt.append(year) if "source" in entry: - source_year = extract_year_from_source(entry["source"]) + expected_year = extract_year_from_source(entry["source"]) + source_year = expected_year list_articles_ids_to_soft.extend(list_ids) list_articles_ids_and_alter_ids_to_soft.extend(list_ids_and_alter) From 35047bf1be3292bbb7d3b0e05d619b985cf7aa4a Mon Sep 17 00:00:00 2001 From: shirazos7 Date: Fri, 24 Jan 2025 16:57:03 +0100 Subject: [PATCH 5/8] adjusting the source_year lines to avoid bugs --- src/zbmath_rest2oai/getAsXml.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/zbmath_rest2oai/getAsXml.py b/src/zbmath_rest2oai/getAsXml.py index 93d236bc..968441fc 100644 --- a/src/zbmath_rest2oai/getAsXml.py +++ b/src/zbmath_rest2oai/getAsXml.py @@ -120,9 +120,10 @@ def api_doc_endpoint(page): year = entry["datestamp"][:4] list_references_year_alt.append(year) - if "source" in entry: - expected_year = extract_year_from_source(entry["source"]) - source_year = expected_year + if "source" in entry: + extracted_year = extract_year_from_source(entry["source"]) + if extracted_year is not None: # Update source_year only if a valid year is found + source_year = extracted_year list_articles_ids_to_soft.extend(list_ids) list_articles_ids_and_alter_ids_to_soft.extend(list_ids_and_alter) From fba5e953d0d4d481f97c44028536a8c4d1cd8287 Mon Sep 17 00:00:00 2001 From: shirazos7 Date: Fri, 24 Jan 2025 17:03:30 +0100 Subject: [PATCH 6/8] adjusting the source_year lines to avoid bugs --- src/zbmath_rest2oai/getAsXml.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/zbmath_rest2oai/getAsXml.py b/src/zbmath_rest2oai/getAsXml.py index 968441fc..1a594097 100644 --- a/src/zbmath_rest2oai/getAsXml.py +++ b/src/zbmath_rest2oai/getAsXml.py @@ -120,9 +120,8 @@ def api_doc_endpoint(page): year = entry["datestamp"][:4] list_references_year_alt.append(year) - if "source" in entry: - extracted_year = extract_year_from_source(entry["source"]) - if extracted_year is not None: # Update source_year only if a valid year is found + if "source" in entry and \ + (extracted_year := extract_year_from_source(entry["source"])) is not None: source_year = extracted_year list_articles_ids_to_soft.extend(list_ids) From 71ae43e6702389f46fcd7611cb06fdb6f4c9357e Mon Sep 17 00:00:00 2001 From: shirazos7 Date: Fri, 24 Jan 2025 17:06:19 +0100 Subject: [PATCH 7/8] adjusting the source_year lines to avoid bugs --- src/zbmath_rest2oai/getAsXml.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/zbmath_rest2oai/getAsXml.py b/src/zbmath_rest2oai/getAsXml.py index 1a594097..13af9bf3 100644 --- a/src/zbmath_rest2oai/getAsXml.py +++ b/src/zbmath_rest2oai/getAsXml.py @@ -120,9 +120,10 @@ def api_doc_endpoint(page): year = entry["datestamp"][:4] list_references_year_alt.append(year) - if "source" in entry and \ - (extracted_year := extract_year_from_source(entry["source"])) is not None: - source_year = extracted_year + if "source" in entry: + extracted_value = extract_year_from_source(entry["source"]) + if extracted_value is not None: + source_year = extracted_value list_articles_ids_to_soft.extend(list_ids) list_articles_ids_and_alter_ids_to_soft.extend(list_ids_and_alter) From 4519253fc84b1cc0427c3221abfa92365275d101 Mon Sep 17 00:00:00 2001 From: Mazztok45 Date: Mon, 27 Jan 2025 11:41:11 +0100 Subject: [PATCH 8/8] refactoring getAsXml.py --- src/zbmath_rest2oai/getAsXml.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/zbmath_rest2oai/getAsXml.py b/src/zbmath_rest2oai/getAsXml.py index 13af9bf3..3e0142cd 100644 --- a/src/zbmath_rest2oai/getAsXml.py +++ b/src/zbmath_rest2oai/getAsXml.py @@ -86,7 +86,22 @@ def extract_year_from_source(source): return book["year"] return None - +def get_datestamp_year(entry): + """ + Returns the year (string) extracted from entry's 'datestamp' + if it exists, otherwise returns None. + """ + datestamp = entry.get("datestamp") + return datestamp[:4] if datestamp else None + + +def get_source_year(entry): + if "source" in entry: + extracted_value = extract_year_from_source(entry["source"]) + if extracted_value is not None: + return extracted_value + else: + return None def add_references_to_software(api_uri, dict_res): list_articles_ids_to_soft = [] list_articles_ids_and_alter_ids_to_soft = [] @@ -116,14 +131,11 @@ def api_doc_endpoint(page): list_ids_and_alter.append(";".join([str(entry["id"])]+list_links)) - if "datestamp" in entry: - year = entry["datestamp"][:4] - list_references_year_alt.append(year) - if "source" in entry: - extracted_value = extract_year_from_source(entry["source"]) - if extracted_value is not None: - source_year = extracted_value + list_references_year_alt.append(get_datestamp_year(entry)) + + + source_year = get_source_year(entry) list_articles_ids_to_soft.extend(list_ids) list_articles_ids_and_alter_ids_to_soft.extend(list_ids_and_alter)