Ejemplo n.º 1
0
def test_reverse_markov_dict():
    full_markov_dict = MarkovDict(source=None, depth=1)
    corpus = Corpus(importStrFromFile("./test/corpora/reverse.txt"))
    full_markov_dict.add(corpus)
    bot = MarkovBot(full_markov_dict)
    print(bot.forward_dict.dict)
    print(bot.reverse_dict.dict)
Ejemplo n.º 2
0
def test():
    print("Creating new markov dict...")
    print(getDepth())
    corpus_path = "./corpora/test/depth.txt"
    corpus = Corpus(importStrFromFile(corpus_path))
    print(corpus)
    reverse_corpus = list(reversed(corpus))
    print(reverse_corpus)
    forward_markov_dict = MarkovDict(source=corpus, depth=getDepth())
    reverse_markov_dict = MarkovDict(source=reverse_corpus, depth=getDepth())
    pprint(forward_markov_dict.dict)
    pprint(reverse_markov_dict.dict)
    bot = MarkovBot(forward_markov_dict, reverse_markov_dict)
    # pprint(bot.forward_dict.dict)
    # pprint(bot.reverse_dict.dict)
    print(bot.response(topic="markov"))
Ejemplo n.º 3
0
def main():
    print("Creating new markov dict...")
    forward_markov_dict = MarkovDict(source=None, depth=getDepth())
    reverse_markov_dict = MarkovDict(source=None, depth=getDepth())
    print("Starting for loop to add corpora...")
    for corpus_path in corporaPaths():
        corpus = Corpus(importStrFromFile(corpus_path))
        print("Adding corpus with path '" + corpus_path + "'...")
        forward_markov_dict.add(corpus)
        reverse_markov_dict.add(list(reversed(corpus)))
    print("Initializing MarkovBot...")
    bot = MarkovBot(forward_markov_dict, reverse_markov_dict)
    print("\nWelcome to MarkovBot! Type a message. Type 'exit()' to quit.")
    message = prompt()
    while message != "exit()":
        print(bot.response(topic=message.split()[0]))
        message = prompt()
Ejemplo n.º 4
0
def main():

    reload(sys)  
    sys.setdefaultencoding('utf8')

    config_path = "slackov.cfg"

    config_default = "slacktoken,\n" \
        "slackid,\n" \
        "avatarsource,\n" \
        "twitterconsumerkey,\n" \
        "twitterconsumersecret,\n" \
        "twitteraccesstoken,\n" \
        "twitteraccesssecret,\n" \
        "twitterid,"

    if os.path.isfile(config_path):
        config_vals = {}
        config_file = open(config_path, 'r')
        for line in config_file:
            try:
                (key, val) = line.split(',')
                if key:
                    key = key.strip()
                if val:
                    val = val.strip()
                config_vals[key] = val
            except ValueError:
                error_message = "Config file not properly setup. " \
                                "Config: {} missing {} value.\n"
                print error_message.format(config_path, line.replace(':', ''))

        slack = {
            "token": config_vals['slacktoken'],
            "id": config_vals['slackid'],
            "avatarsource": config_vals['avatarsource']
        }
        twitter = {
            "consumer_key": config_vals['twitterconsumerkey'],
            "consumer_secret": config_vals['twitterconsumersecret'],
            "access_token": config_vals['twitteraccesstoken'],
            "access_token_secret": config_vals['twitteraccesssecret'],
            "id": config_vals['twitterid']
        }

        if None in (slack['token'],
                    slack['id'],
                    slack['avatarsource']):
            print "Config file not properly setup. " \
                    "Config file located at {}.\n".format(config_path)
        else:
            bot = MarkovBot(None, slack, twitter)
            bot.start()

            bot.process.join()
            print threading.enumerate()

    else:
        print "Could not find a config file. " \
                "Creating a new one: {}\n".format(config_path)
        config_file = open(config_path, 'a')
        config_file.write(config_default)
        config_file.close()
