def make_questions(context_skeleton, qformat, generic=True, HHEd_fix=False): context_dict = context_skeleton.added_contexts if qformat not in ["NN", "HMM"]: print "Error: Invalid question format! " + qformat print "Must be either HMM or NN!" sys.exit() questions = [] if generic == False: for key in context_dict: qtype = getattr(context_skeleton, key) #Setting it removes duplicates and sorting them is important for HMM question creation #(sorting them is also prettier for the NN) vals = list(set(context_dict[key])) vals.sort() if qtype == None: pass elif qtype == "bool": for val in vals: #If this is current phoneme id we apply the HHEd_fix if HHEd_fix == True and key == "cp": val = "-"+str(val)+"+" if qformat == "HMM": questions.append("QS \""+key+"-"+str(val)+"\" {*|"+key+":"+str(val)+"|*}") elif qformat == "NN": questions.append("LQ 0 \""+key+"-"+str(val)+"\" {*|"+key+":"+str(val)+"|*}") elif "float" in qtype: if qformat == "HMM": questions += make_hmm_relational_qs(vals, key, qtype) elif qformat == "NN": for val in vals: #HHEd's pattern matching for both NN and HMM's uses '.' as a special #character. We therefore use the int version of the float value in the #search pattern. But we have to check for xx first. if val == "xx": questions.append("LQ 1 0.0 \""+key+"-xx\" {*|"+key+":xx|*}") else: questions.append("LQ 1 "+str(val)+" \""+key+"-"+strintify(float(val))+"\" {*|"+key+":"+strintify(float(val))+"|*}") elif "int" in qtype: if qformat == "HMM": questions += make_hmm_relational_qs(vals, key, qtype) elif qformat == "NN": for val in vals: #The NN relies on floats for the actual value so we use that there #and the int in the naming. But we have to check for xx first. if val == "xx": questions.append("LQ 1 0.0 \""+key+"-xx\" {*|"+key+":xx|*}") else: questions.append("LQ 1 "+strfloatify(val)+" \""+key+"-"+str(val)+"\" {*|"+key+":"+str(val)+"|*}") else: print "Error: Odd question type, should not exist - "+qtype sys.exit() else: print "Error: Not implemented yet! (Outputting generic question set)" return questions
def make_questions(context_skeleton, qformat, generic=True, HHEd_fix=False, utt=False): context_dict = context_skeleton.added_contexts #We write out each context not used just for checks. #TODO: Make it possible to throw an exception if context not used. #TODO: Currently we ignore this when making GV contexts. if utt == False: for context in vars(context_skeleton).keys(): if context not in context_dict and context != "added_contexts": print context_dict.keys() print "Warning! Context ({0}) not used!".format(context) if qformat not in ["Nitech_NN", "HMM", "CSTR_NN"]: raise SiReError("Invalid question format ({0})! Must be either HMM, Nitech_NN or CSTR_NN!".format(qformat)) questions = [] if generic == False: for key in context_dict: qtype = getattr(context_skeleton, key) #Setting it removes duplicates and sorting them is important for HMM question creation #(sorting them is also prettier for the NN) vals = list(set(context_dict[key])) vals.sort() if qtype == None: pass elif qtype == "bool": for val in vals: #If this is current phoneme id we apply the HHEd_fix if HHEd_fix == True and key == "cp": val = "-"+str(val)+"+" if qformat == "HMM" or qformat == "CSTR_NN": questions.append("QS \""+key+"-"+str(val)+"\" {*|"+key+":"+str(val)+"|*}") elif qformat == "Nitech_NN": questions.append("LQ 0 \""+key+"-"+str(val)+"\" {*|"+key+":"+str(val)+"|*}") elif "float" in qtype: if qformat == "HMM": questions += make_hmm_relational_qs(vals, key, qtype) elif qformat == "Nitech_NN": for val in vals: #HHEd's pattern matching for both NN and HMM's uses '.' as a special #character. We therefore use the int version of the float value in the #search pattern. But we have to check for xx first. if val == "xx": questions.append("LQ 1 0.0 \""+key+"-xx\" {*|"+key+":xx|*}") else: questions.append("LQ 1 "+str(val)+" \""+key+"-"+strintify(float(val))+"\" {*|"+key+":"+strintify(float(val))+"|*}") elif qformat == "CSTR_NN": #For CSTR's DNN system we just need to specify the question and not one for each value of the question if float or int. #Note that floats needs to be strintified in the actual question. questions.append("CQS \""+key+"\" {*|"+key+":(\d+)|*}") elif "int" in qtype: if qformat == "HMM": questions += make_hmm_relational_qs(vals, key, qtype) elif qformat == "Nitech_NN": for val in vals: #The NN relies on floats for the actual value so we use that there #and the int in the naming. But we have to check for xx first. if val == "xx": questions.append("LQ 1 0.0 \""+key+"-xx\" {*|"+key+":xx|*}") else: questions.append("LQ 1 "+strfloatify(int(val))+" \""+key+"-"+str(val)+"\" {*|"+key+":"+str(val)+"|*}") elif qformat == "CSTR_NN": #For CSTR's DNN system we just need to specify the question and not one for each value of the question if float or int. #Note that floats needs to be strintified in the actual question. questions.append("CQS \""+key+"\" {*|"+key+":(\d+)|*}") else: raise SiReError("Odd question type, should not exist - {0}".format(qtype)) else: raise SiReError("Not implemented yet! (Outputting generic question set)") return questions
def make_questions(context_skeleton, qformat, generic=True, HHEd_fix=False, utt=False): context_dict = context_skeleton.added_contexts #We write out each context not used just for checks. #TODO: Make it possible to throw an exception if context not used. #TODO: Currently we ignore this when making GV contexts. if utt == False: for context in vars(context_skeleton).keys(): if context not in context_dict and context != "added_contexts": print context_dict.keys() print "Warning! Context ({0}) not used!".format(context) if qformat not in ["Nitech_NN", "HMM", "CSTR_NN"]: raise SiReError( "Invalid question format ({0})! Must be either HMM, Nitech_NN or CSTR_NN!" .format(qformat)) questions = [] if generic == False: for key in context_dict: qtype = getattr(context_skeleton, key) #Setting it removes duplicates and sorting them is important for HMM question creation #(sorting them is also prettier for the NN) vals = list(set(context_dict[key])) vals.sort() if qtype == None: pass elif qtype == "bool": for val in vals: #If this is current phoneme id we apply the HHEd_fix if HHEd_fix == True and key == "cp": val = "-" + str(val) + "+" if qformat == "HMM" or qformat == "CSTR_NN": questions.append("QS \"" + key + "-" + str(val) + "\" {*|" + key + ":" + str(val) + "|*}") elif qformat == "Nitech_NN": questions.append("LQ 0 \"" + key + "-" + str(val) + "\" {*|" + key + ":" + str(val) + "|*}") elif "float" in qtype: if qformat == "HMM": questions += make_hmm_relational_qs(vals, key, qtype) elif qformat == "Nitech_NN": for val in vals: #HHEd's pattern matching for both NN and HMM's uses '.' as a special #character. We therefore use the int version of the float value in the #search pattern. But we have to check for xx first. if val == "xx": questions.append("LQ 1 0.0 \"" + key + "-xx\" {*|" + key + ":xx|*}") else: questions.append("LQ 1 " + str(val) + " \"" + key + "-" + strintify(float(val)) + "\" {*|" + key + ":" + strintify(float(val)) + "|*}") elif qformat == "CSTR_NN": #For CSTR's DNN system we just need to specify the question and not one for each value of the question if float or int. #Note that floats needs to be strintified in the actual question. questions.append("CQS \"" + key + "\" {*|" + key + ":(\d+)|*}") elif "int" in qtype: if qformat == "HMM": questions += make_hmm_relational_qs(vals, key, qtype) elif qformat == "Nitech_NN": for val in vals: #The NN relies on floats for the actual value so we use that there #and the int in the naming. But we have to check for xx first. if val == "xx": questions.append("LQ 1 0.0 \"" + key + "-xx\" {*|" + key + ":xx|*}") else: questions.append("LQ 1 " + strfloatify(int(val)) + " \"" + key + "-" + str(val) + "\" {*|" + key + ":" + str(val) + "|*}") elif qformat == "CSTR_NN": #For CSTR's DNN system we just need to specify the question and not one for each value of the question if float or int. #Note that floats needs to be strintified in the actual question. questions.append("CQS \"" + key + "\" {*|" + key + ":(\d+)|*}") else: raise SiReError( "Odd question type, should not exist - {0}".format(qtype)) else: raise SiReError( "Not implemented yet! (Outputting generic question set)") return questions