# ACT2-4 functions.
# As comleted by Jadrian's CS0931 class, 2013-03-07.

'''This Program returns the vocabulary size of Moby Dick.'''

def readMobyDickShort():
    '''Reads the text file MobyDick.txt and returns a list of words from the first 1000 characters'''
    fileName = 'MobyDick.txt'
    myFile = open(fileName,'r')
    fileString = myFile.read()
    myFile.close()
    fileString = fileString[0:1000]
    myList = fileString.split()
    return myList

def readMobyDickAll():
    '''Reads the text file MobyDick.txt and returns a list of words from the entire text'''
    fileName = 'MobyDick.txt'
    myFile = open(fileName,'r')
    fileString = myFile.read()
    myFile.close()
    print 'Warning! Returning the entire list of words!'
    myList = fileString.split()
    return myList

def vocabSize():
    '''Gets the vocabulary size of Moby Dick.'''
    wordList = readMobyDickShort()
    return len(uniqueWords(wordList))

def appendToList(listOfWords, word):
    listOfWords = listOfWords + [word]
    return listOfWords

def isInAList(listOfWords, word):
    # Check whether a single word is in a list of words.
    for eachWord in listOfWords:
        if eachWord == word:
            return True
    return False

def testIsInAList():
    if isInAList(['happy', 'birthday', 'to', 'you'], 'to') != True:
        return False
    if isInAList(['happy', 'birthday', 'to', 'you'], 'me') != False:
        return False
    return True

def uniqueWords(wordList):
    # Create a blank "unique" list.  Check every word in the word list; if it's
    # not in the "unique" list, add it, but if it is in the "unique" list, skip
    # it.
    uniqueList = []
    for word in wordList:
        if not(isInAList(uniqueList, word)):
            uniqueList = appendToList(uniqueList, word)
    return uniqueList

def testUniqueWords():
    if uniqueWords(['Call', 'me', 'maybe', 'me']) != ['Call', 'me', 'maybe']:
        return False
    return True
