def readAutomaticQuestions(characterdict): f = open('../../../static/scripts/miscellaneous/automatic_questions.json', 'r', encoding='utf-8') resp = json.load(f) #print(resp) totalQuestions = 0 for i in range(0, len(resp["rows"]) - 1, 1): # Depending on the language, the question is parsed id_count = 0 for i in range(0, len(resp["rows"]) - 1, 1): id_count += 1 # If object is a queastion-answer pair, the relevant information is extracted if "question" in resp["rows"][i]["doc"].keys(): totalQuestions += 1 #do we wanna give it ID ourselves or use the JSON one? #ID= json.dumps(resp["rows"][i]["doc"]["_id"]) video = json.dumps(resp["rows"][i]["doc"]["video"]) #character= json.dumps(resp["rows"][i]["doc"]["character"]) character = json.dumps( resp["rows"][i]["doc"]["video"]).split("_")[0].replace( '"', '') language = "English" ID = id_count else: continue question = json.dumps( resp["rows"][i]["doc"]["question"]).strip(',?."!)') answer = json.dumps(resp["rows"][i]["doc"]["answer"]).strip(',?."!)') # Creates a new character model in the character dictionary if it does not exist already if character not in characterdict.keys(): #characterdict[character] is the model of the respective character characterdict[character] = test_dm.model() #adds to the character's questions list based on the character key; adds all videos regardless of type to questions obj = test_dm.videoRecording(question, answer, video, character, language) characterdict[character].objectMap[ID] = obj # if the video is for silence if (answer == '""' and video != '""'): characterdict[character].fillers[ID] = obj else: characterdict[character].questionsMap[ID] = obj print("Total Questions: ", str(totalQuestions)) print("done")
def readManualQuestions(characterdict, mylanguage): count = 0 #f= open('static/scripts/manual_questions.tsv', 'r', encoding='utf-8') if mylanguage == "Arabic": f = open( '../../static/scripts/miscellaneous/manual_questions_arabic.csv', 'r', encoding='utf-8') else: f = open('../../static/scripts/miscellaneous/manual_questions.tsv', 'r', encoding='utf-8') character = 'margarita' language = mylanguage video = "" characterdict[character] = test_dm.model() lines = f.readlines() del lines[0] for line in lines: count = count + 1 #print(count) if mylanguage == "English": line_split = line.split("\t") if mylanguage == "Arabic": line_split = line.split(",") #print(line_split) if line_split[2] != "": question1 = line_split[2].strip(',?."!') question2 = line_split[3].strip(',?."!') question3 = line_split[4].strip(',?."!') answer = line_split[1].strip(',?."!') obj_1 = test_dm.databaseEntry(question1, answer, video, character, language, "multiple") obj_2 = test_dm.databaseEntry(question2, answer, video, character, language, "multiple") obj_3 = test_dm.databaseEntry(question3, answer, video, character, language, "multiple") characterdict[character].questionsMap[count + 1] = obj_1 characterdict[character].questionsMap[count + 2] = obj_2 characterdict[character].questionsMap[count + 3] = obj_3 count = count + 3