Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
131 lines (117 sloc) 5.17 KB
# Original Rihannsu language generator written by Diane Duane in BASIC
# Ported to Python and expanded by Laurence Toal (@anyaMairead)
# Rihannsu word patterns, as derived from the language in "My Enemy, My Ally"
# and "The Romulan way (where v=vowel and c=consonant):
# v, vc, cv, vcv, cvc, vcvc, cvcv, vcvcv, cvcvc, vcvcvc, cvcvcv, vcvcvcv, cvcvcvc
from random import choice, randint, seed
from string import capitalize
#morpheme lists
#punctuation has been removed from these lists and gets added
#in during the execution of the generate_sentence function.
initial_letters = ["H'", "Ae", "D'", "W","U", "N'", "R'", "O", "V", "Ll"]
vowels = ["ae","A","i'","a","Eh","e","T'","I","u'","s",
consonants = ["s","ll","R","m","k","t","h","r","rr",
rihannsu_text = [] #create an empty array - will use to store text
def c():
"""Returns a random consonant"""
return choice(consonants)
def v():
""""Returns a random vowel"""
return choice(vowels)
def word():
"""Returns a Rihannsu word. Words are comprised of vowel-consonant patterns
as identified by me in My Enemy, My Ally and The Romulan Way. Those patterns are
listed in comments at the beginning of the program, this function assigns
probabilities to them based on existing words. You can change the probabilities of
words of certain lengths by varying the 'i<number' statements."""
i = randint(0, 78)
if i <= 2:
return "ie"
elif i <= 3:
return "au"
elif i < 10:
return v() + c()
elif i < 17:
return c() + v()
elif i < 25:
return v() + c() + v()
elif i < 33:
return c() + v() + c()
elif i < 43:
return v() + c() + v() + c()
elif i < 53:
return c() + v() + c() + v()
elif i < 68:
return v() + c() + v() + c() + v()
elif i < 71:
return c() + v() + c() + v() + c()
elif i < 74:
return v() + c() + v() + c() + v() + c()
elif i < 76:
return c() + v() + c() + v() + c() + v()
elif i < 77:
return v() + c() + v() + c() + v() + c() + v()
elif i <= 78:
return c() + v() + c() + v() + c() + v() + c()
def first_word():
"""Special case when the word is the first one in the sentence: start word
with one of 10 specific morphemes"""
w = word()
#The following tests prevent the occurence of vowel-vowel and consonant-consonant
#combinations, which, from what I can tell, don't occur in the Rihannsu language.
if w[0] in ["a", "e", "i", "o", "u"]:
return choice(["H'", "D'", "W", "N'", "R'", "V", "Ll"]) + w
return choice(["H'", "Ae", "D'", "U", "N'", "R'", "O"]) + w
#In the event that the initial letters list was only necessary because of the
#difficulty of capitalizing words in BASIC, this function and the initial_letters
#array can be deleted, and a capitalization clause added to the generate_sentence function
def generate_sentence():
"""Generates a sentence in Rihannsu that contains between 4 and 8 words.
Sentence length can be changed by changing the numbers in the array
sentence_length = choice([4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 7, 8])
for i in range(1, sentence_length):
w = first_word() if i == 1 else word()
#If a sentence can start with any word, delete the preceeding line and add:
#if i==1:
# w = capitalize(w)
if i == sentence_length - 1: #add ending punctuation
w += choice([".", ".", ".", "....", ".", "?", "?", "!", "."])
elif randint(0, 10) < 1: #add intra-sentence punctuation
w += choice([",", ",", ",", ";"])
def generate_text():
"""Prints a paragrpah of Rihannsu text that contains 30 sentences.
Paragraph length can be adjusted by changing the range."""
for i in range (0,30):
print " ".join(rihannsu_text) #print the entire paragraph
seed() #random number generator