Skip to content

sujaymansingh/sujmarkov

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sujmarkov

A markov generator (in python!)

Installation

pip install git+https://github.com/sujaymansingh/sujmarkov.git

Usage (words)

>>> import sujmarkov
>>> m = sujmarkov.Markov(n=2)
>>> for word in ["Warne", "Warwick", "Warsaw", "Arrington", "Williams", "Willis"]:
...   m.add(word)
...
['W', 'a', 'm', 's']
>>>

Note: generate always returns a list. So when dealing with words, you might want to use join.

>>> "".join(m.generate())
'Wick'

Usage (sentences)

>>> import sujmarkov
>>> m = sujmarkov.Markov(n=2)
>>> m.add(["I", "have", "no", "idea"])
>>> m.add(["Don't", "have", "a", "cow", "man"])
>>> m.add(["I", "have", "a", "dog"])
>>> m.generate()
['I', 'have', 'a', 'cow', 'man']
>>>

Note: it will be case sensitive, so perhaps you might want to lower case your input before hand. In fact, it might be worth stripping out punctuation etc. (Have a play around!)

Utility script

If you have a text file (with one sentence per line), then you can run sujmarkov to generate sentences.

$ cat sample.txt
You can use a file
One sentence per line.

$ python -m sujmarkov generate 1 lines from sample.txt
you can use a file

(Of course, you may want to use a better sample file...)

About

A markov generator (in python!)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages