def main(): # create instance of FieldStorage form = cgi.FieldStorage() # get data from the fields, if present query_str = form.getvalue('str') if query_str == "": query_str = "dog photo" input_phrase = query_str.replace("_", " ") # header print "Content-type: text/html\n\n" print "<html>\n<head>\n<title>" + input_phrase + "</title>\n" # javascript stuff print '''<script type="text/javascript" src="scroll.js"></script>''' print "</script></head>" print "<body>" print "<table><tr><td>" print input_phrase + "</td><td>" print '''<div id="names" onmousemver="recScroll('names'),'up', 1);">''' i = 1 while i < 20: print "<br> " + WNutils.mutateLine(input_phrase, WNutils.sisters) + "<br>" i += 1 print "<br> " + WNutils.mutateLine(input_phrase, WNutils.sisters) + "<br>" print "</td></tr></table>" print "</body></html>"
def main(): # create instance of FieldStorage form = cgi.FieldStorage() # get data from the fields, if present query_str = form.getvalue('str') # avoid script injection query_str = cgi.escape(query_str) if query_str == "": query_str = "dog photo" input_phrase = query_str.replace("_", " ") # log current query string log_fname = next_output_file("logs/log.txt") out_f = open(log_fname, "a") out_f.write(strftime("%H:%M:%S\n", localtime())) out_f.write(input_phrase + " -> \n\n") # header print "Content-type: text/html\n\n" print "<html>\n<head>\n<title>WORD CHIPPER</title>\n" # javascript stuff print '''<link rel="stylesheet" type="text/css" href="jscroller2-1.0.css">''' print '''<link rel="stylesheet" type="text/css" href="../css/sitestyles.css">''' print '''<script type="text/javascript" src="jscroller2-1.5.js"></script>''' print "</script></head>" print '''<body class="bodytext">''' print "<p> </p>" print "<table class=\"bodytext\"><tr><td>" print """ <form name="input" action="mutator2.py"> <input type="text" name="str" size="20"> </form> -></td><td width="400"> """ print '''<div id="scroller_container">''' print ''' <div class="jscroller2_up jscroller2_speed-10 jscroller2_ignoreleave">''' i = 1 while i < 10: result = WNutils.mutateLine(input_phrase, WNutils.sisters) print "<br> " + result + "<br>" out_f.write(result + "\n") i += 1 result = WNutils.mutateLine(input_phrase, WNutils.sisters) print "<br> " + result + "<br>" out_f.write(result + "\n\n") print "</div></div></td></tr></table>" print "</body></html>"
def main(): warnings.simplefilter("ignore") dbpath = '/Volumes/Swimming Pool/Memory' #dbpath='/Volumes/Reservoir/Assets/' print "Parsing file path " + dbpath + "\n" WNutils.walk_db(dbpath) ##print "\n" ##print "In WN:\n\n"+repr(WNutils.WNwords) ##print "\n" sortedwords = sorted(WNutils.WNwords.iteritems(), key=itemgetter(1), reverse=True) print "\n" for li in sortedwords: print li[0], print li[1] print "\n" ## print "\n" ## print "Not in WN:\n\n"+repr(WNutils.nonWNwords) ## print "\n" sortedwords = sorted(WNutils.nonWNwords.iteritems(), key=itemgetter(1), reverse=True) print "\n" for li in sortedwords: print li[0], print li[1] print "\n" #for key,val in nonWNwords.iteritems(): # print key,val #for key,val in WNwords.iteritems(): # print key,val print "\n" print "words in WN: " + str(len(WNutils.WNwords)) print "\n" print "words not in WN: " + str(len(WNutils.nonWNwords))
def main(): warnings.simplefilter("ignore") if len(sys.argv) < 2: in_file = '/Users/rtwomey/script/script.txt' print("Parsing file " + in_file + "\n") WNutils.parse_file(in_file) else: for in_file in sys.argv[1:]: print("Parsing file " + in_file + "\n") WNutils.parse_file(in_file) print("\n") ##print "In WN:\n\n"+repr(WNutils.WNwords) sortedwords = sorted(WNutils.WNwords.items(), key=itemgetter(1), reverse=True) for li in sortedwords: print(li[0], ) print(li[1]) print("\n") print("\n") ## print "Not in WN:\n\n"+repr(WNutils.nonWNwords) sortedwords = sorted(WNutils.nonWNwords.items(), key=itemgetter(1), reverse=True) for li in sortedwords: print(li[0], ) print(li[1]) print("\n") #for key,val in nonWNwords.iteritems(): # print key,val #for key,val in WNwords.iteritems(): # print key,val print("\n") print("words in WN: " + str(len(WNutils.WNwords))) print("\n") print("words not in WN: " + str(len(WNutils.nonWNwords)))
def main(): # check arguments and usage if len(sys.argv)==3: in_file=sys.argv[1] out_file=sys.argv[2] else: print('usage: python mutate_file.py /path/to/input /path/to/output') print('will add a date and increment a file number to the end of the output filename') sys.exit() warnings.simplefilter("ignore") print("opening "+in_file) in_f=open(in_file, encoding = "ISO-8859-1") next_out_file=next_output_file(out_file) print("writing to "+ next_out_file) out_f=open(next_out_file, "w") # look for properly formatted header on input file: # two empty lines, followed by text, followed by two more empty lines double_newlines=0 lastline='' for line in in_f: out_f.write(line) if line == '\n' and lastline=='\n': double_newlines=double_newlines+1 lastline=line if double_newlines==2: #print "Found two double newlines" break if double_newlines!=2: print("read entire file without finding appropriately formed header. exiting.") out_f.close() exit # start print("parsing contents:",) # read the file a line at a time, and transform for line in in_f: mut_line=WNutils.mutateLine(line) out_f.write(mut_line); out_f.write('\n') print("done.") in_f.close() out_f.close()
# # # import WNutils #parse_file('/Users/rtwomey/script/script.txt') #dbpath='/Volumes/Swimming Pool' #walk_db(dbpath) WNutils.parse_file('/Users/rtwomey/script/physical material.txt') WNutils.parse_file('/Users/rtwomey/script/slightly more than shit.txt') WNutils.parse_file('/Users/rtwomey/script/props.txt') WNutils.parse_file('/Users/rtwomey/script/unassigned materials.txt') #parse_file('/Users/rtwomey/script/visual memory reference.txt') #parse_file('/Users/rtwomey/script/reference manuals reference.txt') print "\n" print "In WN:\n\n" + repr(WNutils.WNwords) print "\n" print "\n" print "Not in WN:\n\n" + repr(WNutils.nonWNwords) print "\n" #for key,val in WNutils.nonWNwords.iteritems(): # print key,val #for key,val in WNutils.WNwords.iteritems(): # print key,val print "\n"
# find synset 1 # find synset 2 for synset in wordnet.N[term1][0].closure(wordnet.HYPERNYM): if term2 in synset: return True return False else: morphed_term=morphy(term1,'noun') if morphed_term!=None: if morphed_term in wordnet.N: for synset in wordnet.N[term1][0].closure(wordnet.HYPERNYM): if term2 in synset: return True return False WNutils.parse_file('/Users/rtwomey/script/places.txt') print "\n" print "In WN:\n\n"+repr(WNutils.WNwords) print "\n" print "\n" print "Not in WN:\n\n"+repr(WNutils.nonWNwords) print "\n" #for key,val in nonWNwords.iteritems(): # print key,val print "\n" print "words in WN: "+str(len(WNutils.WNwords)) print "\n"
def check_input(line): global mut_line mut_line = WNutils.mutateLine(line, WNutils.broadest) print mut_line
def check_input(self, line): ## if str(line).split()[0] == 'shift': ## #for line in self.current: ## mut_line=WNutils.mutateLine(line, WNutils.broadest) ## print self.current+'->\n'+mut_line ## self.out_f.write('\n'+line+' ->\n') ## self.out_f.write(mut_line+'\n') ## elif str(line).split()[0] == 'select' and len(str(line).split()) == 4: ## self.current=[] ## if str(line).split()[3]=='characters': ## i=int(str(line).split()[1]) ## while i>0: ## term=self.characters.getranditem() ## print term ## self.out_f.write('\n'+term+'\n') ## self.current.append(term) ## i-=1 ## elif str(line).split()[3]=='props': ## i=int(str(line).split()[1]) ## while i>0: ## term=self.props.getranditem() ## print term ## self.out_f.write('\n'+term+'\n') ## self.current.append(term) ## i-=1 ## elif str(line).split()[3]=='places': ## i=int(str(line).split()[1]) ## while i>0: ## term=self.places.getranditem() ## print term ## self.out_f.write('\n'+term+'\n') ## self.current.append(term) ## i-=1 ## elif str(line).split()[3]=='materials': ## i=int(str(line).split()[1]) ## while i>0: ## term=self.materials.getranditem() ## print term ## self.out_f.write('\n'+term+'\n') ## self.current.append(term) ## i-=1 ## elif str(line).split()[3]=='photos': ## i=int(str(line).split()[1]) ## while i>0: ## term=self.photos.getranditem() ## print term ## self.out_f.write('\n'+term+'\n') ## self.current.append(term) ## i-=1 ## elif str(line).split()[3]=='things_shown': ## i=int(str(line).split()[1]) ## while i>0: ## term=self.things_shown.getranditem() ## print term ## self.out_f.write('\n'+term+'\n') ## self.current.append(term) ## i-=1 ## elif str(line).split()[3]=='database': ## i=int(str(line).split()[1]) ## while i>0: ## term=self.memory.getranditem() ## print term ## self.out_f.write('\n'+term+'\n') ## self.current.append(term) ## i-=1 ## elif str(line).split()[3]=='script': ## i=int(str(line).split()[1]) ## while i>0: ## term=self.script.getranditem() ## print term ## self.out_f.write('\n'+term+'\n') ## self.current.append(term) ## i-=1 ## else: ## mut_line=WNutils.mutateLine(line, WNutils.sisters) ## print '-> '+mut_line ## self.current=mut_line ## self.out_f.write('\n'+line+' ->\n') ## self.out_f.write(mut_line+'\n') ## ## else: mut_line = WNutils.mutateLine(line, WNutils.sisters) print('-> ' + mut_line) self.current = mut_line self.out_f.write('\n' + line + ' ->\n') self.out_f.write(mut_line + '\n') self.out_f.flush()
def check_input(line): global current if str(line).split()[0] == 'shift': for line in current: mut_line=WNutils.mutateLine(line, WNutils.broadest) print(mut_line) out_f.write('\n'+line+' ->\n') out_f.write(mut_line+'\n') elif str(line).split()[0] == 'select' and len(str(line).split()) == 4: current=[] if str(line).split()[3]=='characters': i=int(str(line).split()[1]) while i>0: term=characters.getranditem() print(term) out_f.write('\n'+term+'\n') current.append(term) i-=1 elif str(line).split()[3]=='props': i=int(str(line).split()[1]) while i>0: term=props.getranditem() print(term) out_f.write('\n'+term+'\n') current.append(term) i-=1 elif str(line).split()[3]=='places': i=int(str(line).split()[1]) while i>0: term=places.getranditem() print(term) out_f.write('\n'+term+'\n') current.append(term) i-=1 elif str(line).split()[3]=='materials': i=int(str(line).split()[1]) while i>0: term=materials.getranditem() print(term) out_f.write('\n'+term+'\n') current.append(term) i-=1 elif str(line).split()[3]=='photos': i=int(str(line).split()[1]) while i>0: term=photos.getranditem() print(term) out_f.write('\n'+term+'\n') current.append(term) i-=1 elif str(line).split()[3]=='things_shown': i=int(str(line).split()[1]) while i>0: term=things_shown.getranditem() print(term) out_f.write('\n'+term+'\n') current.append(term) i-=1 elif str(line).split()[3]=='database': i=int(str(line).split()[1]) while i>0: term=memory.getranditem() print(term) out_f.write('\n'+term+'\n') current.append(term) i-=1 elif str(line).split()[3]=='script': i=int(str(line).split()[1]) while i>0: term=script.getranditem() print(term) out_f.write('\n'+term+'\n') current.append(term) i-=1 else: mut_line=WNutils.mutateLine(line, WNutils.broadest) print(mut_line) current=mut_line out_f.write('\n'+line+' ->\n') out_f.write(mut_line+'\n') else: mut_line=WNutils.mutateLine(line, WNutils.broadest) print(mut_line) current=mut_line out_f.write('\n'+line+' ->\n') out_f.write(mut_line+'\n') out_f.flush()
#!/usr/bin/python import WNutils WNutils.parse_file('/Users/rtwomey/script/people in photos.txt') WNutils.parse_file( '/Users/rtwomey/script/everyone in my reading reference.txt') WNutils.parse_file( '/Users/rtwomey/script/cast of characters - dramatis personae.txt') print "\n" print "In WN:\n\n" + repr(WNutils.WNwords) print "\n" print "\n" print "Not in WN:\n\n" + repr(WNutils.nonWNwords) print "\n" #for key,val in nonWNwords.iteritems(): # print key,val #for key,val in WNwords.iteritems(): # print key,val print "\n" print "words in WN: " + str(len(WNutils.WNwords)) print "\n" print "words not in WN: " + str(len(WNutils.nonWNwords))
for line in in_f: out_f.write(line) if line == '\n' and lastline == '\n': double_newlines = double_newlines + 1 lastline = line if double_newlines == 2: #print "Found two double newlines" break if double_newlines != 2: print "read entire file without finding appropriately formed header. exiting." out_f.close() exit print "parsing contents:", # split the rest of the file into lines pattern = r'''[A-Za-z]+|[0-9]+''' for line in in_f: for token in regexp_tokenize(line, pattern): #print token, result = WNutils.mutateWord(token, WNutils.children) out_f.write(result.replace('_', ' ') + ' ', ) #print result, out_f.write('\n') #print '\n' print "done." in_f.close() out_f.close()