Skip to content

Commit

Permalink
Add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashirtz committed Jan 29, 2022
1 parent c97e06f commit ae15505
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions notion_scholar/bibtex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

0 comments on commit ae15505

Please sign in to comment.