In [4]:
# -*- coding: utf-8 -*-
import urllib2

import re
import string
import operator

#剔除常用字函数
def isCommon(ngram):
    commonWords = ["the", "be", "and", "of", "a", "in", "to", "have",
                   "it", "i", "that", "for", "you", "he", "with", "on", "do", "say",
                   "this", "they", "is", "an", "at", "but","we", "his", "from", "that",
                   "not", "by", "she", "or", "as", "what", "go", "their","can", "who",
                   "get", "if", "would", "her", "all", "my", "make", "about", "know",
                   "will","as", "up", "one", "time", "has", "been", "there", "year", "so",
                   "think", "when", "which", "them", "some", "me", "people", "take", "out",
                   "into", "just", "see", "him", "your", "come", "could", "now", "than",
                   "like", "other", "how", "then", "its", "our", "two", "more", "these",
                   "want", "way", "look", "first", "also", "new", "because", "day", "more",
                   "use", "no", "man", "find", "here", "thing", "give", "many", "well"]

    if ngram in commonWords:
        return True
    else:
        return False

def cleanText(input):
    input = re.sub('\n+', " ", input).lower() # 匹配换行用空格替换成空格
    input = re.sub('\[[0-9]*\]', "", input) # 剔除类似[1]这样的引用标记
    input = re.sub(' +', " ", input) #  把连续多个空格替换成一个空格
    input = bytes(input)#.encode('utf-8') # 把内容转换成utf-8格式以消除转义字符
    #input = input.decode("ascii", "ignore")
    return input

def cleanInput(input):
    input = cleanText(input)
    cleanInput = []
    input = input.split(' ') #以空格为分隔符,返回列表


    for item in input:
        item = item.strip(string.punctuation) # string.punctuation获取所有标点符号

        if len(item) > 1 or (item.lower() == 'a' or item.lower() == 'i'): #找出单词,包括i,a等单个单词
            cleanInput.append(item)
    return cleanInput

def getNgrams(input, n):
    input = cleanInput(input)

    output = {} # 构造字典
    for i in range(len(input)-n+1):
        ngramTemp = " ".join(input[i:i+n])#.encode('utf-8')

        if isCommon(ngramTemp.split()[0]) or isCommon(ngramTemp.split()[1]):
            pass
        else:
            if ngramTemp not in output: #词频统计
                output[ngramTemp] = 0 #典型的字典操作
            output[ngramTemp] += 1
    return output

#获取核心词在的句子
def getFirstSentenceContaining(ngram, content):
    #print(ngram)
    sentences = content.split(".")
    for sentence in sentences:
        if ngram in sentence:
            return sentence
    return ""

#方法一:对网页直接进行读取
content = urllib2.urlopen(urllib2.Request("http://pythonscraping.com/files/inaugurationSpeech.txt")).read()

#对本地文件的读取,测试时候用,因为无需联网
#content = open("1.txt").read()
ngrams = getNgrams(content, 2)
sortedNGrams = sorted(ngrams.items(), key = operator.itemgetter(1), reverse=True) # reverse=True 降序排列
print (sortedNGrams) 
for top3 in range(3):
    print "###"+getFirstSentenceContaining(sortedNGrams[top3][0],content.lower())+"###"


