How to use the markovify.text function in markovify

To help you get started, we’ve selected a few markovify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fitnr / twitter_markov / tests / test_markov_methods.py View on Github external
def testCheckModels(self):
        for m in self.tm.models.values():
            self.assertIsInstance(m, markovify.text.NewlineText)
github tonyravioli / dongerdong / extcmd / conspiracy.py View on Github external
#!/usr/bin/env python3
import markovify.text
helptext = "Outputs a markov chain from /r/conspiracy comments"

logfile = "../conspiradump.txt" #This is only here for testing and debugging.
with open(logfile) as f:
    text = f.read()
model = markovify.text.NewlineText(text, state_size=3)

async def doit(irc, target, source, sentences=2):
    #Maybe we'll replace this with a server-side thing on donger.org that provides a
    #response in the form of something like "donger.org/conspiracy.php?sentences=2".
    #That would make it so we don't have to put a 1MB text file in a repo.
    #
    #We could call it "Conspiracies As A Service"


    longstring = ''

    for i in range(sentences):
        try:
            sentence = model.make_sentence(tries=20).strip()
            if sentence.endswith("." or "?"):
                longstring += "{} ".format(sentence)
github caktus / taytay / taytay / views.py View on Github external
def make_title(song):
    while True:
        title_generator = markovify.text.NewlineText(song)
        title = title_generator.make_sentence()
        if title is not None:
            title_list = title.split(" ")
            title = " ".join(title_list[0:3])
            return title.title()
github fitnr / twitter_markov / twitter_markov / twitter_markov.py View on Github external
try:
            for pth in corpora:
                if isinstance(pth, six.string_types):
                    corpus_path = os.path.expanduser(pth)
                    name = os.path.basename(corpus_path)
                    m = open(corpus_path)

                else:
                    m = pth
                    try:
                        name = m.name
                    except AttributeError:
                        name = repr(m)

                try:
                    out[name] = markovify.text.NewlineText(m.read(), state_size=state_size)

                finally:
                    m.close()

        except AttributeError as e:
            self.log.error(e)
            self.log.error("Probably couldn't find the model file.")
            raise e

        except IOError as e:
            self.log.error(e)
            self.log.error('Error reading %s', corpus_path)
            raise e

        self.default_model = os.path.basename(corpora[0])