cthulhusay.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """R'lyehian language generator. The one and only cthulhu-fhtagn-ator.
  4. Copyright 2017 Davide Alberani <da@erlug.linux.it>
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. """
  14. import random
  15. # Summoned from https://www.yog-sothoth.com/wiki/index.php/R'lyehian
  16. WORDS = ["'ai", "'bthnk", "'fhalma", 'ah', 'athg', 'bug', "ch'", 'chtenff', 'ebumna', 'ee', 'ehye', 'ep', 'fhtagn',
  17. "fm'latgh", 'ftaghu', 'geb', 'gnaiih', "gof'nn", 'goka', 'gotha', "grah'n", "hafh'drn", 'hai', 'hlirgh',
  18. 'hrii', 'hupadgh', 'ilyaa', "k'yarnak", 'kadishtu', "kn'a", "li'hee", 'llll', 'lloig', "lw'nafh", "mnahn'",
  19. "n'gha", "n'ghft", 'nglui', "nilgh'ri", 'nog', 'nw', 'ooboshu', "orr'e", 'phlegeth', "r'luh", 'ron', "s'uhn",
  20. "sgn'wahl", 'shagg', 'shogg', 'shtunggli', 'shugg', "sll'ha", "stell'bsna", "syha'h", 'tharanak', 'throd',
  21. 'uaaah', "uh'e", 'uln', 'vulgtlagln', 'vulgtm', "wgah'n", "y'hah", 'ya', 'zhro']
  22. # I'm confident that we'll find other conjunctions
  23. CONJUNCTIONS = ['mg']
  24. PREFIXES = ['c', "f'", "h'", 'na', 'nafl', 'ng', 'nnn', "ph'", 'y']
  25. SUFFIXES = ['agl', 'nyth', 'og', 'or', 'oth', 'yar']
  26. SENTENCE_ENDS = ['!', '?', '.', '.', '.']
  27. PUNCTUATIONS = SENTENCE_ENDS + [',', ';']
  28. def cthulhu_say(words=10, conjuncionsFreq=.2, prefixesFreq=.25, suffixesFreq=.25, pluralsFreq=.3, punctuationsFreq=.1):
  29. """Cthulhu says hi!"""
  30. sentence = [random.choice(WORDS) for x in range(words)]
  31. for idx in [random.randrange(words) for x in range(int(pluralsFreq * words))]:
  32. sentence[idx] += sentence[idx][-1]
  33. for idx in [random.randrange(words) for x in range(int(prefixesFreq * words))]:
  34. sentence[idx] = random.choice(PREFIXES) + sentence[idx]
  35. for idx in [random.randrange(words) for x in range(int(suffixesFreq * words))]:
  36. sentence[idx] += random.choice(SUFFIXES)
  37. for idx in [random.randrange(1, words - 1) for x in range(int(conjuncionsFreq * words))]:
  38. sentence[idx] = random.choice(CONJUNCTIONS)
  39. for idx in [random.randrange(1, words - 1) for x in range(int(punctuationsFreq * words))]:
  40. punctuation = random.choice(PUNCTUATIONS)
  41. if sentence[idx].endswith(tuple(PUNCTUATIONS)) or sentence[idx].lower() in CONJUNCTIONS:
  42. continue
  43. sentence[idx] += punctuation
  44. if punctuation in SENTENCE_ENDS:
  45. sentence[idx+1] = sentence[idx+1].capitalize()
  46. if sentence:
  47. sentence[0] = sentence[0].capitalize()
  48. if punctuationsFreq:
  49. sentence[-1] += random.choice(SENTENCE_ENDS)
  50. return ' '.join(sentence)
  51. if __name__ == '__main__':
  52. print(cthulhu_say())