[('united states', 10), ('general government', 4), ('executive department', 4), ('legislative body', 3), ('mr jefferson', 3), ('same causes', 3), ('called upon', 3), ('chief magistrate', 3), ('whole country', 3), ('government should', 3), ('itself upon', 2), ('upon another', 2), ('pristine health', 2), ('state governments', 2), ('declare void', 2), ('both houses', 2), ('individual members', 2), ('several departments', 2), ('negative upon', 2), ('public money', 2), ('reserved powers', 2), ('strange indeed', 2), ('foreign relations', 2), ('exclusive metallic', 2), ('great increase', 2), ('federal government', 2), ('true spirit', 2), ('were made', 2), ('foreign aggression', 2), ('elective franchise', 2), ('used only', 2), ('american citizens', 2), ('state authorities', 2), ('veto power', 2), ('executive power', 2), ('respectively claim', 2), ('was intended', 2), ('propose amendments', 2), ('heretofore given', 2), ('genuine spirit', 2), ('was observable', 2), ('disputed points', 2), ('observed however', 2), ('metallic currency', 2), ('second term', 2), ('domestic concerns', 2), ('should never', 2), ('high office', 2), ('american citizen', 2), ('reserved rights', 2), ('increase itself', 2), ('immediate representatives', 2), ('religious liberty', 2), ('are attributable', 2), ('express grant', 2), ('may meet', 1), ('power necessary', 1), ('taught us', 1), ('under circumstances', 1), ('administration become', 1), ('political instruments', 1), ('betray however', 1), ('every interest', 1), ('radically changed', 1), ('bitter fruits', 1), ('portion great', 1), ('found ineffectual', 1), ('character however', 1), ('states form', 1), ('roman emperor', 1), ('remote period', 1), ('are executed', 1), ('emphatically insisted', 1), ('domestic government', 1), ('confederacy fellow-citizens', 1), ('great principle', 1), ('institutions does', 1), ('never having', 1), ('well-established free', 1), ('republican principle', 1), ('was created', 1), ('mixed government', 1), ('forces upon', 1), ('several states', 1), ('union produced', 1), ('without denying', 1), ('bill may', 1), ('are upon', 1), ('much less', 1), ('party amongst', 1), ('any sinister', 1), ('delicate character', 1), ('such governments', 1), ('thus separated', 1), ('unusual professions', 1), ('broad foundation', 1), ('exalted station', 1), ('financial concerns', 1), ('golden shackles', 1), ('most watchful', 1), ('veto principle', 1), ('necessarily sententious', 1), ('countrymen far', 1), ('therefore given', 1), ('fatal consequences', 1), ('however may', 1), ('discord between', 1), ('control congress', 1), ('single individual', 1), ('existing revenue', 1), ('federal officers', 1), ('fullest confidence', 1), ('savior seeks', 1), ('noble feelings', 1), ('originate nor', 1), ('great diversity', 1), ('sufficient authority', 1), ('single tyrant', 1), ('trifling importance', 1), ('independent action', 1), ('powers allowed', 1), ('respective governments', 1), ('illustrious predecessors', 1), ('ends beyond', 1), ('elective governments', 1), ('anything imprudent', 1), ('significant allusion', 1), ('states solely', 1), ('every tendency', 1), ('seldom fails', 1), ('christian religion', 1), ('are vested', 1), ('policy are', 1), ('measure better', 1), ('most purely', 1), ('are daily', 1), ('greatly heightened', 1), ('iron bonds', 1), ('amply maintained', 1), ('greatly mitigated', 1), ('thousand years', 1), ('therefore positively', 1), ('giving expression', 1), ('possess shall', 1), ('inferior trusts', 1), ('completely under', 1), ('length upon', 1), ('construction any', 1), ('scheming politician', 1), ('powerful nation', 1), ('constitution rests', 1), ('states may', 1), ('such nation', 1), ('political maxims', 1), ('pliant instrument', 1), ('mischievous purposes', 1), ('lines too', 1), ('entire control', 1), ('greater error', 1), ('individual american', 1), ('simple representative', 1), ('those principles', 1), ('constituted authorities', 1), ('own independence', 1), ('beneficent creator', 1), ('scarcely less', 1), ('violated confidence', 1), ('leading states', 1), ("jefferson's administration", 1), ('created such', 1), ('amidst unusual', 1), ('being changed', 1), ('forms even', 1), ('strictly observed', 1), ('confiding fraternal', 1), ('was withheld', 1), ('another seem', 1), ('political rights', 1), ('republic being', 1), ('organized associations', 1), ('depends upon', 1), ('was formed', 1), ('alienation discord', 1), ('only true', 1), ('country within', 1), ('foregoing remarks', 1), ('institutions far', 1), ('against foreign', 1), ('speak warning', 1), ('every foreign', 1), ('ever exhibit', 1), ('limited sovereignty', 1), ('happily subsists', 1), ('was made', 1), ('sagacious mind', 1), ('senate continued', 1), ('every president', 1), ('most essential', 1), ('fastened itself', 1), ('former however', 1), ('unbiased judgments', 1), ('separate members', 1), ('majority had', 1), ('allies supported', 1), ('treasure should', 1), ('only where', 1), ('interrupted content', 1), ('rendered harmless', 1), ('those parties', 1), ('recommend measures', 1), ('such bills', 1), ('preserve peace', 1), ('former prosperity', 1), ('freemen under', 1), ('arise between', 1), ('judicial branches', 1), ('functionaries within', 1), ('forth proclaiming', 1), ('great principles', 1), ('domestic tranquillity', 1), ('most faithful', 1), ('matters connected', 1), ('powers actually', 1), ('create great', 1), ('promise anything', 1), ('exclusive jurisdiction', 1), ('strictly forbidden', 1), ('others limited', 1), ('embarrassed state', 1), ('essential difference', 1), ('indigent fellow-citizens', 1), ('even direct', 1), ('are others', 1), ('respective jurisdictions', 1), ('powers expressly', 1), ('union effected', 1), ('country requires', 1), ('senate octavius', 1), ('grants are', 1), ('consolation under', 1), ('introduced--a minister', 1), ('religious freedom', 1), ('best historians', 1), ('instance where', 1), ('encouraged upon', 1), ('much greater', 1), ('powerful fleet', 1), ('modern elective', 1), ('certainly assigns', 1), ('president possesses', 1), ('great divisions', 1), ('constitutions are', 1), ('disposal before', 1), ('government accompanied', 1), ('whole revenues', 1), ('years past', 1), ('shall enter', 1), ('considered proper', 1), ('pleasing guaranty', 1), ('times much', 1), ('congress might', 1), ('local authorities', 1), ('tranquillity preserved', 1), ('parties are', 1), ('those great', 1), ('settled upward', 1), ('however largely', 1), ('six presidents--and', 1), ('dispassionate investigation', 1), ('necessary qualification', 1), ('privileges without', 1), ('presidents permitted', 1), ('claimed under', 1), ('most striking', 1), ('sole distributer', 1), ('necessary burdens', 1), ('department upon', 1), ('roman citizen', 1), ('theirs having', 1), ('yield long', 1), ('those scarcely', 1), ('strict examination', 1), ('american subjects', 1), ('hasty enactment', 1), ('course prescribed', 1), ('requiring compliance', 1), ('expected such', 1), ('sinking deeper', 1), ('whose situation', 1), ('early presidents', 1), ('sincerely believe', 1), ('acknowledged defects', 1), ('system without', 1), ('various parts', 1), ('interest duty', 1), ('principle does', 1), ('weaker feeling', 1), ('another ground', 1), ('further removed', 1), ('extensive embracing', 1), ('octavius had', 1), ('exclusively metallic', 1), ('political power', 1), ('perfectly illustrated', 1), ('limited only', 1), ('condemn those', 1), ('better understand', 1), ('existence was', 1), ('presidents above', 1), ('sovereignties even', 1), ('being inexpedient', 1), ('entirely extinguished', 1), ('perfect immunity', 1), ('fervently commending', 1), ('individual predictions', 1), ('system presents', 1), ('adopt measures', 1), ('must ever', 1), ('chief executive', 1), ('considered most', 1), ('remarks relate', 1), ('difference between', 1), ('causes must', 1), ('several cantons', 1), ('process attended', 1), ('means placed', 1), ('union--cordial confiding', 1), ('prosperity unpleasant', 1), ('appears perfectly', 1), ('dominant passion', 1), ('were thus', 1), ('nor any', 1), ('such removal', 1), ('once distinguished', 1), ('veto was', 1), ('every injury', 1), ('really exists', 1), ('representative democracy', 1), ('petty provincial', 1), ('very reverse', 1), ('latter condition', 1), ('present form', 1), ('may claim', 1), ('early period', 1), ('free government', 1), ('relations are', 1), ('different department', 1), ('public liberty', 1), ('part remaining', 1), ('being possessed', 1), ('power established', 1), ('metallic however', 1), ('positively precluded', 1), ('upon us', 1), ('president sufficient', 1), ('clause giving', 1), ('leading principle', 1), ('very strange', 1), ('delusion under', 1), ('abundantly taught', 1), ('long exist', 1), ('any inspiring', 1), ('distinction amongst', 1), ('free institutions', 1), ('must reject', 1), ('any admission', 1), ('full participation', 1), ('always observable', 1), ('claim are', 1), ('liberty secured', 1), ('present purpose', 1), ('persevering bold', 1), ('concluding fellow-citizens', 1), ("men's opinions", 1), ('specified powers', 1), ('republican institutions', 1), ('examples caesar', 1), ('less important', 1), ('high trust', 1), ('revenue bills', 1), ('such dreams', 1), ('long continuance', 1), ('additional force', 1), ('respective parties', 1), ('are essentially', 1), ('caesar became', 1), ('under rules', 1), ('few months', 1), ('still enough', 1), ('harmony among', 1), ('common government', 1), ('utopian dreams', 1), ('may indeed', 1), ('upon none', 1), ('foreign powers', 1), ('states strong', 1), ('disunion violence', 1), ('every patriot', 1), ('general remark', 1), ('motive may', 1), ('earnest endeavor', 1), ('whom circumstances', 1), ('already realized', 1), ('high duties', 1), ('common creator', 1), ('rigid adherence', 1), ("mr jefferson's", 1), ('less jealous', 1), ('essentially connected', 1), ('sectional feelings', 1), ('conceive strictly', 1), ('kind may', 1), ('almost exclusively', 1), ('same individual', 1), ('usefulness ends', 1), ('appropriate orbits', 1), ('after fifty', 1), ('exclusively under', 1), ('fraternal union--is', 1), ('however enlightened', 1), ('most approved', 1), ('important political', 1), ('only against', 1), ('spirit contracted', 1), ('appointment nor', 1), ('old trick', 1), ('own interests', 1), ('found powerful', 1), ('prove effectual', 1), ('watched over', 1), ('liberty itself', 1), ('opinion may', 1), ('devoted exterior', 1), ('never surrendered', 1), ('confederacy experience', 1), ('political career', 1), ('such disputed', 1), ('void those', 1), ('precious privileges', 1), ('considering such', 1), ('intolerant spirit', 1), ('operations upon', 1), ('own immediate', 1), ('present occasion', 1), ('confederated states', 1), ('was certainly', 1), ('former are', 1), ('same liberality', 1), ('times was', 1), ('applied upon', 1), ('certain harbingers', 1), ('british orators', 1), ('occasion sufficiently', 1), ('left where', 1), ('human bosom', 1), ('open warfare', 1), ('any single', 1), ('nothing upon', 1), ('far different', 1), ('are often', 1), ('much difficulty', 1), ('hitherto protected', 1), ('countrymen never', 1), ('precise situation', 1), ('peculiar position', 1), ('alleged departure', 1), ('highly desirable', 1), ('liberty had', 1), ('might suppose', 1), ('unlimited power', 1), ('same hands', 1), ('injurious operation', 1), ('any state', 1), ('feeling produced', 1), ('manly examination', 1), ('treasury without', 1), ('may secure', 1), ('trust before', 1), ('similar reasons', 1), ('larger dividend', 1), ('case whereas', 1), ('appears strange', 1), ('employs whilst', 1), ('general grant', 1), ('making proper', 1), ('democratic principle', 1), ('high place', 1), ('bodies elected', 1), ('fellow-citizens being', 1), ('own votes', 1), ('declining years', 1), ('patronage alone', 1), ('distinctly drawn', 1), ('whom introduced--a', 1), ('without constant', 1), ('exist without', 1), ('elections further', 1), ('acknowledged property', 1), ('must recognize', 1), ('consolidated power', 1), ('either exonerated', 1), ('liberty without', 1), ('those essentially', 1), ('proper plan', 1), ('possessed himself', 1), ('public opinion', 1), ('ancestors derived', 1), ('legislative powers', 1), ('largely partaking', 1), ('state legislatures', 1), ('elapsed since', 1), ('treasure silenced', 1), ('might require', 1), ('alleged cause', 1), ('provincial ruler', 1), ('itself particularly', 1), ('instrument containing', 1), ('far exceeding', 1), ('purposes compose', 1), ('greater effect', 1), ('roman consul', 1), ('public treasure', 1), ('unmake change', 1), ('are called', 1), ('principles upon', 1), ('any indication', 1), ('legal administration', 1), ('supposed was', 1), ('legislative branch', 1), ('every instance', 1), ('proposed course', 1), ('perhaps invidious', 1), ('constitutional authority', 1), ('country are', 1), ('senate under', 1), ('those collected', 1), ('best interests--hostile', 1), ('free governments', 1), ('were are', 1), ('exhibit made', 1), ('himself under', 1), ('celebrated republic', 1), ('judgments never', 1), ('only body', 1), ('public officers', 1), ('larger share', 1), ('are founded', 1), ('thus used', 1), ('argument acquires', 1), ('ages neither', 1), ('should doubt', 1), ('antagonist principle', 1), ('own sphere', 1), ('equitable action', 1), ('worst apprehensions', 1), ('without cause', 1), ('meaning nothing', 1), ('master until', 1), ('views selfish', 1), ('are deprived', 1), ('rapid progress', 1), ('sound morals', 1), ('years since', 1), ('said indeed', 1), ('legislative executive', 1), ('influence given', 1), ('executive party', 1), ('had supposed', 1), ('presiding over', 1), ('become us', 1), ('never returned', 1), ('correct idea', 1), ('greatest number', 1), ('departments composing', 1), ('roman senate', 1), ('safe exercise', 1), ('most important', 1), ('spectacle none', 1), ('parent isle', 1), ('remark was', 1), ('ultimate destruction', 1), ('devoted persevering', 1), ('heretofore confided', 1), ('indeed citizens', 1), ('power withheld', 1), ('divine right', 1), ('country might', 1), ('treasury department', 1), ('domestic institutions', 1), ('daily adding', 1), ('prohibition published', 1), ('wishes too', 1), ('designing men', 1), ('best safeguards', 1), ('desired object', 1), ('charter granted', 1), ('whole mass', 1), ('approved writers', 1), ('power precisely', 1), ('granted still', 1), ('strong may', 1), ('greater must', 1), ('things likely', 1), ('still greatly', 1), ('relate almost', 1), ('pledge heretofore', 1), ('constitution clothes', 1), ('had none', 1), ('former against', 1), ('removable only', 1), ('enterprise are', 1), ('may originate', 1), ('modify it--it', 1), ('confederacy except', 1), ('proud democrat', 1), ('upon any', 1), ('stand either', 1), ('beautiful remark', 1), ('constitution others', 1), ('principle connected', 1), ('elder brutus', 1), ('true republicans', 1), ('are appalling', 1), ('probably disregarded', 1), ('were alarmed', 1), ('enter upon', 1), ('such extensive', 1), ('much resemble', 1), ('exterior guards', 1), ('constant attention', 1), ('quarter whence', 1), ('neck toleration', 1), ('expressly given', 1), ('are most', 1), ('whose charge', 1), ('legislative power', 1), ('revenue should', 1), ('were never', 1), ('written disputes', 1), ('very cause', 1), ('whose existence', 1), ('power given', 1), ('men are', 1), ('pockets become', 1), ('stupid men', 1), ('single scheme', 1), ('broad admissions', 1), ('unalienable rights', 1), ('every portion', 1), ('political architects', 1), ('preserved never', 1), ('former glory', 1), ('sufficiently important', 1), ('good possessed', 1), ('vital injury', 1), ('indeed offer', 1), ('civil war', 1), ('independence secured', 1), ('government was', 1), ('whole government', 1), ('cause does', 1), ('whose coming', 1), ('nation tarnished', 1), ('states accept', 1), ('precisely equal', 1), ('accountable agent', 1), ('exercised under', 1), ('constitution rather', 1), ('necessity obliges', 1), ('exist always', 1), ('each acting', 1), ('christs whose', 1), ('laws necessary', 1), ('shall stand', 1), ('much apprehension', 1), ('responsibility are', 1), ('having made', 1), ('respective orbits', 1), ('each individual', 1), ('former fellow-citizens', 1), ('office having', 1), ('union between', 1), ('members composing', 1), ('pretension upon', 1), ('let us', 1), ('never-dying worm', 1), ('although devoted', 1), ('years trial', 1), ('political privileges', 1), ('trusts heretofore', 1), ('himself bound', 1), ('latter case', 1), ('constituted should', 1), ('ruling passion', 1), ('high degree', 1), ('measures was', 1), ('joint councils', 1), ('jefferson forbidding', 1), ('own unbiased', 1), ('precious legacies', 1), ('certain rights', 1), ('bosom grows', 1), ('however much', 1), ('where american', 1), ('power limited', 1), ('unhallowed purposes', 1), ('each state', 1), ('highly expedient', 1), ('collisions may', 1), ('great difficulty', 1), ('spirit hostile', 1), ('may observe', 1), ('us institutions', 1), ('english writer', 1), ('thorough conviction', 1), ('great bulwark', 1), ('repeated recognitions', 1), ('above referred', 1), ('settled policy', 1), ('functions assigned', 1), ('virtually subject', 1), ('institutions may', 1), ('politician dissipated', 1), ('ordinary legislation', 1), ('purely democratic', 1), ('hated aristocracy', 1), ('any confidence', 1), ('same effects', 1), ('striking contrast', 1), ('states those', 1), ('fully invested', 1), ('should govern', 1), ('becomes insatiable', 1), ('guard protect', 1), ('executive through', 1), ('congress should', 1), ('might become', 1), ('are abundant', 1), ('past experience', 1), ('was indeed', 1), ('chief confidence', 1), ('person elected', 1), ('hitherto justice', 1), ('similar instances', 1), ('occurred between', 1), ('attachment between', 1), ('altogether different', 1), ('good being', 1), ('part effected', 1), ('appointing power', 1), ('dangerous accession', 1), ('supposed violation', 1), ('foreign nation', 1), ('inevitable conqueror', 1), ('powers any', 1), ('own reserved', 1), ('questions forces', 1), ('attending such', 1), ('republic are', 1), ('bills were', 1), ('others lay', 1), ('any interference', 1), ('intrusted power', 1), ('beloved country', 1), ('enlightened character', 1), ('might exert', 1), ('democratic claims', 1), ('full share', 1), ('aristocracy history', 1), ('any claim', 1), ('constitution prescribes', 1), ('ruler whilst', 1), ('glorious union', 1), ('made hitherto', 1), ('any benefit', 1), ('formidable instrument', 1), ('although enjoined', 1), ('power granted', 1), ('enjoyed much', 1), ('must consider', 1), ('was impossible', 1), ('false christs', 1), ('any distinct', 1), ('faithful disciples', 1), ('being fully', 1), ('most warmly', 1), ('different members', 1), ('without success', 1), ('each were', 1), ('state unite', 1), ('confident hopes', 1), ('something however', 1), ('public functionaries', 1), ('disputed questions', 1), ('however consolatory', 1), ('states governments', 1), ('inspiring hope', 1), ('communicate information', 1), ('power therefore', 1), ('foundation upon', 1), ('extensive alarm', 1), ('keep down', 1), ('deliberate opinions', 1), ('best means', 1), ('potent influence', 1), ('great political', 1), ('too separating', 1), ('commonwealth had', 1), ('sufferings secure', 1), ('affectionate attachment', 1), ('controlling power', 1), ('corrupting nothing', 1), ('such examples', 1), ('permit us', 1), ('american political', 1), ('may exist', 1), ('trust nothing', 1), ('restricted grant', 1), ('celebrated confederacy', 1), ('too hasty', 1), ('separating powers', 1), ('may regret', 1), ('was assigned', 1), ('both sides', 1), ('impose upon', 1), ('public press', 1), ('franchise through', 1), ('central head', 1), ('corner stone', 1), ('laws suggested', 1), ('ordinary course', 1), ('political family', 1), ('are compensated', 1), ('american citizen--the', 1), ('great good', 1), ('legitimate right', 1), ('history ancient', 1), ('solemn sanctions', 1), ('knew too', 1), ('passion once', 1), ('distinct lines', 1), ('legitimate exercise', 1), ('scheme having', 1), ('errors had', 1), ('warmly disputed', 1), ('being realized', 1), ('rests being', 1), ('distinguished english', 1), ('executive office', 1), ('virtual monarchy', 1), ('antifederal patriots', 1), ('constant nurture', 1), ('intrinsic difficulty', 1), ('national compact', 1), ('speculative statesmen', 1), ('popular branch', 1), ('such influences', 1), ('devoted republican', 1), ('safety within', 1), ('liberty animates', 1), ('men diverting', 1), ('any feature', 1), ('recognitions under', 1), ('well-ascertained guilt', 1), ('section state', 1), ('ever produce', 1), ('complicated intrigues', 1), ('commissioner shall', 1), ('excellence those', 1), ('coming was', 1), ('whatever pretense', 1), ('effected domestic', 1), ('apparently repugnant', 1), ('within are', 1), ('modern europe', 1), ('never-failing tendency', 1), ('governed must', 1), ('seized upon', 1), ('sententious manner', 1), ('lines mischievous', 1), ('singular incongruity', 1), ('essentially necessary', 1), ('even dangerous', 1), ('are certain', 1), ('unhallowed union', 1), ('actually given', 1), ('duty upon', 1), ('insisted upon', 1), ('columbia are', 1), ('had fled', 1), ('any good', 1), ('pretense imposed', 1), ('are still', 1), ('only legitimate', 1), ('certain purposes', 1), ('right believing', 1), ('august body', 1), ('actually granted', 1), ('powers claimed', 1), ('contrary possess', 1), ('assembled countrymen', 1), ('acquires additional', 1), ('often laboring', 1), ('without singular', 1), ('confidence upon', 1), ('may sometimes', 1), ('discrepancy was', 1), ('union nothing', 1), ('every section', 1), ('citizens requiring', 1), ('only consolation', 1), ('constitution itself', 1), ('ultimately received', 1), ('ardent patriotism', 1), ('free nation', 1), ('sure guaranty', 1), ('prescribe forms', 1), ('greatest good', 1), ('delicate duty', 1), ('free american', 1), ('was applied', 1), ('family are', 1), ('various sections', 1), ('endeavor mutually', 1), ('however repugnant', 1), ('triple tie', 1), ('bolivar possessed', 1), ('forbearing characters', 1), ('any legitimate', 1), ('confidence although', 1), ('concerns however', 1), ('made accessible', 1), ('observance inflict', 1), ('dominant passions', 1), ('devoted attachment', 1), ('appears may', 1), ('mistaken enthusiast', 1), ('friendly intercourse', 1), ('become destructive', 1), ('hitherto without', 1), ('words used', 1), ('most indigent', 1), ('helvetic confederacy', 1), ('may receive', 1), ('rich are', 1), ('amendatory power', 1), ('extensively complained', 1), ('citizen--the grant', 1), ('great difference', 1), ('currency amongst', 1), ('england spoke', 1), ('were once', 1), ('fair construction', 1), ('subjects are', 1), ('earnest desire', 1), ('us acquainted', 1), ('checked such', 1), ('hasty legislation', 1), ('much deprecated', 1), ('distinguished continue', 1), ('leading democratic', 1), ('people--a breath', 1), ('principle certainly', 1), ('aboriginal neighbors', 1), ('gone forth', 1), ('faction--a spirit', 1), ('least virtually', 1), ('power claimed', 1), ('nothing beyond', 1), ('had early', 1), ('any confederacy', 1), ('unpatriotic motive', 1), ('writers upon', 1), ('such constituents', 1), ('citizen derives', 1), ('between free', 1), ('own constant', 1), ('strictly proper', 1), ('greater sacrifices', 1), ('better calculated', 1), ('produce such', 1), ('after well-ascertained', 1), ('most precious', 1), ('another occasion', 1), ('separate states', 1), ('anyone should', 1), ('constitution may', 1), ('most distinguished', 1), ('casual observer', 1), ('secure tranquillity', 1), ('proper therefore', 1), ('liberty although', 1), ('profound reverence', 1), ('enlightened assembly', 1), ('commending every', 1), ('constitution should', 1), ('citizens being', 1), ('existed among', 1), ('best realized', 1), ('determined never', 1), ('banking institutions', 1), ('combinations violative', 1), ('was foretold', 1), ('established leaving', 1), ('perfectly clear', 1), ('shield only', 1), ('bring under', 1), ('any measure', 1), ('varnish crime', 1), ('sovereignty acknowledged', 1), ('former seems', 1), ('constitution making', 1), ('might deceive', 1), ('lay claim', 1), ('seasonably checked', 1), ('ineffectual men', 1), ('different modes', 1), ('established amidst', 1), ('are raised', 1), ('causes inherent', 1), ('constitution was', 1), ('poor sinking', 1), ('favorable issues', 1), ('great interests', 1), ('observations upon', 1), ('necessary employment', 1), ('department entirely', 1), ('plural executive', 1), ('left us', 1), ('warfare may', 1), ('intended appears', 1), ('bitterness alienation', 1), ('are unquestionably', 1), ('constitutional principle', 1), ('lasting happiness', 1), ('become dangerous', 1), ('harsh vindictive', 1), ('speaking unrestrained', 1), ('public virtue', 1), ('predictions were', 1), ('same persons', 1), ('system unalienable', 1), ('only tolerated', 1), ('roman knight', 1), ('are less', 1), ('common copartnership', 1), ('ultimate decision', 1), ('monarchical character', 1), ('sternest republicans', 1), ('was proper', 1), ('after obtaining', 1), ('religious responsibility', 1), ('governments arises', 1), ('investigation under', 1), ('republican patriot', 1), ('such deprivation', 1), ('free operations', 1), ('judgment are', 1), ('was wanting', 1), ('great alarm', 1), ('was afforded', 1), ('are told', 1), ('takes possession', 1), ('however deeply', 1), ('become members', 1), ('varied circumstances', 1), ("country's liberator", 1), ('greatly inferior', 1), ('laws are', 1), ('bad passion', 1), ('statesmen most', 1), ('same forbearance', 1), ('liberal feelings', 1), ('regret anything', 1), ('party assuming', 1), ('personal rights', 1), ('fifty years', 1), ('last hope', 1), ('pass upon', 1), ('amongst men', 1), ('president placed', 1), ('prudent administration', 1), ('men blinded', 1), ('mr madison', 1), ('sovereignty possessed', 1), ('effected public', 1), ('had sought', 1), ('pending negotiations', 1), ('early saw', 1), ("one's observance", 1), ('necessary sacrifices', 1), ('hitherto preserved', 1), ('citizen was', 1), ('others however', 1), ('allied members', 1), ('develop similar', 1), ('free votes', 1), ('sections calling', 1), ('under varied', 1), ('respective communities', 1), ('very remote', 1), ('own discretion', 1), ('decide disputed', 1), ('columbia such', 1), ('indignant roman', 1), ('devising schemes', 1), ('almighty power', 1), ('character might', 1), ('acting within', 1), ('majority should', 1), ('body constituted', 1), ('however strong', 1), ('had probably', 1), ('effectually checked', 1), ('shadow only', 1), ('governments each', 1), ('entirely independent', 1), ('much favor', 1), ('only result', 1), ('promises made', 1), ("one's faith", 1), ('either prepared', 1), ('similar character', 1), ('personal liberty', 1), ('important since', 1), ('violation secondly', 1), ('continue any', 1), ('careful culture', 1), ('fair exhibit', 1), ('best political', 1), ('principles governing', 1), ('necessarily resulted', 1), ('stone upon', 1), ('learned too', 1), ('public revenues', 1), ('constitution whilst', 1), ('appear before', 1), ('restore former', 1), ('spirit antagonist', 1), ('great abilities', 1), ('conservative power', 1), ('revenue laws', 1), ('those noble', 1), ('citizens must', 1), ('historians agree', 1), ('influences might', 1), ('us unite', 1), ('great dread', 1), ('dangerous temptations', 1), ('are produced', 1), ('contain declarations', 1), ('none yet', 1), ('placed it--with', 1), ('contrast was', 1), ('gloriously contended', 1), ('yet begun', 1), ('most intimate', 1), ('few even', 1), ('qualities remaining', 1), ('immediately checked', 1), ('legislation where', 1), ('most solemn', 1), ('measures recommended', 1), ('wise legislation', 1), ('once takes', 1), ('imposed are', 1), ('extensive confederacy', 1), ('sacred treasure', 1), ("country's rights", 1), ('great excitement', 1), ('feeling may', 1), ('since although', 1), ('character confers', 1), ('opinions either', 1), ('every means', 1), ('any agency', 1), ('those feelings', 1), ('only declare', 1), ('republics where', 1), ('every excrescence', 1), ('rules prescribed', 1), ('adopted enough', 1), ('any open', 1), ('human mind', 1), ('are destined', 1), ('recommend since', 1), ('forms prescribed', 1), ('much mischief', 1), ('respective departments', 1), ('worthy representatives', 1), ('blessed us', 1), ('nation are', 1), ('well-established republic', 1), ('latter cromwell', 1), ('perfect harmony', 1), ('magistrate unworthy', 1), ('corrupting passion', 1), ('vigilance sufficient', 1), ('without communicating', 1), ('judiciary forms', 1), ('actual condition', 1), ('acting under', 1), ('proper efforts', 1), ('made us', 1), ('existed--does exist', 1), ('sovereign balm', 1), ('governments nor', 1), ('direct opposition', 1), ('surrender being', 1), ('consider himself', 1), ('affectionate leave', 1), ('legislature upon', 1), ('boasted privilege', 1), ('similar power', 1), ('enactment should', 1), ('ascertain whether', 1), ('most stupid', 1), ('temporary deprivation', 1), ('often found', 1), ('entire remedy', 1), ('positive benefits', 1), ('own rights', 1), ('honor against', 1), ('majority might', 1), ('passed under', 1), ('personal characters', 1), ('executive interference', 1), ('mutual interests', 1), ('own relief', 1), ('operated upon', 1), ('constitution arising', 1), ('station according', 1), ('consent shall', 1), ('department constituted', 1), ('lesser asia', 1), ('immutable history', 1), ('district only', 1), ('mischievous however', 1), ('power introduced', 1), ('world may', 1), ('great danger', 1), ('own principles', 1), ('expected however', 1), ('console himself', 1), ('rights possessed', 1), ('too much', 1), ('sacred privilege', 1), ('world must', 1), ('countrymen were', 1), ('same almighty', 1), ('effective bonds', 1), ('surely nothing', 1), ('without any', 1), ('general clause', 1), ('totally reckless', 1), ('annual magistrates', 1), ('citizens are', 1), ('circumstances attending', 1), ('condition after', 1), ('always justly', 1), ('intimate union', 1), ('proper however', 1), ('were members', 1), ('any member', 1), ('possesses over', 1), ('power placed', 1), ('great error', 1), ('theory those', 1), ('union must', 1), ('are necessary', 1), ('justly regard', 1), ('sought protection', 1), ('any portion', 1), ('national faith--which', 1), ('only upon', 1), ('sublime spectacle', 1), ('thorough examination', 1), ('morals religious', 1), ('seldom carrying', 1), ('excitement imposes', 1), ('whom necessity', 1), ('faith prescribe', 1), ('fellow-citizens are', 1), ('almighty hand', 1), ('executive authority', 1), ('local interests', 1), ('rights alone', 1), ('executive branch', 1), ('termed monarchy', 1), ('zealously contended', 1), ('mother country', 1), ('before concluding', 1), ('public finances', 1), ('affections changed', 1), ('purely patriotic', 1), ('keep us', 1), ('entire confidence', 1), ('imposes itself', 1), ('demagogue rendered', 1), ('jefferson early', 1), ('are much', 1), ('custom coeval', 1)]
### the constitution of the united states is the instrument containing this grant of power to the several departments composing the government###
### the general government has seized upon none of the reserved rights of the states###
### such a one was afforded by the executive department constituted by the constitution###

