Markovify Bot: Pt. 1

  1. USING MARKOVIFY
    1. INSTALLING MARKOVIFY: type the code below into your command line.
           pip install markovify
  1. Troubleshooting:
                               *For an introduction to pip, installing packages, and virtual-
 envs, click here.
*Traceback (most recent call last):
 File"<pyshell#2>", line 1, in <module>
        pip
NameError:name 'pip' is not defined
If you are seeing the above error, you are either not  
typing the code into the command line, or python is not
in your path (although newer versions of python should
do this for you if you checked the box during
installation.) For help with setting your path in
Windows, click here. If that doesn’t work, you may
need to set two paths: one to C:\python34, and one to
C:\python34\scripts. Make sure to restart your comp-
-uter after setting environment variables, or you will
Continue to get an error message.

          *If all else fails, you can type this into the Python Shell (rather
          Than the command line/terminal):
>>> import pip >>> pip.main(['install', 'requests'])

    1. Creating a Corpus: A corpus is simply a collection of written works/texts. In this instance, your corpus will come in the form of a .txt file, which will serve as the “input” for your markov chain model. To make the corpus, paste your selected written works into a .txt file (notepad) and save it in the root directory of your project.  
        1. CORPUS RESOURCES:
    2. THE CODE: The basics of the Markovify package (with additional annotation), as detailed here. Save the code as ____.py, and ensure that it is in the same folder as your corpus (the project directory).Run your program in the Python Shell/IDLE, and it should spit out some randomly generated sentences for you.

import markovify
# Sets ‘f’ (a file object) to the filename of your corpus.
with open("/path/to/my/corpus.txt") as f:
   text = f.read()
# Build the model.
text_model = markovify.Text(text)
# Will print five randomly-generated sentences
for i in range(5):
   print(text_model.make_sentence())
# Prints three randomly-generated sentences of no more than 140 characters
for i in range(3):
   print(text_model.make_short_sentence(140))



  1. MAKING YOUR BOT