Skip to content

Commit

Permalink
condition api_source to contain software terms to apply specific soft…
Browse files Browse the repository at this point in the history
…ware references harvesting
  • Loading branch information
Mazztok45 committed Dec 6, 2024
1 parent fdac8dc commit ada8aa8
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/zbmath_rest2oai/getAsXml.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ def api_doc_endpoint(page):
list_articles_ids_to_soft.extend([entry["id"] for entry in data["result"]])
page+=1

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 = [dict_res]
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 = [dict_res]

return dict_res
def final_xml2(api_source, prefix):
Expand All @@ -107,12 +107,13 @@ def final_xml2(api_source, prefix):
json = r.json()
dict_math_entities = {}
tags = {}
if isinstance(json["result"], dict):
json["result"] = add_references_to_software(api_source, json["result"])
elif isinstance(json["result"], list):
for ent in range(len(json["result"])):
soft_id = json["result"][ent]['id']
json["result"][ent] = add_references_to_software("https://api.zbmath.org/v1/software/"+str(soft_id), json["result"][ent])
if "software" in api_source:
if isinstance(json["result"], dict):
json["result"] = add_references_to_software(api_source, json["result"])
elif isinstance(json["result"], list):
for ent in range(len(json["result"])):
soft_id = json["result"][ent]['id']
json["result"][ent] = add_references_to_software("https://api.zbmath.org/v1/software/"+str(soft_id), json["result"][ent])
for result in json["result"]:
if isinstance(result, list):
result = result[0]
Expand All @@ -122,8 +123,19 @@ def final_xml2(api_source, prefix):
result,
closed_tags_for=[[], '', [None], None]))
tags[identifier] = extract_tags(result)
elif isinstance(result, dict):
apply_zbmath_api_fixes(result, prefix)
identifier = result["id"]
dict_math_entities[identifier] = _illegal_xml_chars_RE.sub("", Converter(wrap="root").build(
result,
closed_tags_for=[[], '', [None], None]))
tags[identifier] = extract_tags(result)
return [dict_math_entities, r.elapsed.total_seconds(), tags]


if __name__ == "__main__":
print(final_xml2(sys.argv[1], '')[0])
if "document" in sys.argv[1]:
prefix="oai:zbmath.org:"
else:
prefix="oai:swmath.org:"
print(final_xml2(sys.argv[1], prefix))

0 comments on commit ada8aa8

Please sign in to comment.