Sunday, September 28, 2014

Ten centimeter friends!

   I am recently inspired on the part of a feedback on a previous post of mine, namely, in sounding a bit deranged.  So I wanted to share this program that I've found useful for building sentences.  Everything from random name generation to creative writing aids.  I am hoping someday to design an A.I. writer to take over my blog writings!  This will be in sequel to Asimov's Gold!


import os
import random
class Readcsvdata:
    def readfile(self):
        file = open(self.file, 'rU')
        datareads = []
        dataread = {}
        for line in file:
            csvlinedata = line.split(',')
            dataread[csvlinedata[0]]=csvlinedata[1:len(csvlinedata)]
        datareads.append(dataread)
        for filex in self.files:
            file = open(filex,'rU')
            dataread = {}
            for line in file:
                csvlinedata = line.split(',')
                dataread[csvlinedata[0]]=csvlinedata[1:len(csvlinedata)]
            datareads.append(dataread)
        return datareads
        
    def __init__(self):
        self.dirpath = 'C:\\Users\\StrangeCharmQuark\\Downloads\\mthes10\\'
        self.dirpath2 = 'C:\\Users\\StrangeCharmQuark\\Downloads\\'
        self.filename = 'mthesaur.txt'
        self.filelist = ['census-dist-male-first.csv','census-dist-female-first.csv',
                         'census-dist-2500-last.csv','steampunk.txt',
                         'clothing.txt','colorterms.txt','fabric.txt', 'ore.txt',
                         'gemstone.txt']
        self.file = self.dirpath+self.filename
        self.files = []
        for filen in self.filelist:
            self.files.append(self.dirpath2+filen)
            
class Readhsvdata:
    def readfile(self):
##        file = open(self.file, 'rU')
        datareads = []
##        dataread = {}
##        for line in file:
##            csvlinedata = line.split('-')
##            dataread[csvlinedata[0]]=csvlinedata[1:len(csvlinedata)]
##        datareads.append(dataread)
        for filex in self.files:
            file = open(filex,'rU')
            dataread = {}
            for line in file:
                csvlinedata = line.split('-')
                dataread[csvlinedata[0]]=csvlinedata[1:len(csvlinedata)]
            datareads.append(dataread)
        return datareads
        
    def __init__(self):
        ##self.dirpath = 'C:\\Users\\StrangeCharmQuark\\Downloads\\mthes10\\'
        self.dirpath2 = 'C:\\Users\\StrangeCharmQuark\\Downloads\\'
        ##self.filename = 'mthesaur.txt'
        self.filelist = ['geology.txt']
        ##self.file = self.dirpath+self.filename
        self.files = []
        for filen in self.filelist:
            self.files.append(self.dirpath2+filen)
            
        
class Namegenerator:
    def pickrandom(self):
        alist =[]
        llist =[]
        nlist =[]
        for i in range(0,10):
            n =''
            intpick = random.randint(0,len(self.adict)-1)
            ##alist.append(self.adict.keys()[intpick])
            n+= self.adict.keys()[intpick]
            n+=' '
            intpick2 = random.randint(0,len(self.ldict)-1)
            n+= self.ldict.keys()[intpick2]
            nlist.append(n)
        return nlist
            
    def __init__(self, adict, ldict):
        self.adict = adict
        self.ldict = ldict

class Namegenerator2:
    def pickrandom(self):
        nlist =[]
        for i in range(0,10):
            n =''
            intpick = random.randint(0,len(self.adict)-1)
            ##alist.append(self.adict.keys()[intpick])
            n+= self.adict.keys()[intpick]
            n+=' '
            intpick2 = random.randint(0,len(self.ldict)-1)
            n+= self.ldict.keys()[intpick2]
            n+=' '
            intpick3 = random.randint(0,len(self.kdict)-1)
            n+= self.kdict.keys()[intpick3]
            nlist.append(n)
        return nlist
            
    def __init__(self, adict, ldict, kdict):
        self.adict = adict
        self.ldict = ldict
        self.kdict = kdict

class Namegenerator3:
    def pickrandom(self):
        nlist =[]
        for i in range(0,10):
            n =''
            intpick = random.randint(0,len(self.adict)-1)
            ##alist.append(self.adict.keys()[intpick])
            n+= self.adict.keys()[intpick]
##            n+=' '
##            intpick2 = random.randint(0,len(self.ldict))
##            n+= self.ldict.keys()[intpick2]
##            n+=' '
##            intpick3 = random.randint(0,len(self.kdict))
##            n+= self.kdict.keys()[intpick3]
            nlist.append(n)
        return nlist
            
    def __init__(self, adict):
        self.adict = adict
##        self.ldict = ldict
##        self.kdict = kdict


a = Readcsvdata()
tdict = a.readfile()
thlist = tdict[0]
mnlist = tdict[1]
fnlist = tdict[2]
lstlist = tdict[3]
steamlist = tdict[4]
clothinglist = tdict[5]
colorlist = tdict[6]
fabriclist = tdict[7]
orelist = tdict[8]
gemlist = tdict[9]

hsvdat = Readhsvdata()
hsvdatlist = hsvdat.readfile()
geologylist = hsvdatlist[0]

b = Namegenerator(mnlist,lstlist)
fullnames = b.pickrandom()

c = Namegenerator(fnlist,lstlist)
ffullnames = c.pickrandom()

d = Namegenerator(steamlist,steamlist)
steamnames = d.pickrandom()

e = Namegenerator(thlist,steamlist)
thsteam = e.pickrandom()

f = Namegenerator2(colorlist,fabriclist,clothinglist)
clothing = f.pickrandom()

g = Namegenerator3(geologylist)
geo = g.pickrandom()

print(fullnames)
print(ffullnames)
print(steamnames)
print(thsteam)
print(clothing)
print(geo)
Obviously if you wanted to make use of this word list reader, you'd simply need build your word list, you can easily modify the script so as work with hyphen separated values, versus comma separated ones, or any spacing, or whatever. Fun project actually!

No comments:

Post a Comment

Oblivion

 Between the fascination of an upcoming pandemic ridden college football season, Taylor Swift, and Kim Kardashian, wildfires, crazier weathe...