def tf_idf(txtFile):
    reviewFile = txtFile
    with open(reviewFile, 'r', encoding='utf8') as file:
        txt = file.read().replace('\n', '')
    reviewList = txt.split('<br /><br />')
    numReviews = len(reviewList)
    for review in reviewList:
        review = re.sub('[^\\w\\s]', '', review)
    vocabTokens = createVocabTokens(reviewList)
    vocabDictIDF = dict.fromkeys(vocabTokens, 0)
    'for i in range(len(reviewList)):\n        words = extractCleanWords(reviewList[i])\n        #bagList = numpy.zeros(len(vocabTokens))\n        for word in words:\n            vocabDict[word] += 1'
    totalNumWords = 0
    sparseMatrixTFIDF = []
    for i in range(len(reviewList)):
        words = extractCleanWords(reviewList[i])
        bagListTF = {}
        for word in words:
            totalNumWords += 1
            if (word in bagListTF):
                bagListTF[word] += 1
            else:
                bagListTF[word] = 1
        for word in list(set(words)):
            bagListTF[word] = (bagListTF[word] / totalNumWords)
            vocabDictIDF[word] += 1
        sparseMatrixTFIDF.append(bagListTF)
    vocabDict = dict.fromkeys(vocabTokens, 0)
    for dictTF in sparseMatrixTFIDF:
        for word in dictTF:
            dictTF[word] = (dictTF[word] * math.log((len(reviewList) / vocabDictIDF[word])))
            vocabDict[word] += dictTF[word]
    return (sparseMatrixTFIDF, vocabDict, numReviews)
def tf_idf(txtFile):
    reviewFile = txtFile
    with open(reviewFile, 'r', encoding='utf8') as file:
        txt = file.read().replace('\n', )
    reviewList = txt.split('<br /><br />')
    numReviews = len(reviewList)
    for review in reviewList:
        review = re.sub('[^\\w\\s]', , review)
    vocabTokens = createVocabTokens(reviewList)
    vocabDictIDF = dict.fromkeys(vocabTokens, 0)
    'for i in range(len(reviewList)):\n        words = extractCleanWords(reviewList[i])\n        #bagList = numpy.zeros(len(vocabTokens))\n        for word in words:\n            vocabDict[word] += 1'
    totalNumWords = 0
    sparseMatrixTFIDF = []
    for i in range(len(reviewList)):
        words = extractCleanWords(reviewList[i])
        bagListTF = {}
        for word in words:
            totalNumWords += 1
            if (word in bagListTF):
                bagListTF[word] += 1
            else:
                bagListTF[word] = 1
        for word in list(set(words)):
            bagListTF[word] = (bagListTF[word] / totalNumWords)
            vocabDictIDF[word] += 1
        sparseMatrixTFIDF.append(bagListTF)
    vocabDict = dict.fromkeys(vocabTokens, 0)
    for dictTF in sparseMatrixTFIDF:
        for word in dictTF:
            dictTF[word] = (dictTF[word] * math.log((len(reviewList) / vocabDictIDF[word])))
            vocabDict[word] += dictTF[word]
    return (sparseMatrixTFIDF, vocabDict, numReviews)