def main(): #recordAudio() recordInfo() fullData = dict() for folder in os.listdir( os.path.join(os.path.dirname(__file__), 'Pictures')): fullData[folder] = (detectVideoEmotion(os.path.join( 'Pictures', folder))) with open('appFaceData.json', 'w') as fp: fp.write(json.dumps(fullData)) print(fullData) scores = dict() for folder in os.listdir(os.path.join(os.path.dirname(__file__), 'Audio')): strList = (detectSpeech( os.path.join(os.path.dirname(__file__), 'Audio', folder))) sentiments = [] for item in strList: #print(item) sentiments.append(detectSpeechEmotion(item)) sum = 0 for item in sentiments: sum = sum + item sum = sum / len(sentiments) goodpart, badpart = os.path.splitext(folder) #print(goodpart) scores[(goodpart)] = sum #print(sum) sortedSpeechData = dict() for k in sorted(scores.keys()): sortedSpeechData[k] = scores[k] with open("appSpeechData.json", "w") as fp: fp.write(json.dumps(sortedSpeechData)) #print(sortedSpeechData) graphs.makeGraph()
def cosineTranscripts(dataset, queryTranscript, queryName, reference, k): matrix, query = cosineComparison.calculateComparison(dataset, queryTranscript, k) scores = cosineComparison.scoreDocuments(query, matrix, reference) xAxis = [pair[0] for pair in scores] values = [pair[1] for pair in scores] graphs.makeGraph(xAxis, "scores", "Transcript Cosine. Reference = {0} K = {1}".\ format(queryName,k), values)
def graphByMonthGraph(dicForm, title, context): monthScore = np.ones( [12]).tolist() # value is on dissimilarity so start at one months = generateMonths() for date in dicForm: month = date.month - 1 monthScore[month] -= dicForm[date] # subtract dissimilarlity graphs.makeGraph(months, "accumulative scores", title, monthScore, context)
def KlPmTranscripts(dataset, queryTranscript, queryName, reference): #print dataset matrix, query = cosineComparison.matrixQueryNoTransformation(dataset, queryTranscript) #print(matrix) scores = cosineComparison.KLdivergence(query, matrix, reference) #jointEntropy scores.sort(key=lambda x: x[0]) print scores xAxis = [pair[0] for pair in scores] values = [pair[1] for pair in scores] graphs.makeGraph(xAxis, "scores", "transcript budget log for {0}".format(queryName), values, queryName)
def KlHansard(dataset, queryTranscript, queryName, reference, smoothing): # This is for when i have a specific target year to compare others to #print dataset #print(matrix) scores = cosineComparison.KLdivergence(queryTranscript, dataset, reference, smoothing) #jointEntropy print scores xAxis = [pair[0] for pair in scores] values = [pair[1] for pair in scores] graphs.makeGraph( xAxis, "scores", "KL Hansard for {0} Smoothing - {1}".format(queryName, smoothing), values, queryName)
def KLBackwardsGraph(dataset, queryTranscript, queryName, reference, smoothing): # Want to compare all years to specific year. All years is reference to predict specific. #print dataset #print(matrix) scores = cosineComparison.KLBackwardsDivergence(queryTranscript, dataset, reference, smoothing) #jointEntropy print scores xAxis = [pair[0] for pair in scores] values = [pair[1] for pair in scores] graphs.makeGraph( xAxis, "scores", "KL Hansard for {0} Smoothing - {1}".format(queryName, smoothing), values, queryName)
def KlHansardIterative(dataset, reference, smoothing): # I want to compare the previous year to current year itteratively print reference print len(dataset) #print dataset[0] klValues = [] yearsInvestigated = [] for i in range(1, len(dataset)): priorBow = dataset[i - 1] currentBow = dataset[i] currentYear = reference[i] yearsInvestigated.append(currentYear) klValues.append(cosineComparison.KLbow(currentBow, priorBow, smoothing)) print klValues graphs.makeGraph( yearsInvestigated, "scores", "KL Iterative Opposition - Smooth = {0}".format(smoothing), klValues, "not sure what this is")
def graphByMonthYearGraph(dicForm, title, context): maxYear, minYear = calculateMinMaxYear(dicForm.keys()) numYears = maxYear - minYear + 1 print maxYear print minYear print numYears monthScore = np.ones([12 * (numYears)]).tolist() print "len is {0}".format(len(monthScore)) xLabel = numYears * generateMonths() for date in dicForm: #print date yearOffset = date.year - minYear monthOffset = date.month - 1 indexOffset = yearOffset * 12 + monthOffset monthScore[indexOffset] += ( 1 - dicForm[date] ) # attempt to make high look good. Note we need to normalise by number in that month graphs.makeGraph(xLabel, "accumulative scores", title, monthScore, context)
def createGraph(referenceBudget, yearAsString): referenceBudget = budget2006 budgets.remove(referenceBudget) # budgets = [budget[0] for budget in budgetList] # names = [[budget[1] for budget in budgetList]] reference, documents = cosineComparison.arrayToBow(budgets, bowDirectory) _, queryBow = cosineComparison.arrayToBow([referenceBudget], bowDirectory) matrix, query = cosineComparison.matrixQueryNoTransformation(documents, queryBow[0]) #print matrix scores = cosineComparison.inverseKLdivergence(query, matrix, reference) #jointEntropy values = [pair[1] for pair in scores] xAxis = [pair[0][0:4] for pair in scores] graphs.makeGraph(xAxis, "scores", "budget log for {0}".format(yearAsString), values)
def makeGraphs(): course = request.args.get("course") makeGraph(str(course)) return render_template("graph.html", courseNum=course)
partyFunction = hansardHandler.filenameToPartyInCharge _, hansardBows, hansardReference = hansardHandler.budgetToBow( initialYear, finalYear, None, partyFunction, True, True, False, hansardSource) #print hansardBows #print reference _, transcriptBows, transcriptReference = transcriptHandler.getTranscriptsBudgetDateTechnique( initialYear, finalYear, None, None, transcriptSource, False, False, True) #print transcriptBows #print transcriptReference klValues = [] xAxis = [] for i in range(len(transcriptBows)): klValues.append(cosineComparison.KLbow(hansardBows[i], transcriptBows[i])) print klValues for i in range(len(klValues)): print "{0} : {1}".format(transcriptReference[i], klValues[i]) xAxis.append(transcriptReference[i]) #xAxis = [pair[0] for pair in transcriptReference[i]] graphs.makeGraph(xAxis, "scores", "KlHansardTranscripts", klValues)