def personal_gberg(self, charList, gPath): full_text = "" while full_text == "": try: full_text = get_zip(gPath) except: full_text = "" gPath = rc(gPaths.values()) endPart = full_text.split("*** START OF THIS PROJECT GUTENBERG EBOOK ")[-1] theMeat = endPart.split("*** END OF THIS PROJECT GUTENBERG EBOOK")[0] theMeat = string.replace(theMeat, "\r\n", " ") if len(theMeat) < DEN+5: text = theMeat else: startLoc = int(len(theMeat)/2.0 - DEN/2.0) text = theMeat[startLoc:startLoc+DEN] spLoc = text.find(" ") text = text[spLoc+1:] try: pos = en.sentence.tag(text) wordtag = map(list, zip(*pos)) words = wordtag[0] tags = wordtag[1] for i in range(len(words)): charRef = rc([rc(charList), charList[0]]) if tags[i] == "PRP": words[i] = charRef.firstName elif tags[i] == "PRP$": words[i] = charRef.firstName+"\'s" elif tags[i] in ["VBD", "VBG", "VBN", "VBZ"]: try: words[i] = en.verb.past(words[i], person=3, negate=False) except: pass else: pass punc = [".", ",", ";", ":", "!", "?"] for i in range(len(words)): if words[i] in punc: words[i] = '\b'+words[i] final_text = " ".join(words) except: final_text = "" return final_text
def make_chars(self): # establish gender ratio charGenders = [ri(0,1) for _ in range(CC)] # initialize list of characters chars = [] # add user defined characters for firstlast in args.charnames: fl_list = firstlast.split('_') # Note that split is an underscore! chars.append(Character(fl_list[0], fl_list[1])) # add generated characters for b in charGenders: if b: chars.append(Character(rc(fFirstNames), rc(surnames))) else: chars.append(Character(rc(mFirstNames), rc(surnames))) # establish list of intro scenes introScenePaths = rs(characterTropeFiles, len(chars)) # establish list of settings settings = rs(settingTropeFiles, len(chars)*TSV) # establish list of drug trips trips = rs(erowidExpPaths, len(chars)*DTV) # establish list of scp articles scps = rs(scpPaths, len(chars)*SCP) # establish list of gberg excerpts gbergs = rs(gPaths.values(), len(chars)*GGV) i = 0 j = 0 m = 0 p = 0 s = 0 for c in chars: # make friends c.friends += rs(chars, ri(1,len(chars)-1)) if c in c.friends: c.friends.remove(c) # add introduction description c.introDesc = self.personal_trope([c], introScenePaths[i]) # add setting scenes for k in range(TSV): c.scenes.append(self.personal_trope([c]+c.friends, settings[j+k])) # add drug trip scenes for n in range(DTV): c.drugTrips.append(self.personal_trip([c]+c.friends, trips[m+n])) # add scp articles for q in range(SCP): c.scpReports.append(self.personal_scp([c]+c.friends, scps[p+q])) # add gberg excerpts for t in range(GGV): c.gbergExcerpts.append(self.personal_gberg([c]+c.friends, gbergs[s+t])) i += 1 j += TSV m += DTV p += SCP s += GGV self.characters = chars