From b91332562c4c7946ff96145a57af7533a2cbd3f3 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Mon, 6 Mar 2023 15:00:13 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- wostools/article.py | 30 +++++++++++++++--------------- wostools/cli.py | 4 ++-- wostools/fields.py | 2 +- wostools/sources/scopus.py | 15 ++++++--------- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/wostools/article.py b/wostools/article.py index 77eac63..695ed29 100644 --- a/wostools/article.py +++ b/wostools/article.py @@ -56,9 +56,7 @@ def __init__( @property def label(self) -> str: - if self.doi: - return self.doi - return self._label() + return self.doi or self._label() def _label(self, exclude_doi=False, lower_p=False) -> str: if not (self.authors and self.year and self.journal): @@ -76,28 +74,30 @@ def _label(self, exclude_doi=False, lower_p=False) -> str: @property def labels(self) -> Set[str]: - if not self.doi: - return {self.label, self._label(lower_p=True)} - return { - self.doi, - self.label, - self._label(exclude_doi=True), - self._label(lower_p=True), - self._label(exclude_doi=True, lower_p=True), - } + return ( + { + self.doi, + self.label, + self._label(exclude_doi=True), + self._label(lower_p=True), + self._label(exclude_doi=True, lower_p=True), + } + if self.doi + else {self.label, self._label(lower_p=True)} + ) def to_dict(self, simplified=True): """ Transform the article into some key value pairs for easy transportation. """ extra = ( - { + {} + if simplified + else { "references": self.references, "extra": self.extra, "sources": list(self.sources), } - if not simplified - else {} ) return { "title": self.title, diff --git a/wostools/cli.py b/wostools/cli.py index 0750b6a..f5ffc08 100644 --- a/wostools/cli.py +++ b/wostools/cli.py @@ -29,7 +29,7 @@ def citation_pairs(sources, output): Build a collection by using the sources and print the citation pairs in json format or dumps them in the `output`. """ - if not len(sources) > 0: + if len(sources) <= 0: click.secho("You should give at least a file with documents.", fg="red") return @@ -63,7 +63,7 @@ def to_json(sources, output, more): Build a collection by using the sources and print the citation pairs in json format or dumps them in the `output`. """ - if not len(sources) > 0: + if len(sources) <= 0: click.secho("You should give at least a file with documents.", fg="red") return diff --git a/wostools/fields.py b/wostools/fields.py index 47e9c31..09d3eab 100644 --- a/wostools/fields.py +++ b/wostools/fields.py @@ -219,5 +219,5 @@ def parse_all(raw_dict: Dict[str, List[str]]) -> Mapping[str, Any]: processed_data = {} raw_dict.setdefault("CR", []) for key, seq in raw_dict.items(): - processed_data.update(parse(key, seq)) + processed_data |= parse(key, seq) return processed_data diff --git a/wostools/sources/scopus.py b/wostools/sources/scopus.py index f5759a1..1b0e342 100644 --- a/wostools/sources/scopus.py +++ b/wostools/sources/scopus.py @@ -27,9 +27,7 @@ def _int_or_nothing(raw: Optional[List[str]]) -> Optional[int]: def _joined(raw: Optional[List[str]]) -> Optional[str]: - if not raw: - return None - return " ".join(raw) + return " ".join(raw) if raw else None def _find_volume_info(ref: str) -> Tuple[Dict[str, str], str]: @@ -51,7 +49,7 @@ def _find_volume_info(ref: str) -> Tuple[Dict[str, str], str]: data = {} if page: - data.update(page.groupdict()) + data |= page.groupdict() if volume: data.update(volume.groupdict()) @@ -84,9 +82,9 @@ def _scopus_ref_to_isi(scopusref: str) -> str: parts = { "author": f"{first_name} {last_name.replace(' ', '').replace('.', '')}", "year": year, - "journal": journal.strip().replace(".", "").upper() - if not journal.isspace() - else None, + "journal": None + if journal.isspace() + else journal.strip().replace(".", "").upper(), "volume": volume_info.get("volume"), "page": volume_info.get("page"), "doi": doi, @@ -156,5 +154,4 @@ def parse_file(file: TextIO) -> Iterable[Article]: for item in file.read().split("\n\n"): if item.isspace(): continue - article = parse_record(item.strip()) - yield article + yield parse_record(item.strip())