Skip to content

Commit

Permalink
[refact] standardizing quotation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatasgrosman committed Feb 5, 2024
1 parent e678009 commit cb327e3
Show file tree
Hide file tree
Showing 39 changed files with 1,353 additions and 1,354 deletions.
46 changes: 23 additions & 23 deletions findpapers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
@app.command("search")
def search(
outputpath: str = typer.Argument(
..., help='A valid file path where the search result JSON file will be placed'
..., help="A valid file path where the search result JSON file will be placed"
),
query: str = typer.Option(
None, "-q", "--query", show_default=True,
help='A query string that will be used to perform the papers search (If not provided it will be loaded from the environment variable FINDPAPERS_QUERY). E.g. [term A] AND ([term B] OR [term C]) AND NOT [term D]'
help="A query string that will be used to perform the papers search (If not provided it will be loaded from the environment variable FINDPAPERS_QUERY). E.g. [term A] AND ([term B] OR [term C]) AND NOT [term D]"
),
query_filepath: str = typer.Option(
None, "-f", "--query-file", show_default=True,
help='A file path that contains the query string that will be used to perform the papers search'
help="A file path that contains the query string that will be used to perform the papers search"
),
since: datetime = typer.Option(
None, "-s", "--since", show_default=True,
Expand Down Expand Up @@ -69,7 +69,7 @@ def search(
"""
Search for papers metadata using a query.
When you have a query and needs to get papers using it, this is the command that you'll need to call.
When you have a query and needs to get papers using it, this is the command that you"ll need to call.
This command will find papers from some databases based on the provided query.
All the query terms need to be enclosed by square brackets and can be associated using boolean operators,
Expand All @@ -80,9 +80,9 @@ def search(
You can use some wildcards in the query too. Use ? to replace a single character or * to replace any number of characters.
E.g.: 'son?' -> will match song, sons, ...
E.g.: "son?" -> will match song, sons, ...
E.g.: 'son*' -> will match song, sons, sonar, songwriting, ...
E.g.: "son*" -> will match song, sons, sonar, songwriting, ...
Nowadays, we search for papers on ACM, arXiv, IEEE, PubMed, and Scopus database.
The searching on IEEE and Scopus requires an API token, that must to be provided
Expand Down Expand Up @@ -118,11 +118,11 @@ def search(
try:
since = since.date() if since is not None else None
until = until.date() if until is not None else None
databases = [x.strip() for x in databases.split(',')] if databases is not None else None
publication_types = [x.strip() for x in publication_types.split(',')] if publication_types is not None else None
databases = [x.strip() for x in databases.split(",")] if databases is not None else None
publication_types = [x.strip() for x in publication_types.split(",")] if publication_types is not None else None

if query is None and query_filepath is not None:
with open(query_filepath, 'r') as f:
with open(query_filepath, "r") as f:
query = f.read().strip()

findpapers.search(outputpath, query, since, until, limit, limit_per_database,
Expand All @@ -138,7 +138,7 @@ def search(
@app.command("refine")
def refine(
filepath: str = typer.Argument(
..., help='A valid file path for the search result file'
..., help="A valid file path for the search result file"
),
categories: List[str] = typer.Option(
[], "-c", "--categories", show_default=True,
Expand Down Expand Up @@ -176,7 +176,7 @@ def refine(
"""
Refine the search results by selecting/classifying the papers.
When you have a search result and wanna refine it, this is the command that you'll need to call.
When you have a search result and wanna refine it, this is the command that you"ll need to call.
This command will iterate through all the papers showing their collected data,
then asking if you wanna select a particular paper or not
Expand All @@ -199,13 +199,13 @@ def refine(
"""

try:
highlights = [x.strip() for x in highlights.split(',')] if highlights is not None else None
highlights = [x.strip() for x in highlights.split(",")] if highlights is not None else None

categories_by_facet = {} if len(categories) > 0 else None
for categories_string in categories:
string_split = categories_string.split(':')
string_split = categories_string.split(":")
facet = string_split[0].strip()
categories_by_facet[facet] = [x.strip() for x in string_split[1].split(',')]
categories_by_facet[facet] = [x.strip() for x in string_split[1].split(",")]

findpapers.refine(filepath, categories_by_facet, highlights, show_abstract, show_extra_info, only_selected_papers, only_removed_papers, read_only, verbose)
except Exception as e:
Expand All @@ -219,10 +219,10 @@ def refine(
@app.command("download")
def download(
filepath: str = typer.Argument(
..., help='A valid file path for the search result file'
..., help="A valid file path for the search result file"
),
outputpath: str = typer.Argument(
..., help='A valid directory path where the downloaded papers will be placed'
..., help="A valid directory path where the downloaded papers will be placed"
),
only_selected_papers: bool = typer.Option(
False, "-s", "--selected", show_default=True,
Expand All @@ -244,7 +244,7 @@ def download(
"""
Download full-text papers using the search results.
If you've done your search, (probably made the search refinement too) and wanna download the papers,
If you"ve done your search, (probably made the search refinement too) and wanna download the papers,
this is the command that you need to call. This command will try to download the PDF version of the papers to
the output directory path.
Expand Down Expand Up @@ -276,9 +276,9 @@ def download(
try:
categories_by_facet = {} if len(categories) > 0 else None
for categories_string in categories:
string_split = categories_string.split(':')
string_split = categories_string.split(":")
facet = string_split[0].strip()
categories_by_facet[facet] = [x.strip() for x in string_split[1].split(',')]
categories_by_facet[facet] = [x.strip() for x in string_split[1].split(",")]

findpapers.download(filepath, outputpath, only_selected_papers, categories_by_facet, proxy, verbose)
except Exception as e:
Expand All @@ -292,10 +292,10 @@ def download(
@app.command("bibtex")
def bibtex(
filepath: str = typer.Argument(
..., help='A valid file path for the search result file'
..., help="A valid file path for the search result file"
),
outputpath: str = typer.Argument(
..., help='A valid directory path where the generated bibtex will be placed'
..., help="A valid directory path where the generated bibtex will be placed"
),
only_selected_papers: bool = typer.Option(
False, "-s", "--selected", show_default=True,
Expand Down Expand Up @@ -336,9 +336,9 @@ def bibtex(
try:
categories_by_facet = {} if len(categories) > 0 else None
for categories_string in categories:
string_split = categories_string.split(':')
string_split = categories_string.split(":")
facet = string_split[0].strip()
categories_by_facet[facet] = [x.strip() for x in string_split[1].split(',')]
categories_by_facet[facet] = [x.strip() for x in string_split[1].split(",")]

findpapers.generate_bibtex(filepath, outputpath, only_selected_papers, categories_by_facet, add_findpapers_citation, verbose)
except Exception as e:
Expand Down
76 changes: 38 additions & 38 deletions findpapers/models/paper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def __init__(self, title: str, abstract: str, authors: List[str], publication: P
"""

if title is None or len(title) == 0:
raise(ValueError('Paper\'s title cannot be null'))
raise(ValueError("Paper's title cannot be null"))

if publication_date is None:
raise(ValueError('Paper\'s publication_date cannot be null'))
raise(ValueError("Paper's publication_date cannot be null"))

self.title = title
self.abstract = abstract
Expand Down Expand Up @@ -97,7 +97,7 @@ def add_database(self, database_name: str):

if database_name not in AVAILABLE_DATABASES:
raise ValueError(
f'Invalid database name "{database_name}". Nowadays only {", ".join(AVAILABLE_DATABASES)} are valid database names')
f"Invalid database name \"{database_name}\". Nowadays only {', '.join(AVAILABLE_DATABASES)} are valid database names")

self.databases.add(database_name)

Expand Down Expand Up @@ -171,17 +171,17 @@ def get_citation_key(self) -> str:
A citation key folowing the pattern <FIRST_AUTHOR><YEAR><TITLE_FIRST_WORD>
"""

author_key = 'unknown'
author_key = "unknown"
if len(self.authors) > 0:
author_key = self.authors[0].lower().replace(' ', '').replace(',','')
author_key = self.authors[0].lower().replace(" ", "").replace(",","")

year_key = 'XXXX'
year_key = "XXXX"
if self.publication_date is not None:
year_key = self.publication_date.year

title_key = self.title.split(' ')[0].lower()
title_key = self.title.split(" ")[0].lower()

citation_key = re.sub(r'[^\w\d]', '', f'{author_key}{year_key}{title_key}') # keeping only letters, numbers
citation_key = re.sub(r"[^\w\d]", "", f"{author_key}{year_key}{title_key}") # keeping only letters, numbers

return citation_key

Expand Down Expand Up @@ -224,23 +224,23 @@ def from_dict(cls, paper_dict: dict) -> Paper:
A Paper instance based on the provided dict object
"""

title = paper_dict.get('title')
abstract = paper_dict.get('abstract')
authors = paper_dict.get('authors')
title = paper_dict.get("title")
abstract = paper_dict.get("abstract")
authors = paper_dict.get("authors")
publication = Publication.from_dict(paper_dict.get(
'publication')) if paper_dict.get('publication') is not None else None
"publication")) if paper_dict.get("publication") is not None else None
publication_date = datetime.datetime.strptime(
paper_dict.get('publication_date'), '%Y-%m-%d').date()
urls = set(paper_dict.get('urls'))
doi = paper_dict.get('doi')
citations = paper_dict.get('citations')
keywords = set(paper_dict.get('keywords'))
comments = paper_dict.get('comments')
number_of_pages = paper_dict.get('number_of_pages')
pages = paper_dict.get('pages')
databases = set(paper_dict.get('databases'))
selected = paper_dict.get('selected')
categories = paper_dict.get('categories')
paper_dict.get("publication_date"), "%Y-%m-%d").date()
urls = set(paper_dict.get("urls"))
doi = paper_dict.get("doi")
citations = paper_dict.get("citations")
keywords = set(paper_dict.get("keywords"))
comments = paper_dict.get("comments")
number_of_pages = paper_dict.get("number_of_pages")
pages = paper_dict.get("pages")
databases = set(paper_dict.get("databases"))
selected = paper_dict.get("selected")
categories = paper_dict.get("categories")

return cls(title, abstract, authors, publication, publication_date, urls, doi, citations, keywords,
comments, number_of_pages, pages, databases, selected, categories)
Expand All @@ -262,19 +262,19 @@ def to_dict(paper: Paper) -> dict:
"""

return {
'title': paper.title,
'abstract': paper.abstract,
'authors': paper.authors,
'publication': Publication.to_dict(paper.publication) if paper.publication is not None else None,
'publication_date': paper.publication_date.strftime('%Y-%m-%d'),
'urls': list(paper.urls),
'doi': paper.doi,
'citations': paper.citations,
'keywords': list(paper.keywords),
'comments': paper.comments,
'number_of_pages': paper.number_of_pages,
'pages': paper.pages,
'databases': list(paper.databases),
'selected': paper.selected,
'categories': paper.categories,
"title": paper.title,
"abstract": paper.abstract,
"authors": paper.authors,
"publication": Publication.to_dict(paper.publication) if paper.publication is not None else None,
"publication_date": paper.publication_date.strftime("%Y-%m-%d"),
"urls": list(paper.urls),
"doi": paper.doi,
"citations": paper.citations,
"keywords": list(paper.keywords),
"comments": paper.comments,
"number_of_pages": paper.number_of_pages,
"pages": paper.pages,
"databases": list(paper.databases),
"selected": paper.selected,
"categories": paper.categories,
}
56 changes: 28 additions & 28 deletions findpapers/models/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, title: str, isbn: Optional[str] = None, issn: Optional[str] =
Citation weighting depends on subject field and prestige (SJR) of the citing serial, by default None
snip : float, optional
Source Normalized Impact per Paper measures actual citations received relative to citations
expected for the serials subject field, by default None
expected for the serial's subject field, by default None
subject_areas : float, optional
Publication subjects areas, by default None
is_potentially_predatory : bool, optional
Expand All @@ -45,7 +45,7 @@ def __init__(self, title: str, isbn: Optional[str] = None, issn: Optional[str] =
"""

if title is None or len(title) == 0:
raise(ValueError('Publication\'s title cannot be null'))
raise(ValueError("Publication's title cannot be null"))

self.title = title
self.isbn = isbn
Expand Down Expand Up @@ -77,12 +77,12 @@ def category(self, value: str):
if value is not None:

# trying to convert a provided invalid category to a valid one [Journal, Conference Proceedings, Book]
if 'journal' in value.lower():
value = 'Journal'
elif 'conference' in value.lower() or 'proceeding' in value.lower():
value = 'Conference Proceedings'
elif 'book' in value.lower():
value = 'Book'
if "journal" in value.lower():
value = "Journal"
elif "conference" in value.lower() or "proceeding" in value.lower():
value = "Conference Proceedings"
elif "book" in value.lower():
value = "Book"
else:
value = None

Expand Down Expand Up @@ -146,16 +146,16 @@ def from_dict(cls, publication_dict: dict) -> Publication:
A Publication instance based on the provided dict object
"""

title = publication_dict.get('title')
isbn = publication_dict.get('isbn')
issn = publication_dict.get('issn')
publisher = publication_dict.get('publisher')
category = publication_dict.get('category')
cite_score = publication_dict.get('cite_score')
sjr = publication_dict.get('sjr')
snip = publication_dict.get('snip')
subject_areas = set(publication_dict.get('subject_areas'))
is_potentially_predatory = publication_dict.get('is_potentially_predatory')
title = publication_dict.get("title")
isbn = publication_dict.get("isbn")
issn = publication_dict.get("issn")
publisher = publication_dict.get("publisher")
category = publication_dict.get("category")
cite_score = publication_dict.get("cite_score")
sjr = publication_dict.get("sjr")
snip = publication_dict.get("snip")
subject_areas = set(publication_dict.get("subject_areas"))
is_potentially_predatory = publication_dict.get("is_potentially_predatory")

return cls(title, isbn, issn, publisher, category, cite_score, sjr, snip, subject_areas, is_potentially_predatory)

Expand All @@ -176,14 +176,14 @@ def to_dict(publication: Publication) -> dict:
"""

return {
'title': publication.title,
'isbn': publication.isbn,
'issn': publication.issn,
'publisher': publication.publisher,
'category': publication.category,
'cite_score': publication.cite_score,
'sjr': publication.sjr,
'snip': publication.snip,
'subject_areas': list(publication.subject_areas),
'is_potentially_predatory': publication.is_potentially_predatory
"title": publication.title,
"isbn": publication.isbn,
"issn": publication.issn,
"publisher": publication.publisher,
"category": publication.category,
"cite_score": publication.cite_score,
"sjr": publication.sjr,
"snip": publication.snip,
"subject_areas": list(publication.subject_areas),
"is_potentially_predatory": publication.is_potentially_predatory
}
Loading

0 comments on commit cb327e3

Please sign in to comment.