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

Change the default values of :func:~.reduce_repeated_substring parameters for general use #20

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions maha/cleaners/functions/remove_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ def remove(


def reduce_repeated_substring(
text: str, min_repeated: int = 3, reduce_to: int = 2
text: str, min_repeated: int = 4, reduce_to: int = 3
) -> str:
"""Reduces consecutive substrings that are repeated at least ``min_repeated`` times
to ``reduce_to`` times. For example with the default arguments, 'hhhhhh' is
reduced to 'hh'
reduced to 'hhh'

TODO: Maybe change the implemention for 50x speed
https://stackoverflow.com/questions/29481088/how-can-i-tell-if-a-string-repeats-itself-in-python/29489919#29489919
Expand All @@ -274,9 +274,9 @@ def reduce_repeated_substring(
text : str
Text to process
min_repeated : int, optional
Minimum number of consecutive repeated substring to consider, by default 3
Minimum number of consecutive repeated substring to consider, by default 4
reduce_to : int, optional
Number of substring to keep, by default 2
Number of substring to keep, by default 3

Returns
-------
Expand All @@ -297,7 +297,7 @@ def reduce_repeated_substring(
>>> from maha.cleaners.functions import reduce_repeated_substring
>>> text = "ههههههههههههههه"
>>> reduce_repeated_substring(text)
'هه'
'ههه'

..code:: pycon

Expand Down
2 changes: 1 addition & 1 deletion maha/processors/base_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def replace_pairs(self, keys: List[str], values: List[str]):
self.apply(partial(replace_pairs, **self._arguments_except_self(locals())))
return self

def reduce_repeated_substring(self, min_repeated: int = 3, reduce_to: int = 2):
def reduce_repeated_substring(self, min_repeated: int = 4, reduce_to: int = 3):
"""Applies :func:`~.reduce_repeated_substring` to each line"""
self.apply(
partial(reduce_repeated_substring, **self._arguments_except_self(locals()))
Expand Down