Skip to content

Commit d53f518

Browse files
authored
fix issue with articles with no author or year (#40)
* Skip articles that don't have authors or year * Prepare release
1 parent d76f8f6 commit d53f518

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/bibx/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"read_wos",
2828
]
2929

30-
__version__ = "0.6.0"
30+
__version__ = "0.6.1"
3131

3232

3333
def query_openalex(

src/bibx/article.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ def permalink(self) -> Optional[str]:
8787
@property
8888
def simple_id(self) -> Optional[str]:
8989
"""Return a simple ID for the article."""
90-
if self.authors and self.year is not None:
91-
author = self.authors[0].split(" ")[0].replace(",", "")
92-
return f"{author}{self.year}".lower()
93-
return None
90+
if not self.authors or self.year is None:
91+
return None
92+
author = self.authors[0].split(" ")[0].replace(",", "")
93+
return f"{author}{self.year}".lower()
9494

9595
def __repr__(self) -> str:
9696
"""Return a string representation of the article."""

src/bibx/builders/scopus_csv.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ def _parse_file(self, file: TextIO) -> Generator[Article]:
9999
reader = csv.DictReader(file)
100100
for row in reader:
101101
datum = Row.model_validate(row)
102+
if not datum.authors or not datum.year:
103+
logger.info(
104+
"skipping row with missing authors or year: %s",
105+
datum.model_dump_json(indent=2),
106+
)
107+
continue
102108
yield (
103109
Article(
104110
label="",
@@ -131,6 +137,9 @@ def _parse_file(self, file: TextIO) -> Generator[Article]:
131137
def _article_from_reference(self, reference: str) -> Optional[Article]:
132138
try:
133139
*authors, journal, issue, year = reference.split(", ")
140+
if not authors:
141+
message = "a minimum of one author is required"
142+
raise ValueError(message)
134143
_year = int(year.lstrip("(").rstrip(")"))
135144
return Article(
136145
label=reference,

0 commit comments

Comments
 (0)