From ae15505900719eb4c75524f6099a96a6b9809f96 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 29 Jan 2022 12:32:34 +0100 Subject: [PATCH] Add docstrings --- notion_scholar/bibtex.py | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/notion_scholar/bibtex.py b/notion_scholar/bibtex.py index 541a5d9..d9e6d62 100644 --- a/notion_scholar/bibtex.py +++ b/notion_scholar/bibtex.py @@ -10,17 +10,46 @@ def get_bib_database_from_file(file_path: str) -> BibDatabase: + """ + Read a file and parse the BibTex entries present in it. + + Args: + file_path: path of the file that needs to be parsed. + + Returns: + BibDatabase object that contains the instances present in the + file. + """ with open(file_path) as bibtex_file: parser = BibTexParser(common_strings=True) return load(bibtex_file, parser=parser) def get_bib_database_from_string(string: str) -> BibDatabase: + """ + Create a BibDatabase object from a string of BibTex entries. + + Args: + string: string containing the BibTex entries. + + Returns: + BibDatabase object that contains the instances present in the + string. + """ bibtex_parser = BibTexParser(interpolate_strings=False, common_strings=True) return bibtex_parser.parse(string) def get_publication_list(bib_database: BibDatabase) -> List[Publication]: + """ + Convert a BibDatabase object into a list of "Publication"s. + + Args: + bib_database: a BibDatabase object. + + Returns: + List of "Publication"s. + """ publications = [] for entry in bib_database.entries: db = BibDatabase() @@ -40,10 +69,29 @@ def get_publication_list(bib_database: BibDatabase) -> List[Publication]: def get_key_list(bib_file_path: str) -> list: + """ + Read a BibTex file and return the list of ID of the paper present in it. + + Args: + bib_file_path: path of the file that needs to be inspected. + + Returns: + List of IDs. + """ bib_database = get_bib_database_from_file(bib_file_path) return [entry['ID'] for entry in bib_database.entries] def get_duplicate_key_list(bib_file_path: str) -> list: + """ + Read a BibTex file and return the list of paper IDs that are in + duplicate in the file. + + Args: + bib_file_path: path of the file that needs to be inspected. + + Returns: + List of IDs. + """ key_list = get_key_list(bib_file_path) return get_duplicates(key_list)