Esempio n. 1
0
def hello(r="hf9831h1rgfewuifgasjkbzxg1e"):
   filename='mycorpus.txt'
   markovLength=2
   if (markov.mapping=={}):
	   markov.buildMapping(markov.wordlist(filename),markovLength)
   sentence = markov.genSentence(markovLength, r.lower())
   page = "<!DOCTYPE html><html><header><title>JAMLITBOT</title><style type='text/css'>a {color:black;text-decoration:none;font-size:16pt;}</style></header><body>"
   for word in sentence.split():
		page += "<a href='"+word.translate(string.maketrans("",""),string.punctuation)+"'>"+word+"</a> "
   page += "<br><br><a href='/'>reload</a></body></html>"
   return page
Esempio n. 2
0
def hello(r="hf9831h1rgfewuifgasjkbzxg1e"):
    filename = 'mycorpus.txt'
    markovLength = 2
    if (markov.mapping == {}):
        markov.buildMapping(markov.wordlist(filename), markovLength)
    sentence = markov.genSentence(markovLength, r.lower())
    page = "<!DOCTYPE html><html><header><title>JAMLITBOT</title><style type='text/css'>a {color:black;text-decoration:none;font-size:16pt;}</style></header><body>"
    for word in sentence.split():
        page += "<a href='" + word.translate(string.maketrans(
            "", ""), string.punctuation) + "'>" + word + "</a> "
    page += "<br><br><a href='/'>reload</a></body></html>"
    return page
def main():
    if len(sys.argv) < 2:
        sys.stderr.write("Usage: " + sys.argv[0] + " text_source [chain_length=1]\n")
        sys.exit(1)

    filename = sys.argv[1]
    markovLength = 1
    if len(sys.argv) == 3:
        markovLength = int(sys.argv[2])

    markov.buildMapping(markov.wordlist(filename), markovLength)
    print markov.genSentence(markovLength)
Esempio n. 4
0
#!/usr/bin/python
import init_twit as tw
import markov, sys, time

markovLength = 3
# change to the absolute path to your corpus file so you can run from anywhere
source_file = '/home/jk/Code/jambot/corpora/corpus.txt'

# optional command line parameters: path/to/corpus_file.txt n-gram_size
if len (sys.argv) >= 2:
	source_file = sys.argv[1]
if len (sys.argv) == 3:
	markovLength = int (sys.argv[2])

if (markov.mapping=={}):
	markov.buildMapping(markov.wordlist(source_file),markovLength)

def genTweet():
	sentence = markov.genSentence(markovLength)
	while (len (sentence) > 130 or len(sentence) < 30):
		sentence = markov.genSentence(markovLength)
	return sentence

while True:
	results = tw.twitter.search(q="@"+tw.handle,since_id=tw.last_id_replied)['results']
	if not results:
		print "Nobody's talking to me...\n"
	for result in results:
		question = result['text'].replace('@jmkp','')
		asker = result['from_user']
		status_id = str(result['id'])