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

Bugfix/fit transform #270

Merged
merged 4 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

[![CI status](https://github.com/artefactory/NLPretext/actions/workflows/ci.yml/badge.svg?branch%3Amain&event%3Apush)](https://github.com/artefactory/NLPretext/actions/workflows/ci.yml?query=branch%3Amain)
[![CD status](https://github.com/artefactory/NLPretext/actions/workflows/cd.yml/badge.svg?event%3Arelease)](https://github.com/artefactory/NLPretext/actions/workflows/cd.yml?query=event%3Arelease)
[![Python Version](https://img.shields.io/badge/Python-3.7-informational.svg)](#supported-python-versions)
[![Python Version](https://img.shields.io/badge/Python-3.8-informational.svg)](#supported-python-versions)
[![Dependencies Status](https://img.shields.io/badge/dependabots-active-informational.svg)](https://github.com/artefactory/NLPretext}/pulls?utf8=%E2%9C%93&q=is%3Apr%20author%3Aapp%2Fdependabot)

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
Expand Down Expand Up @@ -54,7 +54,7 @@ Cannot find what you were looking for? Feel free to open an [issue]((https://git
### Supported Python Versions

- Main version supported : `3.8`
- Other supported versions : `3.9`
- Other supported versions : `3.9`, `3.10`


We strongly advise you to do the remaining steps in a virtual environnement.
Expand Down
2 changes: 1 addition & 1 deletion nlpretext/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ def run(self, text: str) -> str:
{"operation": operation, "args": None} for operation in operations_to_pipe
]
self.pipeline = self.build_pipeline(operations)
text = self.pipeline.fit_transform(text)
text = self.pipeline.transform(text)
return text
32 changes: 14 additions & 18 deletions tests/test_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,27 +501,23 @@ def test_custom_preprocess():
assert expected_result == result


def test_apply_preprocessor():
@pytest.mark.parametrize(
"input_str, expected_str",
[
(
"Some text with @mentions and whitespaces and #hashtags",
"Some text with and whitespaces and",
),
("@twitteruser ✊", ""),
("", ""),
],
)
def test_apply_preprocessor(input_str, expected_str):
# Given
text = "Some text with @mentions and whitespaces and #hashtags"
operations: List[Callable[[Any], Any]] = [
remove_html_tags,
remove_mentions,
remove_emoji,
remove_hashtag,
remove_eol_characters,
fix_bad_unicode,
normalize_whitespace,
]

preprocessor = Preprocessor()

expected_result = text
for function in operations:
expected_result = function(expected_result)

# When
result = preprocessor.run(text)
result = preprocessor.run(input_str)

# Then
assert expected_result == result
assert expected_str == result