Skip to content
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

Possible speed-up: lookup journals on unique input list #77

Merged
merged 2 commits into from
Oct 24, 2023
Merged
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
18 changes: 10 additions & 8 deletions GooseBib/journals.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,22 +273,24 @@ def _renum(self):

def _map(self, journals: list[str], case_sensitive: bool, field: ArrayLike) -> list[str]:
"""
Map List of names.
Map list of names.

:param journals: List to map.
:param case_sensitive: Keep case during look-up.
:param field: Type identifier to use in case of positive match.
:return: Input list with mapped items replaced where a positive match was found.
"""

ret = [i for i in journals]
_, iforward, ibackward = np.unique(journals, return_index=True, return_inverse=True)

if case_sensitive:
variations = self.names
search = journals
search = [journals[i] for i in iforward]
ret = [i for i in journals]
else:
variations = [str(i).lower() for i in self.names]
search = [i.lower() for i in journals]
search = [journals[i].lower() for i in iforward]
ret = [journals[i] for i in iforward]

_, v_index, s_index = np.intersect1d(variations, search, return_indices=True)

Expand All @@ -299,11 +301,11 @@ def _map(self, journals: list[str], case_sensitive: bool, field: ArrayLike) -> l
for i in np.argwhere(np.array(ret) == ret[s]).ravel():
ret[i] = r

return ret
return [ret[i] for i in ibackward]

def map2name(self, journals: list[str], case_sensitive: bool = False) -> list[str]:
"""
Map List of names.
Map list of names.

:param journals: List to map.
:param case_sensitive: Keep case during look-up.
Expand All @@ -313,7 +315,7 @@ def map2name(self, journals: list[str], case_sensitive: bool = False) -> list[st

def map2abbreviation(self, journals: list[str], case_sensitive: bool = False) -> list[str]:
"""
Map List of names.
Map list of names.

:param journals: List to map.
:param case_sensitive: Keep case during look-up.
Expand All @@ -323,7 +325,7 @@ def map2abbreviation(self, journals: list[str], case_sensitive: bool = False) ->

def map2acronym(self, journals: list[str], case_sensitive: bool = False) -> list[str]:
"""
Map List of names.
Map list of names.

:param journals: List to map.
:param case_sensitive: Keep case during look-up.
Expand Down
Loading