Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions wostools/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Article.label refactored with the following changes:


def _label(self, exclude_doi=False, lower_p=False) -> str:
if not (self.authors and self.year and self.journal):
Expand All @@ -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)}
)
Comment on lines -79 to +87
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Article.labels refactored with the following changes:


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 {}
Comment on lines -94 to -100
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Article.to_dict refactored with the following changes:

)
return {
"title": self.title,
Expand Down
4 changes: 2 additions & 2 deletions wostools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function citation_pairs refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

click.secho("You should give at least a file with documents.", fg="red")
return

Expand Down Expand Up @@ -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:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function to_json refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

click.secho("You should give at least a file with documents.", fg="red")
return

Expand Down
2 changes: 1 addition & 1 deletion wostools/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function parse_all refactored with the following changes:

return processed_data
15 changes: 6 additions & 9 deletions wostools/sources/scopus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _joined refactored with the following changes:



def _find_volume_info(ref: str) -> Tuple[Dict[str, str], str]:
Expand All @@ -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()
Comment on lines -54 to +52
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _find_volume_info refactored with the following changes:

if volume:
data.update(volume.groupdict())

Expand Down Expand Up @@ -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(),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _scopus_ref_to_isi refactored with the following changes:

"volume": volume_info.get("volume"),
"page": volume_info.get("page"),
"doi": doi,
Expand Down Expand Up @@ -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())
Comment on lines -159 to +157
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function parse_file refactored with the following changes: