From 65d8f4a31f3a7f60c2e0f1ba43389f503fae21f0 Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Mon, 15 May 2023 19:20:33 +0200 Subject: [PATCH] Add files via upload --- bib/customizations.py | 9 +++++++++ bib/load_bib_file.py | 15 +++++++++++++++ bib/shorten_authorname.py | 10 ++++++++++ bib/unique_author_list.py | 15 +++++++++++++++ bib/unique_type_list.py | 10 ++++++++++ 5 files changed, 59 insertions(+) create mode 100644 bib/customizations.py create mode 100644 bib/load_bib_file.py create mode 100644 bib/shorten_authorname.py create mode 100644 bib/unique_author_list.py create mode 100644 bib/unique_type_list.py diff --git a/bib/customizations.py b/bib/customizations.py new file mode 100644 index 0000000..bdffb1f --- /dev/null +++ b/bib/customizations.py @@ -0,0 +1,9 @@ +import bibtexparser + + +def customizations_tajd(record): + record = bibtexparser.customization.type(record) + record = bibtexparser.customization.author(record) + record = bibtexparser.customization.journal(record) + record = bibtexparser.customization.doi(record) + return record diff --git a/bib/load_bib_file.py b/bib/load_bib_file.py new file mode 100644 index 0000000..5fcce89 --- /dev/null +++ b/bib/load_bib_file.py @@ -0,0 +1,15 @@ +import bibtexparser + + +def load_bib_file(filename_bib: str, customizations): + # Load the bib file: + with open(filename_bib, mode="r") as file: + file_content: str = file.read() + + parser = bibtexparser.bparser.BibTexParser() + parser.customization = customizations + parser.ignore_nonstandard_types = False + + bib_database = bibtexparser.loads(file_content, parser=parser) + + return bib_database diff --git a/bib/shorten_authorname.py b/bib/shorten_authorname.py new file mode 100644 index 0000000..cf709b0 --- /dev/null +++ b/bib/shorten_authorname.py @@ -0,0 +1,10 @@ +def shorten_authorname(input: str) -> str: + temp = input.split(",") + name: str = temp[0].lstrip().rstrip() + str(",") + temp = temp[1].lstrip().rstrip().split(" ") + for i in temp: + if len(i) > 0: + first_letter = i.upper()[0] + if first_letter.isalpha() is True: + name += str(" ") + first_letter + str(".") + return name diff --git a/bib/unique_author_list.py b/bib/unique_author_list.py new file mode 100644 index 0000000..e7106e6 --- /dev/null +++ b/bib/unique_author_list.py @@ -0,0 +1,15 @@ +from bib.shorten_authorname import shorten_authorname + + +def unique_author_list(bib_database): + temp_authors = [] + for idx in range(0, len(bib_database.entries)): + if "author" in bib_database.entries[idx].keys(): + for temp_entry in bib_database.entries[idx]["author"]: + temp_authors.append(shorten_authorname(temp_entry)) + else: + print(f"Author is missing. Entry-ID:{idx}") + + unique_autors = list(set(temp_authors)) + unique_autors.sort() + return unique_autors diff --git a/bib/unique_type_list.py b/bib/unique_type_list.py new file mode 100644 index 0000000..8c5d647 --- /dev/null +++ b/bib/unique_type_list.py @@ -0,0 +1,10 @@ +def unique_type_list(bib_database): + temp_types = [] + for idx in range(0, len(bib_database.entries)): + if "ENTRYTYPE" in bib_database.entries[idx].keys(): + entry = bib_database.entries[idx] + entry_type: str = str(entry["ENTRYTYPE"]).lstrip().rstrip() + temp_types.append(entry_type) + unique_types = list(set(temp_types)) + unique_types.sort() + return unique_types