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

Add a rule for dash-separated words #116

Merged
merged 3 commits into from
Dec 1, 2024
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
20 changes: 20 additions & 0 deletions df_translation_toolkit/utils/df_ignore_string_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ def ignore_dash_prepended_strings(string: str) -> bool:
return re.fullmatch(r"-[a-z0-9_]+-?", string) is not None


@rules.register
def ignore_dash_separated_words(string: str) -> bool:
if " " in string:
return False

if "-" not in string:
return False

parts = string.split("-")
for part in parts:
if not part or not (part.islower() or part.isnumeric()):
return False

if len(parts) >= 3: # noqa: PLR2004
return True

ending = parts[-1]
return ending.isnumeric() or ending in ("on", "off", "log", "gtr", "rtm")


@rules.register
def ignore_mixed_case(string: str) -> bool:
return re.search(r"[a-z]+[A-Z]", string) is not None
Expand Down
3 changes: 3 additions & 0 deletions tests/test_df_ignore_string_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
(rules.ignore_underline_separated_words, "_Thrd_id", True),
(rules.ignore_underline_separated_words, "_initterm_e", True),
(rules.ignore_underline_separated_words, "init_sound returned false!", True),
(rules.ignore_dash_separated_words, "piano-pluck-main", True),
(rules.ignore_dash_separated_words, "gtr-2", True),
(rules.ignore_dash_separated_words, "clouds-off", True),
(rules.ignore_dash_prepended_strings, "-world_sites_and_pops", True),
(rules.ignore_dash_prepended_strings, "-site_map-", True),
(rules.ignore_dash_prepended_strings, "-beta23", True),
Expand Down