Skip to content

Commit

Permalink
Add a rule for dash-separated words (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
insolor authored Dec 1, 2024
1 parent 0ec5595 commit 4b4d64f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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

0 comments on commit 4b4d64f

Please sign in to comment.