-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)} | ||
) | ||
Comment on lines
-79
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
) | ||
return { | ||
"title": self.title, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
click.secho("You should give at least a file with documents.", fg="red") | ||
return | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return processed_data |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
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() | ||
Comment on lines
-54
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
"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()) | ||
Comment on lines
-159
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
There was a problem hiding this comment.
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:reintroduce-else
)assign-if-exp
)or-if-exp-identity
)