tunaLandslide / HonorsContract

This is a project for a computational methods class, its purpose is to generate random sentences following the statistical rules of the input text. This project is free to use.
0 stars 0 forks source link

HonorsContract

The file mchain.py is a library to create markov chains and use them to generate sentences. the included .txt file "extext.txt" is an example text file made up of the introduciton from the Wikipedia article for books.

The functions included in this file are: (1) portText, (2) getMat, (3) genSent, (4) expMat, (5) portMat

(1) "Import text file" returns a of the words in the text file in order. portText(filename) filename - stating the name of the file containing the reference text

(2) "Get probability matrix" returns a of the vocabulary & of probability weights based on the relationships of the words in the refrence text getMat(ref) ref - of words reference text

(3) "Generate sentence" returns a randomly generated sentence genSent(voc,mat,N = 1) voc - of vocabulary words mat - describing the probabilities of each word to follow a previous word N - (optional) number of sentences to generate

(4) "Export matrix" creates a file storing the information for the matrix generated by the getMat function. expMat(name,voc,mat) name - the name of the file voc - of vocabulary words mat - describing the probabilities of each word to follow a previous word

(5) "Import matrix" returns a a of vocabulary & of probability weights based on the relationships of words. Data imported from an existing file,rather then generated. portMat(filename) filename - stating the name of the file containing the reference text