Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: fixes parsing issues #239

Merged
merged 2 commits into from
Dec 12, 2024
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
4 changes: 2 additions & 2 deletions dags/common/parsing/generic_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def parse_author(author):
if "given_names" in author and author["given_names"]:
author["given_names"] = collapse_initials(author["given_names"])
author["full_name"] = "{0}, {1}".format(
author["surname"], author["given_names"]
author.get("surname", ""), author["given_names"]
)
else:
author["full_name"] = author["surname"]
author["full_name"] = author.get("surname")

return author

Expand Down
20 changes: 16 additions & 4 deletions dags/iop/iop_process_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,26 @@
logger = get_logger()


def process_xml(input):
def process_xml(input, italics=True):
input = convert_html_subscripts_to_latex(input)
input = convert_html_italics_to_latex(input)
if italics:
input = convert_html_italics_to_latex(input)
input = replace_cdata_format(input)
return input


def convert_xml_to_et_tree(input):
try:
xml = process_xml(input)
xml = ET.fromstring(xml)

except ET.ParseError:
xml = process_xml(input, italics=False)
xml = ET.fromstring(xml)

return xml


def iop_parse_file(**kwargs):
if "params" not in kwargs or "file" not in kwargs["params"]:
raise Exception("There was no 'file' parameter. Exiting run.")
Expand All @@ -36,8 +49,7 @@ def iop_parse_file(**kwargs):
xml_bytes = base64.b64decode(encoded_xml)
if isinstance(xml_bytes, bytes):
xml_bytes = xml_bytes.decode("utf-8")
xml_bytes = process_xml(xml_bytes)
xml = ET.fromstring(xml_bytes)
xml = convert_xml_to_et_tree(input)

parser = IOPParser(file_path=file_name)
parsed = parser.parse(xml)
Expand Down
Loading
Loading