import pandas as pd
import nltk
from nltk.util import ngrams
nltk.download('punkt')
nltk.download('stopwords')
#Importing the dataset
%cd C:\Users\Matt\Dropbox\Python Workspace\CROW\CROL-PDF
data = pd.read_csv("procPublicationRequest_Oct-Dec_2014_clean - procPublicationRequest_Oct-Dec_2014_clean.csv")
#Snagging the "human_readable" column
human_readableList = list(data['human_readable'])
#Turn the values into strings
strReadable = [str(a) for a in human_readableList]
#Split into individual words
listOfLists = [a.split() for a in strReadable]
[nltk_data] Downloading package punkt to [nltk_data] C:\Users\Matt\AppData\Roaming\nltk_data... [nltk_data] Package punkt is already up-to-date! [nltk_data] Downloading package stopwords to [nltk_data] C:\Users\Matt\AppData\Roaming\nltk_data... [nltk_data] Package stopwords is already up-to-date! C:\Users\Matt\Dropbox\Python Workspace\CROW\CROL-PDF
#While we're here, let's output the raw words to a text file
myCorpus = ''
for myEntry in strReadable:
myCorpus = myCorpus + "\n"+ myEntry
f = open('rawCorpus', 'w')
f.write(myCorpus)
f.close()
#Now we have a data file that'll probably a little faster to mess with (maybe?)
file = open('rawCorpus.txt')
t = file.read()
#Let's tokenize it and turn into an NLTK Text file
myCorpusTokenized = nltk.word_tokenize(t)
corpusText = nltk.Text(myCorpusTokenized)
#Now that we've got a bigger body of text, we can look at more interesting patterns in phrasing
corpusText.collocations()
New York; substantially similar; similar titles; titles within; HEREBY GIVEN; within agency; York City; sidewalk caf; 10:00 A.M.; proposed contract; Annual Contracting; Contracting Plan; agency intends; 2015 Annual; public hearing; square foot; unenclosed sidewalk; COMMUNITY BOARD; four years; End date
corpusFreqDist = nltk.FreqDist(corpusText)
#Most commom words!
list(corpusFreqDist.most_common(50))
[(',', 8033), ('the', 4860), ('of', 4570), ('.', 2727), ('and', 2338), ('to', 2179), (')', 1806), ('(', 1747), (':', 1714), ('in', 1520), ('a', 1259), ('at', 1207), ('for', 1125), ('New', 1107), ('York', 988), ('Street', 910), ('on', 875), ('be', 674), ('City', 665), ('The', 641), ('proposed', 561), ('by', 519), ('an', 513), ('is', 501), ('contract', 498), ('Manhattan', 470), ('will', 461), ('agency', 397), ('that', 396), ('$', 382), ('2014', 379), ('from', 369), ('Borough', 363), ('Floor', 360), ('within', 354), ('Avenue', 332), ('NY', 329), ('date', 321), ('1', 321), ("'s", 311), ('Board', 292), ('public', 285), ('similar', 280), ('or', 279), ('Services', 278), ('Department', 274), ('titles', 272), ('substantially', 272), ('as', 264), ('with', 252)]
#Let's clean things up a little bit. Changing everything to lower-case is usually a good idea.
#"Public Hearing" will equal "PUBLIC HEARING"
lowerTokens = [w.lower() for w in myCorpusTokenized]
lowerText = nltk.Text(lowerTokens)
list(nltk.FreqDist(lowerText).most_common(50))
#Already saved some doubling-up! Note the 5649 mentions of "the", instead of 4860 like in the last list
[(',', 8033), ('the', 5649), ('of', 4822), ('.', 2727), ('to', 2409), ('and', 2392), (')', 1806), ('(', 1747), (':', 1714), ('in', 1686), ('a', 1419), ('for', 1261), ('at', 1215), ('new', 1191), ('york', 1003), ('street', 988), ('on', 888), ('is', 704), ('city', 698), ('be', 674), ('agency', 647), ('contract', 623), ('proposed', 583), ('an', 533), ('public', 532), ('by', 522), ('services', 510), ('manhattan', 479), ('floor', 469), ('will', 461), ('that', 425), ('borough', 414), ('notice', 401), ('board', 396), ('hearing', 385), ('$', 382), ('from', 379), ('2014', 379), ('date', 363), ('within', 356), ('avenue', 336), ('ny', 329), ('district', 325), ("'s", 324), ('1', 321), ('application', 315), ('community', 307), ('a.m.', 291), ('personnel', 290), ('department', 285)]
#Let's see some bigrams!
corpusBigrams = list(ngrams(lowerTokens,2))
corpusBigramFreqs = nltk.FreqDist(corpusBigrams)
corpusBigramFreqs.most_common(50)
[(('of', 'the'), 1267), (('new', 'york'), 999), (('in', 'the'), 666), (('street', ','), 633), (('.', 'the'), 491), ((',', 'new'), 460), (('the', 'proposed'), 454), (('agency', ':'), 409), ((',', 'and'), 392), (('borough', 'of'), 378), (('york', ','), 372), ((',', '2014'), 363), (('contract', ':'), 343), (('for', 'the'), 335), (('to', 'the'), 334), (('york', 'city'), 321), (('date', 'of'), 317), (('on', 'the'), 316), ((',', 'ny'), 314), (('will', 'be'), 308), (('public', 'hearing'), 280), (('substantially', 'similar'), 276), (('in', 'substantially'), 272), (('personnel', 'in'), 272), (('similar', 'titles'), 272), (('titles', 'within'), 269), (('department', 'of'), 266), (('floor', ','), 264), (('within', 'agency'), 264), (('pursuant', 'to'), 259), (('at', 'the'), 252), (('for', 'a'), 241), (('proposed', 'contract'), 228), (('of', 'manhattan'), 226), (('the', 'new'), 221), (('notice', 'is'), 217), (('the', 'following'), 214), (('of', 'a'), 213), (('is', 'hereby'), 213), (('hereby', 'given'), 212), (('--', '--'), 210), (('manhattan', ','), 208), ((',', 'manhattan'), 207), ((',', 'at'), 204), (('the', 'borough'), 202), (('the', 'agency'), 201), (('(', 's'), 196), (('s', ')'), 196), (('office', 'of'), 189), (('of', 'services'), 188)]
#Let's see tri-grams!
corpusTrigrams = list(ngrams(lowerTokens,3))
corpusTrigramFreqs = nltk.FreqDist(corpusTrigrams)
corpusTrigramFreqs.most_common(50)
[((',', 'new', 'york'), 457), (('new', 'york', ','), 372), (('new', 'york', 'city'), 321), (('of', 'the', 'proposed'), 307), (('date', 'of', 'the'), 274), (('in', 'substantially', 'similar'), 272), (('personnel', 'in', 'substantially'), 272), (('substantially', 'similar', 'titles'), 272), (('similar', 'titles', 'within'), 269), (('within', 'agency', ':'), 264), (('titles', 'within', 'agency'), 264), (('borough', 'of', 'manhattan'), 223), (('notice', 'is', 'hereby'), 213), (('is', 'hereby', 'given'), 212), (('the', 'new', 'york'), 206), (('--', '--', '--'), 204), (('the', 'proposed', 'contract'), 201), (('(', 's', ')'), 196), (('proposed', 'contract', ':'), 189), (('in', 'the', 'borough'), 187), (('the', 'borough', 'of'), 187), (('hereby', 'given', 'that'), 185), (('york', ',', 'ny'), 173), (('agency', 'intends', 'to'), 169), (('the', 'agency', 'intends'), 166), (('of', 'new', 'york'), 165), (('end', 'date', 'of'), 145), ((',', 'borough', 'of'), 144), (('to', 'utilize', ':'), 137), (('intends', 'to', 'utilize'), 137), (('a', 'term', 'of'), 136), (('headcount', 'of', 'personnel'), 136), (('of', 'personnel', 'in'), 136), (('for', 'a', 'term'), 136), (('start', 'date', 'of'), 133), (('not', 'included', 'in'), 128), (('annual', 'contracting', 'plan'), 126), (('contracting', 'plan', 'and'), 126), (('s', ')', 'not'), 126), (('plan', 'and', 'schedule'), 126), ((')', 'not', 'included'), 126), (('and', 'operate', 'an'), 125), ((',', 'and', 'operate'), 124), (('caf', 'for', 'a'), 124), (('fy', '2015', 'annual'), 124), (('2015', 'annual', 'contracting'), 124), (('maintain', ',', 'and'), 124), (('sidewalk', 'caf', 'for'), 124), (('years', '.', ')'), 123), (('unenclosed', 'sidewalk', 'caf'), 120)]
#We can keep going!
corpus4grams = list(ngrams(lowerTokens,4))
corpus4gramFreqs = nltk.FreqDist(corpus4grams)
corpus4gramFreqs.most_common(50)
[(('personnel', 'in', 'substantially', 'similar'), 272), (('in', 'substantially', 'similar', 'titles'), 272), (('substantially', 'similar', 'titles', 'within'), 269), ((',', 'new', 'york', ','), 269), (('titles', 'within', 'agency', ':'), 264), (('similar', 'titles', 'within', 'agency'), 264), (('date', 'of', 'the', 'proposed'), 264), (('notice', 'is', 'hereby', 'given'), 212), (('the', 'new', 'york', 'city'), 199), (('of', 'the', 'proposed', 'contract'), 199), (('--', '--', '--', '--'), 198), (('the', 'proposed', 'contract', ':'), 186), (('is', 'hereby', 'given', 'that'), 185), (('in', 'the', 'borough', 'of'), 183), (('new', 'york', ',', 'ny'), 173), (('the', 'agency', 'intends', 'to'), 166), (('agency', 'intends', 'to', 'utilize'), 137), (('intends', 'to', 'utilize', ':'), 137), (('for', 'a', 'term', 'of'), 136), (('headcount', 'of', 'personnel', 'in'), 136), (('of', 'personnel', 'in', 'substantially'), 136), (('start', 'date', 'of', 'the'), 131), (('end', 'date', 'of', 'the'), 131), (('s', ')', 'not', 'included'), 126), (('(', 's', ')', 'not'), 126), (('annual', 'contracting', 'plan', 'and'), 126), ((')', 'not', 'included', 'in'), 126), (('contracting', 'plan', 'and', 'schedule'), 126), (('sidewalk', 'caf', 'for', 'a'), 124), ((',', 'and', 'operate', 'an'), 124), (('fy', '2015', 'annual', 'contracting'), 124), (('caf', 'for', 'a', 'term'), 124), (('maintain', ',', 'and', 'operate'), 124), (('2015', 'annual', 'contracting', 'plan'), 124), (('the', 'borough', 'of', 'manhattan'), 123), (('unenclosed', 'sidewalk', 'caf', 'for'), 120), (('new', 'york', 'city', 'charter'), 116), (('hereby', 'given', 'that', 'the'), 116), (('operate', 'an', 'unenclosed', 'sidewalk'), 112), (('an', 'unenclosed', 'sidewalk', 'caf'), 112), (('and', 'operate', 'an', 'unenclosed'), 112), (('22', 'reade', 'street', ','), 109), (('city', 'of', 'new', 'york'), 108), (('in', 'the', 'matter', 'of'), 106), (('the', 'city', 'of', 'new'), 105), (('of', 'services', 'sought', ':'), 104), (('solicitation', 'the', 'agency', 'intends'), 103), (('method', 'of', 'solicitation', 'the'), 103), (('of', 'solicitation', 'the', 'agency'), 103), (('a', 'term', 'of', 'four'), 102)]
corpus5grams = list(ngrams(lowerTokens,5))
corpus5gramFreqs = nltk.FreqDist(corpus5grams)
corpus5gramFreqs.most_common(50)
[(('personnel', 'in', 'substantially', 'similar', 'titles'), 272), (('in', 'substantially', 'similar', 'titles', 'within'), 269), (('similar', 'titles', 'within', 'agency', ':'), 264), (('substantially', 'similar', 'titles', 'within', 'agency'), 264), (('--', '--', '--', '--', '--'), 192), (('of', 'the', 'proposed', 'contract', ':'), 186), (('date', 'of', 'the', 'proposed', 'contract'), 186), (('notice', 'is', 'hereby', 'given', 'that'), 185), ((',', 'new', 'york', ',', 'ny'), 152), (('agency', 'intends', 'to', 'utilize', ':'), 137), (('headcount', 'of', 'personnel', 'in', 'substantially'), 136), (('of', 'personnel', 'in', 'substantially', 'similar'), 136), (('the', 'agency', 'intends', 'to', 'utilize'), 134), (('start', 'date', 'of', 'the', 'proposed'), 131), (('end', 'date', 'of', 'the', 'proposed'), 131), (('(', 's', ')', 'not', 'included'), 126), (('annual', 'contracting', 'plan', 'and', 'schedule'), 126), (('s', ')', 'not', 'included', 'in'), 126), (('maintain', ',', 'and', 'operate', 'an'), 124), (('caf', 'for', 'a', 'term', 'of'), 124), (('2015', 'annual', 'contracting', 'plan', 'and'), 124), (('fy', '2015', 'annual', 'contracting', 'plan'), 124), (('sidewalk', 'caf', 'for', 'a', 'term'), 124), (('in', 'the', 'borough', 'of', 'manhattan'), 121), (('unenclosed', 'sidewalk', 'caf', 'for', 'a'), 120), (('is', 'hereby', 'given', 'that', 'the'), 116), (('an', 'unenclosed', 'sidewalk', 'caf', 'for'), 112), (('operate', 'an', 'unenclosed', 'sidewalk', 'caf'), 112), ((',', 'and', 'operate', 'an', 'unenclosed'), 112), (('and', 'operate', 'an', 'unenclosed', 'sidewalk'), 112), (('the', 'city', 'of', 'new', 'york'), 104), (('method', 'of', 'solicitation', 'the', 'agency'), 103), (('of', 'solicitation', 'the', 'agency', 'intends'), 103), (('solicitation', 'the', 'agency', 'intends', 'to'), 103), (('a', 'term', 'of', 'four', 'years'), 102), (('for', 'a', 'term', 'of', 'four'), 102), (('of', 'four', 'years', '.', ')'), 101), (('term', 'of', 'four', 'years', '.'), 101), (('the', 'borough', 'of', 'manhattan', '('), 100), ((',', '22', 'reade', 'street', ','), 100), (('borough', 'of', 'manhattan', '(', 'to'), 99), (('to', 'maintain', ',', 'and', 'operate'), 98), (('floor', ',', 'new', 'york', ','), 96), (('solicitation', '(', 's', ')', 'not'), 94), (('titles', 'within', 'agency', ':', 'none'), 93), (('none', 'headcount', 'of', 'personnel', 'in'), 92), (('agency', ':', 'none', 'headcount', 'of'), 92), ((':', 'none', 'headcount', 'of', 'personnel'), 92), (('within', 'agency', ':', 'none', 'headcount'), 91), (('continue', 'to', 'maintain', ',', 'and'), 89)]
corpus6grams = list(ngrams(lowerTokens,6))
corpus6gramFreqs = nltk.FreqDist(corpus6grams)
corpus6gramFreqs.most_common(50)
[(('personnel', 'in', 'substantially', 'similar', 'titles', 'within'), 269), (('substantially', 'similar', 'titles', 'within', 'agency', ':'), 264), (('in', 'substantially', 'similar', 'titles', 'within', 'agency'), 264), (('--', '--', '--', '--', '--', '--'), 186), (('date', 'of', 'the', 'proposed', 'contract', ':'), 186), (('headcount', 'of', 'personnel', 'in', 'substantially', 'similar'), 136), (('of', 'personnel', 'in', 'substantially', 'similar', 'titles'), 136), (('the', 'agency', 'intends', 'to', 'utilize', ':'), 134), (('(', 's', ')', 'not', 'included', 'in'), 126), (('2015', 'annual', 'contracting', 'plan', 'and', 'schedule'), 124), (('sidewalk', 'caf', 'for', 'a', 'term', 'of'), 124), (('fy', '2015', 'annual', 'contracting', 'plan', 'and'), 124), (('unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term'), 120), (('notice', 'is', 'hereby', 'given', 'that', 'the'), 116), (('an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a'), 112), (('operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for'), 112), (('and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf'), 112), (('maintain', ',', 'and', 'operate', 'an', 'unenclosed'), 112), ((',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk'), 112), (('method', 'of', 'solicitation', 'the', 'agency', 'intends'), 103), (('of', 'solicitation', 'the', 'agency', 'intends', 'to'), 103), (('solicitation', 'the', 'agency', 'intends', 'to', 'utilize'), 103), (('caf', 'for', 'a', 'term', 'of', 'four'), 102), (('for', 'a', 'term', 'of', 'four', 'years'), 102), (('term', 'of', 'four', 'years', '.', ')'), 101), (('a', 'term', 'of', 'four', 'years', '.'), 101), (('in', 'the', 'borough', 'of', 'manhattan', '('), 100), (('the', 'borough', 'of', 'manhattan', '(', 'to'), 99), (('to', 'maintain', ',', 'and', 'operate', 'an'), 98), (('end', 'date', 'of', 'the', 'proposed', 'contract'), 96), (('solicitation', '(', 's', ')', 'not', 'included'), 94), (('similar', 'titles', 'within', 'agency', ':', 'none'), 93), (('agency', ':', 'none', 'headcount', 'of', 'personnel'), 92), (('none', 'headcount', 'of', 'personnel', 'in', 'substantially'), 92), ((':', 'none', 'headcount', 'of', 'personnel', 'in'), 92), (('titles', 'within', 'agency', ':', 'none', 'headcount'), 91), (('within', 'agency', ':', 'none', 'headcount', 'of'), 91), (('start', 'date', 'of', 'the', 'proposed', 'contract'), 90), (('continue', 'to', 'maintain', ',', 'and', 'operate'), 89), (('borough', 'of', 'manhattan', '(', 'to', 'continue'), 87), (('of', 'manhattan', '(', 'to', 'continue', 'to'), 86), (('(', 'to', 'continue', 'to', 'maintain', ','), 86), (('to', 'continue', 'to', 'maintain', ',', 'and'), 86), (('similar', 'titles', 'within', 'agency', ':', '0'), 83), (('spector', 'hall', ',', '22', 'reade', 'street'), 82), (('hall', ',', '22', 'reade', 'street', ','), 82), (('in', 'spector', 'hall', ',', '22', 'reade'), 81), (('manhattan', '(', 'to', 'continue', 'to', 'maintain'), 74), (('floor', ',', 'new', 'york', ',', 'ny'), 72), ((',', 'new', 'york', ',', 'ny', '10007'), 66)]
corpus7grams = list(ngrams(lowerTokens,7))
corpus7gramFreqs = nltk.FreqDist(corpus7grams)
corpus7gramFreqs.most_common(50)
[(('personnel', 'in', 'substantially', 'similar', 'titles', 'within', 'agency'), 264), (('in', 'substantially', 'similar', 'titles', 'within', 'agency', ':'), 264), (('--', '--', '--', '--', '--', '--', '--'), 180), (('headcount', 'of', 'personnel', 'in', 'substantially', 'similar', 'titles'), 136), (('of', 'personnel', 'in', 'substantially', 'similar', 'titles', 'within'), 133), (('fy', '2015', 'annual', 'contracting', 'plan', 'and', 'schedule'), 124), (('unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term', 'of'), 120), (('and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for'), 112), (('an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term'), 112), (('operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a'), 112), ((',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf'), 112), (('maintain', ',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk'), 112), (('of', 'solicitation', 'the', 'agency', 'intends', 'to', 'utilize'), 103), (('solicitation', 'the', 'agency', 'intends', 'to', 'utilize', ':'), 103), (('method', 'of', 'solicitation', 'the', 'agency', 'intends', 'to'), 103), (('sidewalk', 'caf', 'for', 'a', 'term', 'of', 'four'), 102), (('caf', 'for', 'a', 'term', 'of', 'four', 'years'), 102), (('a', 'term', 'of', 'four', 'years', '.', ')'), 101), (('for', 'a', 'term', 'of', 'four', 'years', '.'), 101), (('in', 'the', 'borough', 'of', 'manhattan', '(', 'to'), 99), (('end', 'date', 'of', 'the', 'proposed', 'contract', ':'), 96), (('solicitation', '(', 's', ')', 'not', 'included', 'in'), 94), (('substantially', 'similar', 'titles', 'within', 'agency', ':', 'none'), 93), (('none', 'headcount', 'of', 'personnel', 'in', 'substantially', 'similar'), 92), (('agency', ':', 'none', 'headcount', 'of', 'personnel', 'in'), 92), ((':', 'none', 'headcount', 'of', 'personnel', 'in', 'substantially'), 92), (('to', 'maintain', ',', 'and', 'operate', 'an', 'unenclosed'), 91), (('titles', 'within', 'agency', ':', 'none', 'headcount', 'of'), 91), (('similar', 'titles', 'within', 'agency', ':', 'none', 'headcount'), 91), (('within', 'agency', ':', 'none', 'headcount', 'of', 'personnel'), 91), (('start', 'date', 'of', 'the', 'proposed', 'contract', ':'), 90), (('continue', 'to', 'maintain', ',', 'and', 'operate', 'an'), 89), (('the', 'borough', 'of', 'manhattan', '(', 'to', 'continue'), 87), (('to', 'continue', 'to', 'maintain', ',', 'and', 'operate'), 86), (('(', 'to', 'continue', 'to', 'maintain', ',', 'and'), 86), (('borough', 'of', 'manhattan', '(', 'to', 'continue', 'to'), 86), (('substantially', 'similar', 'titles', 'within', 'agency', ':', '0'), 83), (('spector', 'hall', ',', '22', 'reade', 'street', ','), 82), (('in', 'spector', 'hall', ',', '22', 'reade', 'street'), 81), (('manhattan', '(', 'to', 'continue', 'to', 'maintain', ','), 74), (('of', 'manhattan', '(', 'to', 'continue', 'to', 'maintain'), 74), (('notice', 'is', 'hereby', 'given', 'that', 'the', 'mayor'), 65), (('s', ')', 'not', 'included', 'in', 'the', 'fy'), 63), (('hereby', 'given', 'that', 'the', 'mayor', 'will', 'be'), 63), (('schedule', 'that', 'is', 'published', 'pursuant', 'to', 'new'), 63), (('contracting', 'plan', 'and', 'schedule', 'notice', 'is', 'hereby'), 63), (('plan', 'and', 'schedule', 'notice', 'is', 'hereby', 'given'), 63), (('annual', 'contracting', 'plan', 'and', 'schedule', 'notice', 'is'), 63), (('to', 'new', 'york', 'city', 'charter', '312', '('), 63), (('annual', 'contracting', 'plan', 'and', 'schedule', 'that', 'is'), 63)]
corpus8grams = list(ngrams(lowerTokens,8))
corpus8gramFreqs = nltk.FreqDist(corpus8grams)
corpus8gramFreqs.most_common(50)
[(('personnel', 'in', 'substantially', 'similar', 'titles', 'within', 'agency', ':'), 264), (('--', '--', '--', '--', '--', '--', '--', '--'), 174), (('headcount', 'of', 'personnel', 'in', 'substantially', 'similar', 'titles', 'within'), 133), (('of', 'personnel', 'in', 'substantially', 'similar', 'titles', 'within', 'agency'), 129), (('and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a'), 112), ((',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for'), 112), (('maintain', ',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf'), 112), (('an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term', 'of'), 112), (('operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term'), 112), (('of', 'solicitation', 'the', 'agency', 'intends', 'to', 'utilize', ':'), 103), (('method', 'of', 'solicitation', 'the', 'agency', 'intends', 'to', 'utilize'), 103), (('sidewalk', 'caf', 'for', 'a', 'term', 'of', 'four', 'years'), 102), (('caf', 'for', 'a', 'term', 'of', 'four', 'years', '.'), 101), (('unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term', 'of', 'four'), 101), (('for', 'a', 'term', 'of', 'four', 'years', '.', ')'), 101), (('in', 'substantially', 'similar', 'titles', 'within', 'agency', ':', 'none'), 93), (('agency', ':', 'none', 'headcount', 'of', 'personnel', 'in', 'substantially'), 92), (('none', 'headcount', 'of', 'personnel', 'in', 'substantially', 'similar', 'titles'), 92), ((':', 'none', 'headcount', 'of', 'personnel', 'in', 'substantially', 'similar'), 92), (('titles', 'within', 'agency', ':', 'none', 'headcount', 'of', 'personnel'), 91), (('to', 'maintain', ',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk'), 91), (('similar', 'titles', 'within', 'agency', ':', 'none', 'headcount', 'of'), 91), (('substantially', 'similar', 'titles', 'within', 'agency', ':', 'none', 'headcount'), 91), (('within', 'agency', ':', 'none', 'headcount', 'of', 'personnel', 'in'), 91), (('in', 'the', 'borough', 'of', 'manhattan', '(', 'to', 'continue'), 87), (('the', 'borough', 'of', 'manhattan', '(', 'to', 'continue', 'to'), 86), (('(', 'to', 'continue', 'to', 'maintain', ',', 'and', 'operate'), 86), (('to', 'continue', 'to', 'maintain', ',', 'and', 'operate', 'an'), 86), (('in', 'substantially', 'similar', 'titles', 'within', 'agency', ':', '0'), 83), (('continue', 'to', 'maintain', ',', 'and', 'operate', 'an', 'unenclosed'), 82), (('in', 'spector', 'hall', ',', '22', 'reade', 'street', ','), 81), (('borough', 'of', 'manhattan', '(', 'to', 'continue', 'to', 'maintain'), 74), (('manhattan', '(', 'to', 'continue', 'to', 'maintain', ',', 'and'), 74), (('of', 'manhattan', '(', 'to', 'continue', 'to', 'maintain', ','), 74), (('notice', 'is', 'hereby', 'given', 'that', 'the', 'mayor', 'will'), 63), (('contracting', 'plan', 'and', 'schedule', 'that', 'is', 'published', 'pursuant'), 63), (('annual', 'contracting', 'plan', 'and', 'schedule', 'notice', 'is', 'hereby'), 63), (('to', 'new', 'york', 'city', 'charter', '312', '(', 'a'), 63), (('(', 's', ')', 'not', 'included', 'in', 'the', 'fy'), 63), (('annual', 'contracting', 'plan', 'and', 'schedule', 'that', 'is', 'published'), 63), (('pursuant', 'to', 'new', 'york', 'city', 'charter', '312', '('), 63), (('that', 'is', 'published', 'pursuant', 'to', 'new', 'york', 'city'), 63), (('city', 'charter', '312', '(', 'a', ')', ':', 'agency'), 63), (('schedule', 'notice', 'is', 'hereby', 'given', 'that', 'the', 'mayor'), 63), (('published', 'pursuant', 'to', 'new', 'york', 'city', 'charter', '312'), 63), (('schedule', 'that', 'is', 'published', 'pursuant', 'to', 'new', 'york'), 63), (('contracting', 'plan', 'and', 'schedule', 'notice', 'is', 'hereby', 'given'), 63), (('york', 'city', 'charter', '312', '(', 'a', ')', ':'), 63), (('and', 'schedule', 'notice', 'is', 'hereby', 'given', 'that', 'the'), 63), (('plan', 'and', 'schedule', 'notice', 'is', 'hereby', 'given', 'that'), 63)]
corpus9grams = list(ngrams(lowerTokens,9))
corpus9gramFreqs = nltk.FreqDist(corpus9grams)
corpus9gramFreqs.most_common(50)
[(('--', '--', '--', '--', '--', '--', '--', '--', '--'), 168), (('of', 'personnel', 'in', 'substantially', 'similar', 'titles', 'within', 'agency', ':'), 129), (('headcount', 'of', 'personnel', 'in', 'substantially', 'similar', 'titles', 'within', 'agency'), 129), (('maintain', ',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for'), 112), ((',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a'), 112), (('and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term'), 112), (('operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term', 'of'), 112), (('method', 'of', 'solicitation', 'the', 'agency', 'intends', 'to', 'utilize', ':'), 103), (('sidewalk', 'caf', 'for', 'a', 'term', 'of', 'four', 'years', '.'), 101), (('unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term', 'of', 'four', 'years'), 101), (('caf', 'for', 'a', 'term', 'of', 'four', 'years', '.', ')'), 101), (('an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term', 'of', 'four'), 94), (('personnel', 'in', 'substantially', 'similar', 'titles', 'within', 'agency', ':', 'none'), 93), ((':', 'none', 'headcount', 'of', 'personnel', 'in', 'substantially', 'similar', 'titles'), 92), (('agency', ':', 'none', 'headcount', 'of', 'personnel', 'in', 'substantially', 'similar'), 92), (('within', 'agency', ':', 'none', 'headcount', 'of', 'personnel', 'in', 'substantially'), 91), (('to', 'maintain', ',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf'), 91), (('substantially', 'similar', 'titles', 'within', 'agency', ':', 'none', 'headcount', 'of'), 91), (('similar', 'titles', 'within', 'agency', ':', 'none', 'headcount', 'of', 'personnel'), 91), (('titles', 'within', 'agency', ':', 'none', 'headcount', 'of', 'personnel', 'in'), 91), (('in', 'substantially', 'similar', 'titles', 'within', 'agency', ':', 'none', 'headcount'), 91), (('none', 'headcount', 'of', 'personnel', 'in', 'substantially', 'similar', 'titles', 'within'), 89), (('(', 'to', 'continue', 'to', 'maintain', ',', 'and', 'operate', 'an'), 86), (('in', 'the', 'borough', 'of', 'manhattan', '(', 'to', 'continue', 'to'), 86), (('personnel', 'in', 'substantially', 'similar', 'titles', 'within', 'agency', ':', '0'), 83), (('continue', 'to', 'maintain', ',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk'), 82), (('to', 'continue', 'to', 'maintain', ',', 'and', 'operate', 'an', 'unenclosed'), 79), (('of', 'manhattan', '(', 'to', 'continue', 'to', 'maintain', ',', 'and'), 74), (('manhattan', '(', 'to', 'continue', 'to', 'maintain', ',', 'and', 'operate'), 74), (('borough', 'of', 'manhattan', '(', 'to', 'continue', 'to', 'maintain', ','), 74), (('the', 'borough', 'of', 'manhattan', '(', 'to', 'continue', 'to', 'maintain'), 74), (('and', 'schedule', 'notice', 'is', 'hereby', 'given', 'that', 'the', 'mayor'), 63), (('schedule', 'that', 'is', 'published', 'pursuant', 'to', 'new', 'york', 'city'), 63), (('to', 'new', 'york', 'city', 'charter', '312', '(', 'a', ')'), 63), (('contracting', 'plan', 'and', 'schedule', 'notice', 'is', 'hereby', 'given', 'that'), 63), (('city', 'charter', '312', '(', 'a', ')', ':', 'agency', ':'), 63), (('pursuant', 'to', 'new', 'york', 'city', 'charter', '312', '(', 'a'), 63), (('notice', 'is', 'hereby', 'given', 'that', 'the', 'mayor', 'will', 'be'), 63), (('that', 'is', 'published', 'pursuant', 'to', 'new', 'york', 'city', 'charter'), 63), (('york', 'city', 'charter', '312', '(', 'a', ')', ':', 'agency'), 63), (('and', 'schedule', 'that', 'is', 'published', 'pursuant', 'to', 'new', 'york'), 63), (('plan', 'and', 'schedule', 'notice', 'is', 'hereby', 'given', 'that', 'the'), 63), (('annual', 'contracting', 'plan', 'and', 'schedule', 'notice', 'is', 'hereby', 'given'), 63), (('schedule', 'notice', 'is', 'hereby', 'given', 'that', 'the', 'mayor', 'will'), 63), (('plan', 'and', 'schedule', 'that', 'is', 'published', 'pursuant', 'to', 'new'), 63), (('contracting', 'plan', 'and', 'schedule', 'that', 'is', 'published', 'pursuant', 'to'), 63), (('new', 'york', 'city', 'charter', '312', '(', 'a', ')', ':'), 63), (('published', 'pursuant', 'to', 'new', 'york', 'city', 'charter', '312', '('), 63), (('is', 'published', 'pursuant', 'to', 'new', 'york', 'city', 'charter', '312'), 63), (('annual', 'contracting', 'plan', 'and', 'schedule', 'that', 'is', 'published', 'pursuant'), 63)]
corpus5grams = ngrams(lowerTokens,5)
corpus5gramFreqs = nltk.FreqDist(corpus5grams)
corpus5gramFreqs.most_common(50)
[(('personnel', 'in', 'substantially', 'similar', 'titles'), 272), (('in', 'substantially', 'similar', 'titles', 'within'), 269), (('similar', 'titles', 'within', 'agency', ':'), 264), (('substantially', 'similar', 'titles', 'within', 'agency'), 264), (('--', '--', '--', '--', '--'), 192), (('of', 'the', 'proposed', 'contract', ':'), 186), (('date', 'of', 'the', 'proposed', 'contract'), 186), (('notice', 'is', 'hereby', 'given', 'that'), 185), ((',', 'new', 'york', ',', 'ny'), 152), (('agency', 'intends', 'to', 'utilize', ':'), 137), (('headcount', 'of', 'personnel', 'in', 'substantially'), 136), (('of', 'personnel', 'in', 'substantially', 'similar'), 136), (('the', 'agency', 'intends', 'to', 'utilize'), 134), (('start', 'date', 'of', 'the', 'proposed'), 131), (('end', 'date', 'of', 'the', 'proposed'), 131), (('(', 's', ')', 'not', 'included'), 126), (('annual', 'contracting', 'plan', 'and', 'schedule'), 126), (('s', ')', 'not', 'included', 'in'), 126), (('maintain', ',', 'and', 'operate', 'an'), 124), (('caf', 'for', 'a', 'term', 'of'), 124), (('2015', 'annual', 'contracting', 'plan', 'and'), 124), (('fy', '2015', 'annual', 'contracting', 'plan'), 124), (('sidewalk', 'caf', 'for', 'a', 'term'), 124), (('in', 'the', 'borough', 'of', 'manhattan'), 121), (('unenclosed', 'sidewalk', 'caf', 'for', 'a'), 120), (('is', 'hereby', 'given', 'that', 'the'), 116), (('an', 'unenclosed', 'sidewalk', 'caf', 'for'), 112), (('operate', 'an', 'unenclosed', 'sidewalk', 'caf'), 112), ((',', 'and', 'operate', 'an', 'unenclosed'), 112), (('and', 'operate', 'an', 'unenclosed', 'sidewalk'), 112), (('the', 'city', 'of', 'new', 'york'), 104), (('method', 'of', 'solicitation', 'the', 'agency'), 103), (('of', 'solicitation', 'the', 'agency', 'intends'), 103), (('solicitation', 'the', 'agency', 'intends', 'to'), 103), (('a', 'term', 'of', 'four', 'years'), 102), (('for', 'a', 'term', 'of', 'four'), 102), (('of', 'four', 'years', '.', ')'), 101), (('term', 'of', 'four', 'years', '.'), 101), (('the', 'borough', 'of', 'manhattan', '('), 100), ((',', '22', 'reade', 'street', ','), 100), (('borough', 'of', 'manhattan', '(', 'to'), 99), (('to', 'maintain', ',', 'and', 'operate'), 98), (('floor', ',', 'new', 'york', ','), 96), (('solicitation', '(', 's', ')', 'not'), 94), (('titles', 'within', 'agency', ':', 'none'), 93), (('none', 'headcount', 'of', 'personnel', 'in'), 92), (('agency', ':', 'none', 'headcount', 'of'), 92), ((':', 'none', 'headcount', 'of', 'personnel'), 92), (('within', 'agency', ':', 'none', 'headcount'), 91), (('continue', 'to', 'maintain', ',', 'and'), 89)]
#...and let's stop here for now
corpus10grams = list(ngrams(lowerTokens,10))
corpus10gramFreqs = nltk.FreqDist(corpus10grams)
corpus10gramFreqs.most_common(50)
[(('--', '--', '--', '--', '--', '--', '--', '--', '--', '--'), 162), (('headcount', 'of', 'personnel', 'in', 'substantially', 'similar', 'titles', 'within', 'agency', ':'), 129), (('maintain', ',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a'), 112), ((',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term'), 112), (('and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term', 'of'), 112), (('sidewalk', 'caf', 'for', 'a', 'term', 'of', 'four', 'years', '.', ')'), 101), (('unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term', 'of', 'four', 'years', '.'), 100), (('operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term', 'of', 'four'), 94), (('an', 'unenclosed', 'sidewalk', 'caf', 'for', 'a', 'term', 'of', 'four', 'years'), 94), (('agency', ':', 'none', 'headcount', 'of', 'personnel', 'in', 'substantially', 'similar', 'titles'), 92), (('in', 'substantially', 'similar', 'titles', 'within', 'agency', ':', 'none', 'headcount', 'of'), 91), (('substantially', 'similar', 'titles', 'within', 'agency', ':', 'none', 'headcount', 'of', 'personnel'), 91), (('titles', 'within', 'agency', ':', 'none', 'headcount', 'of', 'personnel', 'in', 'substantially'), 91), (('within', 'agency', ':', 'none', 'headcount', 'of', 'personnel', 'in', 'substantially', 'similar'), 91), (('personnel', 'in', 'substantially', 'similar', 'titles', 'within', 'agency', ':', 'none', 'headcount'), 91), (('similar', 'titles', 'within', 'agency', ':', 'none', 'headcount', 'of', 'personnel', 'in'), 91), (('to', 'maintain', ',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf', 'for'), 91), ((':', 'none', 'headcount', 'of', 'personnel', 'in', 'substantially', 'similar', 'titles', 'within'), 89), (('none', 'headcount', 'of', 'personnel', 'in', 'substantially', 'similar', 'titles', 'within', 'agency'), 85), (('of', 'personnel', 'in', 'substantially', 'similar', 'titles', 'within', 'agency', ':', '0'), 83), (('continue', 'to', 'maintain', ',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk', 'caf'), 82), (('(', 'to', 'continue', 'to', 'maintain', ',', 'and', 'operate', 'an', 'unenclosed'), 79), (('to', 'continue', 'to', 'maintain', ',', 'and', 'operate', 'an', 'unenclosed', 'sidewalk'), 79), (('the', 'borough', 'of', 'manhattan', '(', 'to', 'continue', 'to', 'maintain', ','), 74), (('manhattan', '(', 'to', 'continue', 'to', 'maintain', ',', 'and', 'operate', 'an'), 74), (('in', 'the', 'borough', 'of', 'manhattan', '(', 'to', 'continue', 'to', 'maintain'), 74), (('borough', 'of', 'manhattan', '(', 'to', 'continue', 'to', 'maintain', ',', 'and'), 74), (('of', 'manhattan', '(', 'to', 'continue', 'to', 'maintain', ',', 'and', 'operate'), 74), (('published', 'pursuant', 'to', 'new', 'york', 'city', 'charter', '312', '(', 'a'), 63), (('new', 'york', 'city', 'charter', '312', '(', 'a', ')', ':', 'agency'), 63), (('annual', 'contracting', 'plan', 'and', 'schedule', 'that', 'is', 'published', 'pursuant', 'to'), 63), (('is', 'published', 'pursuant', 'to', 'new', 'york', 'city', 'charter', '312', '('), 63), (('contracting', 'plan', 'and', 'schedule', 'notice', 'is', 'hereby', 'given', 'that', 'the'), 63), (('schedule', 'notice', 'is', 'hereby', 'given', 'that', 'the', 'mayor', 'will', 'be'), 63), (('and', 'schedule', 'that', 'is', 'published', 'pursuant', 'to', 'new', 'york', 'city'), 63), (('plan', 'and', 'schedule', 'that', 'is', 'published', 'pursuant', 'to', 'new', 'york'), 63), (('york', 'city', 'charter', '312', '(', 'a', ')', ':', 'agency', ':'), 63), (('pursuant', 'to', 'new', 'york', 'city', 'charter', '312', '(', 'a', ')'), 63), (('to', 'new', 'york', 'city', 'charter', '312', '(', 'a', ')', ':'), 63), (('schedule', 'that', 'is', 'published', 'pursuant', 'to', 'new', 'york', 'city', 'charter'), 63), (('that', 'is', 'published', 'pursuant', 'to', 'new', 'york', 'city', 'charter', '312'), 63), (('annual', 'contracting', 'plan', 'and', 'schedule', 'notice', 'is', 'hereby', 'given', 'that'), 63), (('and', 'schedule', 'notice', 'is', 'hereby', 'given', 'that', 'the', 'mayor', 'will'), 63), (('plan', 'and', 'schedule', 'notice', 'is', 'hereby', 'given', 'that', 'the', 'mayor'), 63), (('contracting', 'plan', 'and', 'schedule', 'that', 'is', 'published', 'pursuant', 'to', 'new'), 63), (('included', 'in', 'fy', '2015', 'annual', 'contracting', 'plan', 'and', 'schedule', 'notice'), 62), (('fy', '2015', 'annual', 'contracting', 'plan', 'and', 'schedule', 'that', 'is', 'published'), 62), (('in', 'the', 'fy', '2015', 'annual', 'contracting', 'plan', 'and', 'schedule', 'that'), 62), (('in', 'fy', '2015', 'annual', 'contracting', 'plan', 'and', 'schedule', 'notice', 'is'), 62), (('2015', 'annual', 'contracting', 'plan', 'and', 'schedule', 'that', 'is', 'published', 'pursuant'), 62)]