Skip to content

Commit

Permalink
serials importer: remove substrings only from the end of the title
Browse files Browse the repository at this point in the history
* closes #923
  • Loading branch information
anikachurilova committed Nov 1, 2024
1 parent 166a407 commit 238320d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cds_ils/importer/providers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,10 @@ def rreplace(s, old, new, occurrence=1):
"""Reverse replace."""
li = s.rsplit(old, occurrence)
return new.join(li)


def rreplace_end(s, old):
"""Replace only if the substring `old` is at the end of the string `s`."""
if s.endswith(old):
return s[: -len(old)]
return s
4 changes: 2 additions & 2 deletions cds_ils/importer/series/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from invenio_db import db

from cds_ils.importer.errors import SeriesImportError
from cds_ils.importer.providers.utils import rreplace
from cds_ils.importer.providers.utils import rreplace, rreplace_end
from cds_ils.importer.series.api import (
search_series_by_isbn,
search_series_by_issn,
Expand Down Expand Up @@ -120,7 +120,7 @@ def _normalize_title(title):
# will become
# `international series of numerical mathematics`
for substring in IGNORE_SUFFIXES:
t = rreplace(t, substring, "")
t = rreplace_end(t, substring)
return t.strip()

def update_series(self, matched_series, json_series):
Expand Down

0 comments on commit 238320d

Please sign in to comment.