Skip to content

Instantly share code, notes, and snippets.

Created August 7, 2014 05:37
Show Gist options
  • Save anonymous/44bf2a4cc24ddf1b861a to your computer and use it in GitHub Desktop.
Save anonymous/44bf2a4cc24ddf1b861a to your computer and use it in GitHub Desktop.
The true and that celebrated Confederacy, except in the ambition of Caesar to be to propose amendments, and confiding people, it becomes my principles for which appeared not think proper that by which has a fair construction any good Being who framed the lesser Asia would furnish the body than another seem to it by indications in many years past experience the just and common Creator, than those which our institutions of their union that we shall be left where the right to produce the Treasury Department entirely extinguished, or the preservation of party, assuming to decay;
The outline of the execution of their part of that most intimate, a vote of another ground of them, to them would be interrupted by my countrymen or the direction in its pristine health and Decii, and vigor, as a conservative power, to the words of the commencement of the President to have been granted to union of candidates for no care of the latter;
State authorities of those of such governments in common with which had been in that portion which they could then submitted it as power to me to the aggregate people if not be effected by the rights and fostering a one measure of interest, it is a despotism is mainly to a misconstruction of principles to be assigned to preserve the Government, but in our system with this I sincerely believe to prevent the wants of exclusive metallic currency.
The people to apply their peculiar position and religious liberty, and be found in his country in different is the love of the patronage alone not much greater effect of our institutions may be, and the necessity obliges them would become members of them from making it had the bosoms of each acting under which operated upon any of the management of one of Congress.
Scipios, to the latter case than bitterness, alienation, discord, and commissioner shall be thought of.
District only true spirit that exists in periods like this character and ascertain whether the world may receive.
Cromwell, in all the Government the parent isle.
All the parties at its citizens.
Constitution or small, from the days of power limited only where their respective parties at least to Congress to the supervision of such deprivation is concerned the senate under their fears.
I have examples of a full participation in legislation, and, in their defective or because errors there are not insensible of their flatterer, it had been assigned to gather from infancy to exist in my fellow-citizens will restore former against the respective orbits in perfect harmony among them, they would be supposed violation of their partiality has endowed them.
However strong may secure a motive may claim and prejudices.
"""
A light markov chain implementation implemented using Redis to
store bigrams.
The text in this example is William Henry Harrison's Innaugural Address
(medium-length and pretty consistent word choice.)
"""
from strings import ascii_letters
whh = open('whh.txt', 'r').read().split()
r = redis.StrictRedic()
key = lambda k: 'whh:%s' % k
# weighted_choice is http://stackoverflow.com/a/3679747/112785
# generate bigrams
[
r.zincrby(key(fst), snd)
for fst, snd
in zip([None] + whh, whh)[1:] # a quick way of getting bigrams
]
# get a list of starting words (capitalized)
[
r.zincrby(key('start'), word)
for word in whh
if word[0].isupper()
]
def sentence():
# make a weighted choice from the starting words
# (although this wouldn't have to be weighted, necessarily)
cur = weighted_choice(r.zrange(
'whh:start', 0, -1, withscores=True
))
sent = [cur]
# we end when the last character is not a letter - punctuation, in
# this corpus.
while cur[-1] in ascii_letters:
nxt = weighted_choice(r.zrange(
key(cur), 0, -1, withscores=True
))
if nxt is None:
return sent
sent.append(nxt)
cur = nxt
return sent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment