예제 #1
0
def generateElements():
    # generate the elements - random integer between 100 and 200
    numElts = random.randint(100,200)
    f = open('elements.dat', 'w')
    for i in range(0, numElts):
        en = wordgen.gen_word(random.randint(1, 6), random.randint(1, 6))
        # if a generated word is longer than 5, then it gets the suffix "-ium" appended to the end.
        if len(en) > 5:
            en = en + "ium\n"
        # otherwise it stays as it is.
        else:
            en = en + "\n"
        # this has no real science behind it, it's just for fun.
        f.write(en)
    print(f"\n{numElts} elements generated.")
    print("These elements are broken down into: ")
    eltType = []
    for i in range(0, 10):
        et = wordgen.gen_word(random.randint(1,4), random.randint(1,6))
        print(f"{et}s, ")
        eltType.append(et)
    numSolids = int((numElts * 76.3) // 100)
    print(f"{numSolids} elements exist in a solid state under normal conditions.")
    numLiquids = int((numElts * 1.7) // 100)
    print(f"{numLiquids} elements exist in a liquid state under normal conditions.")
    numGasses = int((numElts * 10.2) // 100)
    print(f"{numGasses} elements exist in a gaseous state under normal conditions.")
    numUn = int((numElts * 11.86) // 100)
    print(f"{numUn} elements exist in an unknown state under normal conditions.")
    f.close()
    print("\n")
예제 #2
0
def dateYourPlanet(eons, planetstr):
    systemName = wordgen.gen_word(random.randint(1, 5), random.randint(1,7))
    planetAge = str(round(random.uniform(0.01, eons), roundPrecision))
    print(f"\nYour planet, {planetstr}, formed roughly {planetAge} billion years ago in the cluster named {systemName}.")
    moons = generateMoons()
    if moons > 0:
        moonNames = []
        for i in range(0, moons):
            moon_name = wordgen.gen_word(random.randint(1, 5), random.randint(1,7))
            moonNames.append(moon_name)
        moonList = ', '.join(moonNames)
        print(f"\n{planetstr} has {moons} moons. They are named: {moonList}")
    return planetAge
예제 #3
0
    def __init__(self, game, level):
        self.light = random.random()
        self.chunks = numpy.array(
            [[[Chunk(game, level, self) for _ in xrange(2)] for _ in xrange(2)]
             for _ in xrange(1)])
        self.name = wordgen.gen_word(1, 4)
        self.links = []
        self.all_stuff = []
        self.game = game
        self.level = level

        for a, x in enumerate(list(self.chunks)):
            for b, y in enumerate(x):
                for c, z in enumerate(y):
                    if z.objects != []:
                        for o in z.objects:
                            if o.visible(self.light):
                                self.all_stuff.append(
                                    (o.description(),
                                     str("{}, {}, {}".format(a, b, c))))

        if not self.all_stuff:
            self.all_stuff = [["nothing", ""]]

        self.descriptor =\
        "This is a {} room. Somehow your brain associates it with the name {}. You see {} in here. There are {} corridors: {}.".format(
            self.game.light_descriptors[int(self.light * len(self.game.light_descriptors) - 1)],
            self.name,
            ", ".join(["{} {}".format(v, k) for k, v in self.all_stuff]),
            len(self.links),
            ", ".join([x.name for x in self.links])
        )

        if game.starting_chunk is None:
            game.starting_chunk = random.sample(self.chunks, 1)[0]
예제 #4
0
def generateYearLength():
    # get the class and name of the home star
    starClass = generateStarClass()
    starColor = getColor(starClass)
    starName = wordgen.gen_word(random.randint(1, 5), random.randint(1,7))
    print(f"The class of the host star, {starName}, is {starClass}.")
    print(f"{starName} is {starColor} in color. How beautiful it is!")
    # arbitrary but some reasoning involved to get the luminosity of the star.
    luminosity = averageLuminosity(starClass)
    # simple, divide sqrt luminosity by 1.1 for inner boundary and sqrt luminosity by 0.53 for outer
    inner_boundary = round(np.sqrt(luminosity / 1.1), roundPrecision)
    outer_boundary = round(np.sqrt(luminosity / 0.53), roundPrecision)
    # pick a random spot in that range for planet distance from star
    planet_distance = round(random.uniform(inner_boundary, outer_boundary), roundPrecision)
    print(f"The planet is located {planet_distance} AUs away from {starName}.")
    # use Kepler's third law to calculate the length of a year
    # T^2 = 4pi^2 / G(Mstar + Mplanet)(R^3)
    # where T is the time period, G is the Newtonian gravitational constant, M represents the mass, and R is the semi-major axis of the elliptical orbit
    # G is apparently 6.67x10^-11 newton meters squared per kilogram squared, so we're using that (0.0000000000667, or 6.67e-11 for simplicity)
    # We're also assuming that the planet's mass is negligible compared to the host star (as are most), for ease.
    newtonianGravitationConstant = 6.67e-11
    lengthYearSquared = round(np.sqrt((4*np.pi**2)/(newtonianGravitationConstant*averageMass(starClass))*planet_distance**3), roundPrecision)
    # For some reason, I did this such that the universe assumes a "standard year" is 336 days (12 months of exactly 28 days each).
    # This is why I divide by 336 here.
    standardYearLength = 336 # days
    return round(lengthYearSquared/standardYearLength, roundPrecision)
예제 #5
0
def geologicTimeScale(s):
    timeString = wordgen.gen_word(random.randint(1, 10), random.randint(1, 10))
    return {
        'Age'    : f"The age of {timeString} has begun!"   ,
        'Eon'    : f"The eon of {timeString} has begun!"   ,
        'Period' : f"The period of {timeString} has begun!",
        'Epoch'  : f"The epoch of {timeString} has begun!"
    }[s]
예제 #6
0
def replaceTokens(playData,script):
    charList = []
    tokenList = []
    
    
    for i in range(0,len(playData.charList)+5):
        charList.append(gen_word(2, 4))
        
    for i in range(0,len(playData.tokenList)+5):
        tokenList.append(gen_word(2, 4))
    print "_________________"
    print charList
    print tokenList
    print ""
    print ""
    print ""    
    return replaceTokensLine(script,charList,tokenList)
    
예제 #7
0
    def __init__(self, game, level, rooms):
        Chunk.__init__(self, game, level)
        self.game = game
        self.level = level
        self.name = wordgen.gen_word(1, 4)
        self.connected_rooms = rooms
        self.parent_room.chunks.append(self)

        for r in rooms:
            r.links.append(self)

            r.new_link(self)
예제 #8
0
print "-After merge"
print ""
for char in scriptN.charList:
    print char.name
    for line in char.lines:
        print "\t"+line[1].text
print scriptN

#create corpusi from PlayData
SaveCorpusi(scriptN)

#create play
nameList = []
tokenList = []
for char in scriptN.charList:
    nameList.append(gen_word(2,4))
for token in scriptN.tokenList:    
    tokenList.append(gen_word(1, 5))
    


script = createPlay(scriptN)
#print script
script = replaceTokens(scriptN,script)


file = open('outputTestLOTRTMTG.txt','w')
script = ''.join([c for c in script if c in string.printable])
file.write(script)
file.close()
예제 #9
0
from nltk.corpus import cmudict
from wordgen import gen_word
tokenlist = []
tokendict = {}
''' 
d = cmudict.dict()
def nsyl(word):
  return [list(y for y in x if y[-1].isdigit()) for x in d[word.lower()]]
'''
sentence = "Michael Jackson likes to eat at McDonalds"
tagged_sent = pos_tag(sentence.split())
# [('Michael', 'NNP'), ('Jackson', 'NNP'), ('likes', 'VBZ'), ('to', 'TO'), ('eat', 'VB'), ('at', 'IN'), ('McDonalds', 'NNP')]
print sentence
propernouns = [word for word,pos in tagged_sent if pos == 'NNP']
#print propernouns
# ['Michael','Jackson', 'McDonalds']

for noun in propernouns:
    if noun not in tokenlist:
        tokenlist.append(noun)
    sentence = sentence.replace(noun, "0x"+str(tokenlist.index(noun))+"x")
    #print nsyl(noun)
    
    
print sentence
 
for var in tokenlist:
    word = gen_word(2, 4)
    sentence = sentence.replace("0x"+str(tokenlist.index(var))+"x",word)
    
print sentence
예제 #10
0
 def generateName(self):
     self.name = gen_word(1, 4)
예제 #11
0
from nltk.tag import pos_tag
from nltk.corpus import cmudict
from wordgen import gen_word
tokenlist = []
tokendict = {}
''' 
d = cmudict.dict()
def nsyl(word):
  return [list(y for y in x if y[-1].isdigit()) for x in d[word.lower()]]
'''
sentence = "Michael Jackson likes to eat at McDonalds"
tagged_sent = pos_tag(sentence.split())
# [('Michael', 'NNP'), ('Jackson', 'NNP'), ('likes', 'VBZ'), ('to', 'TO'), ('eat', 'VB'), ('at', 'IN'), ('McDonalds', 'NNP')]
print sentence
propernouns = [word for word, pos in tagged_sent if pos == 'NNP']
#print propernouns
# ['Michael','Jackson', 'McDonalds']

for noun in propernouns:
    if noun not in tokenlist:
        tokenlist.append(noun)
    sentence = sentence.replace(noun, "0x" + str(tokenlist.index(noun)) + "x")
    #print nsyl(noun)

print sentence

for var in tokenlist:
    word = gen_word(2, 4)
    sentence = sentence.replace("0x" + str(tokenlist.index(var)) + "x", word)

print sentence
예제 #12
0
scriptN = scriptA = mergeDB(scriptA, scriptB)

print ""
print "-After merge"
print ""
for char in scriptN.charList:
    print char.name
    for line in char.lines:
        print "\t" + line[1].text
print scriptN

#create corpusi from PlayData
SaveCorpusi(scriptN)

#create play
nameList = []
tokenList = []
for char in scriptN.charList:
    nameList.append(gen_word(2, 4))
for token in scriptN.tokenList:
    tokenList.append(gen_word(1, 5))

script = createPlay(scriptN)
#print script
script = replaceTokens(scriptN, script)

file = open('outputTestLOTRTMTG.txt', 'w')
script = ''.join([c for c in script if c in string.printable])
file.write(script)
file.close()
예제 #13
0
def nameYourPlanet():
    randomstr = wordgen.gen_word(random.randint(1, 5), random.randint(1,7))
    print("\nLuckily, we find ourselves at one of that vast number.")
    print(f"The name of your home planet is {randomstr}.")
    return randomstr
예제 #14
0
def generateAgeNames(numberOfAges):
    agesList = []
    for i in range(0, numberOfAges):
        ageStr = wordgen.gen_word(random.randint(1, 5), random.randint(1,7))
        agesList.append(ageStr)
    return agesList
예제 #15
0
 def generateName(self):
     self.name = gen_word(1,4)