Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def orthographize(word):
- word = word.replace("tsh", "ch")
- word = word.replace("kw", "qu")
- word = word.replace("sh", "x")
- word = word.replace("w", "hu")
- word = word.replace("k", "c")
- return word
- def orthographize_french(word):
- word = word.replace("tsh", "ch")
- word = word.replace("kw", "qu")
- word = word.replace("sh", "x")
- word = word.replace("w", "hu")
- word = word.replace("k", "c")
- word = word.replace("ts", "z")
- return word
- def expand_expression(expression):
- new_expression = []
- for term in expression:
- if term in rules:
- term_expansion = random.choice(rules[term])
- new_terms = term_expansion.split(" ")
- new_expression.extend(new_terms)
- else:
- new_expression.append(term)
- return new_expression
- def generate_word():
- root = "WORD"
- expression = [root]
- i = 0
- limit = 10
- unexpanded_nodes = True
- new_expression = expand_expression(expression)
- while (i < limit and unexpanded_nodes == True):
- i += 1
- if " ".join(expression) == " ".join(new_expression):
- unexpanded_nodes = False
- else:
- expression = new_expression
- new_expression = expand_expression(expression)
- if i == limit:
- return "-".join(expression)
- else:
- return "".join(expression)
- rules = {
- "WORD": ["MULTI_SYLLABLE_WORD"],
- "ONE_SYLLABLE_WORD": "WORD_INITIAL_CONSONANT VD WORD_FINAL_CONSONANT | WORD_INITIAL_CONSONANT VD | VD WORD_FINAL_CONSONANT".split(" | "),
- "MULTI_SYLLABLE_WORD": "INITIAL_SYLLABLE . FINAL_SYLLABLE | INITIAL_SYLLABLE . MID_SYLLABLES . FINAL_SYLLABLE".split(" | "),
- "INITIAL_SYLLABLE": "WORD_INITIAL_CONSONANT VD SYLLABLE_FINAL_CONSONANT | VD SYLLABLE_FINAL_CONSONANT | WORD_INITIAL_CONSONANT VD | VD".split(" | "),
- "FINAL_SYLLABLE": "SYLLABLE_INITIAL_CONSONANT VD WORD_FINAL_CONSONANT | SYLLABLE_INITIAL_CONSONANT VD | VD WORD_FINAL_CONSONANT".split(" | "),
- "MID_SYLLABLES": "MID_SYLLABLE".split(" | "),
- "MID_SYLLABLE": "SYLLABLE_INITIAL_CONSONANT VD SYLLABLE_FINAL_CONSONANT | VD SYLLABLE_FINAL_CONSONANT | SYLLABLE_INITIAL_CONSONANT VD".split(" | "),
- "VD": "VOWEL".split(" | "),
- "VOWEL": "a|e|i|o".split("|"),
- "DIPHTHONG": "ia|ai|oa|eo|ei|io|ao".split("|"),
- "WORD_INITIAL_CONSONANT": "k|kw|m|n|p|sh|t|tl|ts|tsh|w|y".split("|"),
- "WORD_FINAL_CONSONANT": "h|k|l|n|tl|tsh".split("|"),
- "SYLLABLE_INITIAL_CONSONANT": "k|kw|l|m|n|p|sh|t|tl|ts|tsh|w|y".split("|"),
- "SYLLABLE_FINAL_CONSONANT": "h|k|l|n|tl|tsh".split("|"),
- }
- out_path = "fake_nauatl_words.txt"
- out = open(out_path, 'w', encoding="utf-8")
- for j in range(30):
- word = generate_word()
- word = word.translate({ord(c): None for c in "."})
- word = orthographize_french(word)
- out.write(word + "\n")
- out.close()
Advertisement
Add Comment
Please, Sign In to add comment