In [5]:
import numpy as np
import PIL.Image as Image
from wordcloud import WordCloud, ImageColorGenerator
import matplotlib.pyplot as plt


# the font from github: https://github.com/adobe-fonts
font = r'simhei.ttf'
#coloring = np.array(Image.open("screenshot.png"))  # 遮罩层自己定义,可选自己的图片
wc = WordCloud(background_color="white",
               collocations=False, 
               font_path=font,
               width=1400, 
               height=1400,
               margin=2,
               ).generate_from_frequencies(dict(sortedNGrams))

# 这里采用了generate_from_frequencies(dict_)的方法,里面传入的值是{‘歌手1’:5,‘歌手2’:8,},分别是歌手及出现次数,其实和jieba分词
# 之后使用generate(text)是一个效果,只是这里的text已经被jieba封装成字典了

#image_colors = ImageColorGenerator(np.array(Image.open("screenshot.png")))
#plt.imshow(wc.recolor(color_func=image_colors))
plt.imshow(wc)
plt.axis("off")
plt.show()
wc.to_file('save.png')  # 把词云保存下来


Out[5]:
<wordcloud.wordcloud.WordCloud at 0x10f1cfe50>

In [6]:
sortedNGrams


Out[6]:
[('united states', 10),
 ('general government', 4),
 ('executive department', 4),
 ('legislative body', 3),
 ('mr jefferson', 3),
 ('same causes', 3),
 ('called upon', 3),
 ('chief magistrate', 3),
 ('whole country', 3),
 ('government should', 3),
 ('itself upon', 2),
 ('upon another', 2),
 ('pristine health', 2),
 ('state governments', 2),
 ('declare void', 2),
 ('both houses', 2),
 ('individual members', 2),
 ('several departments', 2),
 ('negative upon', 2),
 ('public money', 2),
 ('reserved powers', 2),
 ('strange indeed', 2),
 ('foreign relations', 2),
 ('exclusive metallic', 2),
 ('great increase', 2),
 ('federal government', 2),
 ('true spirit', 2),
 ('were made', 2),
 ('foreign aggression', 2),
 ('elective franchise', 2),
 ('used only', 2),
 ('american citizens', 2),
 ('state authorities', 2),
 ('veto power', 2),
 ('executive power', 2),
 ('respectively claim', 2),
 ('was intended', 2),
 ('propose amendments', 2),
 ('heretofore given', 2),
 ('genuine spirit', 2),
 ('was observable', 2),
 ('disputed points', 2),
 ('observed however', 2),
 ('metallic currency', 2),
 ('second term', 2),
 ('domestic concerns', 2),
 ('should never', 2),
 ('high office', 2),
 ('american citizen', 2),
 ('reserved rights', 2),
 ('increase itself', 2),
 ('immediate representatives', 2),
 ('religious liberty', 2),
 ('are attributable', 2),
 ('express grant', 2),
 ('may meet', 1),
 ('power necessary', 1),
 ('taught us', 1),
 ('under circumstances', 1),
 ('administration become', 1),
 ('political instruments', 1),
 ('betray however', 1),
 ('every interest', 1),
 ('radically changed', 1),
 ('bitter fruits', 1),
 ('portion great', 1),
 ('found ineffectual', 1),
 ('character however', 1),
 ('states form', 1),
 ('roman emperor', 1),
 ('remote period', 1),
 ('are executed', 1),
 ('emphatically insisted', 1),
 ('domestic government', 1),
 ('confederacy fellow-citizens', 1),
 ('great principle', 1),
 ('institutions does', 1),
 ('never having', 1),
 ('well-established free', 1),
 ('republican principle', 1),
 ('was created', 1),
 ('mixed government', 1),
 ('forces upon', 1),
 ('several states', 1),
 ('union produced', 1),
 ('without denying', 1),
 ('bill may', 1),
 ('are upon', 1),
 ('much less', 1),
 ('party amongst', 1),
 ('any sinister', 1),
 ('delicate character', 1),
 ('such governments', 1),
 ('thus separated', 1),
 ('unusual professions', 1),
 ('broad foundation', 1),
 ('exalted station', 1),
 ('financial concerns', 1),
 ('golden shackles', 1),
 ('most watchful', 1),
 ('veto principle', 1),
 ('necessarily sententious', 1),
 ('countrymen far', 1),
 ('therefore given', 1),
 ('fatal consequences', 1),
 ('however may', 1),
 ('discord between', 1),
 ('control congress', 1),
 ('single individual', 1),
 ('existing revenue', 1),
 ('federal officers', 1),
 ('fullest confidence', 1),
 ('savior seeks', 1),
 ('noble feelings', 1),
 ('originate nor', 1),
 ('great diversity', 1),
 ('sufficient authority', 1),
 ('single tyrant', 1),
 ('trifling importance', 1),
 ('independent action', 1),
 ('powers allowed', 1),
 ('respective governments', 1),
 ('illustrious predecessors', 1),
 ('ends beyond', 1),
 ('elective governments', 1),
 ('anything imprudent', 1),
 ('significant allusion', 1),
 ('states solely', 1),
 ('every tendency', 1),
 ('seldom fails', 1),
 ('christian religion', 1),
 ('are vested', 1),
 ('policy are', 1),
 ('measure better', 1),
 ('most purely', 1),
 ('are daily', 1),
 ('greatly heightened', 1),
 ('iron bonds', 1),
 ('amply maintained', 1),
 ('greatly mitigated', 1),
 ('thousand years', 1),
 ('therefore positively', 1),
 ('giving expression', 1),
 ('possess shall', 1),
 ('inferior trusts', 1),
 ('completely under', 1),
 ('length upon', 1),
 ('construction any', 1),
 ('scheming politician', 1),
 ('powerful nation', 1),
 ('constitution rests', 1),
 ('states may', 1),
 ('such nation', 1),
 ('political maxims', 1),
 ('pliant instrument', 1),
 ('mischievous purposes', 1),
 ('lines too', 1),
 ('entire control', 1),
 ('greater error', 1),
 ('individual american', 1),
 ('simple representative', 1),
 ('those principles', 1),
 ('constituted authorities', 1),
 ('own independence', 1),
 ('beneficent creator', 1),
 ('scarcely less', 1),
 ('violated confidence', 1),
 ('leading states', 1),
 ("jefferson's administration", 1),
 ('created such', 1),
 ('amidst unusual', 1),
 ('being changed', 1),
 ('forms even', 1),
 ('strictly observed', 1),
 ('confiding fraternal', 1),
 ('was withheld', 1),
 ('another seem', 1),
 ('political rights', 1),
 ('republic being', 1),
 ('organized associations', 1),
 ('depends upon', 1),
 ('was formed', 1),
 ('alienation discord', 1),
 ('only true', 1),
 ('country within', 1),
 ('foregoing remarks', 1),
 ('institutions far', 1),
 ('against foreign', 1),
 ('speak warning', 1),
 ('every foreign', 1),
 ('ever exhibit', 1),
 ('limited sovereignty', 1),
 ('happily subsists', 1),
 ('was made', 1),
 ('sagacious mind', 1),
 ('senate continued', 1),
 ('every president', 1),
 ('most essential', 1),
 ('fastened itself', 1),
 ('former however', 1),
 ('unbiased judgments', 1),
 ('separate members', 1),
 ('majority had', 1),
 ('allies supported', 1),
 ('treasure should', 1),
 ('only where', 1),
 ('interrupted content', 1),
 ('rendered harmless', 1),
 ('those parties', 1),
 ('recommend measures', 1),
 ('such bills', 1),
 ('preserve peace', 1),
 ('former prosperity', 1),
 ('freemen under', 1),
 ('arise between', 1),
 ('judicial branches', 1),
 ('functionaries within', 1),
 ('forth proclaiming', 1),
 ('great principles', 1),
 ('domestic tranquillity', 1),
 ('most faithful', 1),
 ('matters connected', 1),
 ('powers actually', 1),
 ('create great', 1),
 ('promise anything', 1),
 ('exclusive jurisdiction', 1),
 ('strictly forbidden', 1),
 ('others limited', 1),
 ('embarrassed state', 1),
 ('essential difference', 1),
 ('indigent fellow-citizens', 1),
 ('even direct', 1),
 ('are others', 1),
 ('respective jurisdictions', 1),
 ('powers expressly', 1),
 ('union effected', 1),
 ('country requires', 1),
 ('senate octavius', 1),
 ('grants are', 1),
 ('consolation under', 1),
 ('introduced--a minister', 1),
 ('religious freedom', 1),
 ('best historians', 1),
 ('instance where', 1),
 ('encouraged upon', 1),
 ('much greater', 1),
 ('powerful fleet', 1),
 ('modern elective', 1),
 ('certainly assigns', 1),
 ('president possesses', 1),
 ('great divisions', 1),
 ('constitutions are', 1),
 ('disposal before', 1),
 ('government accompanied', 1),
 ('whole revenues', 1),
 ('years past', 1),
 ('shall enter', 1),
 ('considered proper', 1),
 ('pleasing guaranty', 1),
 ('times much', 1),
 ('congress might', 1),
 ('local authorities', 1),
 ('tranquillity preserved', 1),
 ('parties are', 1),
 ('those great', 1),
 ('settled upward', 1),
 ('however largely', 1),
 ('six presidents--and', 1),
 ('dispassionate investigation', 1),
 ('necessary qualification', 1),
 ('privileges without', 1),
 ('presidents permitted', 1),
 ('claimed under', 1),
 ('most striking', 1),
 ('sole distributer', 1),
 ('necessary burdens', 1),
 ('department upon', 1),
 ('roman citizen', 1),
 ('theirs having', 1),
 ('yield long', 1),
 ('those scarcely', 1),
 ('strict examination', 1),
 ('american subjects', 1),
 ('hasty enactment', 1),
 ('course prescribed', 1),
 ('requiring compliance', 1),
 ('expected such', 1),
 ('sinking deeper', 1),
 ('whose situation', 1),
 ('early presidents', 1),
 ('sincerely believe', 1),
 ('acknowledged defects', 1),
 ('system without', 1),
 ('various parts', 1),
 ('interest duty', 1),
 ('principle does', 1),
 ('weaker feeling', 1),
 ('another ground', 1),
 ('further removed', 1),
 ('extensive embracing', 1),
 ('octavius had', 1),
 ('exclusively metallic', 1),
 ('political power', 1),
 ('perfectly illustrated', 1),
 ('limited only', 1),
 ('condemn those', 1),
 ('better understand', 1),
 ('existence was', 1),
 ('presidents above', 1),
 ('sovereignties even', 1),
 ('being inexpedient', 1),
 ('entirely extinguished', 1),
 ('perfect immunity', 1),
 ('fervently commending', 1),
 ('individual predictions', 1),
 ('system presents', 1),
 ('adopt measures', 1),
 ('must ever', 1),
 ('chief executive', 1),
 ('considered most', 1),
 ('remarks relate', 1),
 ('difference between', 1),
 ('causes must', 1),
 ('several cantons', 1),
 ('process attended', 1),
 ('means placed', 1),
 ('union--cordial confiding', 1),
 ('prosperity unpleasant', 1),
 ('appears perfectly', 1),
 ('dominant passion', 1),
 ('were thus', 1),
 ('nor any', 1),
 ('such removal', 1),
 ('once distinguished', 1),
 ('veto was', 1),
 ('every injury', 1),
 ('really exists', 1),
 ('representative democracy', 1),
 ('petty provincial', 1),
 ('very reverse', 1),
 ('latter condition', 1),
 ('present form', 1),
 ('may claim', 1),
 ('early period', 1),
 ('free government', 1),
 ('relations are', 1),
 ('different department', 1),
 ('public liberty', 1),
 ('part remaining', 1),
 ('being possessed', 1),
 ('power established', 1),
 ('metallic however', 1),
 ('positively precluded', 1),
 ('upon us', 1),
 ('president sufficient', 1),
 ('clause giving', 1),
 ('leading principle', 1),
 ('very strange', 1),
 ('delusion under', 1),
 ('abundantly taught', 1),
 ('long exist', 1),
 ('any inspiring', 1),
 ('distinction amongst', 1),
 ('free institutions', 1),
 ('must reject', 1),
 ('any admission', 1),
 ('full participation', 1),
 ('always observable', 1),
 ('claim are', 1),
 ('liberty secured', 1),
 ('present purpose', 1),
 ('persevering bold', 1),
 ('concluding fellow-citizens', 1),
 ("men's opinions", 1),
 ('specified powers', 1),
 ('republican institutions', 1),
 ('examples caesar', 1),
 ('less important', 1),
 ('high trust', 1),
 ('revenue bills', 1),
 ('such dreams', 1),
 ('long continuance', 1),
 ('additional force', 1),
 ('respective parties', 1),
 ('are essentially', 1),
 ('caesar became', 1),
 ('under rules', 1),
 ('few months', 1),
 ('still enough', 1),
 ('harmony among', 1),
 ('common government', 1),
 ('utopian dreams', 1),
 ('may indeed', 1),
 ('upon none', 1),
 ('foreign powers', 1),
 ('states strong', 1),
 ('disunion violence', 1),
 ('every patriot', 1),
 ('general remark', 1),
 ('motive may', 1),
 ('earnest endeavor', 1),
 ('whom circumstances', 1),
 ('already realized', 1),
 ('high duties', 1),
 ('common creator', 1),
 ('rigid adherence', 1),
 ("mr jefferson's", 1),
 ('less jealous', 1),
 ('essentially connected', 1),
 ('sectional feelings', 1),
 ('conceive strictly', 1),
 ('kind may', 1),
 ('almost exclusively', 1),
 ('same individual', 1),
 ('usefulness ends', 1),
 ('appropriate orbits', 1),
 ('after fifty', 1),
 ('exclusively under', 1),
 ('fraternal union--is', 1),
 ('however enlightened', 1),
 ('most approved', 1),
 ('important political', 1),
 ('only against', 1),
 ('spirit contracted', 1),
 ('appointment nor', 1),
 ('old trick', 1),
 ('own interests', 1),
 ('found powerful', 1),
 ('prove effectual', 1),
 ('watched over', 1),
 ('liberty itself', 1),
 ('opinion may', 1),
 ('devoted exterior', 1),
 ('never surrendered', 1),
 ('confederacy experience', 1),
 ('political career', 1),
 ('such disputed', 1),
 ('void those', 1),
 ('precious privileges', 1),
 ('considering such', 1),
 ('intolerant spirit', 1),
 ('operations upon', 1),
 ('own immediate', 1),
 ('present occasion', 1),
 ('confederated states', 1),
 ('was certainly', 1),
 ('former are', 1),
 ('same liberality', 1),
 ('times was', 1),
 ('applied upon', 1),
 ('certain harbingers', 1),
 ('british orators', 1),
 ('occasion sufficiently', 1),
 ('left where', 1),
 ('human bosom', 1),
 ('open warfare', 1),
 ('any single', 1),
 ('nothing upon', 1),
 ('far different', 1),
 ('are often', 1),
 ('much difficulty', 1),
 ('hitherto protected', 1),
 ('countrymen never', 1),
 ('precise situation', 1),
 ('peculiar position', 1),
 ('alleged departure', 1),
 ('highly desirable', 1),
 ('liberty had', 1),
 ('might suppose', 1),
 ('unlimited power', 1),
 ('same hands', 1),
 ('injurious operation', 1),
 ('any state', 1),
 ('feeling produced', 1),
 ('manly examination', 1),
 ('treasury without', 1),
 ('may secure', 1),
 ('trust before', 1),
 ('similar reasons', 1),
 ('larger dividend', 1),
 ('case whereas', 1),
 ('appears strange', 1),
 ('employs whilst', 1),
 ('general grant', 1),
 ('making proper', 1),
 ('democratic principle', 1),
 ('high place', 1),
 ('bodies elected', 1),
 ('fellow-citizens being', 1),
 ('own votes', 1),
 ('declining years', 1),
 ('patronage alone', 1),
 ('distinctly drawn', 1),
 ('whom introduced--a', 1),
 ('without constant', 1),
 ('exist without', 1),
 ('elections further', 1),
 ('acknowledged property', 1),
 ('must recognize', 1),
 ('consolidated power', 1),
 ('either exonerated', 1),
 ('liberty without', 1),
 ('those essentially', 1),
 ('proper plan', 1),
 ('possessed himself', 1),
 ('public opinion', 1),
 ('ancestors derived', 1),
 ('legislative powers', 1),
 ('largely partaking', 1),
 ('state legislatures', 1),
 ('elapsed since', 1),
 ('treasure silenced', 1),
 ('might require', 1),
 ('alleged cause', 1),
 ('provincial ruler', 1),
 ('itself particularly', 1),
 ('instrument containing', 1),
 ('far exceeding', 1),
 ('purposes compose', 1),
 ('greater effect', 1),
 ('roman consul', 1),
 ('public treasure', 1),
 ('unmake change', 1),
 ('are called', 1),
 ('principles upon', 1),
 ('any indication', 1),
 ('legal administration', 1),
 ('supposed was', 1),
 ('legislative branch', 1),
 ('every instance', 1),
 ('proposed course', 1),
 ('perhaps invidious', 1),
 ('constitutional authority', 1),
 ('country are', 1),
 ('senate under', 1),
 ('those collected', 1),
 ('best interests--hostile', 1),
 ('free governments', 1),
 ('were are', 1),
 ('exhibit made', 1),
 ('himself under', 1),
 ('celebrated republic', 1),
 ('judgments never', 1),
 ('only body', 1),
 ('public officers', 1),
 ('larger share', 1),
 ('are founded', 1),
 ('thus used', 1),
 ('argument acquires', 1),
 ('ages neither', 1),
 ('should doubt', 1),
 ('antagonist principle', 1),
 ('own sphere', 1),
 ('equitable action', 1),
 ('worst apprehensions', 1),
 ('without cause', 1),
 ('meaning nothing', 1),
 ('master until', 1),
 ('views selfish', 1),
 ('are deprived', 1),
 ('rapid progress', 1),
 ('sound morals', 1),
 ('years since', 1),
 ('said indeed', 1),
 ('legislative executive', 1),
 ('influence given', 1),
 ('executive party', 1),
 ('had supposed', 1),
 ('presiding over', 1),
 ('become us', 1),
 ('never returned', 1),
 ('correct idea', 1),
 ('greatest number', 1),
 ('departments composing', 1),
 ('roman senate', 1),
 ('safe exercise', 1),
 ('most important', 1),
 ('spectacle none', 1),
 ('parent isle', 1),
 ('remark was', 1),
 ('ultimate destruction', 1),
 ('devoted persevering', 1),
 ('heretofore confided', 1),
 ('indeed citizens', 1),
 ('power withheld', 1),
 ('divine right', 1),
 ('country might', 1),
 ('treasury department', 1),
 ('domestic institutions', 1),
 ('daily adding', 1),
 ('prohibition published', 1),
 ('wishes too', 1),
 ('designing men', 1),
 ('best safeguards', 1),
 ('desired object', 1),
 ('charter granted', 1),
 ('whole mass', 1),
 ('approved writers', 1),
 ('power precisely', 1),
 ('granted still', 1),
 ('strong may', 1),
 ('greater must', 1),
 ('things likely', 1),
 ('still greatly', 1),
 ('relate almost', 1),
 ('pledge heretofore', 1),
 ('constitution clothes', 1),
 ('had none', 1),
 ('former against', 1),
 ('removable only', 1),
 ('enterprise are', 1),
 ('may originate', 1),
 ('modify it--it', 1),
 ('confederacy except', 1),
 ('proud democrat', 1),
 ('upon any', 1),
 ('stand either', 1),
 ('beautiful remark', 1),
 ('constitution others', 1),
 ('principle connected', 1),
 ('elder brutus', 1),
 ('true republicans', 1),
 ('are appalling', 1),
 ('probably disregarded', 1),
 ('were alarmed', 1),
 ('enter upon', 1),
 ('such extensive', 1),
 ('much resemble', 1),
 ('exterior guards', 1),
 ('constant attention', 1),
 ('quarter whence', 1),
 ('neck toleration', 1),
 ('expressly given', 1),
 ('are most', 1),
 ('whose charge', 1),
 ('legislative power', 1),
 ('revenue should', 1),
 ('were never', 1),
 ('written disputes', 1),
 ('very cause', 1),
 ('whose existence', 1),
 ('power given', 1),
 ('men are', 1),
 ('pockets become', 1),
 ('stupid men', 1),
 ('single scheme', 1),
 ('broad admissions', 1),
 ('unalienable rights', 1),
 ('every portion', 1),
 ('political architects', 1),
 ('preserved never', 1),
 ('former glory', 1),
 ('sufficiently important', 1),
 ('good possessed', 1),
 ('vital injury', 1),
 ('indeed offer', 1),
 ('civil war', 1),
 ('independence secured', 1),
 ('government was', 1),
 ('whole government', 1),
 ('cause does', 1),
 ('whose coming', 1),
 ('nation tarnished', 1),
 ('states accept', 1),
 ('precisely equal', 1),
 ('accountable agent', 1),
 ('exercised under', 1),
 ('constitution rather', 1),
 ('necessity obliges', 1),
 ('exist always', 1),
 ('each acting', 1),
 ('christs whose', 1),
 ('laws necessary', 1),
 ('shall stand', 1),
 ('much apprehension', 1),
 ('responsibility are', 1),
 ('having made', 1),
 ('respective orbits', 1),
 ('each individual', 1),
 ('former fellow-citizens', 1),
 ('office having', 1),
 ('union between', 1),
 ('members composing', 1),
 ('pretension upon', 1),
 ('let us', 1),
 ('never-dying worm', 1),
 ('although devoted', 1),
 ('years trial', 1),
 ('political privileges', 1),
 ('trusts heretofore', 1),
 ('himself bound', 1),
 ('latter case', 1),
 ('constituted should', 1),
 ('ruling passion', 1),
 ('high degree', 1),
 ('measures was', 1),
 ('joint councils', 1),
 ('jefferson forbidding', 1),
 ('own unbiased', 1),
 ('precious legacies', 1),
 ('certain rights', 1),
 ('bosom grows', 1),
 ('however much', 1),
 ('where american', 1),
 ('power limited', 1),
 ('unhallowed purposes', 1),
 ('each state', 1),
 ('highly expedient', 1),
 ('collisions may', 1),
 ('great difficulty', 1),
 ('spirit hostile', 1),
 ('may observe', 1),
 ('us institutions', 1),
 ('english writer', 1),
 ('thorough conviction', 1),
 ('great bulwark', 1),
 ('repeated recognitions', 1),
 ('above referred', 1),
 ('settled policy', 1),
 ('functions assigned', 1),
 ('virtually subject', 1),
 ('institutions may', 1),
 ('politician dissipated', 1),
 ('ordinary legislation', 1),
 ('purely democratic', 1),
 ('hated aristocracy', 1),
 ('any confidence', 1),
 ('same effects', 1),
 ('striking contrast', 1),
 ('states those', 1),
 ('fully invested', 1),
 ('should govern', 1),
 ('becomes insatiable', 1),
 ('guard protect', 1),
 ('executive through', 1),
 ('congress should', 1),
 ('might become', 1),
 ('are abundant', 1),
 ('past experience', 1),
 ('was indeed', 1),
 ('chief confidence', 1),
 ('person elected', 1),
 ('hitherto justice', 1),
 ('similar instances', 1),
 ('occurred between', 1),
 ('attachment between', 1),
 ('altogether different', 1),
 ('good being', 1),
 ('part effected', 1),
 ('appointing power', 1),
 ('dangerous accession', 1),
 ('supposed violation', 1),
 ('foreign nation', 1),
 ('inevitable conqueror', 1),
 ('powers any', 1),
 ('own reserved', 1),
 ('questions forces', 1),
 ('attending such', 1),
 ('republic are', 1),
 ('bills were', 1),
 ('others lay', 1),
 ('any interference', 1),
 ('intrusted power', 1),
 ('beloved country', 1),
 ('enlightened character', 1),
 ('might exert', 1),
 ('democratic claims', 1),
 ('full share', 1),
 ('aristocracy history', 1),
 ('any claim', 1),
 ('constitution prescribes', 1),
 ('ruler whilst', 1),
 ('glorious union', 1),
 ('made hitherto', 1),
 ('any benefit', 1),
 ('formidable instrument', 1),
 ('although enjoined', 1),
 ('power granted', 1),
 ('enjoyed much', 1),
 ('must consider', 1),
 ('was impossible', 1),
 ('false christs', 1),
 ('any distinct', 1),
 ('faithful disciples', 1),
 ('being fully', 1),
 ('most warmly', 1),
 ('different members', 1),
 ('without success', 1),
 ('each were', 1),
 ('state unite', 1),
 ('confident hopes', 1),
 ('something however', 1),
 ('public functionaries', 1),
 ('disputed questions', 1),
 ('however consolatory', 1),
 ('states governments', 1),
 ('inspiring hope', 1),
 ('communicate information', 1),
 ('power therefore', 1),
 ('foundation upon', 1),
 ('extensive alarm', 1),
 ('keep down', 1),
 ('deliberate opinions', 1),
 ('best means', 1),
 ('potent influence', 1),
 ('great political', 1),
 ('too separating', 1),
 ('commonwealth had', 1),
 ('sufferings secure', 1),
 ('affectionate attachment', 1),
 ('controlling power', 1),
 ('corrupting nothing', 1),
 ('such examples', 1),
 ('permit us', 1),
 ('american political', 1),
 ('may exist', 1),
 ('trust nothing', 1),
 ('restricted grant', 1),
 ('celebrated confederacy', 1),
 ('too hasty', 1),
 ('separating powers', 1),
 ('may regret', 1),
 ('was assigned', 1),
 ('both sides', 1),
 ('impose upon', 1),
 ('public press', 1),
 ('franchise through', 1),
 ('central head', 1),
 ('corner stone', 1),
 ('laws suggested', 1),
 ('ordinary course', 1),
 ('political family', 1),
 ('are compensated', 1),
 ('american citizen--the', 1),
 ('great good', 1),
 ('legitimate right', 1),
 ('history ancient', 1),
 ('solemn sanctions', 1),
 ('knew too', 1),
 ('passion once', 1),
 ('distinct lines', 1),
 ('legitimate exercise', 1),
 ('scheme having', 1),
 ('errors had', 1),
 ('warmly disputed', 1),
 ('being realized', 1),
 ('rests being', 1),
 ('distinguished english', 1),
 ('executive office', 1),
 ('virtual monarchy', 1),
 ('antifederal patriots', 1),
 ('constant nurture', 1),
 ('intrinsic difficulty', 1),
 ('national compact', 1),
 ('speculative statesmen', 1),
 ('popular branch', 1),
 ('such influences', 1),
 ('devoted republican', 1),
 ('safety within', 1),
 ('liberty animates', 1),
 ('men diverting', 1),
 ('any feature', 1),
 ('recognitions under', 1),
 ('well-ascertained guilt', 1),
 ('section state', 1),
 ('ever produce', 1),
 ('complicated intrigues', 1),
 ('commissioner shall', 1),
 ('excellence those', 1),
 ('coming was', 1),
 ('whatever pretense', 1),
 ('effected domestic', 1),
 ('apparently repugnant', 1),
 ('within are', 1),
 ('modern europe', 1),
 ('never-failing tendency', 1),
 ('governed must', 1),
 ('seized upon', 1),
 ('sententious manner', 1),
 ('lines mischievous', 1),
 ('singular incongruity', 1),
 ('essentially necessary', 1),
 ('even dangerous', 1),
 ('are certain', 1),
 ('unhallowed union', 1),
 ('actually given', 1),
 ('duty upon', 1),
 ('insisted upon', 1),
 ('columbia are', 1),
 ('had fled', 1),
 ('any good', 1),
 ('pretense imposed', 1),
 ('are still', 1),
 ('only legitimate', 1),
 ('certain purposes', 1),
 ('right believing', 1),
 ('august body', 1),
 ('actually granted', 1),
 ('powers claimed', 1),
 ('contrary possess', 1),
 ('assembled countrymen', 1),
 ('acquires additional', 1),
 ('often laboring', 1),
 ('without singular', 1),
 ('confidence upon', 1),
 ('may sometimes', 1),
 ('discrepancy was', 1),
 ('union nothing', 1),
 ('every section', 1),
 ('citizens requiring', 1),
 ('only consolation', 1),
 ('constitution itself', 1),
 ('ultimately received', 1),
 ('ardent patriotism', 1),
 ('free nation', 1),
 ('sure guaranty', 1),
 ('prescribe forms', 1),
 ('greatest good', 1),
 ('delicate duty', 1),
 ('free american', 1),
 ('was applied', 1),
 ('family are', 1),
 ('various sections', 1),
 ('endeavor mutually', 1),
 ('however repugnant', 1),
 ('triple tie', 1),
 ('bolivar possessed', 1),
 ('forbearing characters', 1),
 ('any legitimate', 1),
 ('confidence although', 1),
 ('concerns however', 1),
 ('made accessible', 1),
 ('observance inflict', 1),
 ('dominant passions', 1),
 ('devoted attachment', 1),
 ('appears may', 1),
 ('mistaken enthusiast', 1),
 ('friendly intercourse', 1),
 ('become destructive', 1),
 ('hitherto without', 1),
 ('words used', 1),
 ('most indigent', 1),
 ('helvetic confederacy', 1),
 ('may receive', 1),
 ('rich are', 1),
 ('amendatory power', 1),
 ('extensively complained', 1),
 ('citizen--the grant', 1),
 ('great difference', 1),
 ('currency amongst', 1),
 ('england spoke', 1),
 ('were once', 1),
 ('fair construction', 1),
 ('subjects are', 1),
 ('earnest desire', 1),
 ('us acquainted', 1),
 ('checked such', 1),
 ('hasty legislation', 1),
 ('much deprecated', 1),
 ('distinguished continue', 1),
 ('leading democratic', 1),
 ('people--a breath', 1),
 ('principle certainly', 1),
 ('aboriginal neighbors', 1),
 ('gone forth', 1),
 ('faction--a spirit', 1),
 ('least virtually', 1),
 ('power claimed', 1),
 ('nothing beyond', 1),
 ('had early', 1),
 ('any confederacy', 1),
 ('unpatriotic motive', 1),
 ('writers upon', 1),
 ('such constituents', 1),
 ('citizen derives', 1),
 ('between free', 1),
 ('own constant', 1),
 ('strictly proper', 1),
 ('greater sacrifices', 1),
 ('better calculated', 1),
 ('produce such', 1),
 ('after well-ascertained', 1),
 ('most precious', 1),
 ('another occasion', 1),
 ('separate states', 1),
 ('anyone should', 1),
 ('constitution may', 1),
 ('most distinguished', 1),
 ('casual observer', 1),
 ('secure tranquillity', 1),
 ('proper therefore', 1),
 ('liberty although', 1),
 ('profound reverence', 1),
 ('enlightened assembly', 1),
 ('commending every', 1),
 ('constitution should', 1),
 ('citizens being', 1),
 ('existed among', 1),
 ('best realized', 1),
 ('determined never', 1),
 ...]

In [15]:
import matplotlib.pyplot as plt

plt.hist(filter(lambda y:y>1,map(lambda x:x[-1],sortedNGrams)),bins=20)  # 统计各个词频下种类的个数,这里使用filter去掉了出现一次的词了
plt.xlabel('words frequence')
plt.ylabel('times')
plt.show()



In [ ]:
# 更多统计等你自己好好玩