Ejemplo n.º 5
0
    def __init__(self):
        EasyFrame.__init__(self, title='Markov Bot GUI')

        #row 0
        self.addLabel('Build:', 0, 0)
        self.addLabel('', 0, 9)

        #row 1
        self.addLabel('Input file name:', 1, 0)
        self.input_file_name = self.addTextField('',
                                                 1,
                                                 1,
                                                 columnspan=8,
                                                 width=50,
                                                 sticky=N + W)

        #row 2
        self.addLabel('Tokenizer select:', 2, 0)
        self.tokenizer_select = self.addRadiobuttonGroup(2,
                                                         1,
                                                         columnspan=7,
                                                         orient=HORIZONTAL)
        self.tokenizer_select_basic = self.tokenizer_select.addRadiobutton(
            'basic')
        self.tokenizer_select_group_aware = self.tokenizer_select.addRadiobutton(
            'group aware')
        self.tokenizer_select.setSelectedButton(
            self.tokenizer_select_group_aware)

        #row 3
        self.build_button = self.addButton('Build',
                                           3,
                                           0,
                                           columnspan=9,
                                           command=self.build)

        #row 4
        self.addLabel('Generate:', 4, 0)

        #row 5
        self.addLabel('Output select:', 5, 0)
        self.output_select = self.addRadiobuttonGroup(5,
                                                      1,
                                                      columnspan=2,
                                                      orient=HORIZONTAL)
        self.output_select_console = self.output_select.addRadiobutton(
            'console')
        self.output_select_file = self.output_select.addRadiobutton('file')
        self.output_select.setSelectedButton(self.output_select_console)
        self.addLabel('Output file name:', 5, 3)
        self.output_file_name = self.addTextField('',
                                                  5,
                                                  4,
                                                  columnspan=5,
                                                  width=50,
                                                  sticky=N + W)

        #row 6
        self.addLabel('Start string:', 6, 0)
        self.start_string = self.addTextField('', 6, 1, sticky=N + W)
        self.addLabel('Stop string:', 6, 2)
        self.stop_string = self.addTextField('.', 6, 3, sticky=N + W)
        self.addLabel('Limit:', 6, 4)
        self.limit = self.addIntegerField(15, 6, 5, sticky=N + W)

        #row 7
        self.addLabel('Repeat:', 7, 0)
        self.repeat = self.addIntegerField(3, 7, 1, sticky=N + W)
        self.repeat_select = self.addRadiobuttonGroup(7,
                                                      2,
                                                      columnspan=4,
                                                      orient=HORIZONTAL)
        self.repeat_select_new_line = self.repeat_select.addRadiobutton(
            'new line')
        self.repeat_select_append = self.repeat_select.addRadiobutton('append')
        self.repeat_select.setSelectedButton(self.repeat_select_new_line)

        #row 8
        self.generate_button = self.addButton('Generate',
                                              8,
                                              0,
                                              columnspan=9,
                                              command=self.generate)

        #row 9
        self.console = self.addTextArea('', 9, 0, columnspan=9)

        #row 10
        self.addLabel('By Jeffrey Matthews', 10, 0)

        #non GUI members
        self.mbot = MarkovBot()
Ejemplo n.º 6
0
'''A terminal program demonstrating the use of Markov Bot Py'''

import Formatter
from MarkovBot import MarkovBot
import Tokenizer

fname = 'seuss.txt'
tokens = Tokenizer.group_aware(Tokenizer.read_all(fname))
bot = MarkovBot(tokens)

print(
    'Five random Dr. Seuss sentences that start with sam and (most likely) end in a period:'
)
for i in range(5):
    walk = bot.walk(20, start='sam', stop='.')
    print(Formatter.capped_sentences(walk))
Ejemplo n.º 7
0
from MarkovBot import MarkovBot
import time

token = "your-token-here"
id = "bot-id"

bot = MarkovBot(token, None, id)
bot.start()
Ejemplo n.º 8
0
#!/usr/bin/env python
import sys
from time import sleep
from random import random

from MarkovBot import MarkovBot
from keys import keys

TWEET_MAX_LENGTH = 280
"""
NOTE: for smaller tweet bodies, lower the min_word_freq to get more realistic (but less original) tweets
"""
argc = len(sys.argv)
bot = MarkovBot(keys["MarkovSports"],
                "AdamSchefter",
                max_chains=5,
                min_word_freq=2,
                active_hours=range(7, 21))

while True:
    if bot.is_active():
        twt = bot.tweet_chain(max_length=90, safe=True)
        print twt

    tweet_offset = (
        1 - random() * 2
    ) * 60 * 30  # up to a half hour in either direction == waits 0.5-1.5 hours
    # print tweet_offset + 3600
    sleep(60 * 60 + tweet_offset)  # sleep for an hour or so
Ejemplo n.º 9
0
if os.path.isfile(config_path):
    config_vals = dict()
    config_file = open(config_path, 'r')
    for line in config_file:
        try:
            (key, val) = line.split(',')
            config_vals[key] = val
        except ValueError as e:
            print "Config file not properly setup. Config: {} missing {} value.\n".format(
                config_path, line.replace(':', ''))

    if None in (config_vals['token'], config_vals['id'],
                config_vals['avatarsource']):
        print "Config file not properly setup. Config file located at {}.\n".format(
            config_path)
    else:
        bot = MarkovBot(config_vals['token'].strip(), None,
                        config_vals['id'].strip(),
                        config_vals['avatarsource'].strip())
        bot.start()

        bot.process.join()
        print threading.enumerate()

else:
    print "Could not find a config file. Creating a new one: {}\n".format(
        config_path)
    config_file = open(config_path, 'a')
    config_file.write(config_default)
    config_file.close()