Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions src/zbmath_rest2oai/getAsXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,40 @@ def extract_tags(result):
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 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 = []
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]
Expand All @@ -102,9 +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)

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)
Expand All @@ -113,9 +144,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
Expand Down
1 change: 1 addition & 0 deletions test/data/software/plain_with_references.xml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
<name>deal.ii</name>
</related_software>
<source_code/>
<source_year>2005</source_year>
<standard_articles>
<authors/>
<id>2187846</id>
Expand Down
Loading