text: # helper.py
  
  # DATA 620 Assignment 12
  # Written by Carlton B. Matthews II
  # Last Updated 20 April 2016
  # Utility Package for Assignment 12 
  # Contains the functions for building the word
  # frequency dictionaries and sorted list.
  # Contains the stop words list
  
  # Build my stop words list
  stopwords = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
  stopwords += ['a', 'about', 'above', 'across', 'after', 'afterwards']
  stopwords += ['again', 'against', 'all', 'almost', 'alone', 'along']
  stopwords += ['already', 'also', 'although', 'always', 'am', 'among']
  stopwords += ['amongst', 'amoungst', 'amount', 'an', 'and', 'another']
  stopwords += ['any', 'anyhow', 'anyone', 'anything', 'anyway', 'anywhere']
  stopwords += ['are', 'around', 'as', 'at', 'back', 'be', 'became']
  stopwords += ['because', 'become', 'becomes', 'becoming', 'been']
  stopwords += ['before', 'beforehand', 'behind', 'being', 'below']
  stopwords += ['beside', 'besides', 'between', 'beyond', 'bill', 'both']
  stopwords += ['bottom', 'but', 'by', 'call', 'can', 'cannot', 'cant']
  stopwords += ['co', 'computer', 'con', 'could', 'couldnt', 'cry', 'de']
  stopwords += ['describe', 'detail', 'did', 'do', 'done', 'down', 'due']
  stopwords += ['during', 'each', 'eg', 'eight', 'either', 'eleven', 'else']
  stopwords += ['elsewhere', 'empty', 'enough', 'etc', 'even', 'ever']
  stopwords += ['every', 'everyone', 'everything', 'everywhere', 'except', 'far']
  stopwords += ['few', 'fifteen', 'fifty', 'fill', 'find', 'fire', 'first']
  stopwords += ['five', 'for', 'former', 'formerly', 'forty', 'found']
  stopwords += ['four', 'from', 'front', 'full', 'further', 'get', 'give']
  stopwords += ['go', 'had', 'has', 'hasnt', 'have', 'he', 'hence', 'her']
  stopwords += ['here', 'hereafter', 'hereby', 'herein', 'hereupon', 'hers']
  stopwords += ['herself', 'him', 'himself', 'his', 'how', 'however']
  stopwords += ['hundred', 'i', 'ie', 'if', 'in', 'inc', 'indeed']
  stopwords += ['interest', 'into', 'is', 'it', 'its', 'itself', 'keep']
  stopwords += ['last', 'latter', 'latterly', 'least', 'less', 'long', 'ltd', 'made', 'm']
  stopwords += ['many', 'may', 'me', 'meanwhile', 'might', 'mill', 'mine']
  stopwords += ['more', 'moreover', 'most', 'mostly', 'move', 'mr', 'much']
  stopwords += ['must', 'my', 'myself', 'name', 'namely', 'neither', 'never']
  stopwords += ['nevertheless', 'new', 'next', 'nine', 'no', 'nobody', 'none']
  stopwords += ['noone', 'non', 'nor', 'not', 'nothing', 'now', 'nowhere', 'of']
  stopwords += ['off', 'often', 'on','once', 'one', 'only', 'onto', 'or']
  stopwords += ['other', 'others', 'otherwise', 'our', 'ours', 'ourselves']
  stopwords += ['out', 'over', 'own', 'p', 'part', 'per', 'perhaps', 'please']
  stopwords += ['put', 'rather', 're', 's', 'same', 'see', 'seem', 'seemed']
  stopwords += ['seeming', 'seems', 'serious', 'several', 'she', 'should']
  stopwords += ['show', 'side', 'since', 'sincere', 'six', 'sixty', 'so']
  stopwords += ['some', 'somehow', 'someone', 'something', 'sometime', 't']
  stopwords += ['sometimes', 'somewhere', 'still', 'such', 'system', 'take']
  stopwords += ['ten', 'than', 'that', 'the', 'their', 'them', 'themselves']
  stopwords += ['then', 'thence', 'there', 'thereafter', 'thereby']
  stopwords += ['therefore', 'therein', 'thereupon', 'these', 'they']
  stopwords += ['thick', 'thin', 'third', 'this', 'those', 'though', 'three']
  stopwords += ['three', 'through', 'throughout', 'thru', 'thus', 'time', 'to']
  stopwords += ['together', 'too', 'top', 'toward', 'towards', 'twelve']
  stopwords += ['twenty', 'two', 'u', 'un', 'under', 'until', 'up', 'upon']
  stopwords += ['us', 've', 'very', 'via', 'was', 'we', 'well', 'were', 'what']
  stopwords += ['whatever', 'when', 'whence', 'whenever', 'where']
  stopwords += ['whereafter', 'whereas', 'whereby', 'wherein', 'whereupon']
  stopwords += ['wherever', 'whether', 'which', 'while', 'whither', 'who']
  stopwords += ['whoever', 'whole', 'whom', 'whose', 'why', 'will', 'with']
  stopwords += ['within', 'without', 'would', 'year', 'years', 'yet', 'you', 'your']
  stopwords += ['yours', 'yourself', 'yourselves']
  
  # Given a file name, return a blob of text
  def getText(filename):
  	bulkdata = open(filename, 'r') #Open File
  	return bulkdata.read()
  
  
  def getSortedList(text):
  	# Remove all non-alphanumeric characters using a regular expression
  	import re
  	bloblist = re.compile(r'\W+', re.UNICODE).split(text)
  
  	# Remove any of the words in the stopwords list
  	wordlist = [w for w in bloblist if w.lower() not in stopwords]
  
  	# Create a dictionary of word and word frequency pairs
  	wordfreq = [wordlist.count(p) for p in wordlist]
  	dictionary =  dict(list(zip(wordlist,wordfreq)))
  
  	# Sort the dictionay in decending order
  	aux = [(dictionary[key], key) for key in dictionary]
  	aux.sort()
  	aux.reverse()
  
  	# Return the sorted list.
  	return aux