Skip to content

Commit

Permalink
Facing issues with appending nodes. Strategy to try written at the en…
Browse files Browse the repository at this point in the history
…d of the code.
  • Loading branch information
Mazztok45 committed Dec 15, 2023
1 parent b93b7b7 commit 2900917
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 14 deletions.
74 changes: 65 additions & 9 deletions src/zbmath_rest2oai/getWithSwagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ 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']
nodes_names_not_to_add = ['_position','_series_id','_prefix','_number', '_type', '_states', 'discriminator', '_biographic_references', '_data_source']
if type(obj) in swagger_client_dicttype_list:
obj = obj.__dict__

Expand All @@ -83,13 +83,22 @@ def func_get_doc_to_xml(obj, xml):
elif obj[i] is None:
xml = append_text_child(xmld, xml, parent_name, 'missing')
elif type(obj[i]) in [str,int]:
if parent_name.endswith('s'):
parent_name = parent_name[:-1]
if parent_name in ['zbmath:ref_classifications', 'zbmath:ref_id', 'zbmath:_doi', 'zbmath:text']:
if xml.getElementsByTagName('zbmath:_references') != []:
xml = append_text_child(xmld, xml.getElementsByTagName('zbmath:references')[-1], parent_name, obj[i])

if xml._get_lastChild().nodeName == parent_name:
xml = append_text_child(xmld, xml, parent_name, obj[i])
else:
xml = append_text_child(xmld, xml._get_lastChild(), parent_name, obj[i])
#if parent_name.endswith('s'):
# parent_name = parent_name[:-1]


if xml._get_lastChild().nodeName == parent_name :
xml = append_text_child(xmld, xml, parent_name, obj[i])

else:
xml = append_text_child(xmld, xml, parent_name, obj[i])


elif type(obj[i]) in all_iter_list:
func_get_doc_to_xml(obj[i], xml)
else:
Expand All @@ -102,22 +111,35 @@ def func_get_doc_to_xml(obj, xml):
for key_init in obj.keys():
if key_init in d.keys():
if key_init == '_code':
if xml.lastChild.nodeName=='zbmath:ref_classification':
if xml.lastChild.nodeName=='zbmath:ref_classifications':
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])

if key in ['ref_classifications', 'ref_id', '_doi', 'text']:
b= xml.getElementsByTagName('zbmath:references')
b = [s for s in b if not b == '']
if len(b)!=0:
xml = append_text_child(xmld, b[-1], key, new_obj[key])
else:
print('HEEREEEEE')
print(key)
print(new_obj[key])
print(dir(xml))
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)
Expand All @@ -129,13 +151,47 @@ def func_get_doc_to_xml(obj, xml):


l= final_xml.childNodes

####

## STRATEGY TO SOLVE the situation with inner indentation. IF elem in Happening node, append child and recurs func ELSE, happend node normally
##
list_nodes_remove = []
for i in range(len(l)):
if l[i].localName in ['_contributors','_authors', '_aliases', '_checked']:
if l[i].localName in ['_contributors','_authors', '_aliases', '_checked', '_author_references', '_reviewer', '_editors','_editorial_contributions', '_author_codes']:
list_nodes_remove.append(l[i])

for node in list_nodes_remove:
final_xml.removeChild(node)

print(final_xml.toprettyxml())
#print(dir(final_xml))




### PART OF THE CODE TO SORT THE FINAL XML
ron1 = xmld.createElement("oai_zb_preview:zbmath")
ron1.setAttributeNS(
"xmls",
"xmlns:oai_zb_preview",
"https://zbmath.org/OAI/2.0/oai_zb_preview/",
)
ron1.setAttributeNS(
"xmls",
"xmlns:zbmath",
"https://zbmath.org/zbmath/elements/1.0/",
)
ron1.setAttributeNS(
"xmls",
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance",
)

#sorted_dict = dict(sorted(dict(zip([i.localName for i in l],l)).items()))
#for key in sorted_dict.keys():
# ron1.appendChild(sorted_dict[key])

#print(ron1.toprettyxml())


10 changes: 5 additions & 5 deletions src/zbmath_rest2oai/output mapping - Copy.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

"_title": [ "document_title"
],


"_author_code":["reviewer_id"],

"_id": [ "document_id"

Expand Down Expand Up @@ -48,7 +47,7 @@
"spelling": ["_author_code"
],

"reviewer_id": ["reviewer_id"
"_reviewer_id": ["reviewer"
],

"_sign": ["review_sign"
Expand All @@ -75,9 +74,10 @@
],
"_document_id": ["ref_id"
],
"_msc": ["ref_classification"
"_msc": ["ref_classifications"

]
],
"_zbmath": ["references"]



Expand Down

0 comments on commit 2900917

Please sign in to comment.