Created
November 16, 2018 17:04
-
-
Save amidvidy/2c6d83cb81e33dff2028e3e415402a27 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 json | |
from collections import defaultdict | |
persontext = defaultdict(list) | |
transitions = [] | |
rawm = [] | |
rawm.extend(reversed(json.load(open('../kairosnotkronos_6d07770cde/message.json'))['messages'])) | |
for m in rawm: | |
sender = m['sender_name'] | |
content = m['content'] | |
transitions.append(sender) | |
persontext[sender].append(content) | |
pgens = {n: markovify.Text(t, state_size=3) for (n,t) in persontext.items()} | |
chain = markovify.Chain([[name] for name in transitions], state_size=2) | |
next_person = markovify.Text('', chain=chain) | |
for i in range(10): | |
person = next_person.make_sentence() | |
text = pgens[person].make_sentence(tries=100000) | |
if person and text: | |
print(f'{person}: {text}') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment