cipheron

brainrot text converter

Dec 13th, 2025 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. import random
  2. import re
  3.  
  4. # Abbreviations
  5. abbreviations = {
  6. "you know": "yn",
  7. "for real": "fr",
  8. "because": "bc",
  9. "laughing out loud": "lol",
  10. "be right back": "brb",
  11. "oh my god": "omg",
  12. "by the way": "btw",
  13. "see you": "cu",
  14. "great": "gr8",
  15. "okay": "k"
  16. }
  17.  
  18. # Random suffixes
  19. random_suffixes = ["yn", "fr", "idk", "smh", "tbh", "lol"]
  20.  
  21. def remove_vowels(word):
  22. return re.sub(r'[aeiou]', '', word)
  23.  
  24. def compress_word(word):
  25. """Compress word according to rules."""
  26. if word == "i":
  27. return "i"
  28. elif word == "a":
  29. return "" # Drop 'a' but still counts for buffer
  30. elif len(word) < 5:
  31. return word[0]
  32. else:
  33. return remove_vowels(word)
  34.  
  35. def chain_single_chars(chars):
  36. """Chain single-char words into groups 2-3 letters (up to 5)."""
  37. result = []
  38. temp = ""
  39. i = 0
  40. while i < len(chars):
  41. temp += chars[i]
  42. min_group = random.randint(2, 3)
  43. max_group = 5
  44. if len(temp) >= min_group or i == len(chars) - 1:
  45. if len(temp) > max_group:
  46. result.append(temp[:max_group])
  47. temp = temp[max_group:]
  48. else:
  49. result.append(temp)
  50. temp = ""
  51. i += 1
  52. if temp:
  53. result.append(temp)
  54. return result
  55.  
  56. def abbreviate_text(text):
  57. text = text.lower()
  58.  
  59. # Replace known phrases first
  60. for phrase, abbr in abbreviations.items():
  61. text = text.replace(phrase, abbr)
  62.  
  63. # Tokenize words and punctuation
  64. tokens = re.findall(r'\b\w+\b|[^\w\s]', text, re.UNICODE)
  65.  
  66. compressed_tokens = []
  67. single_char_buffer = []
  68.  
  69. for token in tokens:
  70. if token.isalpha():
  71. compressed = compress_word(token)
  72. # If compressed word is single-char OR deleted (""), add to buffer
  73. if len(compressed) <= 1:
  74. if compressed: # non-empty
  75. single_char_buffer.append(compressed)
  76. else:
  77. # Flush buffer first
  78. if single_char_buffer:
  79. compressed_tokens.extend(chain_single_chars(single_char_buffer))
  80. single_char_buffer = []
  81. compressed_tokens.append(compressed)
  82. else:
  83. # Non-word token: flush buffer
  84. if single_char_buffer:
  85. compressed_tokens.extend(chain_single_chars(single_char_buffer))
  86. single_char_buffer = []
  87. compressed_tokens.append(token)
  88.  
  89. # Flush remaining buffer
  90. if single_char_buffer:
  91. compressed_tokens.extend(chain_single_chars(single_char_buffer))
  92.  
  93. # Rejoin tokens preserving spacing/punctuation
  94. compressed_text = ''
  95. for i, tok in enumerate(compressed_tokens):
  96. if re.match(r'\w', tok) and i > 0 and re.match(r'\w', compressed_tokens[i-1]):
  97. compressed_text += ' '
  98. compressed_text += tok
  99.  
  100. # Append random suffix
  101. compressed_text += " " + random.choice(random_suffixes)
  102.  
  103. return compressed_text
  104.  
  105. if __name__ == "__main__":
  106. message = "it’s seriously going to put me into a coma anytime soon."
  107. print(abbreviate_text(message))
  108.  
Advertisement
Add Comment
Please, Sign In to add comment