Created
January 18, 2017 07:16
-
-
Save d6e/8018c6ea5fc993f2ba89e06883f66bac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import markovify | |
import os | |
import json | |
import re | |
directory = os.path.join(os.getcwd(), "general") | |
filenames = os.listdir(directory) | |
data = [] | |
for filename in filenames: | |
fpath = os.path.join(directory, filename) | |
with open(fpath) as f: | |
contents = json.load(f) | |
contents = [m['text'] for m in contents] #list of lists | |
data.extend(contents) | |
url_pattern = re.compile(r'<.*>') | |
codeb_pattern = re.compile(r'`.*`') | |
text = '\n'.join(data) | |
text = re.sub(url_pattern, '', text) | |
text = re.sub(codeb_pattern, '', text) | |
# Build the model. | |
text_model = markovify.Text(text) | |
# Print five randomly-generated sentences | |
#for i in range(5): | |
# print(text_model.make_sentence()) | |
# Print three randomly-generated sentences of no more than 140 characters | |
for i in range(30): | |
text_model.make_short_sentence(140) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment