Skip to content

Commit

Permalink
Refactor remove_articles()
Browse files Browse the repository at this point in the history
Fix so it's doesn't return lowered results, and *only* removes articles
  • Loading branch information
bpepple committed Oct 12, 2021
1 parent db8097e commit 823234b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
13 changes: 2 additions & 11 deletions darkseid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,11 @@ def remove_articles(text: str) -> str:
:param str text: A string with articles (ex. 'and', 'a', 'the').
"""
text = text.lower()
articles: List[str] = ["and", "a", "&", "issue", "the"]
new_text: str = ""
for word in text.split(" "):
if word not in articles:
new_text += word + " "
articles = ["and", "a", "&", "issue", "the"]
new_text = "".join(word + " " for word in text.split(" ") if word.lower() not in articles)

new_text = new_text[:-1]

# now get rid of some other junk
new_text = new_text.replace(":", "")
new_text = new_text.replace(",", "")
new_text = new_text.replace("-", " ")

return new_text


Expand Down
9 changes: 8 additions & 1 deletion tests/test_darkseid_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@

def test_remove_articles():
txt = "The Champions & Inhumans"
expected_result = "champions inhumans"
expected_result = "Champions Inhumans"
result = utils.remove_articles(txt)
assert result == expected_result


def test_removes_articles_that_contain_no_articles():
txt = "Justice League"
expected_result = "Justice League"
result = utils.remove_articles(txt)
assert result == expected_result

Expand Down

0 comments on commit 823234b

Please sign in to comment.