Skip to content

Commit dc0f8c8

Browse files
committed
Fix author names
1 parent 830d68a commit dc0f8c8

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

main.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,36 @@ def parse(cls, bib: TextIO) -> List["LiteratureRef"]:
9090
date=int(entry.get("year", 0)),
9191
series=LiteratureRef.__series_of(entry),
9292
title=entry.get("title", "").replace("{", "").replace("}", ""),
93-
authors=entry.get("author", "").split(" and "),
93+
authors=LiteratureRef.__authors_of(entry),
9494
link=entry.get("url", ""),
9595
code=entry.get("code", None),
9696
)
9797
references.append(ref)
9898
return references
9999

100+
@classmethod
101+
def __authors_of(cls, entry: Dict[str, str]) -> List[str]:
102+
"""
103+
Extracts authors from a BibTeX entry.
104+
"""
105+
106+
def reorder_name(name: str) -> str:
107+
"""
108+
Reorders the name from 'Last, First' to 'First Last'.
109+
"""
110+
parts = name.split(", ")
111+
if len(parts) == 2:
112+
return f"{parts[1]} {parts[0]}"
113+
return name
114+
115+
authors = entry.get("author", "").split(" and ")
116+
return [reorder_name(author.strip()) for author in authors]
117+
100118
@classmethod
101119
def __series_of(cls, entry: Dict[str, str]) -> str:
120+
"""
121+
Extracts the series from a BibTeX entry.
122+
"""
102123
if "booktitle" in entry:
103124
booktitle = entry["booktitle"]
104125
for key, value in BOOKTITLE_PATTERN.items():

0 commit comments

Comments
 (0)