diff --git a/camel b/camel new file mode 100755 index 0000000..a0abd2b --- /dev/null +++ b/camel @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +import re +import os +import nltk +from nltk.corpus import words +from nltk.corpus import wordnet + +try: + word_list = words.words() + nltk.download('wordnet') +except LookupError: + nltk.download('words') + nltk.download('wordnet') + word_list = words.words() + +word_set = set(word.lower() for word in word_list) +common_words = ['and', 'in', 'the', 'of', 'to', 'at', 'by', 'for', 'with', 'from'] +always_valid = {'the', 'a', 'an', 'and', 'or', 'but', 'nor', 'for', 'yet', 'so'} + +def is_word(word): + if word.lower() in always_valid: + print(f" Checking if '{word}' is in dictionary: True (common word)") + return True + + in_words = word.lower() in word_set + in_wordnet = bool(wordnet.synsets(word)) + result = in_words and in_wordnet + print(f" Checking if '{word}' is in dictionary: {result} (words:{in_words}, wordnet:{in_wordnet})") + return result + +def process_word(word): + print(f"\nProcessing word: '{word}'") + + if is_word(word): + print(f" '{word}' is in dictionary, returning as-is") + return word + + print(f" '{word}' not in dictionary, checking for common words at end...") + for common in common_words: + if word.lower().endswith(common): + print(f" Found '{common}' at end of '{word}'") + remainder = word[:-len(common)] + common_case = word[-len(common):] + print(f" Recursively processing remainder: '{remainder}'") + return f"{process_word(remainder)} {common_case}" + + print(f" No common words found at end of '{word}'") + + match = re.search(r'([a-zA-Z]+)(\d+)$', word) + if match: + text, num = match.groups() + print(f" Found number at end: '{text}' + '{num}'") + if is_word(text): + return f"{text} {num}" + + print(f" Returning '{word}' unchanged") + return word + +def split_filename(filename): + print(f"\nProcessing filename: {filename}") + base = os.path.splitext(filename)[0] + ext = os.path.splitext(filename)[1] + + print(f"Splitting on delimiters...") + parts = re.split('([_\-\s])', base) + + result = [] + for part in parts: + if part in '_-': + result.append(' ') + else: + print(f"\nSplitting on capitals: {part}") + words = re.split('(? {new_name}") + except OSError as e: + print(f"Error renaming {filename}: {e}") + +if __name__ == "__main__": + main() + diff --git a/emoji-flag b/emoji_flag similarity index 100% rename from emoji-flag rename to emoji_flag diff --git a/import-finder b/import_finder similarity index 100% rename from import-finder rename to import_finder diff --git a/mamba-exporter b/mamba_exporter similarity index 100% rename from mamba-exporter rename to mamba_exporter diff --git a/mamba-importer b/mamba_importer similarity index 100% rename from mamba-importer rename to mamba_importer diff --git a/nocomment b/nocomment old mode 100644 new mode 100755 diff --git a/tmux-merge b/tmux_merge similarity index 100% rename from tmux-merge rename to tmux_merge diff --git a/txt-line-merge-abc b/txt_line_merge_abc similarity index 100% rename from txt-line-merge-abc rename to txt_line_merge_abc