How to use the markovify.Text.from_json 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 jsvine / markovify / test / test_itertext.py View on Github external
def test_from_json_without_retaining(self):
        with open(os.path.join(os.path.dirname(__file__), "texts/senate-bills.txt")) as f:
            original_model = markovify.Text(f, retain_original=False)
        d = original_model.to_json()
        new_model = markovify.Text.from_json(d)
        sent = new_model.make_sentence()
        assert sent is not None
        assert len(sent) != 0
github jsvine / markovify / test / test_basic.py View on Github external
def test_json(self):
        text_model = self.sherlock_model
        json_model = text_model.to_json()
        new_text_model = markovify.Text.from_json(json_model)
        sent = new_text_model.make_sentence()
        assert(len(sent) != 0)
github joyeusenoelle / ananas-ebooks / ebooks.py View on Github external
def generate(self, length=None):
    modelfile = self.model_name
    if not os.path.exists(modelfile):
      sys.exit('no model -- please scrape first')
    with open(modelfile, 'r') as f:
      reconstituted_model = markovify.Text.from_json(f.read())
#    okay_to_return = False
#    excluded_pattern = re.compile(r'{}'.format("|".join(self.excluded_words.split(","))))
#    while not okay_to_return:
    if length:
      msg = reconstituted_model.make_short_sentence(length)
    else:
      msg = reconstituted_model.make_sentence()
      #if not excluded_pattern.findall(msg):
        #okay_to_return = True
    return msg.replace(chr(31), "\n")
github diracdeltas / icowid-generator / main.py View on Github external
import sys
import markovify

with open('ico.json') as f:
    text = f.read()
ico_model = markovify.Text.from_json(text)

with open('erowid.json') as f:
    text = f.read()
erowid_model = markovify.Text.from_json(text)

# Combine models
combo = markovify.combine([ico_model, erowid_model], [1.5, 1])

for i in range(int(sys.argv[1])):
    print(combo.make_short_sentence(200))
github diracdeltas / icowid-generator / main.py View on Github external
import sys
import markovify

with open('ico.json') as f:
    text = f.read()
ico_model = markovify.Text.from_json(text)

with open('erowid.json') as f:
    text = f.read()
erowid_model = markovify.Text.from_json(text)

# Combine models
combo = markovify.combine([ico_model, erowid_model], [1.5, 1])

for i in range(int(sys.argv[1])):
    print(combo.make_short_sentence(200))