Skip to content

Commit

Permalink
improvement on renaming nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazztok45 committed Dec 14, 2023
1 parent 200933b commit b93b7b7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
50 changes: 37 additions & 13 deletions src/zbmath_rest2oai/getWithSwagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ def func_get_doc_to_xml(obj, xml):
all_iter_list = [list, dict]
all_iter_list.extend(swagger_client_dicttype_list)

nodes_names_not_to_add = ['_position','_series_id','_prefix','_number', '_type', '_states', 'discriminator', '_biographic_references']
if type(obj) in swagger_client_dicttype_list:
obj = obj.__dict__

if type(obj) == list:
for i in range(len(obj)):
parent_name = xml.lastChild.nodeName

str_no_zbmath_parent_name = re.sub("zbmath:", "", parent_name)

if str_no_zbmath_parent_name in d.keys():
parent_name = parent_name.replace(str_no_zbmath_parent_name, d[str_no_zbmath_parent_name][0])

if obj[i]==[]:
xml = append_text_child(xmld, xml, parent_name, 'missing')
elif obj[i] is None:
Expand All @@ -98,20 +98,44 @@ def func_get_doc_to_xml(obj, xml):


if type(obj) == dict:
for key in obj.keys():
if obj[key]==[]:
xml = append_text_child(xmld, xml, key, 'missing')
elif obj[key] is None:
xml = append_text_child(xmld, xml, key, 'missing')
elif type(obj[key]) in [str,int]:
xml = append_text_child(xmld, xml, key, obj[key])
elif type(obj[key]) in all_iter_list:
xml = append_text_child(xmld, xml, key, "")
func_get_doc_to_xml(obj[key], xml)
new_obj = dict()
for key_init in obj.keys():
if key_init in d.keys():
if key_init == '_code':
if xml.lastChild.nodeName=='zbmath:ref_classification':
new_obj[d[key_init][1]] = obj[key_init]
else:
new_obj[d[key_init][0]] = obj[key_init]
else:
new_obj[d[key_init][0]] = obj[key_init]
else:
new_obj[key_init] = obj[key_init]
for key in new_obj.keys():
if key not in nodes_names_not_to_add:
if new_obj[key]==[]:
xml = append_text_child(xmld, xml, key, 'missing')
elif new_obj[key] is None:
xml = append_text_child(xmld, xml, key, 'missing')
elif type(new_obj[key]) in [str,int]:
xml = append_text_child(xmld, xml, key, new_obj[key])
elif type(new_obj[key]) in all_iter_list:
xml = append_text_child(xmld, xml, key, "")
func_get_doc_to_xml(new_obj[key], xml)
else:
continue
return xml

final_xml = func_get_doc_to_xml(res.result, ron)

print(final_xml.toprettyxml())

l= final_xml.childNodes
list_nodes_remove = []
for i in range(len(l)):
if l[i].localName in ['_contributors','_authors', '_aliases', '_checked']:
list_nodes_remove.append(l[i])

for node in list_nodes_remove:
final_xml.removeChild(node)

print(final_xml.toprettyxml())

2 changes: 1 addition & 1 deletion src/zbmath_rest2oai/output mapping - Copy.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],


"_code":[ "author_id"
"_code":[ "author_id", "classification"
],


Expand Down

0 comments on commit b93b7b7

Please sign in to comment.