Python script to generate sentences based on 3-grams from input text

Someone once gave me this as an engineering puzzle (circa 2007?). I don't remember the specifics, but it's actually come in handy a couple of times over the years. Basically, it puts a bunch of 3-grams into a nested python dictionary and then randomly generates sentences based on input. The sample input provided was a copy of the tao_te_ching teachings. This python script takes arguments in the form:

python mkgen.py <filename>

github
mkgen.py - python script
tao_te_ching.txt - source file

Example: