Preinfarction

fake-nahuatl-word-maker.py

Nov 22nd, 2022 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. import random
  2.  
  3. def orthographize(word):
  4. word = word.replace("tsh", "ch")
  5. word = word.replace("kw", "qu")
  6. word = word.replace("sh", "x")
  7. word = word.replace("w", "hu")
  8. word = word.replace("k", "c")
  9. return word
  10.  
  11. def orthographize_french(word):
  12. word = word.replace("tsh", "ch")
  13. word = word.replace("kw", "qu")
  14. word = word.replace("sh", "x")
  15. word = word.replace("w", "hu")
  16. word = word.replace("k", "c")
  17. word = word.replace("ts", "z")
  18. return word
  19.  
  20. def expand_expression(expression):
  21. new_expression = []
  22. for term in expression:
  23. if term in rules:
  24. term_expansion = random.choice(rules[term])
  25. new_terms = term_expansion.split(" ")
  26. new_expression.extend(new_terms)
  27. else:
  28. new_expression.append(term)
  29. return new_expression
  30.  
  31. def generate_word():
  32. root = "WORD"
  33. expression = [root]
  34. i = 0
  35. limit = 10
  36. unexpanded_nodes = True
  37. new_expression = expand_expression(expression)
  38. while (i < limit and unexpanded_nodes == True):
  39. i += 1
  40. if " ".join(expression) == " ".join(new_expression):
  41. unexpanded_nodes = False
  42. else:
  43. expression = new_expression
  44. new_expression = expand_expression(expression)
  45. if i == limit:
  46. return "-".join(expression)
  47. else:
  48. return "".join(expression)
  49.  
  50. rules = {
  51. "WORD": ["MULTI_SYLLABLE_WORD"],
  52. "ONE_SYLLABLE_WORD": "WORD_INITIAL_CONSONANT VD WORD_FINAL_CONSONANT | WORD_INITIAL_CONSONANT VD | VD WORD_FINAL_CONSONANT".split(" | "),
  53. "MULTI_SYLLABLE_WORD": "INITIAL_SYLLABLE . FINAL_SYLLABLE | INITIAL_SYLLABLE . MID_SYLLABLES . FINAL_SYLLABLE".split(" | "),
  54. "INITIAL_SYLLABLE": "WORD_INITIAL_CONSONANT VD SYLLABLE_FINAL_CONSONANT | VD SYLLABLE_FINAL_CONSONANT | WORD_INITIAL_CONSONANT VD | VD".split(" | "),
  55. "FINAL_SYLLABLE": "SYLLABLE_INITIAL_CONSONANT VD WORD_FINAL_CONSONANT | SYLLABLE_INITIAL_CONSONANT VD | VD WORD_FINAL_CONSONANT".split(" | "),
  56. "MID_SYLLABLES": "MID_SYLLABLE".split(" | "),
  57. "MID_SYLLABLE": "SYLLABLE_INITIAL_CONSONANT VD SYLLABLE_FINAL_CONSONANT | VD SYLLABLE_FINAL_CONSONANT | SYLLABLE_INITIAL_CONSONANT VD".split(" | "),
  58. "VD": "VOWEL".split(" | "),
  59. "VOWEL": "a|e|i|o".split("|"),
  60. "DIPHTHONG": "ia|ai|oa|eo|ei|io|ao".split("|"),
  61. "WORD_INITIAL_CONSONANT": "k|kw|m|n|p|sh|t|tl|ts|tsh|w|y".split("|"),
  62. "WORD_FINAL_CONSONANT": "h|k|l|n|tl|tsh".split("|"),
  63. "SYLLABLE_INITIAL_CONSONANT": "k|kw|l|m|n|p|sh|t|tl|ts|tsh|w|y".split("|"),
  64. "SYLLABLE_FINAL_CONSONANT": "h|k|l|n|tl|tsh".split("|"),
  65. }
  66.  
  67. out_path = "fake_nauatl_words.txt"
  68. out = open(out_path, 'w', encoding="utf-8")
  69. for j in range(30):
  70. word = generate_word()
  71. word = word.translate({ord(c): None for c in "."})
  72. word = orthographize_french(word)
  73. out.write(word + "\n")
  74. out.close()
Advertisement
Add Comment
Please, Sign In to add comment